-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Update TestMultitenantAdminMixin to use default operator group …
- Loading branch information
1 parent
b70b735
commit 9ac518d
Showing
7 changed files
with
113 additions
and
32 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
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
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,16 @@ | ||
# Manually Created | ||
|
||
from django.db import migrations | ||
from testapp.migrations import update_administrator_permissions | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('testapp', '0004_library'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
update_administrator_permissions, reverse_code=migrations.RunPython.noop | ||
), | ||
] |
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,27 @@ | ||
import swapper | ||
from django.contrib.auth.management import create_permissions | ||
from django.contrib.auth.models import Permission | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.db.models import Q | ||
|
||
|
||
def update_administrator_permissions(apps, schema_editor): | ||
model_name = swapper.get_model_name('openwisp_users', 'Group') | ||
model_label = swapper.split(model_name)[0] | ||
Group = apps.get_model(model_label, 'Group') | ||
|
||
for app_config in apps.get_app_configs(): | ||
app_config.models_module = True | ||
create_permissions(app_config, apps=apps, verbosity=0) | ||
app_config.models_module = None | ||
|
||
try: | ||
operator = Group.objects.get(name='Administrator') | ||
permissions = Permission.objects.filter( | ||
Q(codename__endswith='template') | ||
| Q(codename__endswith='shelf') | ||
| Q(codename__endswith='book') | ||
).values_list('pk', flat=True) | ||
operator.permissions.add(*permissions) | ||
except ObjectDoesNotExist: | ||
pass |
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
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
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