-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Management command to refresh permission objects. Closes #1137
- Loading branch information
1 parent
064f641
commit 24b124a
Showing
6 changed files
with
93 additions
and
14 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
7 changes: 7 additions & 0 deletions
7
docs/source/modules/tcms.core.management.commands.refresh_permissions.rst
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,7 @@ | ||
tcms.core.management.commands.refresh\_permissions module | ||
========================================================= | ||
|
||
.. automodule:: tcms.core.management.commands.refresh_permissions | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,42 @@ | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
from tcms.utils.permissions import assign_default_group_permissions | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ('Refresh permissions for Tester group ' | ||
'(set by DEFAULT_GROUPS setting) and remove stale ones.' | ||
) | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--noinput', '--no-input', action='store_false', | ||
dest='interactive', | ||
help='Automatic mode. Does not require user input', | ||
) | ||
|
||
def handle(self, *args, **kwargs): | ||
output = None | ||
if kwargs['verbosity']: | ||
output = self.stdout | ||
|
||
call_command('update_permissions', '--verbosity=%i' % | ||
kwargs['verbosity']) | ||
|
||
# Assign permissions to Tester group | ||
if output: | ||
self.stdout.write('\nSetting up missing permissions') | ||
assign_default_group_permissions(output=output, refresh_all=True) | ||
if output: | ||
self.stdout.write('Done.') | ||
|
||
# Removing stale permissions | ||
if output: | ||
self.stdout.write('\nRemoving stale permissions') | ||
call_command('remove_stale_contenttypes', '--include-stale-apps', | ||
'--verbosity=%i' % kwargs['verbosity'], | ||
interactive=kwargs['interactive']) | ||
call_command('clean_orphan_obj_perms', '--verbosity=%i' % | ||
kwargs['verbosity']) | ||
if output: | ||
self.stdout.write('Done.') |
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