Code

new rdbms config item sqlite_timeout makes the previously hard-coded
[roundup.git] / tools / fixroles.py
1 import sys
3 from roundup import admin
5 class 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
18     def do_fixroles(self, args):
19         '''Usage: fixroles
20         Set the roles property for all users to reasonable defaults.
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
38 if __name__ == '__main__':
39     tool = AdminTool()
40     sys.exit(tool.main())