1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-25 02:00:06 +00:00
seahub/thirdpart/constance/apps.py

40 lines
1.4 KiB
Python
Raw Normal View History

2019-10-25 07:01:41 +00:00
from django.db.models import signals
2023-06-12 01:53:31 +00:00
from django.apps import apps, AppConfig
2019-10-25 07:01:41 +00:00
class ConstanceConfig(AppConfig):
name = 'constance'
verbose_name = 'Constance'
def ready(self):
super(ConstanceConfig, self).ready()
signals.post_migrate.connect(self.create_perm,
dispatch_uid='constance.create_perm')
def create_perm(self, using=None, *args, **kwargs):
"""
Creates a fake content type and permission
to be able to check for permissions
"""
from django.conf import settings
constance_dbs = getattr(settings, 'CONSTANCE_DBS', None)
if constance_dbs is not None and using not in constance_dbs:
return
2023-06-12 01:53:31 +00:00
if (
apps.is_installed('django.contrib.contenttypes') and
apps.is_installed('django.contrib.auth')
):
ContentType = apps.get_model('contenttypes.ContentType')
Permission = apps.get_model('auth.Permission')
2019-10-25 07:01:41 +00:00
content_type, created = ContentType.objects.using(using).get_or_create(
app_label='constance',
model='config',
)
permission, created = Permission.objects.using(using).get_or_create(
content_type=content_type,
codename='change_config',
defaults={'name': 'Can change config'})