enable-user and disable-user cli commands

This commit is contained in:
Mike Bonnet 2007-03-19 14:06:05 -04:00
parent 6a7b2ed972
commit 73e2a50113
2 changed files with 59 additions and 2 deletions

View file

@ -1045,14 +1045,14 @@ def handle_add_user(options, session, args):
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--principal", help=_("The Kerberos principal for this user"))
parser.add_option("--blocked", help=_("Prohibit logins by this user"), action="store_true")
parser.add_option("--disabled", help=_("Prohibit logins by this user"), action="store_true")
(options, args) = parser.parse_args(args)
if len(args) < 1:
parser.error(_("You must specify the username of the user to add"))
elif len(args) > 1:
parser.error(_("This command only accepts one argument (username)"))
username = args[0]
if options.blocked:
if options.disabled:
status = koji.USER_STATUS['BLOCKED']
else:
status = koji.USER_STATUS['NORMAL']
@ -1060,6 +1060,34 @@ def handle_add_user(options, session, args):
user_id = session.addUser(username, status=status, krb_principal=options.principal)
print "Added user %s (%i)" % (username, user_id)
def handle_enable_user(options, session, args):
"[admin] Enable logins by a user"
usage = _("usage: %prog enable-user username")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args(args)
if len(args) < 1:
parser.error(_("You must specify the username of the user to enable"))
elif len(args) > 1:
parser.error(_("This command only accepts one argument (username)"))
username = args[0]
activate_session(session)
session.enableUser(username)
def handle_disable_user(options, session, args):
"[admin] Disable logins by a user"
usage = _("usage: %prog disable-user username")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args(args)
if len(args) < 1:
parser.error(_("You must specify the username of the user to enable"))
elif len(args) > 1:
parser.error(_("This command only accepts one argument (username)"))
username = args[0]
activate_session(session)
session.disableUser(username)
def handle_list_signed(options, session, args):
"[admin] List signed copies of rpms"
usage = _("usage: %prog list-signed [options]")

View file

@ -3620,6 +3620,19 @@ def get_group_members(group):
WHERE active = TRUE AND group_id = %%(group_id)i""" % ','.join(fields)
return _multiRow(q, locals(), fields)
def set_user_status(user, status):
if not koji.USER_STATUS.get(status):
raise koji.GenericError, 'invalid status: %s' % status
if user['status'] == status:
# nothing to do
return
update = """UPDATE users SET status = %(status)i WHERE id = %(user_id)i"""
user_id = user['id']
rows = _dml(update, locals())
# sanity check
if rows == 0:
raise koji.GenericError, 'invalid user ID: %i' % user_id
class QueryProcessor(object):
"""
Build a query from its components.
@ -4723,6 +4736,22 @@ class RootExports(object):
c.execute(insert, locals())
return userID
def enableUser(self, username):
"""Enable logins by the specified user"""
context.session.assertPerm('admin')
user = get_user(username)
if not user:
raise koji.GenericError, 'unknown user: %s' % username
set_user_status(user, koji.USER_STATUS['NORMAL'])
def disableUser(self, username):
"""Disable logins by the specified user"""
context.session.assertPerm('admin')
user = get_user(username)
if not user:
raise koji.GenericError, 'unknown user: %s' % username
set_user_status(user, koji.USER_STATUS['BLOCKED'])
#group management calls
newGroup = staticmethod(new_group)
addGroupMember = staticmethod(add_group_member)