Skip to content

Commit

Permalink
Develop (#20)
Browse files Browse the repository at this point in the history
* hotfix: update gitignore

* hotfix: update docker-compose file - remove env-files config

* hotfix: structured and enhancement project (#3)

* hotfix: update readme project

* feat: add new environment variable

* feat: add package beanie-odm

* fix: remove unsing config in docker-compose file

* feat: update botoclient function

* feat: cleanup error codes and add news

* feat: remove unusing functions and update utils functionnal

* feat: define bucket policy config

* test: add tests for endpoints and functional (#5)

* test: restructured test config, add test to media endpoint (#7)

* test: add tests for endpoints and functional

* test: restructured test config, add test to media endpoint

* feat: add workflow config (#9)

* feat: update workflow (#10)

* feat: add workflow config

* feat: add github action

* fix: fix workflow ci (#11)

* Fix/worklows (#12)

* fix: fix workflow ci

* fix: fix workflow ci

* Fix/worklows (#13)

* fix: fix workflow ci

* fix: fix workflow ci

* fix: create docker image (#15)

* fix: fix workflow ci

* fix: fix workflow ci

* fix: environment

* feat: add permissions to endpoint

* hotfix: fix appdesc config

* hotfix: fix appdesc config
  • Loading branch information
flavien-hugs authored Nov 4, 2024
1 parent 8fe7206 commit 8c01370
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 102 deletions.
88 changes: 32 additions & 56 deletions appdesc.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,34 @@
-
app:
name: "likya"
- app:
name: "sfs"
title:
fr: "LIKYA: Plateforme de financement participatif (crowdfunding) pour le domaine médical"
en: "LIKYA: Crowdfunding platform for the medical field"
fr: "Service de stockage et gestion de fichiers"
en: "File storage and management service"
permissions:
-
code: "likya:can-create-category"
desc:
fr: "Peut créer une catégorie"
en: "Can create a category"
-
code: "likya:can-read-category"
desc:
fr: "Peut afficher une catégorie"
en: "Can display a category"
-
code: "likya:can-update-category"
desc:
fr: "Peut modifier une catégorie"
en: "Can modify a category"
-
code: "likya:can-delete-category"
desc:
fr: "Peut supprimer une catégorie"
en: "Can delete a category"

-
code: "likya:can-create-fundraising"
desc:
fr: "Peut créer une campagne de financement"
en: "Can create a fundraising campaign"
-
code: "likya:can-read-fundraising"
desc:
fr: "Peut afficher une campagne de financement"
en: "Can display a fundraising campaign"
-
code: "likya:can-update-fundraising"
desc:
fr: "Peut modifier une campagne de financement"
en: "Can modify a fundraising campaign"
-
code: "likya:can-delete-fundraising"
desc:
fr: "Peut supprimer une campagne de financement"
en: "Can delete a fundraising campaign"
-
code: "likya:can-update-fundraising-access"
desc:
fr: "Peut modifier l'accès à une campagne de financement"
en: "Can modify access to a fundraising campaign"
-
code: "likya:validate-or-reject-fundraising"
desc:
fr: "Peut valider ou rejeter une campagne de financement"
en: "Can validate or reject a fundraising campaign"
- code: "sfs:can-read-bucket"
desc:
fr: "Peut lire un dossier d'images"
en: "Can read an image folder"
- code: "sfs:can-create-bucket"
desc:
fr: "Peut créer un dossier d'images"
en: "Can create an image folder"
- code: "sfs:can-delete-bucket"
desc:
fr: "Peut supprimer un dossier d'images"
en: "Can delete an image folder"
- code: "sfs:can-write-bucket"
desc:
fr: "Peut écrire dans un dossier d'images"
en: "Can write in an image folder"
- code: "sfs:can-read-file"
desc:
fr: "Peut lire un fichier"
en: "Can read a file"
- code: "sfs:can-write-file"
desc:
fr: "Peut ajouter un fichier dans un dossier d'images"
en: "Can add a file in an image folder"
- code: "sfs:can-delete-file"
desc:
fr: "Peut supprimer un fichier"
en: "Can delete a file"
76 changes: 30 additions & 46 deletions src/common/setup_app_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,83 +47,67 @@ async def __load_app_description(filpath) -> dict:
return data


async def __load_app_data(
async def load_app_description(
mongodb_client: AsyncIOMotorClient,
collection_path: str,
filename: str,
data_key: str,
update_key: str,
update_value: callable,
collection_path: str = None,
filename: str = "appdesc.yml",
):
"""
Load app data from a JSON file and update the database.
Load the app description from a JSON file and update the database.
"""

coll = await __init_collection(mongodb_client, collection_path)
if not (coll_path := collection_path or os.environ.get("APP_DESC_DB_COLLECTION")):
raise ValueError("Invalid collection path")

coll = await __init_collection(mongodb_client, coll_path)

filepath = BASE_DIR / f"{filename}"
data = await __load_app_description(filepath)

if not (appname := data[0].get("app", {}).get("name", "").strip()):
raise ValueError(f"App name '{appname}' not found in {filepath}")

if not (value := data[0].get("app", {}).get(data_key, {})):
raise ValueError(f"{data_key} section for app '{appname}' not found in {filepath}")
if not (title := data[0].get("app", {}).get("title", {})):
raise ValueError(f"title section for app '{appname}' not found in {filepath}")

await coll.update_one(
{"app": slugify(appname)},
{"$set": {update_key: update_value(value)}},
{"$set": {"title": title}},
upsert=True,
)


async def load_app_description(
async def load_app_permissions(
mongodb_client: AsyncIOMotorClient,
collection_path: str = None,
filename: str = "appdesc.yml",
):
"""
Load the app description from a JSON file and update the database.
Load the app permissions from a JSON file and update the database.
"""

if not (coll_path := collection_path or os.environ.get("APP_DESC_DB_COLLECTION")):
if not (coll_path := collection_path or os.environ.get("PERMS_DB_COLLECTION")):
raise ValueError("Invalid collection path")

await __init_collection(mongodb_client, coll_path)

await __load_app_data(
mongodb_client,
coll_path,
filename,
"title",
"title",
lambda value: value,
)
coll = await __init_collection(mongodb_client, coll_path)

filepath = BASE_DIR / f"{filename}"
data = await __load_app_description(filepath)

async def load_app_permissions(
mongodb_client: AsyncIOMotorClient,
collection_path: str = None,
filename: str = "appdesc.yml",
):
"""
Load the app permissions from a JSON file and update the database.
"""
if not (appname := data[0].get("app", {}).get("name", "").strip()):
raise ValueError(f"App name '{appname}' not found in {filepath}")

if not (coll_path := collection_path or os.environ.get("PERMS_DB_COLLECTION")):
raise ValueError("Invalid collection path")
if not (permissions := data[0].get("app", {}).get("permissions", [])):
return

await __load_app_data(
mongodb_client,
coll_path,
filename,
"permissions",
"permissions",
lambda value: [
{
"code": slugify(perm.get("code", ""), regex_pattern=r"[^a-zA-Z0-9:]+"),
"desc": perm.get("desc", ""),
await coll.update_one(
{"app": slugify(appname)},
{
"$set": {
"permissions": [
{"code": slugify(item["code"], regex_pattern=r"[^a-zA-Z0-9:]+"), "desc": item["desc"]} for item in permissions
]
}
for perm in value
],
},
upsert=True,
)

0 comments on commit 8c01370

Please sign in to comment.