feat: adapt UGs to roles

This commit is contained in:
swve 2024-03-28 11:20:42 +00:00
parent 0df250c729
commit a6152ef1f5
9 changed files with 265 additions and 70 deletions

View file

@ -1,25 +1,27 @@
from fastapi import HTTPException, status
async def check_element_type(element_id):
async def check_element_type(element_uuid):
"""
Check if the element is a course, a user, a house or a collection, by checking its prefix
"""
if element_id.startswith("course_"):
if element_uuid.startswith("course_"):
return "courses"
elif element_id.startswith("user_"):
elif element_uuid.startswith("user_"):
return "users"
elif element_id.startswith("house_"):
elif element_uuid.startswith("usergroup_"):
return "usergroups"
elif element_uuid.startswith("house_"):
return "houses"
elif element_id.startswith("org_"):
elif element_uuid.startswith("org_"):
return "organizations"
elif element_id.startswith("chapter_"):
elif element_uuid.startswith("chapter_"):
return "coursechapters"
elif element_id.startswith("collection_"):
elif element_uuid.startswith("collection_"):
return "collections"
elif element_id.startswith("activity_"):
elif element_uuid.startswith("activity_"):
return "activities"
elif element_id.startswith("role_"):
elif element_uuid.startswith("role_"):
return "roles"
else:
raise HTTPException(
@ -28,8 +30,8 @@ async def check_element_type(element_id):
)
async def get_singular_form_of_element(element_id):
element_type = await check_element_type(element_id)
async def get_singular_form_of_element(element_uuid):
element_type = await check_element_type(element_uuid)
if element_type == "activities":
return "activity"
@ -38,8 +40,8 @@ async def get_singular_form_of_element(element_id):
return singular_form_element
async def get_id_identifier_of_element(element_id):
singular_form_element = await get_singular_form_of_element(element_id)
async def get_id_identifier_of_element(element_uuid):
singular_form_element = await get_singular_form_of_element(element_uuid)
if singular_form_element == "ogranizations":
return "org_id"