Api

Version

mediamosa-30

Class

mediamosa_rest_call_acl_collection_set_rights

Code

File: /sites/all/modules/mediamosa/modules/acl/mediamosa_acl.rest.class.inc
<?php


/**
 * URI: collection/$coll_id/acl
 * Method: POST
 */
class mediamosa_rest_call_acl_collection_set_rights extends mediamosa_rest_call {

  
// ------------------------------------------------------------------- Consts.
  // Rest vars;
  
const COLL_ID 'coll_id';
  const 
USER_ID 'user_id';
  const 
REPLACE 'replace';
  const 
ACL_APP 'acl_app';

  
// Aliases, do NOT use in code(!).
  
const ALIAS_AUT_APP 'aut_app';

  
// ------------------------------------------------------- Functions (public).
  
public function get_var_setup() {
    
$var_setup = array();

    
$var_setup[self::VARS][self::COLL_ID] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_COLLECTION_ID,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
      
self::VAR_DESCRIPTION => 'Collection ID',
    );

    
$var_setup[self::VARS][self::USER_ID] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_USER_ID,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
      
self::VAR_DESCRIPTION => 'User id, for authorization the changing  process.',
    );

    
$var_setup[self::VARS][self::REPLACE] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_BOOL,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_NO,
      
self::VAR_DEFAULT_VALUE => 'true',
      
self::VAR_DESCRIPTION => "'TRUE' or 'FALSE'. Whether the existing rules overwritten or not. Default is 'TRUE'. Defining it as 'FALSE', if you want to keep the old rights."
    
);

    
$var_setup[self::VARS][self::ACL_APP] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_APP_ID,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_NO,
      
self::VAR_IS_ARRAY => self::VAR_IS_ARRAY_YES,
      
self::VAR_DESCRIPTION => 'Application(s) that access to the collection.',
      
self::VAR_DEFAULT_VALUE => array(),
      
self::VAR_ALIAS_FOR => array(self::ALIAS_AUT_APP),
    );

    
// Enrich with required REST vars.
    
return self::get_var_setup_default($var_setup);
  }

  public function 
do_call() {
    
$mediamosa mediamosa::get();

    
// Get the app id(s).
    
$app_ids $this->get_param_value_app();
    
$collection_id $this->get_param_value(self::COLL_ID);
    
$user_id $this->get_param_value(self::USER_ID);
    
$is_app_admin $this->get_param_value(self::IS_APP_ADMIN);

    
// First is always the main app.
    
$app_id reset($app_ids);

    
// Make sure the media file exists
    
$a_collection mediamosa_db::db_must_exists(mediamosa_collection_db::TABLE_NAME, array(mediamosa_collection_db::ID => $collection_id));

    
$a_acl_app_ids $this->get_param_value(self::ACL_APP);
    
$b_replace $this->get_param_value(self::REPLACE);

    
// Set access rights
    
$result_rights_set mediamosa_acl::rights_set(
      
$app_id,
      
$user_id,
      
mediamosa_acl::ACL_TYPE_COLLECTION,
      
$a_collection,
      
$a_acl_app_ids,
      array(),
      array(),
      array(),
      array(),
      
$b_replace,
      array(
mediamosa_acl::RIGHT_ACCESS),
      
$is_app_admin
    
);

    if (
mediamosa::is_v3_output()) {
      
$types = array(
        
mediamosa_acl::ACL_NAME_TYPE_APP => 'acl_app',
      );
    }
    else {
      
$types = array(
        
mediamosa_acl::ACL_NAME_TYPE_APP => 'aut_app',
      );
    }

    foreach (
$result_rights_set as $error) {
      
$type = (isset($types[$error['type']]) ? $types[$error['type']] : 'unknown');

      if (
$error['a_error'] === FALSE) {
        
$mediamosa->add_item(
          array(
            
$type => array(
              
'value' => $error['value'],
              
'result' => mediamosa_response::SUCCESS,
              
'result_id' => mediamosa_error::ERRORCODE_OKAY,
              
'result_description' => '',
            )
          )
        );
      }
      else {
        
$mediamosa->add_item(
          array(
            
$type => array(
              
'value' => $error['value'],
              
'result' => mediamosa_response::ERROR,
              
'result_id' => $error['a_error']['code'],
              
'result_description' => $error['a_error']['message'],
            )
          )
        );
      }
    }
  }
}