Add support for farm plan entity permissions in farm_access module.
This commit is contained in:
parent
cb25b4070f
commit
8818b1aad5
|
@ -55,6 +55,40 @@ function farm_asset_farm_access_perms($role) {
|
|||
return $perms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_farm_access_perms().
|
||||
*/
|
||||
function farm_plan_farm_access_perms($role) {
|
||||
$perms = array();
|
||||
|
||||
// Set up default CRUD permissions for all farm plan entity types.
|
||||
$plan_types = farm_plan_types();
|
||||
$access_types = array(
|
||||
'farm_plan' => array(),
|
||||
);
|
||||
foreach ($plan_types as $type => $data) {
|
||||
$access_types['farm_plan'][] = $type;
|
||||
}
|
||||
switch ($role) {
|
||||
|
||||
// Grant full access to Farm Manager and Worker roles.
|
||||
case 'Farm Manager':
|
||||
case 'Farm Worker':
|
||||
$perms = farm_access_entity_perms($access_types);
|
||||
break;
|
||||
|
||||
// Grant read-only access to Farm Viewer role.
|
||||
case 'Farm Viewer':
|
||||
$perms = farm_access_entity_perms($access_types, array('view'));
|
||||
break;
|
||||
}
|
||||
|
||||
// Grant access to view farm plans.
|
||||
$perms[] = 'view farm plans';
|
||||
|
||||
return $perms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_farm_access_perms().
|
||||
*/
|
||||
|
|
|
@ -270,6 +270,33 @@ function farm_access_entity_perms(array $types, $ops = array()) {
|
|||
}
|
||||
break;
|
||||
|
||||
// Farm Plan.
|
||||
case 'farm_plan':
|
||||
|
||||
// Create.
|
||||
if (in_array('create', $ops)) {
|
||||
$perms[] = 'create ' . $bundle . ' farm plans';
|
||||
}
|
||||
|
||||
// View.
|
||||
if (in_array('view', $ops)) {
|
||||
$perms[] = 'view any ' . $bundle . ' farm plans';
|
||||
$perms[] = 'view own ' . $bundle . ' farm plans';
|
||||
}
|
||||
|
||||
// Edit.
|
||||
if (in_array('edit', $ops)) {
|
||||
$perms[] = 'edit any ' . $bundle . ' farm plans';
|
||||
$perms[] = 'edit own ' . $bundle . ' farm plans';
|
||||
}
|
||||
|
||||
// Delete.
|
||||
if (in_array('delete', $ops)) {
|
||||
$perms[] = 'delete any ' . $bundle . ' farm plans';
|
||||
$perms[] = 'delete own ' . $bundle . ' farm plans';
|
||||
}
|
||||
break;
|
||||
|
||||
// Log.
|
||||
case 'log':
|
||||
|
||||
|
|
Loading…
Reference in New Issue