#!/usr/bin/env python3 """Showcase module RBAC permission registration""" import os, sys, subprocess # Find Sage root SAGE_ROOT = None for candidate in [os.path.expanduser("~/repos/sage"), os.path.expanduser("~/sage")]: if os.path.isdir(os.path.join(candidate, "wwwroot")): SAGE_ROOT = candidate break if not SAGE_ROOT: print("ERROR: Sage root not found") sys.exit(1) MOD = "showcase" SET_PERM = os.path.join(SAGE_ROOT, "set_role_perm.py") PY = os.path.join(SAGE_ROOT, "py3", "bin", "python") def set_perm(role, path): cmd = [PY, SET_PERM, role, path] r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: print(f" WARN: {path} -> {r.stderr.strip()}") # Public resources (no auth needed) PATHS_ANY = [ f"/{MOD}/showcase.css", f"/{MOD}/showcase.js", f"/{MOD}/menu.ui", ] # Authenticated endpoints PATHS_LOGINED = [ f"/{MOD}", f"/{MOD}/index.ui", f"/{MOD}/detail.ui", # API endpoints f"/{MOD}/api/showcase_feed.dspy", f"/{MOD}/api/showcase_post_detail.dspy", f"/{MOD}/api/showcase_post_create.dspy", f"/{MOD}/api/showcase_post_update.dspy", f"/{MOD}/api/showcase_post_delete.dspy", f"/{MOD}/api/showcase_comment_create.dspy", f"/{MOD}/api/showcase_comment_update.dspy", f"/{MOD}/api/showcase_comment_delete.dspy", f"/{MOD}/api/showcase_comments_list.dspy", f"/{MOD}/api/showcase_like_toggle.dspy", f"/{MOD}/api/showcase_download_purchase.dspy", # CRUD generated directories f"/{MOD}/showcase_posts_list", f"/{MOD}/showcase_posts_list/index.ui", f"/{MOD}/showcase_posts_list/get_showcase_posts_list.dspy", f"/{MOD}/showcase_posts_list/add_showcase_posts_list.dspy", f"/{MOD}/showcase_posts_list/update_showcase_posts_list.dspy", f"/{MOD}/showcase_posts_list/delete_showcase_posts_list.dspy", f"/{MOD}/showcase_comments_list", f"/{MOD}/showcase_comments_list/index.ui", f"/{MOD}/showcase_comments_list/get_showcase_comments_list.dspy", f"/{MOD}/showcase_comments_list/add_showcase_comments_list.dspy", f"/{MOD}/showcase_comments_list/update_showcase_comments_list.dspy", f"/{MOD}/showcase_comments_list/delete_showcase_comments_list.dspy", f"/{MOD}/showcase_downloads_list", f"/{MOD}/showcase_downloads_list/index.ui", f"/{MOD}/showcase_downloads_list/get_showcase_downloads_list.dspy", f"/{MOD}/showcase_downloads_list/add_showcase_downloads_list.dspy", f"/{MOD}/showcase_downloads_list/update_showcase_downloads_list.dspy", f"/{MOD}/showcase_downloads_list/delete_showcase_downloads_list.dspy", ] print(f"Registering RBAC permissions for {MOD}...") for p in PATHS_ANY: set_perm("any", p) for p in PATHS_LOGINED: set_perm("logined", p) print("Done.")