@@ -21,6 +21,7 @@ class EncryptionKeysController extends AppController
21
21
22
22
public function index ()
23
23
{
24
+ $ currentUser = $ this ->ACL ->getUser ();
24
25
$ this ->EncryptionKeys ->initializeGpg ();
25
26
$ Model = $ this ->EncryptionKeys ;
26
27
$ this ->CRUD ->index ([
@@ -33,7 +34,7 @@ public function index()
33
34
],
34
35
'contain ' => $ this ->containFields ,
35
36
'statisticsFields ' => $ this ->statisticsFields ,
36
- 'afterFind ' => function ($ data ) use ($ Model ) {
37
+ 'afterFind ' => function ($ data ) use ($ Model, $ currentUser ) {
37
38
if ($ data ['type ' ] === 'pgp ' ) {
38
39
$ keyInfo = $ Model ->verifySingleGPG ($ data );
39
40
$ data ['status ' ] = __ ('OK ' );
@@ -45,6 +46,7 @@ public function index()
45
46
$ data ['fingerprint ' ] = $ keyInfo [4 ];
46
47
}
47
48
}
49
+ $ data ['_canBeEdited ' ] = $ Model ->canEdit ($ currentUser , $ data );
48
50
return $ data ;
49
51
}
50
52
]);
@@ -96,24 +98,12 @@ private function buildBeforeSave(array $params, $currentUser, array &$orgConditi
96
98
}
97
99
$ params ['beforeSave ' ] = function ($ entity ) use ($ currentUser ) {
98
100
if ($ entity ['owner_model ' ] === 'organisation ' ) {
99
- if ($ entity [ ' owner_id ' ] !== $ currentUser[ ' organisation_id ' ] ) {
101
+ if (! $ this -> EncryptionKeys -> canEditForOrganisation ( $ currentUser, $ entity ) ) {
100
102
throw new MethodNotAllowedException (__ ('Selected organisation cannot be linked by the current user. ' ));
101
103
}
102
- } else {
103
- if ($ currentUser ['role ' ]['perm_org_admin ' ]) {
104
- $ this ->loadModel ('Alignments ' );
105
- $ validIndividuals = $ this ->Alignments ->find ('list ' , [
106
- 'keyField ' => 'individual_id ' ,
107
- 'valueField ' => 'id ' ,
108
- 'conditions ' => ['organisation_id ' => $ currentUser ['organisation_id ' ]]
109
- ])->toArray ();
110
- if (!isset ($ validIndividuals [$ entity ['owner_id ' ]])) {
111
- throw new MethodNotAllowedException (__ ('Selected individual cannot be linked by the current user. ' ));
112
- }
113
- } else {
114
- if ($ entity ['owner_id ' ] !== $ currentUser ['id ' ]) {
115
- throw new MethodNotAllowedException (__ ('Selected individual cannot be linked by the current user. ' ));
116
- }
104
+ } else if ($ entity ['owner_model ' ] === 'individual ' ) {
105
+ if (!$ this ->EncryptionKeys ->canEditForIndividual ($ currentUser , $ entity )) {
106
+ throw new MethodNotAllowedException (__ ('Selected individual cannot be linked by the current user. ' ));
117
107
}
118
108
}
119
109
return $ entity ;
0 commit comments