You are here

function scald_action_permitted in Scald: Media Management made easy 7

Same name and namespace in other branches
  1. 6 scald.module \scald_action_permitted()

Determines if a given User can act on a given Atom in a given way.

@codingStandardsIgnoreStart

Parameters

ScaldAtom $atom: A Scald Atom.

mixed $action: A Scald Action slug or an array of actions with operator AND or OR (by default). Examples:

  • 'fetch'
  • array('fetch', 'view', 'op' => 'AND').

object $account: A Drupal user account. Defaults to the current $user.

Return value

bool TRUE if the action is allowed, FALSE otherwise.

9 calls to scald_action_permitted()
EntityTranslationScaldHandler::getAccess in includes/scald.translation_handler.inc
Checks whether the current user has access to this product.
scald_atom_access in ./scald.module
Entity integration for access callback.
scald_atom_actions_available in ./scald.module
Builds an array of action available for a given atom.
scald_atom_add in includes/scald.pages.inc
Creates the page listing possible Scald Atom Types.
scald_atom_add_access in ./scald.module
Access callback for the atom add page.

... See full list

1 string reference to 'scald_action_permitted'
scald_menu in ./scald.module
Implements hook_menu().

File

./scald.module, line 1098
The Scald Core, which handles all Scald Registries and dispatch.

Code

function scald_action_permitted($atom, $action = 'fetch', $account = NULL) {

  // @codingStandardsIgnoreEnd
  if (is_array($action)) {
    $operator = !isset($actions['op']) || $actions['op'] !== 'AND' ? 'OR' : 'AND';
    foreach ($action as $key => $name) {

      // If the key is 'op', continue.
      if (!is_numeric($key)) {
        continue;
      }

      // If the decision can be taken immediately, do it.
      if (scald_action_permitted($atom, $name)) {
        if ($operator === 'OR') {
          return TRUE;
        }
      }
      else {
        if ($operator === 'AND') {
          return FALSE;
        }
      }
    }
    return $operator === 'OR' ? FALSE : TRUE;
  }

  // Check hook based permissions first, because role based permissions are
  // "ALLOW-like" and therefore can not negate hook based permission.
  $access = scald_invoke_atom_access($atom, $action, $account);
  if ($access === SCALD_ATOM_ACCESS_ALLOW) {
    return TRUE;
  }
  elseif ($access === SCALD_ATOM_ACCESS_DENY) {
    return FALSE;
  }
  $scald_actions = scald_actions();

  // If asked for an unknown action, simply return.
  if (!isset($scald_actions[$action])) {
    return FALSE;
  }
  return (bool) (scald_user_actions($atom, $account) & $scald_actions[$action]['bitmask']);
}