/** * Introspect ACL models and make them available. */ public function beforeFilter() { parent::beforeFilter(); $this->Aco = Admin::introspectModel('Admin.ControlObject'); $this->Aro = Admin::introspectModel('Admin.RequestObject'); $this->Permission = Admin::introspectModel('Admin.ObjectPermission'); $this->Permission->cacheQueries = false; }
/** * Validate the user is authorized. * * @param array $user * @return bool * @throws ForbiddenException * @throws UnauthorizedException */ public function isAuthorized($user = null) { if (!$user) { throw new ForbiddenException(__d('admin', 'Invalid User')); } $aro = Admin::introspectModel('Admin.RequestObject'); if ($aro->isAdmin($user['id'])) { if (!$this->Session->read('Admin.crud')) { $this->Session->write('Admin.crud', $aro->getCrudPermissions($user['id'])); } return true; } throw new UnauthorizedException(__d('admin', 'Insufficient Access Permissions')); }
/** * List out all models and plugins. */ public function index() { $plugins = Admin::getModels(); $counts = array(); // Gather record counts foreach ($plugins as $plugin) { foreach ($plugin['models'] as $model) { if ($model['installed']) { $object = Admin::introspectModel($model['class']); if ($object->hasMethod('getCount')) { $count = $object->getCount(); } else { $count = $object->find('count', array('cache' => array($model['class'], 'count'), 'cacheExpires' => '+24 hours')); } $counts[$model['class']] = $count; } } } $this->set('plugins', $plugins); $this->set('counts', $counts); }
/** * Admin override for Forum model delete action. * Provides support for moving topics and forums to a new forum. * * @param int $id * @throws NotFoundException */ public function admin_delete($id) { $this->Model = Admin::introspectModel('Forum.Forum'); $this->Model->id = $id; $result = $this->AdminToolbar->getRecordById($this->Model, $id); if (!$result) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } if ($this->request->is('post')) { if ($this->Model->delete($id, true)) { $this->Forum->Topic->moveAll($id, $this->request->data['Forum']['move_topics']); $this->Forum->moveAll($id, $this->request->data['Forum']['move_forums']); $this->AdminToolbar->logAction(ActionLog::DELETE, $this->Model, $id); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully deleted %s with ID %s', array(mb_strtolower($this->Model->singularName), $id))); $this->AdminToolbar->redirectAfter($this->Model); } else { $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to delete %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)), 'error'); } } // Get tree excluding this record $forums = $this->Model->generateTreeList(array('Forum.id !=' => $id), null, null, ' -- '); $this->set('result', $result); $this->set('moveTopics', $forums); $this->set('moveForums', $forums); }
/** * Return a list of all models within a plugin. * * @param string $plugin * @return array */ public static function getPluginModels($plugin) { return self::cache(array(__METHOD__, $plugin), function () use($plugin) { $search = 'Model'; $core = Configure::read('Admin.coreName') ?: 'Core'; if ($plugin !== $core) { $search = $plugin . '.' . $search; } // Fetch models and filter out AppModel's $models = array_filter(App::objects($search), function ($value) { return mb_strpos($value, 'AppModel') === false; }); // Filter out models that don't connect to the database or are admin disabled $map = array(); $ignore = Configure::read('Admin.ignoreModels'); foreach ($models as $model) { list($plugin, $model, $id, $class) = Admin::parseName($plugin . '.' . $model); if (in_array($id, $ignore)) { continue; } $object = Admin::introspectModel($id); if (!$object) { continue; } $map[] = array_merge($object->admin, array('id' => $id, 'title' => $object->pluralName, 'alias' => $model, 'class' => $class, 'url' => Inflector::underscore($id), 'installed' => Admin::isModelInstalled($id), 'group' => $object->useDbConfig)); } return $map; }); }
/** * Before filter. */ public function beforeFilter() { parent::beforeFilter(); $this->Model = Admin::introspectModel('Admin.ActionLog'); }
/** * Return a modified model object. * * @param string $model * @return Model */ public function introspect($model) { return Admin::introspectModel($model); }
/** * Before filter. */ public function beforeFilter() { parent::beforeFilter(); $this->Model = Admin::introspectModel('Admin.ItemReport'); }
/** * Set hasAndBelongsToMany data for forms. This allows for saving of associated data. * * @param Model $model */ public function setHabtmData(Model $model) { foreach ($model->hasAndBelongsToMany as $assoc) { if (!$assoc['showInForm']) { continue; } $object = Admin::introspectModel($assoc['className']); $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['associationForeignKey']))); $this->Controller->set($variable, $this->getRecordList($object)); } }
/** * Before filter. */ public function beforeFilter() { parent::beforeFilter(); // Introspect model if (isset($this->params['model'])) { $this->Model = Admin::introspectModel($this->params['model']); if (!$this->Model) { throw new ForbiddenException(__d('admin', 'Invalid Model')); } } // Parse request and set null fields to null if ($data = $this->request->data) { foreach ($data as $model => $fields) { foreach ($fields as $key => $value) { if (mb_substr($key, -5) === '_null' && $value) { $data[$model][str_replace('_null', '', $key)] = null; } } } $this->request->data = $data; } // Don't validate post since data changes constantly $this->Security->validatePost = false; }