-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix permissions for non-logged in users in dataset page
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |