Source of file AccessAuthority.php
Size: 3,586 Bytes - Last Modified: 2021-12-23T10:34:03+00:00
/var/www/docs.ssmods.com/process/src/code/dataobjects/AccessAuthority.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?php /** * An access authority describes the Role a user or group has * which is then associated with a given object * * @author marcus@silverstripe.com.au * @license BSD License http://silverstripe.org/bsd-license/ */ class AccessAuthority extends DataObject { private static $db = array( 'Type' => "Varchar(64)", 'AuthorityID' => 'Int', 'Role' => 'Varchar', // recorded so future role changes can propagate 'Perms' => 'MultiValueField', 'Grant' => "Enum('GRANT,DENY','GRANT')", 'ItemID' => 'Int', 'ItemType' => 'Varchar', ); private static $indexes = array( 'Item' => '(ItemID,ItemType)', ); public function getAuthority() { if ($this->Type && $this->AuthorityID > 0) { return DataObject::get_by_id($this->Type, $this->AuthorityID); } if ($this->AuthorityID == -1) { return singleton('PublicMember'); } } public function getAuthorityTitle() { $authority = $this->getAuthority(); return $authority ? $authority->Title : ''; } public function getItem() { return DataObject::get_by_id($this->ItemType, $this->ItemID); } public function PermList() { if ($this->Perms->getValues()) { return '<p>'.implode('</p><p>', $this->Perms->getValues()).'</p>'; } } public function onAfterDelete() { parent::onAfterDelete(); if ($values = $this->Perms->getValues()) { foreach ($values as $perm) { singleton('PermissionService')->clearPermCacheFor($this->getItem(), $perm); } } } public function canView($member = null) { return Member::currentUserID() > 0; } public function getCMSFields() { $fields = FieldList::create(); $dummy = singleton('AccessAuthority'); $members = new CheckboxSetField('Members', _t('AccessAuthority.MEMBERS', 'Members'), Member::get()->map()->toArray()); $groups = new CheckboxSetField('Groups', _t('AccessAuthority.GROUPS', 'Groups'), Group::get()->map()->toArray()); $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; } public function summaryFields() { $fieldList = array( 'Type' => 'Type', 'getAuthorityTitle' => 'Authority', 'Grant' => 'Grant', 'PermList' => 'Perms' ); return $fieldList; } } |