From 7cf8212a64a5e9834e61536595561fb0bcc50f96 Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Sun, 25 Feb 2024 11:06:36 -0700 Subject: [PATCH] fix: Move class to api file --- tm_admin/users/api.py | 62 ++++++++++++++++++++++++++++++++++++++++ tm_admin/users/users.py | 63 ----------------------------------------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/tm_admin/users/api.py b/tm_admin/users/api.py index 9fc7ee57..50bc26a8 100755 --- a/tm_admin/users/api.py +++ b/tm_admin/users/api.py @@ -109,6 +109,68 @@ async def getByName(self, results = await self.execute(sql) return results + async def updateRole(self, + id: int, + role: Userrole, + ): + """ + Update the role for a user. + + Args: + id (int): The users ID + role (Userrole): The new role. + """ + role = Userrole(role) + return self.updateColumn(id, {'role': role.name}) + + async def updateMappingLevel(self, + id: int, + level: Mappinglevel, + ): + """ + Update the mapping level for a user. + + Args: + id (int): The users ID. + level (Mappinglevel): The new level. + """ + mlevel = Mappinglevel(level) + result = await self.updateColumn(id, {'mapping_level': mlevel.name}) + return result + + async def updateExpert(self, + id: int, + mode: bool, + ): + """ + Toggle the expert mode for a user. + + Args: + id (int): The users ID. + mode (bool): The new mode.. + """ + result = await self.updateColumn(id, {'expert_mode': mode}) + return result + + async def getRegistered(self, + start: datetime, + end: datetime, + ): + """ + Get all users registered in this timeframe. + + Args: + start (datetime): The starting timestamp + end (datetime): The starting timestamp + + Returns: + (list): The users registered in this timeframe. + """ + + where = f" date_registered > '{start}' and date_registered < '{end}'" + result = self.getByWhere(where) + return result + async def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser() diff --git a/tm_admin/users/users.py b/tm_admin/users/users.py index 9a04c75c..308c5fb7 100755 --- a/tm_admin/users/users.py +++ b/tm_admin/users/users.py @@ -291,69 +291,6 @@ async def mergeFavorites(self, timer.stop() return True - # These are just convience wrappers to support the REST API. - async def updateRole(self, - id: int, - role: Userrole, - ): - """ - Update the role for a user. - - Args: - id (int): The users ID - role (Userrole): The new role. - """ - role = Userrole(role) - return self.updateColumn(id, {'role': role.name}) - - async def updateMappingLevel(self, - id: int, - level: Mappinglevel, - ): - """ - Update the mapping level for a user. - - Args: - id (int): The users ID. - level (Mappinglevel): The new level. - """ - mlevel = Mappinglevel(level) - result = await self.updateColumn(id, {'mapping_level': mlevel.name}) - return result - - async def updateExpert(self, - id: int, - mode: bool, - ): - """ - Toggle the expert mode for a user. - - Args: - id (int): The users ID. - mode (bool): The new mode.. - """ - result = await self.updateColumn(id, {'expert_mode': mode}) - return result - - async def getRegistered(self, - start: datetime, - end: datetime, - ): - """ - Get all users registered in this timeframe. - - Args: - start (datetime): The starting timestamp - end (datetime): The starting timestamp - - Returns: - (list): The users registered in this timeframe. - """ - - where = f" date_registered > '{start}' and date_registered < '{end}'" - result = self.getByWhere(where) - return result - async def mergeAuxTables(self, inuri: str, outuri: str,