From 27bd8b305b5a20c0442d8d0c0d8eefda11e3afe5 Mon Sep 17 00:00:00 2001 From: Olivier Leger Date: Fri, 14 May 2021 15:03:10 -0400 Subject: [PATCH 1/5] Imply "add_submissions" when choosing "change_submissions" --- jsapp/js/components/permissions/permissionsMocks.es6 | 3 ++- jsapp/js/components/permissions/userAssetPermsEditor.es6 | 5 +++++ kpi/models/asset.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/jsapp/js/components/permissions/permissionsMocks.es6 b/jsapp/js/components/permissions/permissionsMocks.es6 index ccd9115b88..5cc6f457ab 100644 --- a/jsapp/js/components/permissions/permissionsMocks.es6 +++ b/jsapp/js/components/permissions/permissionsMocks.es6 @@ -33,7 +33,8 @@ const permissions = { 'codename': 'change_submissions', 'implied': [ '/api/v2/permissions/view_asset/', - '/api/v2/permissions/view_submissions/' + '/api/v2/permissions/view_submissions/', + '/api/v2/permissions/add_submissions/' ], 'contradictory': [ '/api/v2/permissions/partial_submissions/' diff --git a/jsapp/js/components/permissions/userAssetPermsEditor.es6 b/jsapp/js/components/permissions/userAssetPermsEditor.es6 index 273be13456..7f231c2a5b 100644 --- a/jsapp/js/components/permissions/userAssetPermsEditor.es6 +++ b/jsapp/js/components/permissions/userAssetPermsEditor.es6 @@ -160,6 +160,11 @@ class UserAssetPermsEditor extends React.Component { stateObj.formViewDisabled = true; } + // checking `submissionsEdit` implies having `submissionsAdd` checked + if (stateObj.submissionsEdit) { + stateObj.submissionsAdd = true; + } + // checking these options implies having `submissionsView` checked if ( stateObj.submissionsDelete || diff --git a/kpi/models/asset.py b/kpi/models/asset.py index 5c7798b890..ca065313d7 100644 --- a/kpi/models/asset.py +++ b/kpi/models/asset.py @@ -630,7 +630,10 @@ class Meta: PERM_ADD_SUBMISSIONS: (PERM_VIEW_ASSET,), PERM_VIEW_SUBMISSIONS: (PERM_VIEW_ASSET,), PERM_PARTIAL_SUBMISSIONS: (PERM_VIEW_ASSET,), - PERM_CHANGE_SUBMISSIONS: (PERM_VIEW_SUBMISSIONS,), + PERM_CHANGE_SUBMISSIONS: ( + PERM_VIEW_SUBMISSIONS, + PERM_ADD_SUBMISSIONS, + ), PERM_DELETE_SUBMISSIONS: (PERM_VIEW_SUBMISSIONS,), PERM_VALIDATE_SUBMISSIONS: (PERM_VIEW_SUBMISSIONS,), } From 74ceb4fa77aa06bcd295d87413ce15df64147c01 Mon Sep 17 00:00:00 2001 From: Olivier Leger Date: Fri, 14 May 2021 15:27:27 -0400 Subject: [PATCH 2/5] Revert permission for duplication to "change_submissions" only --- jsapp/js/components/modalForms/submission.es6 | 1 - kpi/permissions.py | 5 +---- kpi/tests/api/v2/test_api_submissions.py | 14 +++----------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/jsapp/js/components/modalForms/submission.es6 b/jsapp/js/components/modalForms/submission.es6 index ed0d16a64c..697801a1aa 100644 --- a/jsapp/js/components/modalForms/submission.es6 +++ b/jsapp/js/components/modalForms/submission.es6 @@ -457,7 +457,6 @@ class Submission extends React.Component { } {this.userCan('change_submissions', this.props.asset) && - this.userCan('add_submissions', this.props.asset) && Date: Fri, 14 May 2021 15:28:11 -0400 Subject: [PATCH 3/5] Fixed typos --- jsapp/js/actions.es6 | 2 +- jsapp/js/components/assetrow.es6 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jsapp/js/actions.es6 b/jsapp/js/actions.es6 index 86cf9e83f9..ad8ebc88f8 100644 --- a/jsapp/js/actions.es6 +++ b/jsapp/js/actions.es6 @@ -539,7 +539,7 @@ actions.resources.duplicateSubmission.listen((uid, sid, duplicatedSubmission) => actions.resources.loadAsset({id: uid}); }) .fail((response) => { - alertify.error(t('Failed to duplicate submisson')); + alertify.error(t('Failed to duplicate submission')); actions.resources.duplicateSubmission.failed(response); }); }); diff --git a/jsapp/js/components/assetrow.es6 b/jsapp/js/components/assetrow.es6 index b312e3a294..2b6df8797c 100644 --- a/jsapp/js/components/assetrow.es6 +++ b/jsapp/js/components/assetrow.es6 @@ -203,7 +203,7 @@ class AssetRow extends React.Component { { this.props.asset_type == ASSET_TYPES.survey.id && { From e7c077a4334b5474203694a93ef62bc82df3134b Mon Sep 17 00:00:00 2001 From: Olivier Leger Date: Fri, 14 May 2021 15:29:05 -0400 Subject: [PATCH 4/5] Fixed tests to support new implied permission --- kpi/tests/test_permissions.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kpi/tests/test_permissions.py b/kpi/tests/test_permissions.py index a655549e56..fc5cf365da 100644 --- a/kpi/tests/test_permissions.py +++ b/kpi/tests/test_permissions.py @@ -1,4 +1,5 @@ # coding: utf-8 +import unittest from django.contrib.auth.models import User, AnonymousUser from django.test import TestCase @@ -256,7 +257,11 @@ def test_implied_asset_grant_permissions(self): PERM_CHANGE_ASSET: (PERM_VIEW_ASSET,), PERM_ADD_SUBMISSIONS: (PERM_VIEW_ASSET,), PERM_VIEW_SUBMISSIONS: (PERM_VIEW_ASSET,), - PERM_CHANGE_SUBMISSIONS: (PERM_VIEW_ASSET, PERM_VIEW_SUBMISSIONS), + PERM_CHANGE_SUBMISSIONS: ( + PERM_VIEW_ASSET, + PERM_VIEW_SUBMISSIONS, + PERM_ADD_SUBMISSIONS, + ), PERM_VALIDATE_SUBMISSIONS: (PERM_VIEW_ASSET, PERM_VIEW_SUBMISSIONS), } asset = self.admin_asset @@ -293,6 +298,7 @@ def test_remove_implied_asset_permissions(self): PERM_VIEW_ASSET, PERM_VIEW_SUBMISSIONS, PERM_CHANGE_SUBMISSIONS, + PERM_ADD_SUBMISSIONS, ] self.assertListEqual( sorted(asset.get_perms(grantee)), sorted(expected_perms) @@ -394,7 +400,7 @@ def test_contradict_implied_asset_deny_permissions(self): ) expected_perms = [ # codename, deny - (PERM_ADD_SUBMISSIONS, True), + (PERM_ADD_SUBMISSIONS, False), (PERM_CHANGE_ASSET, True), (PERM_CHANGE_SUBMISSIONS, False), (PERM_DELETE_SUBMISSIONS, True), @@ -473,6 +479,7 @@ def test_calculated_submission_editor_permissions(self): grantee = self.someuser asset = self.admin_asset submission_editor_permissions = [ + PERM_ADD_SUBMISSIONS, PERM_CHANGE_SUBMISSIONS, PERM_VIEW_ASSET, PERM_VIEW_SUBMISSIONS, @@ -715,6 +722,8 @@ def test_remove_partial_submission_permission(self): self.assertFalse(grantee.has_perm(PERM_PARTIAL_SUBMISSIONS, asset)) self.assertTrue(asset.asset_partial_permissions.count() == 0) + @unittest.skip(reason='Skip until this branch is merged within ' + '`3115-allowed-write-actions-with-partial-perm`') def test_implied_partial_submission_permission(self): """ This test is present even though we can only restrict users to view From 1e943da5079a3caea85d9b82cc5ca7fe72ec6079 Mon Sep 17 00:00:00 2001 From: noliveleger Date: Wed, 19 May 2021 10:34:07 -0400 Subject: [PATCH 5/5] Update userAssetPermsEditor.es6 Disable "Add submissions" when clicking "Edit submissions" --- jsapp/js/components/permissions/userAssetPermsEditor.es6 | 1 + 1 file changed, 1 insertion(+) diff --git a/jsapp/js/components/permissions/userAssetPermsEditor.es6 b/jsapp/js/components/permissions/userAssetPermsEditor.es6 index 7f231c2a5b..0320792528 100644 --- a/jsapp/js/components/permissions/userAssetPermsEditor.es6 +++ b/jsapp/js/components/permissions/userAssetPermsEditor.es6 @@ -163,6 +163,7 @@ class UserAssetPermsEditor extends React.Component { // checking `submissionsEdit` implies having `submissionsAdd` checked if (stateObj.submissionsEdit) { stateObj.submissionsAdd = true; + stateObj.submissionsAddDisabled = true; } // checking these options implies having `submissionsView` checked