Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
justinfreeman (Agileware)
Core
Commits
79089019
Commit
79089019
authored
12 years ago
by
colemanw
Browse files
Options
Downloads
Patches
Plain Diff
Implement defaults and action equivalents for api perms CRM-11817
parent
082d771a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CRM/Core/DAO/permissions.php
+53
-1
53 additions, 1 deletion
CRM/Core/DAO/permissions.php
with
53 additions
and
1 deletion
CRM/Core/DAO/permissions.php
+
53
−
1
View file @
79089019
...
...
@@ -39,8 +39,33 @@
function
_civicrm_api3_permissions
(
$entity
,
$action
,
&
$params
)
{
$entity
=
strtolower
(
$entity
);
$action
=
strtolower
(
$action
);
/**
* @var array of permissions
*
* For each entity, we declare an array of permissions required for each action
* The action is the array key, possible values:
* * create: applies to create (with no id in params)
* * update: applies to update, setvalue, create (with id in params)
* * get: applies to getcount, getsingle, getvalue and other gets
* * delete: applies to delete, replace
* * meta: applies to getfields, getoptions, getspec
* * default: catch-all for anything not declared
*
* Note: some APIs declare other actions as well
*/
$permissions
=
array
();
// These are the default permissions - if any entity does not declare permissions for a given action,
// (or the entity does not declare permissions at all) - then the action will be used from here
$permissions
[
'default'
]
=
array
(
// applies to getfields, getoptions, etc.
'meta'
=>
array
(
'access CiviCRM'
),
// catch-all, applies to create, get, delete, etc.
// If an entity declares it's own 'default' action it will override this one
'default'
=>
array
(
'administer CiviCRM'
),
);
$permissions
[
'activity'
]
=
array
(
'delete'
=>
array
(
'access CiviCRM'
,
...
...
@@ -550,10 +575,37 @@ function _civicrm_api3_permissions($entity, $action, &$params) {
),
);
// Translate 'create' action to 'update' if id is set
if
(
$action
==
'create'
&&
(
!
empty
(
$params
[
'id'
])
||
!
empty
(
$params
[
$entity
.
'_id'
])))
{
$action
=
'update'
;
}
// let third parties modify the permissions
CRM_Utils_Hook
::
alterAPIPermissions
(
$entity
,
$action
,
$params
,
$permissions
);
return
isset
(
$permissions
[
$entity
][
$action
])
?
$permissions
[
$entity
][
$action
]
:
array
(
'administer CiviCRM'
);
// Merge permissions for this entity with the defaults
$perm
=
CRM_Utils_Array
::
value
(
$entity
,
$permissions
,
array
())
+
$permissions
[
'default'
];
// Return exact match if permission for this action has been declared
if
(
isset
(
$perm
[
$action
]))
{
return
$perm
[
$action
];
}
// Translate specific actions into their generic equivalents
$snippet
=
substr
(
$action
,
0
,
3
);
if
(
$action
==
'replace'
||
$snippet
==
'del'
)
{
$action
=
'delete'
;
}
elseif
(
$action
==
'setvalue'
||
$snippet
==
'upd'
)
{
$action
=
'update'
;
}
elseif
(
$action
==
'getfields'
||
$action
==
'getspec'
||
$action
==
'getoptions'
)
{
$action
=
'meta'
;
}
elseif
(
$snippet
==
'get'
)
{
$action
=
'get'
;
}
return
isset
(
$perm
[
$action
])
?
$perm
[
$action
]
:
$perm
[
'default'
];
}
# FIXME: not sure how to permission the following API 3 calls:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment