Revision ebd369d0 snf-astakos-app/astakos/im/management/commands/modifyuser.py
b/snf-astakos-app/astakos/im/management/commands/modifyuser.py | ||
---|---|---|
39 | 39 |
|
40 | 40 |
|
41 | 41 |
class Command(BaseCommand): |
42 |
args = "<user_id or email>"
|
|
42 |
args = "<user ID or email>"
|
|
43 | 43 |
help = "Modify a user's attributes" |
44 | 44 |
|
45 | 45 |
option_list = BaseCommand.option_list + ( |
... | ... | |
47 | 47 |
dest='invitations', |
48 | 48 |
metavar='NUM', |
49 | 49 |
help="Update user's invitations"), |
50 |
make_option('--level', |
|
51 |
dest='level', |
|
52 |
metavar='NUM', |
|
53 |
help="Update user's level"), |
|
50 | 54 |
make_option('--password', |
51 | 55 |
dest='password', |
52 | 56 |
metavar='PASSWORD', |
... | ... | |
66 | 70 |
dest='noadmin', |
67 | 71 |
default=False, |
68 | 72 |
help="Revoke user's admin rights"), |
69 |
make_option('--inactive', |
|
73 |
make_option('--set-active', |
|
74 |
action='store_true', |
|
75 |
dest='active', |
|
76 |
default=False, |
|
77 |
help="Change user's state to inactive"), |
|
78 |
make_option('--set-inactive', |
|
70 | 79 |
action='store_true', |
71 | 80 |
dest='inactive', |
72 | 81 |
default=False, |
... | ... | |
75 | 84 |
|
76 | 85 |
def handle(self, *args, **options): |
77 | 86 |
if len(args) != 1: |
78 |
raise CommandError("Please provide a user_id or email")
|
|
87 |
raise CommandError("Please provide a user ID or email")
|
|
79 | 88 |
|
80 | 89 |
user = get_user(args[0]) |
81 | 90 |
if not user: |
... | ... | |
86 | 95 |
elif options.get('noadmin'): |
87 | 96 |
user.is_superuser = False |
88 | 97 |
|
98 |
if options.get('active'): |
|
99 |
user.is_active = True |
|
100 |
elif options.get('inactive'): |
|
101 |
user.is_active = False |
|
102 |
|
|
89 | 103 |
invitations = options.get('invitations') |
90 | 104 |
if invitations is not None: |
91 | 105 |
user.invitations = int(invitations) |
92 | 106 |
|
107 |
level = options.get('level') |
|
108 |
if level is not None: |
|
109 |
user.level = int(level) |
|
110 |
|
|
93 | 111 |
password = options.get('password') |
94 | 112 |
if password is not None: |
95 | 113 |
user.set_password(password) |
... | ... | |
97 | 115 |
if options['renew_token']: |
98 | 116 |
user.renew_token() |
99 | 117 |
|
100 |
if options.get('inactive'): |
|
101 |
user.is_active = False |
|
102 |
user.save() |
|
118 |
user.save() |
Also available in: Unified diff