Project/scenario overviews and project-based permissions - #39
Project/scenario overviews and project-based permissions#39PaulScheerRLI wants to merge 15 commits into
Conversation
Projects bundle scenarios; access is granted through a per-project
group with guardian object permissions ('view'/'details'). db_deepcopy
provides recursive DB-level copying used by duplicate_project and
duplicate_scenario(_with_permissions), which transfer group and
area permissions to the copies. The JSON ApiView handles rename,
delete and duplicate for projects and scenarios. has_authorization
moves from views to models and is checked against the project.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Projects page lists all accessible projects as cards or table rows with persisted search/sort/view state. The project overview shows the project's scenarios. Ellipsis dropdowns and modals drive rename, duplicate and delete through the ports JSON api (cotton api_button shows request state inline). Management pages share the extracted base_management shell with header and footer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The tz cookie (set by the script shipped with the overview pages' imports.html) holds the browser's IANA zone name; the middleware activates it per request so every |date filter renders local dates. Missing or invalid cookies fall back to UTC. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ture/project-overviews
Remove duplicate select2 import
Fix missing closing script in imports remove debug print
| <div class="grid grid-cols-1 gap-y-2 pt-2"> | ||
| <div class="bg-[#f8fafc] content-stretch flex items-start relative shrink-0 w-full rounded-lg"> | ||
| <div class="flex-[1_0_0] font-['Inter:Regular',sans-serif] font-normal min-h-px min-w-px not-italic relative text-[#1e293b] text-[14px] "> | ||
| <p class="leading-[23px] mb-0">{% translate 'Erstelle ein Projekt, um deine Energiezukunft zu planen:' %}</p> |
There was a problem hiding this comment.
General question: how formal/professional has this to be? I would suggest to put this as neutral as possible, e.g. "Neues Projekt erstellen, um Energiezukunft zu planen"
| def _check_permission(self, request): | ||
| is_authorized = False | ||
| match self.instance: | ||
| case Project(): | ||
| is_authorized = has_authorization(self.instance, request.user, "details") | ||
| case Scenario(): | ||
| is_authorized = has_authorization(self.instance.project, request.user, "details") | ||
| return is_authorized |
There was a problem hiding this comment.
suggestion:
def _check_permission(self, request):
project = self.instance if isinstance(self.instance, Project) else self.instance.project
return has_authorization(project, request.user, "details")
There was a problem hiding this comment.
Its likely the API will grow, and so will the permission check.
| return is_authorized | ||
|
|
||
| def post(self, request, *args, **kwargs): | ||
| match self.instance: |
There was a problem hiding this comment.
could also be if isinstance instead of match case
|
|
||
| def duplicate(self, request, *args, **kwargs): | ||
| try: | ||
| if self.Model == Project: |
There was a problem hiding this comment.
isinstance(self.instance) may be safer than relying on self.Model
There was a problem hiding this comment.
self.instance was found using self.Model. Other methods are using pattern matching though. Maybe use the same pattern in every method? I like pattern matching since its slightly less redundant
Second of two stacked PRs splitting
feature/geometry_import— based onfeature/geodata-import(#38); retarget todevafter #38 merges. The diff shown here is only the overview/permission work.This is meant to make review easier
What
Projectmodel bundling scenarios; access via per-project group with guardian object permissions (migration0019)uv run manage.py clean_orphan_obj_permsProjects /projects/
Manage Projects inside user projects space
@mosc5 right now everyone with "details" permission can duplicate/rename and delete projects.
Scenarios / Project Overview /project_overview/project_uuid/
Manage Scenarios for a given project
Duplicate Scenarios
Delete Scenarios
Rename Scenario and Description
@mosc5 right now everyone with "details" permission can duplicate/rename and delete scenarios.
duplication of scenarios does transfer area permissions.
minor issue: Deepcopying the scenarios creates objects in a non-deterministic way. When ordering objects/areas based on creation time, this can rearrange them in between scenarios. Needs fix?
Scenario duplication and selecting scenarios from the project also works from the tool view
Other
db_deepcopyrecursive DB copy;duplicate_project/duplicate_scenario(_with_permissions)transfer group membership and area permissions to the copiesApiViewfor rename/duplicate/delete of projects and scenarios;has_authorizationmoved toports/models.pyand checked against the projectapi_button)base_managementshell with header/footertzcookie (browser IANA zone) activates the client timezone per request, all|datefilters render local datestest_duplicate_permissions.py(project/scenario/area permission transfer on duplication), extendedtest_detail_view.pyThe splitting was done by claude. the diff together with #38 is identical to the original geometry_import
tests were generated by claude
Open TODOS for other PRs
Implement user rights / Nutzerverwaltung
Implement Szenarienvergleich
Implement scenario specific Ergebnisse