Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Fix roles in the users table
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Mar 26, 2024
1 parent 6e823a7 commit efe45a3
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tm_admin/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
# 1100 13th Street NW Suite 800 Washington, D.C. 20005
# <[email protected]>

"""
This class is used to import the auxilary tables into the primary table
"""

import argparse
import logging
import sys
Expand All @@ -30,14 +34,14 @@
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
from tqdm import tqdm
import tqdm.asyncio
import asyncio
from codetiming import Timer
from tm_admin.dbsupport import DBSupport

# Instantiate logger
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit efe45a3

Please sign in to comment.