diff --git a/tm_admin/users/users.py b/tm_admin/users/users.py index 701a9f7..4a53229 100755 --- a/tm_admin/users/users.py +++ b/tm_admin/users/users.py @@ -19,6 +19,10 @@ # 1100 13th Street NW Suite 800 Washington, D.C. 20005 # +""" +This class is used to import the auxilary tables into the primary table +""" + import argparse import logging import sys @@ -30,7 +34,6 @@ from tm_admin.types_tm import Userrole, Mappinglevel, Teammemberfunctions import concurrent.futures from cpuinfo import get_cpu_info -from tm_admin.dbsupport import DBSupport from tm_admin.users.users_class import UsersTable from osm_rawdata.pgasync import PostgresClient from tm_admin.types_tm import Userrole @@ -38,6 +41,7 @@ import tqdm.asyncio import asyncio from codetiming import Timer +from tm_admin.dbsupport import DBSupport # Instantiate logger log = logging.getLogger(__name__) @@ -116,6 +120,34 @@ def __init__(self, # super().__init__('users', dburi) super().__init__('users') + async def fixRoles(self, + inpg: PostgresClient, + outpg: PostgresClient, + ): + + """ + Fix the roles after importing from TM. + + Args: + inpg (PostgresClient): The input database + outpg (PostgresClient): The output database + """ + # For some reason the user role doesn't import + # correctly, but it barely matters as this is + # now in the members column of the projects + # table. But we might as well fix this in the user + # table. Most are MAPPERS, so set that as the default. + sql = f"UPDATE users SET role = 'MAPPER'" + result = await outpg.execute(sql) + # Get the few users that are a project manager + sql = f"SELECT json_agg(tmp) FROM (SELECT id,role FROM users WHERE role>0) AS tmp;" + # print(sql) + result = await inpg.execute(sql) + admins = dict() + for entry in eval(result[0]['json_agg']): + sql = f"UPDATE users SET role = 'PROJECT_MANAGER' WHERE id={entry['id']}" + result = await outpg.execute(sql) + async def mergeInterests(self, inpg: PostgresClient, ): @@ -307,6 +339,11 @@ async def mergeAuxTables(self, inpg = PostgresClient() await inpg.connect(inuri) + outpg = PostgresClient() + await outpg.connect(outuri) + + await self.fixRoles(inpg, outpg) + await self.mergeFavorites(inpg) await self.mergeInterests(inpg)