Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sentry-FLAGSMITH-API-4BN): update permission method #3851

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/api_keys/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ def get_permitted_projects(
)

def get_permitted_environments(
self, permission_key: str, project: "Project", tag_ids: typing.List[int] = None
self,
permission_key: str,
project: "Project",
tag_ids: typing.List[int] = None,
prefetch_metadata: bool = False,
) -> QuerySet["Environment"]:
return get_permitted_environments_for_master_api_key(
self.key, project, permission_key, tag_ids
self.key, project, permission_key, tag_ids, prefetch_metadata
)
14 changes: 10 additions & 4 deletions api/permissions/permission_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,19 @@ def get_permitted_environments_for_master_api_key(
project: Project,
permission_key: str,
tag_ids: List[int] = None,
prefetch_metadata: bool = False,
) -> QuerySet[Environment]:
if is_master_api_key_project_admin(master_api_key, project):
return project.environments.all()
queryset = project.environments.all()
else:
queryset = get_permitted_environments_for_master_api_key_using_roles(
master_api_key, project, permission_key, tag_ids
)

return get_permitted_environments_for_master_api_key_using_roles(
master_api_key, project, permission_key, tag_ids
)
if prefetch_metadata:
queryset = queryset.prefetch_related("metadata")

return queryset


def user_has_organisation_permission(
Expand Down
Loading