Added ‘view virtual machine plan ’ permission, Added ‘delete virtual machine plan’ permission , Added ‘view hosting order’ permission
This commit is contained in:
		
					parent
					
						
							
								3e6502133e
							
						
					
				
			
			
				commit
				
					
						4352094680
					
				
			
		
					 7 changed files with 47 additions and 16 deletions
				
			
		| 
						 | 
					@ -185,8 +185,8 @@ DATABASES = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AUTHENTICATION_BACKENDS = (
 | 
					AUTHENTICATION_BACKENDS = (
 | 
				
			||||||
    'django.contrib.auth.backends.ModelBackend',
 | 
					 | 
				
			||||||
    'guardian.backends.ObjectPermissionBackend',
 | 
					    'guardian.backends.ObjectPermissionBackend',
 | 
				
			||||||
 | 
					    'django.contrib.auth.backends.ModelBackend',
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,9 @@ class HostingOrderAdmin(admin.ModelAdmin):
 | 
				
			||||||
            # If the Stripe payment was successed, set order status approved
 | 
					            # If the Stripe payment was successed, set order status approved
 | 
				
			||||||
            obj.set_approved()
 | 
					            obj.set_approved()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Assigning permissions
 | 
				
			||||||
 | 
					            obj.assign_permissions(customer.user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            context = {
 | 
					            context = {
 | 
				
			||||||
                'order': obj,
 | 
					                'order': obj,
 | 
				
			||||||
                'vm': obj.vm_plan,
 | 
					                'vm': obj.vm_plan,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										19
									
								
								hosting/migrations/0027_auto_20160711_0210.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								hosting/migrations/0027_auto_20160711_0210.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
 | 
					# Generated by Django 1.9.4 on 2016-07-11 02:10
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.db import migrations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Migration(migrations.Migration):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dependencies = [
 | 
				
			||||||
 | 
					        ('hosting', '0026_auto_20160625_0028'),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    operations = [
 | 
				
			||||||
 | 
					        migrations.AlterModelOptions(
 | 
				
			||||||
 | 
					            name='hostingorder',
 | 
				
			||||||
 | 
					            options={'permissions': (('view_hostingorder', 'View Hosting Order'),)},
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
| 
						 | 
					@ -4,8 +4,6 @@ from django.db import models
 | 
				
			||||||
from django.utils.translation import ugettext_lazy as _
 | 
					from django.utils.translation import ugettext_lazy as _
 | 
				
			||||||
from django.utils.functional import cached_property
 | 
					from django.utils.functional import cached_property
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from Crypto.PublicKey import RSA
 | 
					from Crypto.PublicKey import RSA
 | 
				
			||||||
from stored_messages.settings import stored_messages_settings
 | 
					from stored_messages.settings import stored_messages_settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -106,9 +104,9 @@ class VirtualMachinePlan(AssignPermissionsMixin, models.Model):
 | 
				
			||||||
        (NODEJS, 'Debian, NodeJS'),
 | 
					        (NODEJS, 'Debian, NodeJS'),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    permissions = ('virtualmachineplan.view_virtualmachineplan', 
 | 
					    permissions = ('view_virtualmachineplan',
 | 
				
			||||||
                   'virtualmachineplan.cancel_virtualmachineplan',
 | 
					                   'cancel_virtualmachineplan',
 | 
				
			||||||
                   'virtualmachineplan.change_virtualmachineplan')
 | 
					                   'change_virtualmachineplan')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cores = models.IntegerField()
 | 
					    cores = models.IntegerField()
 | 
				
			||||||
    memory = models.IntegerField()
 | 
					    memory = models.IntegerField()
 | 
				
			||||||
| 
						 | 
					@ -180,7 +178,7 @@ class VirtualMachinePlan(AssignPermissionsMixin, models.Model):
 | 
				
			||||||
        self.save(update_fields=['status'])
 | 
					        self.save(update_fields=['status'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HostingOrder(models.Model):
 | 
					class HostingOrder(AssignPermissionsMixin, models.Model):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ORDER_APPROVED_STATUS = 'Approved'
 | 
					    ORDER_APPROVED_STATUS = 'Approved'
 | 
				
			||||||
    ORDER_DECLINED_STATUS = 'Declined'
 | 
					    ORDER_DECLINED_STATUS = 'Declined'
 | 
				
			||||||
| 
						 | 
					@ -194,6 +192,13 @@ class HostingOrder(models.Model):
 | 
				
			||||||
    cc_brand = models.CharField(max_length=10)
 | 
					    cc_brand = models.CharField(max_length=10)
 | 
				
			||||||
    stripe_charge_id = models.CharField(max_length=100, null=True)
 | 
					    stripe_charge_id = models.CharField(max_length=100, null=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    permissions = ('view_hostingorder',)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        permissions = (
 | 
				
			||||||
 | 
					            ('view_hostingorder', 'View Hosting Order'),
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return "%s" % (self.id)
 | 
					        return "%s" % (self.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -205,6 +210,7 @@ class HostingOrder(models.Model):
 | 
				
			||||||
    def create(cls, vm_plan=None, customer=None, billing_address=None):
 | 
					    def create(cls, vm_plan=None, customer=None, billing_address=None):
 | 
				
			||||||
        instance = cls.objects.create(vm_plan=vm_plan, customer=customer,
 | 
					        instance = cls.objects.create(vm_plan=vm_plan, customer=customer,
 | 
				
			||||||
                                      billing_address=billing_address)
 | 
					                                      billing_address=billing_address)
 | 
				
			||||||
 | 
					        instance.assign_permissions(customer.user)
 | 
				
			||||||
        return instance
 | 
					        return instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_approved(self):
 | 
					    def set_approved(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,7 @@
 | 
				
			||||||
    <meta name="description" content="">
 | 
					    <meta name="description" content="">
 | 
				
			||||||
    <meta name="author" content="">
 | 
					    <meta name="author" content="">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <title>nngleich</title>
 | 
					    <title>ungleich</title>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!-- Bootstrap Core CSS -->
 | 
					    <!-- Bootstrap Core CSS -->
 | 
				
			||||||
    <link href="{% static 'hosting/css/bootstrap.min.css' %}" rel="stylesheet">
 | 
					    <link href="{% static 'hosting/css/bootstrap.min.css' %}" rel="stylesheet">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ from django.http import HttpResponseRedirect
 | 
				
			||||||
from django.contrib.auth import authenticate, login
 | 
					from django.contrib.auth import authenticate, login
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from guardian.mixins import PermissionRequiredMixin
 | 
				
			||||||
from stored_messages.settings import stored_messages_settings
 | 
					from stored_messages.settings import stored_messages_settings
 | 
				
			||||||
from stored_messages.models import Message
 | 
					from stored_messages.models import Message
 | 
				
			||||||
from stored_messages.api import mark_read
 | 
					from stored_messages.api import mark_read
 | 
				
			||||||
| 
						 | 
					@ -406,10 +406,11 @@ class PaymentVMView(LoginRequiredMixin, FormView):
 | 
				
			||||||
            return self.form_invalid(form)
 | 
					            return self.form_invalid(form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class OrdersHostingDetailView(LoginRequiredMixin, DetailView):
 | 
					class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailView):
 | 
				
			||||||
    template_name = "hosting/order_detail.html"
 | 
					    template_name = "hosting/order_detail.html"
 | 
				
			||||||
    context_object_name = "order"
 | 
					    context_object_name = "order"
 | 
				
			||||||
    login_url = reverse_lazy('hosting:login')
 | 
					    login_url = reverse_lazy('hosting:login')
 | 
				
			||||||
 | 
					    permission_required = ['view_hostingorder']
 | 
				
			||||||
    model = HostingOrder
 | 
					    model = HostingOrder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -447,11 +448,12 @@ class VirtualMachinesPlanListView(LoginRequiredMixin, ListView):
 | 
				
			||||||
        return super(VirtualMachinesPlanListView, self).get_queryset()
 | 
					        return super(VirtualMachinesPlanListView, self).get_queryset()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class VirtualMachineView(LoginRequiredMixin, UpdateView):
 | 
					class VirtualMachineView(PermissionRequiredMixin, LoginRequiredMixin, UpdateView):
 | 
				
			||||||
    template_name = "hosting/virtual_machine_detail.html"
 | 
					    template_name = "hosting/virtual_machine_detail.html"
 | 
				
			||||||
    login_url = reverse_lazy('hosting:login')
 | 
					    login_url = reverse_lazy('hosting:login')
 | 
				
			||||||
    model = VirtualMachinePlan
 | 
					    model = VirtualMachinePlan
 | 
				
			||||||
    context_object_name = "virtual_machine"
 | 
					    context_object_name = "virtual_machine"
 | 
				
			||||||
 | 
					    permission_required = ['view_virtualmachineplan', 'cancel_virtualmachineplan']
 | 
				
			||||||
    fields = '__all__'
 | 
					    fields = '__all__'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_success_url(self):
 | 
					    def get_success_url(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,8 @@ REGISTRATION_MESSAGE = {'subject': "Validation mail",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_anonymous_user_instance(User):
 | 
					def get_anonymous_user_instance(User):
 | 
				
			||||||
    return User.register('Anonymous', None, 'anonymous@ungleich.ch')
 | 
					    return CustomUser(name='Anonymous', email='anonymous@ungleich.ch',
 | 
				
			||||||
 | 
					                      validation_slug=make_password(None))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,10 +109,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
 | 
				
			||||||
    def __str__(self):  # __unicode__ on Python 2
 | 
					    def __str__(self):  # __unicode__ on Python 2
 | 
				
			||||||
        return self.email
 | 
					        return self.email
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def has_perm(self, perm, obj=None):
 | 
					    # def has_perm(self, perm, obj=None):
 | 
				
			||||||
        "Does the user have a specific permission?"
 | 
					    #     "Does the user have a specific permission?"
 | 
				
			||||||
        # Simplest possible answer: Yes, always
 | 
					    #     # Simplest possible answer: Yes, always
 | 
				
			||||||
        return self.is_admin
 | 
					    #     return self.is_admin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def has_module_perms(self, app_label):
 | 
					    def has_module_perms(self, app_label):
 | 
				
			||||||
        "Does the user have permissions to view the app `app_label`?"
 | 
					        "Does the user have permissions to view the app `app_label`?"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue