mirror of https://github.com/zulip/zulip.git
Add a parameter to knight.py to remove user rights.
(imported from commit 4527955f688298ba56296e9f24d42e33f7d04948)
This commit is contained in:
parent
f22abf2b8a
commit
2daf8db3a5
|
@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError
|
|||
from django.db.utils import IntegrityError
|
||||
from django.core import validators
|
||||
|
||||
from guardian.shortcuts import assign_perm
|
||||
from guardian.shortcuts import assign_perm, remove_perm
|
||||
|
||||
from zephyr.models import Realm, UserProfile
|
||||
|
||||
|
@ -19,6 +19,12 @@ ONLY perform this on customer request from an authorized person.
|
|||
"""
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--revoke',
|
||||
dest='grant',
|
||||
action="store_false",
|
||||
default=True,
|
||||
help='Remove an administrator\'s rights.'),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
|
@ -29,8 +35,16 @@ ONLY perform this on customer request from an authorized person.
|
|||
profile = UserProfile.objects.get(email=email)
|
||||
except ValidationError:
|
||||
raise CommandError("No such user.")
|
||||
if profile.has_perm('administer', profile.realm):
|
||||
raise CommandError("User already has permission for this realm.")
|
||||
|
||||
if options['grant']:
|
||||
if profile.has_perm('administer', profile.realm):
|
||||
raise CommandError("User already has permission for this realm.")
|
||||
else:
|
||||
assign_perm('administer', profile, profile.realm)
|
||||
print "Done!"
|
||||
else:
|
||||
assign_perm('administer', profile, profile.realm)
|
||||
print "Done!"
|
||||
if profile.has_perm('administer', profile.realm):
|
||||
remove_perm('administer', profile, profile.realm)
|
||||
print "Done!"
|
||||
else:
|
||||
raise CommandError("User did not have permission for this realm!")
|
||||
|
|
Loading…
Reference in New Issue