Bug 274
[auf_roundup.git] / tools / fixroles.py
CommitLineData
c638d827
CR
1import sys
2
3from roundup import admin
4
5class AdminTool(admin.AdminTool):
6 def __init__(self):
7 self.commands = admin.CommandDict()
8 for k in AdminTool.__dict__.keys():
9 if k[:3] == 'do_':
10 self.commands[k[3:]] = getattr(self, k)
11 self.help = {}
12 for k in AdminTool.__dict__.keys():
13 if k[:5] == 'help_':
14 self.help[k[5:]] = getattr(self, k)
15 self.instance_home = ''
16 self.db = None
17
18 def do_fixroles(self, args):
19 '''Usage: fixroles
20 Set the roles property for all users to reasonable defaults.
21
22 The admin user gets "Admin", the anonymous user gets "Anonymous"
23 and all other users get "User".
24 '''
25 # get the user class
26 cl = self.get_class('user')
27 for userid in cl.list():
28 username = cl.get(userid, 'username')
29 if username == 'admin':
30 roles = 'Admin'
31 elif username == 'anonymous':
32 roles = 'Anonymous'
33 else:
34 roles = 'User'
35 cl.set(userid, roles=roles)
36 return 0
37
38if __name__ == '__main__':
39 tool = AdminTool()
40 sys.exit(tool.main())