From a593bf95eb5e847ae9b4cb218558464c4813bd15 Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Tue, 10 Oct 2023 16:16:26 +0530 Subject: [PATCH] Roles without remapping in VenueRoom (resolves #1893) (#1896) --- funnel/models/project_membership.py | 5 ++++- funnel/models/venue.py | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/funnel/models/project_membership.py b/funnel/models/project_membership.py index 7b50b15c5..fda29e6b3 100644 --- a/funnel/models/project_membership.py +++ b/funnel/models/project_membership.py @@ -12,7 +12,7 @@ from .membership_mixin import ImmutableUserMembershipMixin from .project import Project -__all__ = ['ProjectMembership', 'project_child_role_map'] +__all__ = ['ProjectMembership', 'project_child_role_map', 'project_child_role_set'] #: Roles in a project and their remapped names in objects attached to a project project_child_role_map: dict[str, str] = { @@ -24,6 +24,9 @@ 'reader': 'reader', } +#: A model that is indirectly under a project needs the role names without remapping +project_child_role_set: set[str] = set(project_child_role_map.values()) + #: ProjectMembership maps project's `account_admin` role to membership's `editor` #: role in addition to the recurring role grant map project_membership_role_map: dict[str, str | set[str]] = { diff --git a/funnel/models/venue.py b/funnel/models/venue.py index 5f52e5443..620da0b01 100644 --- a/funnel/models/venue.py +++ b/funnel/models/venue.py @@ -2,8 +2,6 @@ from __future__ import annotations -import itertools - from sqlalchemy.ext.orderinglist import ordering_list from coaster.sqlalchemy import add_primary_relationship, with_roles @@ -19,7 +17,7 @@ ) from .helpers import MarkdownCompositeBasic, reopen from .project import Project -from .project_membership import project_child_role_map +from .project_membership import project_child_role_map, project_child_role_set __all__ = ['Venue', 'VenueRoom'] @@ -113,7 +111,7 @@ class VenueRoom(UuidMixin, BaseScopedNameMixin, Model): venue: Mapped[Venue] = with_roles( relationship(Venue, back_populates='rooms'), # Since Venue already remaps Project roles, we just want the remapped role names - grants_via={None: set(itertools.chain(*project_child_role_map.values()))}, + grants_via={None: project_child_role_set}, ) parent: Mapped[Venue] = sa.orm.synonym('venue') description, description_text, description_html = MarkdownCompositeBasic.create(