public function index()
 {
     return MagmaAccess::getAccessRules();
 }
 public function testGetPermissions()
 {
     // Should get crud permissions for each model
     $perms = MagmaAccess::getAccessRules();
 }
Beispiel #3
0
 /**
  * Update a model record
  * Returns updated resource in basic form
  * @param string $model
  *   A model class e.g. User
  * @param integer $id
  *   ID of the model record
  * @param array $values
  *   Any values to explicitly set and/or override hydration
  * @return Response
  */
 public static function update($model, $id, $values = [], $onSuccess = null)
 {
     $record = $model::find($id);
     if (!$record) {
         return Response::json(['errors' => [ucwords($model) . ' not found']], 403);
     }
     $record->autoHydrateEntityFromInput = false;
     $record->forceEntityHydrationFromInput = false;
     $record->autoPurgeRedundantAttributes = true;
     $relations = static::getRelations($record);
     $input = Input::all();
     if ($input) {
         $fill = [];
         foreach ($input as $key => $value) {
             if ($relations && isset($relations[$key])) {
                 continue;
             }
             if (MagmaAccess::accessField($record, 'update', $key)) {
                 $fill[$key] = $value;
             }
         }
         $record->fill($fill);
     }
     if ($values) {
         foreach ($values as $key => $value) {
             $record->{$key} = $value;
         }
     }
     $values = array_merge($input, $values);
     if (!MagmaAccess::access($record, 'update')) {
         return static::responseAccessDenied();
     }
     if ($record->updateUniques()) {
         // Update relations
         static::syncRelations($record, $values, 'update');
         if ($onSuccess) {
             // If success callback returns something, return that instead of record
             $return = $onSuccess($record);
             if ($return) {
                 return $return;
             }
         }
         return $record;
     }
     return Response::json(['errors' => $record->errors()->all(':message')], 403);
 }