Revert "ListUsers: UAP and APP renamed, function updates /home/users.txt"

This reverts commit 84cc83db3c.
feature-admin-split
Darksider3 5 years ago
parent 84cc83db3c
commit 389b614de9

@ -53,7 +53,7 @@ class Backup:
if __name__ == "__main__": if __name__ == "__main__":
try: try:
L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved) L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved)
fetch = L.getFetch() fetch = L.getFetch()
B = Backup(args.file) B = Backup(args.file)
B.BackupToFile(fetch) B.BackupToFile(fetch)

@ -37,7 +37,7 @@ def ImportFromFile(fname: str, db: str, userids: tuple = tuple([])):
exit(0) exit(0)
import lib.sqlitedb import lib.sqlitedb
import lib.System import lib.System
sysctl = lib.System.System(db) sysctl = lib.System.System()
reader = csv.DictReader(f) # @TODO csv.Sniffer to compare? When yes, give force-accept option reader = csv.DictReader(f) # @TODO csv.Sniffer to compare? When yes, give force-accept option
for row in reader: for row in reader:
if row["status"] == "1": if row["status"] == "1":

@ -4,16 +4,23 @@ from lib.sqlitedb import SQLitedb
import configparser import configparser
import lib.uis.default as default_cmd # Follows -u, -a, -f flags import lib.uis.default as default_cmd # Follows -u, -a, -f flags
default_cmd.argparser.description += " - Lists Users from the Tilde database."
default_cmd.argparser.add_argument('--list', default=False, action="store_true",
help='Output a newline seperated list of users', required=False)
args = default_cmd.argparser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
class ListUsers: class ListUsers:
db = None db = None
usersFetch = None usersFetch = None
def __init__(self, db: str, unapproved: bool = False, approved: bool = True): def __init__(self, db: str, uap: bool = False, app: bool = True):
self.db = SQLitedb(db) self.db = SQLitedb(db)
if unapproved: # only unapproved users if uap: # only unapproved users
query = "SELECT * FROM `applications` WHERE `status` = '0'" query = "SELECT * FROM `applications` WHERE `status` = '0'"
elif approved: # Approved users elif app: # Approved users
query = "SELECT * FROM `applications` WHERE `status` = '1'" query = "SELECT * FROM `applications` WHERE `status` = '1'"
else: # All users else: # All users
query = "SELECT * FROM `applications`" query = "SELECT * FROM `applications`"
@ -62,15 +69,9 @@ print(t.draw())
)) ))
""" """
if __name__ == "__main__": if __name__ == "__main__":
default_cmd.argparser.description += " - Lists Users from the Tilde database."
default_cmd.argparser.add_argument('--list', default=False, action="store_true",
help='Output a newline seperated list of users', required=False)
args = default_cmd.argparser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
try: try:
ret = "" ret = ""
L = ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved) L = ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved)
if args.list: if args.list:
ret = L.outputaslist() ret = L.outputaslist()
else: else:

@ -47,7 +47,7 @@ if __name__ == "__main__":
print(f"User {args.user} doesn't exist in the database.") print(f"User {args.user} doesn't exist in the database.")
exit(1) exit(1)
DB = lib.sqlitedb.SQLitedb(db) DB = lib.sqlitedb.SQLitedb(db)
Sysctl = lib.System.System(db) Sysctl = lib.System.System()
if not DB: if not DB:
print("Couldn't establish connection to database") print("Couldn't establish connection to database")
exit(1) exit(1)

@ -10,9 +10,8 @@ class System:
dry = False dry = False
create_command = [] create_command = []
home = "" home = ""
db = None
def __init__(self, db: str, dryrun: bool = False, home: str = "/home/"): def __init__(self, dryrun: bool = False, home: str = "/home/"):
"""Creates an objects. Can set dry run. """Creates an objects. Can set dry run.
:param dryrun: Run all command in a dry-run? When enabled, doesn't make any changes to the system (defaults to :param dryrun: Run all command in a dry-run? When enabled, doesn't make any changes to the system (defaults to
@ -22,7 +21,6 @@ class System:
:type home: str :type home: str
""" """
self.db = db
self.dry = dryrun self.dry = dryrun
if not home.endswith("/"): if not home.endswith("/"):
home += "/" home += "/"
@ -49,7 +47,6 @@ class System:
rt = subprocess.call(cc) rt = subprocess.call(cc)
if rt != 0: if rt != 0:
raise lib.UserExceptions.UserExistsAlready(f"User {username} exists already") raise lib.UserExceptions.UserExistsAlready(f"User {username} exists already")
self._createUserIndex()
return True return True
def unregister(self, username: str): def unregister(self, username: str):
@ -187,16 +184,8 @@ class System:
if ret != 0 and ret != 6: if ret != 0 and ret != 6:
raise lib.UserExceptions.UnknownReturnCode( raise lib.UserExceptions.UnknownReturnCode(
f"Could not delete user with command {cc}. Return code: {ret}") f"Could not delete user with command {cc}. Return code: {ret}")
self._createUserIndex()
return True return True
def _createUserIndex(self, index_file: str = "/home/users.txt"):
import ListUsers
L = ListUsers.ListUsers(self.db, unapproved=False, approved=True)
user_list = L.outputaslist()
with open(index_file, "w") as f:
print(user_list, file=f)
def AIO(username, pubkey, group="tilde"): def AIO(username, pubkey, group="tilde"):
syst = System(dryrun=False) syst = System(dryrun=False)

Loading…
Cancel
Save