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

export permissions fixes #965

Merged
merged 1 commit into from
Feb 2, 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
4 changes: 2 additions & 2 deletions app/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def current_user_has_export_permission(self):
from app.modules.users.permissions.rules import ObjectActionRule
from app.modules.users.permissions.types import AccessOperation

rule = ObjectActionRule(obj=self, action=AccessOperation.READ)
rule = ObjectActionRule(obj=self, action=AccessOperation.EXPORT)
return rule.check()

def current_user_has_edit_permission(self):
Expand All @@ -512,7 +512,7 @@ def user_has_export_permission(self, user):
from app.modules.users.permissions.rules import ObjectActionRule
from app.modules.users.permissions.types import AccessOperation

rule = ObjectActionRule(obj=self, action=AccessOperation.READ, user=user)
rule = ObjectActionRule(obj=self, action=AccessOperation.EXPORT, user=user)
return rule.check()

def user_has_view_permission(self, user):
Expand Down
27 changes: 24 additions & 3 deletions tests/modules/collaborations/resources/test_collaboration_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
module_unavailable('collaborations'), reason='Collaborations module disabled'
)
def test_use_collaboration(
flask_app_client, researcher_1, researcher_2, admin_user, test_root, db, request
flask_app_client,
researcher_1,
researcher_2,
admin_user,
user_manager_user,
test_root,
db,
request,
):
from app.modules.sightings.models import Sighting

Expand All @@ -33,6 +40,7 @@ def test_use_collaboration(
assert sighting.user_has_export_permission(researcher_1)
assert not sighting.user_has_view_permission(researcher_2)
assert not sighting.user_has_export_permission(researcher_2)
assert not sighting.user_has_export_permission(user_manager_user)

# should not work and should give informative error
ags_resp = asset_group_utils.read_asset_group_sighting(
Expand All @@ -44,7 +52,20 @@ def test_use_collaboration(
)
assert ags_resp['message'] == access_error

# create a (view) collab and approve
# create a (view) collab (between researcher1 and user_manager_user) and approve
create_resp = collab_utils.create_simple_collaboration(
flask_app_client, researcher_1, user_manager_user
)
collab_guid = create_resp.json['guid']
collab = collab_utils.get_collab_object_for_user(researcher_1, collab_guid)
request.addfinalizer(collab.delete)
collab_utils.approve_view_on_collaboration(
flask_app_client, collab_guid, user_manager_user, researcher_1
)
assert sighting.user_has_view_permission(user_manager_user)
assert not sighting.user_has_export_permission(user_manager_user)

# create a (view) collab (between researchers) and approve
create_resp = collab_utils.create_simple_collaboration(
flask_app_client, researcher_1, researcher_2
)
Expand All @@ -58,7 +79,7 @@ def test_use_collaboration(
assert sighting.user_has_view_permission(researcher_1)
assert sighting.user_has_export_permission(researcher_1)
assert sighting.user_has_view_permission(researcher_2)
assert sighting.user_has_export_permission(researcher_2)
assert not sighting.user_has_export_permission(researcher_2)

# Researcher 2 should be able to view all the data but edit none of it
asset_group_utils.read_asset_group(flask_app_client, researcher_2, asset_group_uuid)
Expand Down
Loading