Skip to content

Commit 5397ae8

Browse files
authored
Merge pull request civicrm#33358 from rbaugh/issue5879
dev/core#5879 Extending Afform UI Permissions
2 parents 6b3a889 + df418e9 commit 5397ae8

19 files changed

Lines changed: 185 additions & 41 deletions

ext/afform/admin/Civi/AfformAdmin/AfformAdminInjector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function preprocess($e) {
4949
'url' => \CRM_Utils_System::url('civicrm/admin/afform', NULL, FALSE, "/edit/{$afform['name']}", TRUE, FALSE, TRUE),
5050
'text' => E::ts('Edit %1 in FormBuilder', [1 => "<em>{$afform['title']}</em>"]),
5151
'icon' => 'fa-pencil',
52-
'permission' => 'administer afform',
52+
'permission' => 'manage own afform',
5353
],
5454
];
5555
if ($afform['search_displays']) {

ext/afform/admin/ang/afAdmin.ang.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
'settingsFactory' => ['Civi\AfformAdmin\AfformAdminMeta', 'getAdminSettings'],
1313
'basePages' => ['civicrm/admin/afform'],
1414
'bundles' => ['bootstrap3'],
15+
'permissions' => [
16+
'administer afform',
17+
'manage own afform',
18+
],
1519
];

ext/afform/admin/ang/afAdmin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Load data for lists
1212
afforms: function(crmApi4) {
1313
return crmApi4('Afform', 'get', {
14-
select: ['name', 'title', 'type', 'server_route', 'is_public', 'submission_count', 'submission_date', 'submit_limit', 'submit_enabled', 'submit_currently_open', 'has_local', 'has_base', 'base_module', 'base_module:label', 'placement:label', 'tags:label']
14+
select: ['name', 'title', 'type', 'server_route', 'is_public', 'submission_count', 'submission_date', 'submit_limit', 'submit_enabled', 'submit_currently_open', 'has_local', 'has_base', 'base_module', 'base_module:label', 'placement:label', 'tags:label', 'created_id']
1515
});
1616
}
1717
}

ext/afform/admin/ang/afAdmin/afAdminList.controller.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
if (afform.submission_date) {
3030
afform.submission_date = CRM.utils.formatDate(afform.submission_date);
3131
}
32+
afform.can_manage = CRM.checkPerm('administer afform');
33+
// Check for ownership and correct permission
34+
if (afform.created_id) {
35+
// Permission, manage own afform, is to only manage afform's the user created
36+
if (CRM.checkPerm('manage own afform') && (CRM.config.cid === afform.created_id)) {
37+
afform.can_manage = true;
38+
}
39+
} else if (CRM.checkPerm('manage own afform')) {
40+
// No created_id, so user doesn't have permission to manage.
41+
afform.can_manage = false;
42+
}
3243
afforms[afform.type] = afforms[afform.type] || [];
3344
afforms[afform.type].push(afform);
3445
}, {});
@@ -107,7 +118,7 @@
107118
}, 0]);
108119
}
109120
var apiCall = crmStatus(
110-
afform.has_base ? {start: ts('Reverting...')} : {start: ts('Deleting...'), success: ts('Deleted')},
121+
afform.has_base ? {start: ts('Reverting...')} : {start: ts('Deleting...'), success: ts('Deleted'), error: ts('Error deleting')},
111122
crmApi4(apiOps)
112123
);
113124
if (afform.has_base) {
@@ -116,7 +127,9 @@
116127
ctrl.afforms[ctrl.tab][index] = result[1];
117128
});
118129
} else {
119-
ctrl.afforms[ctrl.tab].splice(index, 1);
130+
apiCall.then(function() {
131+
ctrl.afforms[ctrl.tab].splice(index, 1);
132+
});
120133
}
121134
}
122135
};

ext/afform/admin/ang/afAdmin/afAdminList.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ <h1 crm-page-title>{{:: ts('FormBuilder') }}</h1>
119119
{{:: afform.tags.join(', ') }}
120120
</td>
121121
<td class="text-right">
122-
<a ng-if="afform.type !== 'system'" ng-href="#/edit/{{:: afform.name }}" class="btn btn-xs btn-primary">{{:: ts('Edit') }}</a>
122+
<a ng-if="afform.type !== 'system' && afform.can_manage" ng-href="#/edit/{{:: afform.name }}" class="btn btn-xs btn-primary">{{:: ts('Edit') }}</a>
123123
<a ng-if="afform.type !== 'system'" ng-href="#/clone/{{:: afform.name }}" class="btn btn-xs btn-secondary">{{:: ts('Clone') }}</a>
124-
<a href ng-if="afform.has_local" class="btn btn-xs btn-{{ afform.has_base ? 'warning' : 'danger' }}" crm-confirm="{type: afform.has_base ? 'revert' : 'delete', obj: afform}" on-yes="$ctrl.revert(afform)">
124+
<a href ng-if="afform.has_local && afform.can_manage" class="btn btn-xs btn-{{ afform.has_base ? 'warning' : 'danger' }}" crm-confirm="{type: afform.has_base ? 'revert' : 'delete', obj: afform}" on-yes="$ctrl.revert(afform)">
125125
{{ afform.has_base ? ts('Revert') : ts('Delete') }}
126126
</a>
127127
</td>

ext/afform/admin/ang/afAdminFormSubmissionList.aff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
'type' => 'system',
66
'title' => E::ts('Submissions'),
77
'server_route' => 'civicrm/admin/afform/submissions',
8-
'permission' => ['administer afform'],
8+
'permission' => ['manage own afform'],
99
];

ext/afform/admin/managed/Navigation_afform_admin.mgd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'name' => 'afform_admin',
1414
'label' => E::ts('FormBuilder'),
1515
'permission' => [
16-
'administer afform',
16+
'manage own afform',
1717
],
1818
'parent_id.name' => 'Customize Data and Screens',
1919
'weight' => 1,

ext/afform/admin/xml/Menu/afform_admin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<item>
44
<path>civicrm/admin/afform</path>
55
<page_callback>CRM_AfformAdmin_Page_Base</page_callback>
6-
<access_arguments>administer afform</access_arguments>
6+
<access_arguments>manage own afform</access_arguments>
77
</item>
88
</menu>

ext/afform/core/Civi/Api4/Action/Afform/Revert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function doTask($item) {
8484
* @return string[]
8585
*/
8686
protected function getSelect() {
87-
return ['name', 'title', 'placement', 'server_route'];
87+
return ['name', 'title', 'placement', 'server_route', 'created_id'];
8888
}
8989

9090
}

ext/afform/core/Civi/Api4/Afform.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ public static function getFields($checkPermissions = TRUE) {
309309
'title' => E::ts('Confirmation Message'),
310310
'input_type' => 'Text',
311311
],
312+
[
313+
'name' => 'created_id',
314+
'title' => ts('Created By Contact ID'),
315+
'data_type' => 'Integer',
316+
'fk_entity' => 'Contact',
317+
'fk_column' => 'id',
318+
'input_type' => 'EntityRef',
319+
'label' => ts('Created By'),
320+
'default_value' => NULL,
321+
'readonly' => TRUE,
322+
'required' => FALSE,
323+
],
312324
];
313325
// Calculated fields returned by get action
314326
if ($self->getAction() === 'get') {
@@ -390,7 +402,7 @@ public static function getFields($checkPermissions = TRUE) {
390402
public static function permissions() {
391403
return [
392404
'meta' => ['access CiviCRM'],
393-
'default' => ['administer afform'],
405+
'default' => ['manage own afform'],
394406
// These all check form-level permissions
395407
'get' => [],
396408
'getOptions' => [],

0 commit comments

Comments
 (0)