function cacheflush_ui_access in CacheFlush 7.3
Determines whether the given user can perform actions on cacheflush entity.
For create operations, the pattern is to create an entity and then check if the user has create access.
Parameters
string $op: The operation being performed. One of 'view', 'update', 'create', 'clear' or 'delete'.
object $entity: Optionally an entity to check access for. If no entity is given, it will be determined whether access is allowed for all entities of the given type.
object $account: The user to check for. Leave it to NULL to check for the global user.
Return value
bool Whether access is allowed or not. If the entity type does not specify any access information, NULL is returned.
See also
1 call to cacheflush_ui_access()
- CacheflushUIController::overviewTable in modules/
cacheflush_ui/ includes/ cacheflush_ui.class.inc - Overrides EntityDefaultUIController::overviewTable().
2 string references to 'cacheflush_ui_access'
- cacheflush_ui_entity_info_alter in modules/
cacheflush_ui/ cacheflush_ui.module - Implements hook_entity_info_alter().
- cacheflush_ui_menu in modules/
cacheflush_ui/ cacheflush_ui.module - Implements hook_menu().
File
- modules/
cacheflush_ui/ cacheflush_ui.module, line 236 - Cacheflush User Interface.
Code
function cacheflush_ui_access($op, $entity, $account = NULL) {
global $user;
$rights =& drupal_static(__FUNCTION__, array());
if (empty($account)) {
$account = $user;
}
// User #1 has all privileges:
if ($account->uid == 1) {
return TRUE;
}
if (is_numeric($entity)) {
$entity = cacheflush_load($entity);
}
elseif (empty($entity)) {
$entity = new stdClass();
$entity->id = 0;
}
// If we've already checked access for this preset, user and op, return from
// cache.
if (isset($rights[$account->uid][$entity->id][$op])) {
return $rights[$account->uid][$entity->id][$op];
}
switch ($op) {
case 'create':
$rights[$account->uid][$entity->id][$op] = user_access("cacheflush create new", $account);
break;
case 'clear':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush clear any', 'cacheflush clear own', $account, $entity);
break;
case 'view':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush view any', 'cacheflush view own', $account, $entity);
break;
case 'update':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush edit any', 'cacheflush edit own', $account, $entity);
break;
case 'delete':
$rights[$account->uid][$entity->id][$op] = cacheflush_ui_access_single_many('cacheflush delete any', 'cacheflush delete own', $account, $entity);
break;
}
return $rights[$account->uid][$entity->id][$op];
}