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

Commit

Permalink
fix: Update to use Access.Roles
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Mar 26, 2024
1 parent 74f6a0f commit a795ada
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
18 changes: 10 additions & 8 deletions tm_admin/projects/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
import geojson
from shapely.geometry import shape
from shapely import centroid
from tm_admin.types_tm import Mappingtypes, Projectstatus, Taskcreationmode, Editors, Permissions, Projectpriority, Projectdifficulty, Teamrole
from tm_admin.types_tm import Mappingtypes, Projectstatus, Taskcreationmode, Editors, Permissions, Projectpriority, Projectdifficulty
from tm_admin.projects.projects_class import ProjectsTable
from tm_admin.tasks.tasks_class import TasksTable
from shapely import wkb, get_coordinates
from tm_admin.pgsupport import PGSupport
from osm_rawdata.pgasync import PostgresClient
import re
from tm_admin.access import Roles
# from progress import Bar, PixelBar
from tqdm import tqdm
import tqdm.asyncio
Expand All @@ -63,11 +64,11 @@ def __init__(self):
Returns:
(ProjectsAPI): An instance of this class
"""
self.allowed_roles = [
Teamrole.TEAM_MAPPER,
Teamrole.TEAM_VALIDATOR,
Teamrole.TEAM_MANAGER,
]
# self.allowed_roles = [
# Teamrole.MAPPER,
# Teamrole.VALIDATOR,
# Teamrole.MANAGER,
# ]
from tm_admin.users.api import UsersAPI
self.users = None
self.tasks = None
Expand Down Expand Up @@ -122,7 +123,8 @@ async def getTeamRole(self,
#data = await self.getColumns(['id', 'teams'], where)
# The role is in a list of dicts in a jsonb column.

sql = f"SELECT jsonb_path_query(teams, '$.teams[*] ? (@.team_id[*] == {team_id})') AS results FROM projects WHERE id = {project_id};"
sql = f"SELECT jsonb_path_query(members, '$.members[*] ? (@.team_id[*] == {team_id})') AS results FROM projects WHERE id = {project_id};"
# print(sql)
results = await self.execute(sql)

# There should only be one item in the results. Since it's a jsonb column
Expand All @@ -131,7 +133,7 @@ async def getTeamRole(self,
if len(results) > 0:
if results[0]['results'][0] == '{':
tmp1 = eval(results[0]['results'])
tmp2 = f"Teamrole.{tmp1['role']}"
tmp2 = f"Roles.{tmp1['role']}"
role = eval(tmp2)
return role

Expand Down
8 changes: 4 additions & 4 deletions tm_admin/tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def updateHistory(self,
data += f'" {v}", '
#asc = str(entry).replace("'", '"').replace("\\'", "'")
sql = "UPDATE tasks SET history = '{\"history\": [%s]}' WHERE id=%d AND project_id=%d" % (data[:-2], task_id, project_id)
print(sql)
# print(sql)
result = await self.execute(sql)

async def appendHistory(self,
Expand Down Expand Up @@ -350,8 +350,8 @@ async def updateIssues(self,
result = await self.execute(sql)

async def mapAllAPI(self,
project_id: int,
):
project_id: int,
):
"""
Map all tasks on a project. Can only be done by the project
manager.
Expand Down Expand Up @@ -386,7 +386,7 @@ async def validateAllAPI(self,

return False

async def resetBadImageryAllAPI(self):
async def resetBadImagery(self):
"""
Set all bad imagery tasks as ready for mapping.
Expand Down
5 changes: 1 addition & 4 deletions tm_admin/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@
from shapely import wkb, get_coordinates
from tm_admin.pgsupport import PGSupport
import typing
#if typing.TYPE_CHECKING:
# from tm_admin.projects.api import ProjectsAPI
# from tm_admin.tasks.api import TasksAPI
import tm_admin
import re
# from progress import Bar, PixelBar
from tqdm import tqdm
import tqdm.asyncio
from codetiming import Timer
import asyncio
from http import HTTPStatus
from tm_admin.access import Roles

# The number of threads is based on the CPU cores
info = get_cpu_info()
Expand Down

0 comments on commit a795ada

Please sign in to comment.