Skip to content

Commit

Permalink
Fix permissions for non-logged in users in dataset page
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed May 22, 2024
1 parent 840a22e commit 03e62c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ckanext/embeddings/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ckan.plugins import toolkit
from ckan.authz import is_authorized


@toolkit.auth_allow_anonymous_access
def package_similar_show(context, data_dict):
return is_authorized("package_show", context, data_dict)
35 changes: 35 additions & 0 deletions ckanext/embeddings/tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from ckan.plugins import toolkit
from ckan.tests import factories, helpers

pytestmark = pytest.mark.usefixtures("with_plugins")


def test_package_similar_show_auth_public_dataset():

dataset = factories.Dataset()
context = {"user": ""}
assert helpers.call_auth("package_similar_show", context, id=dataset["id"])

user = factories.User()
context = {"user": user["name"]}
assert helpers.call_auth("package_similar_show", context, id=dataset["id"])


def test_package_similar_show_auth_private_dataset():

user1 = factories.User()
user2 = factories.User()
org = factories.Organization(users=[{"name": user1["name"], "capacity": "member"}])
dataset = factories.Dataset(private=True, owner_org=org["id"])
context = {"user": ""}
with pytest.raises(toolkit.NotAuthorized):
helpers.call_auth("package_similar_show", context, id=dataset["id"])

context = {"user": user2["name"]}
with pytest.raises(toolkit.NotAuthorized):
helpers.call_auth("package_similar_show", context, id=dataset["id"])

context = {"user": user1["name"]}
assert helpers.call_auth("package_similar_show", context, id=dataset["id"])

0 comments on commit 03e62c0

Please sign in to comment.