You are here

protected function FarmAssetProcessor::entitySaveAccess in farmOS 7

Check that the user has permission to save a farm asset.

File

modules/farm/farm_asset/includes/feeds/plugins/FarmAssetProcessor.inc, line 71
Class definition of FarmAssetProcessor.

Class

FarmAssetProcessor
Creates farm assets from feed items.

Code

protected function entitySaveAccess($entity) {

  // The check will be skipped for anonymous assets.
  if ($this->config['authorize'] && !empty($entity->uid)) {
    $author = user_load($entity->uid);

    // If the uid was mapped directly, rather than by email or username, it
    // could be invalid.
    if (!$author) {
      $message = 'User %uid is not a valid user.';
      throw new FeedsAccessException(t($message, array(
        '%uid' => $entity->uid,
      )));
    }
    if (empty($entity->id) || !empty($entity->is_new)) {
      $op = 'create';
      $access = farm_asset_access($op, $entity->type, $author);
    }
    else {
      $op = 'update';
      $access = farm_asset_access($op, $entity, $author);
    }
    if (!$access) {
      $message = t('The user %name is not authorized to %op assets of type %content_type. To import this item, either the user "@name" (author of the item) must be given the permission to @op assets of type @content_type, or the option "Authorize" on the farm asset processor settings must be turned off.', array(
        '%name' => $author->name,
        '%op' => $op,
        '%content_type' => $entity->type,
        '@name' => $author->name,
        '@op' => $op,
        '@content_type' => $entity->type,
      ));
      throw new FeedsAccessException($message);
    }
  }
}