Commit e90d930e authored by Michal Čihař's avatar Michal Čihař

Fix anoymous user creation

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c7c7e3ab
......@@ -3,6 +3,7 @@
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.auth.hashers import make_password
from weblate.appsettings import ANONYMOUS_USER_NAME
......@@ -10,13 +11,18 @@ from weblate.appsettings import ANONYMOUS_USER_NAME
def add_anonymous_profile(apps, schema_editor):
"""Ensure anonymous user has profile"""
User = apps.get_model('auth', 'User')
Group = apps.get_model('auth', 'Group')
Profile = apps.get_model('accounts', 'Profile')
anon_user = User.objects.get_or_create(
username=ANONYMOUS_USER_NAME,
defaults={
'is_active': False
'is_active': False,
'password': make_password(None),
}
)[0]
guest_group = Group.objects.get_or_create(name='Guests')[0]
anon_user.groups.clear()
anon_user.groups.add(guest_group)
Profile.objects.get_or_create(user=anon_user)
......
......@@ -876,7 +876,7 @@ def create_groups(update):
Creates standard groups and gives them permissions.
'''
guest_group, created = Group.objects.get_or_create(name='Guests')
if created or update:
if created or update or guest_group.permissions.count() == 0:
guest_group.permissions.add(
Permission.objects.get(codename='can_see_git_repository'),
Permission.objects.get(codename='add_suggestion'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment