implement user list, enable, disable
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from owrx.version import openwebrx_version
|
||||
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword
|
||||
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser
|
||||
import argparse
|
||||
import sys
|
||||
import traceback
|
||||
@ -9,12 +9,14 @@ def main():
|
||||
print("OpenWebRX admin version {version}".format(version=openwebrx_version))
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("command", help="One of the following commands: adduser, removeuser, resetpassword")
|
||||
parser.add_argument("command", help="""One of the following commands:
|
||||
adduser, removeuser, listusers, resetpassword, enableuser, disableuser""")
|
||||
parser.add_argument(
|
||||
"--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)"
|
||||
)
|
||||
parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)")
|
||||
parser.add_argument("-u", "--user", help="User name to perform action upon")
|
||||
parser.add_argument("-a", "--all", action="store_true", help="Show all users")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "adduser":
|
||||
@ -23,6 +25,12 @@ def main():
|
||||
command = DeleteUser()
|
||||
elif args.command == "resetpassword":
|
||||
command = ResetPassword()
|
||||
elif args.command == "listusers":
|
||||
command = ListUsers()
|
||||
elif args.command == "disableuser":
|
||||
command = DisableUser()
|
||||
elif args.command == "enableuser":
|
||||
command = EnableUser()
|
||||
else:
|
||||
if not args.silent:
|
||||
print("Unknown command: {command}".format(command=args.command))
|
||||
|
@ -76,3 +76,28 @@ class ResetPassword(UserCommand):
|
||||
# this is a change to an object in the list, not the list itself
|
||||
# in this case, store() is explicit
|
||||
userList.store()
|
||||
|
||||
|
||||
class DisableUser(UserCommand):
|
||||
def run(self, args):
|
||||
username = self.getUser(args)
|
||||
userList = UserList()
|
||||
userList[username].disable()
|
||||
userList.store()
|
||||
|
||||
|
||||
class EnableUser(UserCommand):
|
||||
def run(self, args):
|
||||
username = self.getUser(args)
|
||||
userList = UserList()
|
||||
userList[username].enable()
|
||||
userList.store()
|
||||
|
||||
|
||||
class ListUsers(Command):
|
||||
def run(self, args):
|
||||
userList = UserList()
|
||||
print("List of enabled users:")
|
||||
for u in userList.values():
|
||||
if args.all or u.enabled:
|
||||
print(" {name}".format(name=u.name))
|
||||
|
Reference in New Issue
Block a user