Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
brienne
Developer Documentation
Commits
5dee4a74
Commit
5dee4a74
authored
8 years ago
by
Sean Madsen
Browse files
Options
Downloads
Patches
Plain Diff
hook_civicrm_alterAPIPermissions - clean up after content import
Fixes #79
parent
765bd9e4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/hooks/hook_civicrm_alterAPIPermissions.md
+35
-40
35 additions, 40 deletions
docs/hooks/hook_civicrm_alterAPIPermissions.md
with
35 additions
and
40 deletions
docs/hooks/hook_civicrm_alterAPIPermissions.md
+
35
−
40
View file @
5dee4a74
...
@@ -3,28 +3,31 @@
...
@@ -3,28 +3,31 @@
## Description
## Description
This hook is called when API 3 permissions are checked and can alter the
This hook is called when API 3 permissions are checked and can alter the
$permissions structure from CRM/Core/DAO/
.
permissions.php (as well as
`
$permissions
`
structure from
`
CRM/Core/DAO/permissions.php
`
(as well as
the API $params array) based on the $entity and $action (or
the API
`
$params
`
array) based on the
`
$entity
`
and
`
$action
`
(or
unconditionally).
unconditionally).
Note that if a given entity/action permissions are unset, the default
!!! Note
‘access CiviCRM’ permission is enforced.
If a given entity/action permissions are unset, the default
"access CiviCRM" permission is enforced.
Note also that the entity in $permissions array use the camel case
syntax (e.g. $permissions
[
'option_group'
][
'get'
]
= ... and not
$permissions
[
'OptionGroup'
][
'get'
]
= ...)
## Definition
## Definition
hook_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
```
php
hook_civicrm_alterAPIPermissions
(
$entity
,
$action
,
&
$params
,
&
$permissions
)
```
## Parameters
## Parameters
-
string $entity the API entity (like contact)
-
string
`
$entity
`
-
the API entity (like contact)
-
string $action the API action (like get)
-
string
`
$action
`
-
the API action (like get)
-
array &$params the API parameters
-
array
`
&$params
`
-
the API parameters
-
array &$permisisons the associative permissions array (probably to
-
array
`
&$permisisons
`
-
the associative permissions array (probably to
be altered by this hook)
be altered by this hook)
-
Note: the entity in
`$permissions`
array use the camel case
syntax (e.g.
`$permissions['option_group']['get'] = ...`
and not
`$permissions['OptionGroup']['get'] = ...`
)
## Returns
## Returns
...
@@ -36,39 +39,31 @@ $permissions['OptionGroup']['get'] = ...)
...
@@ -36,39 +39,31 @@ $permissions['OptionGroup']['get'] = ...)
## Example
## Example
/**
```
php
* alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
function
civitest_civicrm_alterAPIPermissions
(
$entity
,
$action
,
&
$params
,
&
$permissions
)
*/
{
function civitest_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
// skip permission checks for contact/create calls
{
// (but keep the ones for email, address, etc./create calls)
// skip permission checks for contact/create calls
// note: unsetting the below would require the default ‘access CiviCRM’ permission
// (but keep the ones for email, address, etc./create calls)
$permissions
[
'contact'
][
'create'
]
=
array
();
// note: unsetting the below would require the default ‘access CiviCRM’ permission
$permissions['contact']['create'] = array();
// enforce ‘view all contacts’ check for contact/get, but do not test ‘access CiviCRM’
// enforce ‘view all contacts’ check for contact/get, but do not test ‘access CiviCRM’
$permissions['contact']['get'] = array('view all contacts');
$permissions
[
'contact'
][
'get'
]
=
array
(
'view all contacts'
);
// add a new permission requirement for your own custom API call
// add a new permission requirement for your own custom API call
// (if all you want to enforce is ‘access CiviCRM’ you can skip the below altogether)
// (if all you want to enforce is ‘access CiviCRM’ you can skip the below altogether)
$permissions['foo']['get'] = array('access CiviCRM', 'get all foos');
$permissions
[
'foo'
][
'get'
]
=
array
(
'access CiviCRM'
,
'get all foos'
);
// allow everyone to get info for a given event; also – another way to skip permissions
// allow everyone to get info for a given event; also – another way to skip permissions
if ($entity == 'event' and $action == 'get' and $params['title'] == 'CiviCon 2038') {
if
(
$entity
==
'event'
and
$action
==
'get'
and
$params
[
'title'
]
==
'CiviCon 2038'
)
{
$params['check_permissions'] = false;
$params
[
'check_permissions'
]
=
false
;
}
}
}
}
```
## Notes on Example
When developing an extension with custom API, this code is placed
When developing an extension with custom API, this code is placed
directly in the API php file that you have created. In this case the
directly in the API php file that you have created. In this case the
extension would be named CiviTest. The API function for the GET would be
extension would be named CiviTest. The API function for the GET would be
:
function civicrm_api3_civi_test_get(); The alterAPIPermissions
`
function civicrm_api3_civi_test_get();
`
.
The
`
alterAPIPermissions
`
function is prefixed with the full extension name, all lowercase,
function is prefixed with the full extension name, all lowercase,
followed by "_civicrm_alterAPIPermissions".
followed by
`_civicrm_alterAPIPermissions`
.
There seems to be a bit of inconsistency between civiCRM 4.2.6 and
civiCRM 4.2.13. See attached screen.
\

\ No newline at end of file
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