From a7908747327c565543f4fb80fea7d04d2a2391a8 Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Thu, 7 Mar 2024 10:35:46 -0700 Subject: [PATCH] fix: Drop create, update, delete as they're now in pgsupport --- tm_admin/campaigns/api.py | 18 +------ tm_admin/messages/api.py | 55 ------------------- tm_admin/organizations/api.py | 68 +----------------------- tm_admin/projects/api.py | 99 ++++------------------------------- tm_admin/tasks/api.py | 55 +------------------ tm_admin/teams/api.py | 54 ------------------- tm_admin/users/api.py | 50 ------------------ 7 files changed, 13 insertions(+), 386 deletions(-) diff --git a/tm_admin/campaigns/api.py b/tm_admin/campaigns/api.py index b9a3942..86084f7 100644 --- a/tm_admin/campaigns/api.py +++ b/tm_admin/campaigns/api.py @@ -83,7 +83,7 @@ async def initialize(self, Args: inuri (str): The URI for the TM Admin output database """ - await self.connect(uri) + await self.connect(inuri) await self.getTypes("campaigns") #await self.usersdb.connect(uri) #await self.teamsdb.connect(uri) @@ -159,22 +159,6 @@ async def update(self, return False - async def delete(self, - campaign_id: int, - ): - """ - Delete a campaign from the database. - - Args: - campaign_id (id): The campaign data - - Returns: - (bool): Whether the campaign got deleted - """ - log.warning(f"delete(): unimplemented!") - - return False - async def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser() diff --git a/tm_admin/messages/api.py b/tm_admin/messages/api.py index 85f4221..5389a92 100755 --- a/tm_admin/messages/api.py +++ b/tm_admin/messages/api.py @@ -121,61 +121,6 @@ async def getByName(self, results = await self.execute(sql) return results - async def create(self, - message: MessagesTable, - ): - """ - Create a message and add it to the database. - - Args: - message (MessagesTable): The team data - - Returns: - (bool): Whether the message got created - """ - # log.warning(f"create(): unimplemented!") - - result = await self.insertRecords([message]) - - # The ID of the record that just got inserted is returned - if result: - return True - - return False - - async def update(self, - message: MessagesTable, - ): - """ - Update a message that is already in the database. - - Args: - message (MessagesTable): The message data - - Returns: - (bool): Whether the message got updated - """ - log.warning(f"update(): unimplemented!") - - return False - - async def delete(self, - message_ids: list, - ): - """ - Delete messages from the database. - - Args: - message_ids (list): The messages - - Returns: - (bool): Whether the messages got deleted - """ - # log.warning(f"delete(): unimplemented!") - await self.deleteRecords(message_ids) - - return False - async def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser() diff --git a/tm_admin/organizations/api.py b/tm_admin/organizations/api.py index 8034363..a0b277a 100644 --- a/tm_admin/organizations/api.py +++ b/tm_admin/organizations/api.py @@ -71,7 +71,7 @@ async def initialize(self, Args: inuri (str): The URI for the TM Admin output database """ - await self.connect(uri) + await self.connect(inuri) await self.getTypes("organizations") #await self.messagesdb.connect(uri) #await self.usersdb.connect(uri) @@ -111,57 +111,6 @@ async def getByName(self, results = await self.execute(sql) return results - async def create(self, - org: OrganizationsTable, - ): - """ - Create a project and add it to the database. - - Args: - org (OrganizationsTable): The organization data - - Returns: - (bool): Whether the organization got created - """ - # log.warning(f"create(): unimplemented!") - result = await self.insertRecords([org]) - - # The ID of the record that just got inserted is returned - if result: - return True - - return False - - async def update(self, - organization: OrganizationsTable, - ): - """ - Update a organization that is already in the database. - - Args: - organization (OrganizationsTable): The organization data - - Returns: - (bool): Whether the organization got updated - """ - log.warning(f"update(): unimplemented!") - - return False - - async def delete(self, - org_id: int, - ): - """ - Delete an organization from the database. - - Args: - org_id (id): The organization ID - - Returns: - (bool): Whether the organization got deleted - """ - log.warning(f"delete(): unimplemented!") - async def getStats(self, org_id: int, ): @@ -175,19 +124,6 @@ async def getStats(self, """ log.warning(f"getStats(): unimplemented!") - async def isManager(self, - user_id: int, - ): - """ - - Args: - - - Returns: - - """ - log.warning(f"isManager(): unimplemented!") - async def validateName(self, name: str, ): @@ -219,7 +155,7 @@ async def main(): """This main function lets this class be run standalone by a bash script.""" parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", nargs="?", const="0", help="verbose output") - parser.add_argument("-u", "--uri", default='localhost/tm_admin', help="Database URI") + parser.add_argument("-u", "--uri", default='localhost/testdata', help="Database URI") args = parser.parse_args() diff --git a/tm_admin/projects/api.py b/tm_admin/projects/api.py index 90119a3..4810f64 100755 --- a/tm_admin/projects/api.py +++ b/tm_admin/projects/api.py @@ -89,60 +89,6 @@ async def initialize(self, await self.connect(inuri) await self.getTypes("projects") - async def create(self, - project: ProjectsTable, - ): - """ - Create a project and add it to the database. - - Args: - project (ProjectsTable): The team data - - Returns: - (bool): Whether the project got created - """ - # log.warning(f"--- create() ---") - result = await self.insertRecords([project]) - - # The ID of the record that just got inserted is returned - if result > 0: - return True - - return False - - async def update(self, - project: ProjectsTable, - ): - """ - Update a project that is already in the database. - - Args: - project (ProjectsTable): The project data - - Returns: - (bool): Whether the project got updated - """ - log.warning(f"update(): unimplemented!") - - return False - - async def delete(self, - project_ids: int, - ): - """ - Delete a project from the database. - - Args: - project_ids (id): The project to delete - - Returns: - (bool): Whether the project got deleted - """ - # log.warning(f"delete(): unimplemented!") - await self.deleteRecords([project_ids]) - - return False - async def evaluateMappingPermissions(self, uid: int, pid: int, @@ -208,13 +154,14 @@ async def getTeamRole(self, # There should only be one item in the results. Since it's a jsonb column # the data is returned as a string. In the string is an enum value, which # gets converted to the actual enum for Teamroles. - if results[0]['results'][0] == '{': - tmp1 = eval(results[0]['results']) - tmp2 = f"Teamroles.{tmp1['role']}" - role = eval(tmp2) - return role - else: - # we should never get here, but you never know... + if len(results) > 0: + if results[0]['results'][0] == '{': + tmp1 = eval(results[0]['results']) + tmp2 = f"Teamroles.{tmp1['role']}" + role = eval(tmp2) + return role + + # we should never get here, but you never know... return None async def getByName(self, @@ -249,7 +196,7 @@ async def changeStatus(self, Returns: (bool): Whether locking/unlocking the task was sucessful """ - log.warning(f"delete(): unimplemented!") + log.warning(f"changeStatus(): unimplemented!") return False @@ -327,34 +274,6 @@ async def getProjectStats(self, return False - async def deleteTasks(self, - project_id: int, - ): - """ - - Args: - - - Returns: - - """ - log.warning(f"deleteTasks(): Unimplemented!") - - return False - - async def getTasks(self): - """ - - Args: - - - Returns: - - """ - log.warning(f"getTasks(): Unimplemented!") - - return False - async def getAOI(self, project_id: int, ): diff --git a/tm_admin/tasks/api.py b/tm_admin/tasks/api.py index 808413d..320733f 100755 --- a/tm_admin/tasks/api.py +++ b/tm_admin/tasks/api.py @@ -139,59 +139,6 @@ async def getByUser(self, results = await self.execute(sql) return results - async def create(self, - task: TasksTable, - ): - """ - Create a task and add it to the database. - - Args: - task (TasksTable): The task data - - Returns: - (bool): Whether the task got created - """ - # log.warning(f"create(): unimplemented!") - result = await self.insertRecords([task]) - - # The ID of the record that just got inserted is returned - if result: - return True - - return False - - async def update(self, - task: TasksTable, - ): - """ - Update a task that is already in the database. - - Args: - task (TasksTable): The task data - - Returns: - (bool): Whether the task got updated - """ - log.warning(f"update(): unimplemented!") - - return False - - async def delete(self, - task_id: int, - ): - """ - Delete a task from the database. - - Args: - task_id (int): The team to delete - - Returns: - (bool): Whether the task got deleted - """ - log.warning(f"delete(): unimplemented!") - - return False - async def changeStatus(self, user_id: int, task_id: int, @@ -211,7 +158,7 @@ async def changeStatus(self, Returns: (bool): Whether locking/unlocking the task was sucessful """ - log.warning(f"delete(): unimplemented!") + log.warning(f"changeStatus(): unimplemented!") async def markAllMapped(self): """ diff --git a/tm_admin/teams/api.py b/tm_admin/teams/api.py index 8d8f387..5d4ef4f 100755 --- a/tm_admin/teams/api.py +++ b/tm_admin/teams/api.py @@ -113,60 +113,6 @@ async def getByName(self, sql = f"SELECT * FROM teams WHERE name='{name}'" results = await self.execute(sql) return results - - async def create(self, - team: TeamsTable, - ): - """ - Create a team and add it to the database. - - Args: - team (TeamsTable): The team data - - Returns: - (bool): Whether the team got created - """ - # log.warning(f"create(): unimplemented!") - result = await self.insertRecords([team]) - - # The ID of the record that just got inserted is returned - if result: - return True - - return False - - async def update(self, - team: Team_membersTable, - ): - """ - Update a team that is already in the database. - - Args: - team (TeamsTable): The team data - - Returns: - (bool): Whether the team got updated - """ - log.warning(f"update(): unimplemented!") - - return False - - async def delete(self, - team_ids: int, - ): - """ - Delete a team from the database. - - Args: - team_ids (int): The team ID - - Returns: - (bool): Whether the team got deleted - """ - # log.warning(f"delete(): unimplemented!") - await self.deleteRecords(team_ids) - - return True async def addMember(self, member: Team_membersTable, diff --git a/tm_admin/users/api.py b/tm_admin/users/api.py index ef8a47c..ea2b1c3 100755 --- a/tm_admin/users/api.py +++ b/tm_admin/users/api.py @@ -83,56 +83,6 @@ async def initialize(self, #await self.usersdb.connect(uri) #await self.teamsdb.connect(uri) - async def create(self, - user: UsersTable, - ): - """ - Create a user and add them to the database. - - Args: - user (UsersTable): The user's data - - Returns: - (bool): Whether the user got created - """ - # log.warning(f"create(): unimplemented!") - result = await self.insertRecords([user]) - - # The ID of the record that just got inserted is returned - if result: - return True - - return False - - async def update(self, - user: UsersTable, - ): - """ - Update a user that is already in the database. - - Args: - user (UsersTable): The user's data - - Returns: - (bool): Whether the user got updated - """ - log.warning(f"update(): unimplemented!") - - async def delete(self, - user_ids: list, - ): - """ - Delete a user from the database. - - Args: - user_ids (int): The user's ID - - Returns: - (bool): Whether the user got deleted - """ - #log.warning(f"delete(): unimplemented!") - await self.deleteRecords(user_ids) - async def getByID(self, user_id: int, ):