-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1716aaf
commit 3fe0e32
Showing
3 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
geonode/people/management/commands/setcontributorsgroup.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Assign the contributors group to users according to #7364 | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group, Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from django.db import migrations | ||
from django.db.migrations.operations import RunPython | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
# assign contributors group to users | ||
cont_group, created = Group.objects.get_or_create(name='contributors') | ||
ctype = ContentType.objects.get_for_model(cont_group) | ||
perm, created = Permission.objects.get_or_create( | ||
codename='base_addresourcebase', | ||
name='Can add resources', | ||
content_type=ctype, | ||
) | ||
if perm: | ||
cont_group.permissions.add(perm) | ||
# Exclude admins and anonymous user | ||
users_to_update = get_user_model().objects.filter( | ||
pk__gt=0, is_staff=False, is_superuser=False | ||
) | ||
for user in users_to_update: | ||
cont_group.user_set.add(user) | ||
|
||
def reverse_func(apps, schema_editor): | ||
# remove contributors group from users | ||
try: | ||
cont_group = Group.objects.get(name='contributors') | ||
users_to_update = get_user_model().objects.filter( | ||
pk__gt=0, is_staff=False, is_superuser=False | ||
) | ||
for user in users_to_update: | ||
user.groups.remove(cont_group) | ||
except Exception: | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('people', '0031_merge_20210205_0824'), | ||
] | ||
|
||
operations = [ | ||
RunPython(forwards_func, reverse_func) | ||
] |