view tools/fixroles.py @ 8408:e882a5d52ae5

refactor: move RateLimitExceeded to roundup.cgi.exceptions RateLimitExceeded is an HTTP exception that raises code 429. Move it to roundup.cgi.exceptions where all the other exceptions that result in http status codes are located. Also make it inherit from HTTPException since it is one. Also add docstrings for all HTTP exceptions and order HTTPExceptions by status code. BREAKING CHANGE: if somebody is importing RateLimitExceeded they will need to change their import. I consider it unlikely anybody is using RateLimitExceeded. Detectors and extensions are unlikely to raise RateLimitExceeded. So I am leaving it out of the upgrading doc. Just doc in change log.
author John Rouillard <rouilj@ieee.org>
date Sun, 10 Aug 2025 21:27:06 -0400
parents 52c8324d1539
children
line wrap: on
line source

import sys

from roundup import admin

class AdminTool(admin.AdminTool):
    def __init__(self):
        self.commands = admin.CommandDict()
        for k in AdminTool.__dict__.keys():
            if k[:3] == 'do_':
                self.commands[k[3:]] = getattr(self, k)
        self.help = {}
        for k in AdminTool.__dict__.keys():
            if k[:5] == 'help_':
                self.help[k[5:]] = getattr(self, k)
        self.instance_home = ''
        self.db = None

    def do_fixroles(self, args):
        '''Usage: fixroles
        Set the roles property for all users to reasonable defaults.

        The admin user gets "Admin", the anonymous user gets "Anonymous"
        and all other users get "User".
        '''
        # get the user class
        cl = self.get_class('user')
        for userid in cl.list():
            username = cl.get(userid, 'username')
            if username == 'admin':
                roles = 'Admin'
            elif username == 'anonymous':
                roles = 'Anonymous'
            else:
                roles = 'User'
            cl.set(userid, roles=roles)
        return 0

if __name__ == '__main__':
    tool = AdminTool()
    sys.exit(tool.main())

Roundup Issue Tracker: http://roundup-tracker.org/