Skip to content

Commit

Permalink
Differently handle intermediate signals we trigger to create permissions
Browse files Browse the repository at this point in the history
We need Django to generate permissions, but we can not yet execute own
code as all migrations are not yet applied. This can be removed once
new permissions (#1798) are implemented.

Issue #1838

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Feb 8, 2018
1 parent 0d35e96 commit e1c6a4d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions weblate/lang/models.py
Expand Up @@ -327,9 +327,9 @@ def have_translation(self):


@receiver(post_migrate)
def setup_lang(sender, **kwargs):
def setup_lang(sender, intermediate=False, **kwargs):
"""Hook for creating basic set of languages on database migration."""
if sender.label == 'lang':
if not intermediate and sender.label == 'lang':
with transaction.atomic():
Language.objects.setup(False)

Expand Down
2 changes: 1 addition & 1 deletion weblate/permissions/migrations/0006_auto_20170404_1637.py
Expand Up @@ -16,7 +16,7 @@ def migrate_acl(apps, schema_editor):

# Workaround to ensure the permission added in 0083_auto_20170404_1633
# is actually created, see https://code.djangoproject.com/ticket/23422
emit_post_migrate_signal(0, False, schema_editor.connection.alias)
emit_post_migrate_signal(0, False, schema_editor.connection.alias, intermediate=True)

groups = {}
all_perms = Permission.objects.filter(codename__in=ADMIN_PERMS)
Expand Down
4 changes: 3 additions & 1 deletion weblate/permissions/models.py
Expand Up @@ -174,8 +174,10 @@ def move_users():


@receiver(post_migrate)
def sync_create_groups(sender, **kwargs):
def sync_create_groups(sender, intermediate=False, **kwargs):
"""Create groups on syncdb."""
if intermediate:
return
# Figure out last app in signals
for app_config in apps.get_app_configs():
if app_config.models_module is None:
Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/migrations/0085_auto_20170406_0904.py
Expand Up @@ -9,7 +9,7 @@
def add_perm(apps, schema_editor):
# Workaround to ensure the permission added in 0084_auto_20170406_0858
# is actually created, see https://code.djangoproject.com/ticket/23422
emit_post_migrate_signal(0, False, schema_editor.connection.alias)
emit_post_migrate_signal(0, False, schema_editor.connection.alias, intermediate=True)

GroupACL = apps.get_model('permissions', 'GroupACL')
Group = apps.get_model('auth', 'Group')
Expand Down

0 comments on commit e1c6a4d

Please sign in to comment.