feat(setting): Enable super admin to set ALL software as global
sets is_global=true and creates software in global organization !11 closes #27
This commit is contained in:
68
app/settings/models/app_settings.py
Normal file
68
app/settings/models/app_settings.py
Normal file
@ -0,0 +1,68 @@
|
||||
from django.db import models
|
||||
|
||||
from access.fields import *
|
||||
from access.models import Organization
|
||||
|
||||
from core.mixin.history_save import SaveHistory
|
||||
|
||||
|
||||
class AppSettingsCommonFields(models.Model):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
id = models.AutoField(
|
||||
primary_key=True,
|
||||
unique=True,
|
||||
blank=False
|
||||
)
|
||||
|
||||
slug = None
|
||||
|
||||
created = AutoCreatedField()
|
||||
|
||||
modified = AutoLastModifiedField()
|
||||
|
||||
|
||||
|
||||
class AppSettings(AppSettingsCommonFields, SaveHistory):
|
||||
|
||||
|
||||
owner_organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
blank= True,
|
||||
default = None,
|
||||
null = True,
|
||||
help_text = 'Organization the settings belong to',
|
||||
related_name = 'owner_organization'
|
||||
)
|
||||
|
||||
software_is_global = models.BooleanField (
|
||||
verbose_name = 'All Software is global',
|
||||
blank= False,
|
||||
default = False,
|
||||
)
|
||||
|
||||
global_organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
blank= True,
|
||||
default = None,
|
||||
null = True,
|
||||
help_text = 'Organization global items will be created in',
|
||||
related_name = 'global_organization'
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
if self.software_is_global and self.global_organization is None:
|
||||
|
||||
raise ValidationError("Global Software must have a global organization")
|
||||
|
||||
__all__ = [
|
||||
'software_is_global',
|
||||
'global_organization',
|
||||
]
|
||||
|
@ -2,9 +2,7 @@ from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from access.fields import *
|
||||
from access.models import TenancyObject, Organization
|
||||
|
||||
from core.mixin.history_save import SaveHistory
|
||||
from access.models import Organization
|
||||
|
||||
|
||||
class UserSettingsCommonFields(models.Model):
|
||||
|
Reference in New Issue
Block a user