Skip to content

Commit

Permalink
Fix: pipeline run user perms (#795)
Browse files Browse the repository at this point in the history
* fix: Use a real error in the except clause

* fix(Analytics): The url has to end with a slash

* fix(Auth): PipelineRunUser was not able to get the datasets from the SDK.

Fixes OPENHEXA-16J
  • Loading branch information
qgerome authored Aug 23, 2024
1 parent 48008b1 commit 975ec57
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion hexa/analytics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
app_name = "analytics"

urlpatterns = [
path("track", views.track_event, name="track"),
path("track/", views.track_event, name="track"),
]
10 changes: 3 additions & 7 deletions hexa/datasets/schema/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ def resolve_create_dataset(_, info, **kwargs):
mutation_input = kwargs["input"]

try:
# FIXME: Use a generic permission system instead of differencing between User and PipelineRunUser
if isinstance(request.user, PipelineRunUser):
workspace = request.user.pipeline_run.pipeline.workspace
else:
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
)
workspace = Workspace.objects.filter_for_user(request.user).get(
slug=mutation_input["workspaceSlug"]
)
dataset = Dataset.objects.create_if_has_perm(
principal=request.user,
workspace=workspace,
Expand Down
4 changes: 2 additions & 2 deletions hexa/pipelines/signals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from corsheaders.signals import check_request_enabled
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.urls import ResolverMatch, resolve
from django.urls import NoReverseMatch, resolve

from hexa.workspaces.models import WorkspaceMembership

Expand All @@ -27,5 +27,5 @@ def cors_allow_pipeline_run(sender, request, **kwargs):
try:
match = resolve(request.path)
return match.view_name in ("pipelines:run", "pipelines:run_with_version")
except ResolverMatch:
except NoReverseMatch:
return False
2 changes: 1 addition & 1 deletion hexa/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def filter_for_user(self, user: AnonymousUser | User) -> models.QuerySet:
if isinstance(user, PipelineRunUser):
return self._filter_for_user_and_query_object(
user,
Q(workspace=user.pipeline_run.pipeline.workspace, archived=False),
Q(id=user.pipeline_run.pipeline.workspace.id, archived=False),
return_all_if_superuser=False,
)
else:
Expand Down

0 comments on commit 975ec57

Please sign in to comment.