public function requireDefaultRecords() { parent::requireDefaultRecords(); $existing = DataObject::get('AccessRole'); if ($existing && $existing->count()) { return; } $dp = self::allPermissions(); $role = new AccessRole(); $role->Title = 'Admin'; $role->Composes = array_values($dp); $role->write(); $ownerPerms = $dp; // get rid of publish from owners unset($ownerPerms['Publish']); $role = new AccessRole(); $role->Title = 'Owner'; $role->Composes = array_keys($ownerPerms); $role->write(); unset($dp['TakeOwnership']); unset($dp['Configure']); $role = new AccessRole(); $role->Title = 'Manager'; $role->Composes = array_keys($dp); $role->write(); $role = new AccessRole(); $role->Title = 'Editor'; $role->Composes = array('View', 'Write', 'CreateChildren'); $role->write(); }
/** * Sets up all the roles and their hierarchy with all the elements that the * module is able to provide in the installation. * * @param string $moduleid */ public function actionModule($moduleid) { $module = YiiPlug::app()->getAutoloadedModule($moduleid); if ($module === null) { throw new CException(Yii::t('access.install', 'Impossible to find the module {id}.', array('{id}' => $moduleid))); } /* @var $accessModule AccessModule */ $accessModule = $this->getModule(); try { $transaction = AccessRole::model()->getDbConnection()->beginTransaction(); $accessModule->registerAuthHierarchyFromModule($module); $transaction->commit(); } catch (CDbException $e) { try { $transaction->rollback(); } catch (CException $e2) { /* silent */ } echo "The module hierarchy couldn't be installed.\n"; echo $e->getMessage() . "\n"; echo $e->getTraceAsString() . "\n"; return; } echo "The module hierarchy is correctly installed.\n"; }
public function __construct($auth, $folderId, ArrayOfGuid $userIds, $role) { $this->auth = $auth; $this->folderId = $folderId; $this->userIds = $userIds; $this->role = AccessRole::getAccessRoleFromAccessRoleName($role); }
/** * The index action. This view lists the installed modules that are * available in the database to see their item hierarchy. */ public function actionIndex() { $criteria = new CDbCriteria(); $criteria->select = 'module_name'; $criteria->distinct = true; $roles = AccessRole::model()->findAll($criteria); $module_names = array(); foreach ($roles as $role) { $module_names[] = $role->module_name; } $this->title = Yii::t('access.controller.role', 'All registered modules'); $this->render('index', array('module_names' => $module_names)); }
public function getCMSFields() { $fields = FieldList::create(); $dummy = singleton('AccessAuthority'); $members = new CheckboxSetField('Members', _t('AccessAuthority.MEMBERS', 'Members'), DataObject::get('Member')); $groups = new CheckboxSetField('Groups', _t('AccessAuthority.GROUPS', 'Groups'), DataObject::get('Group')); $allRoles = DataObject::get('AccessRole'); if ($allRoles) { $allRoles = $allRoles->map('Title', 'Title'); } else { $allRoles = array(); } $roles = DropdownField::create('Role', _t('AccessAuthority.ROLE', 'Role'), $allRoles)->setEmptyString('(Role)'); // deliberately only allow singles here - people should define roles! $perms = DropdownField::create('Perms', _t('PermissionTable.PERMS', 'Permission - use roles for multiple!'), AccessRole::allPermissions())->setEmptyString('(Permission)'); $detailFormFields = new FieldList($roles, $perms, $members, $groups, new DropdownField('Grant', _t('AccessAuthority.Grant', 'Grant Access'), $dummy->dbObject('Grant')->enumValues())); return $detailFormFields; }
/** * {@inheritDoc} * @see IPluggableAccessManager::clearAll() */ public function clearAll(IPluggableModule $module) { $criteria = new CDbCriteria(); $criteria->compare('module_name', $module->getId()); return AccessRole::model()->deleteAll($criteria); }