Автор: XE Developers (developers@xpressengine.com)
Наследование: extends Illuminate\Support\Fluent
 /**
  * Register permission
  *
  * @param Request      $request   request instance
  * @param string       $key       permission key
  * @param array|string $abilities abilities
  * @param string       $siteKey   site key
  * @return void
  */
 public function permissionRegister(Request $request, $key, $abilities, $siteKey = 'default')
 {
     $abilities = !is_array($abilities) ? [$abilities] : $abilities;
     $grant = new Grant();
     foreach ($abilities as $ability) {
         if ($data = $this->makeGrantData($request, $ability)) {
             $grant->set($ability, $data);
         }
     }
     $this->permissionRegisterGrant($key, $grant, $siteKey);
 }
 /**
  * createAccessGrant
  *
  * @param array $inputs to create grant params array
  * @param Grant $grant  if need to add already exist grant this param is not null
  *
  * @return Grant
  *
  */
 protected function createAccessGrant(array $inputs)
 {
     $grant = new Grant();
     $rating = $inputs['accessRating'];
     $group = $this->innerParamParsing($inputs['accessGroup']);
     $user = $this->innerParamParsing($inputs['accessUser']);
     $except = $this->innerParamParsing($inputs['accessExcept']);
     $grant->add(Action::ACCESS, 'rating', $rating);
     $grant->add(Action::ACCESS, 'group', $group);
     $grant->add(Action::ACCESS, 'user', $user);
     $grant->add(Action::ACCESS, 'except', $except);
     return $grant;
 }
 public function testRegisterExecutedUpdateWhenNotExists()
 {
     list($repo) = $this->getMocks();
     $instance = m::mock('Xpressengine\\Permission\\PermissionHandler[getOrNew]', [$repo])->shouldAllowMockingProtectedMethods();
     $grant = new Grant();
     $grant->set('access', 'guest');
     $grant->set('delete', 'group', ['group_id_1', 'group_id_2']);
     $mockParent = m::mock('Xpressengine\\Permission\\Permission');
     $mockParent->shouldReceive('get')->with('siteKey')->andReturn('default');
     $mockParent->shouldReceive('get')->with('name')->andReturn('plugin');
     $mockPermission = m::mock('Xpressengine\\Permission\\Permission');
     $mockPermission->exists = true;
     $mockPermission->shouldReceive('setGrant')->once()->with($grant)->andReturnNull();
     $instance->shouldReceive('getOrNew')->once()->with('plugin.dummy', 'default')->andReturn($mockPermission);
     $repo->shouldReceive('update')->once()->with($mockPermission)->andReturn($mockPermission);
     $instance->register('plugin.dummy', $grant, 'default');
 }
 /**
  * 위젯박스를 생성한다.
  *
  * @param array $data 생성할 위젯박스의 데이터
  *
  * @return void
  */
 public function create($data)
 {
     $id = array_get($data, 'id');
     if ($id === null) {
         throw new IDNotFoundException();
     }
     if (str_contains($id, '.')) {
         throw new InvalidIDException();
     }
     if ($this->repository->find($id) !== null) {
         throw new IDAlreadyExistsException();
     }
     $options = array_get($data, 'options', []);
     if (is_array($options)) {
         $options = json_encode($options);
     }
     $title = array_get($data, 'title', $id);
     $content = array_get($data, 'content', '');
     $widgetbox = $this->repository->create(compact('id', 'title', 'content', 'options'));
     $grant = new Grant();
     $grant->set('edit', [Grant::RATING_TYPE => Rating::SUPER, Grant::GROUP_TYPE => [], Grant::USER_TYPE => [], Grant::EXCEPT_TYPE => []]);
     $this->permissionHandler->register('widgetbox.' . $id, $grant);
     return $widgetbox;
 }
Пример #5
0
 public function init()
 {
     app('xe.config')->set(EditorHandler::CONFIG_NAME, ['height' => 400, 'fontSize' => '14px', 'fontFamily' => null, 'uploadActive' => true, 'fileMaxSize' => 2, 'attachMaxSize' => 10, 'extensions' => '*', 'tools' => []]);
     $data = [Grant::RATING_TYPE => Rating::MEMBER, Grant::GROUP_TYPE => [], Grant::USER_TYPE => [], Grant::EXCEPT_TYPE => [], Grant::VGROUP_TYPE => []];
     $grant = new Grant();
     $grant->set('html', $data);
     $grant->set('tool', $data);
     $grant->set('upload', $data);
     $grant->set('download', $data);
     app('xe.permission')->register(EditorHandler::CONFIG_NAME, $grant);
 }
 /**
  * getSampleGrant
  *
  * @return Grant
  */
 protected function getSampleGrant()
 {
     $grant = new Grant();
     $grant->add(Action::ACCESS, 'manager');
     $grant->add(Action::ACCESS, 'group', []);
     $grant->add(Action::ACCESS, 'user', []);
     $grant->add(Action::ACCESS, 'except', []);
     return $grant;
 }
Пример #7
0
 /**
  * Get default grant
  *
  * @return Grant
  */
 public function getDefaultGrant()
 {
     $grant = new Grant();
     $grant->add(static::ACCESS, 'rating', 'guest');
     $grant->add(static::ACCESS, 'group', []);
     $grant->add(static::ACCESS, 'user', []);
     $grant->add(static::ACCESS, 'except', []);
     $grant->add(static::VISIBLE, 'rating', 'guest');
     $grant->add(static::VISIBLE, 'group', []);
     $grant->add(static::VISIBLE, 'user', []);
     $grant->add(static::VISIBLE, 'except', []);
     return $grant;
 }
 /**
  * createAccessGrant
  *
  * @param array $inputs to create grant params array
  * @param Grant $grant  if need to add already exist grant this param is not null
  *
  * @return Grant
  *
  */
 public function createVisibleGrant(array $inputs, $grant = null)
 {
     if ($grant === null) {
         $grant = new Grant();
     }
     if (isset($inputs['visibleMode']) && $inputs['visibleMode'] === 'inherit') {
         return $grant;
     }
     $rating = $inputs['visibleRating'];
     $group = $this->innerParamParsing($inputs['visibleGroup']);
     $user = $this->innerParamParsing($inputs['visibleUser']);
     $except = $this->innerParamParsing($inputs['visibleExcept']);
     $grant->add(Action::VISIBLE, 'rating', $rating);
     $grant->add(Action::VISIBLE, 'group', $group);
     $grant->add(Action::VISIBLE, 'user', $user);
     $grant->add(Action::VISIBLE, 'except', $except);
     return $grant;
 }
Пример #9
0
 public function testRegisterExecutedUpdateWhenNotExists()
 {
     list($auth, $routes, $repo) = $this->getMocks();
     $grant = new Grant();
     $grant->set('access', 'guest');
     $grant->set('delete', 'group', ['group_id_1', 'group_id_2']);
     $mockParent = m::mock('Xpressengine\\Permission\\Registered');
     $mockRegistered = m::mock('Xpressengine\\Permission\\Registered');
     $mockRegistered->shouldReceive('setGrant')->once()->with($grant)->andReturnNull();
     $mockRegistered->shouldReceive('getOriginal')->once()->andReturn(["access" => ["rating" => "manager", "group" => [], "user" => [], "except" => []]]);
     $mockRegistered->shouldReceive('addParent')->once()->with($mockParent);
     $repo->shouldReceive('findByTypeAndName')->once()->with('default', 'instance', 'plugin.dummy')->andReturn($mockRegistered);
     $repo->shouldReceive('fetchAncestor')->once()->andReturn([$mockParent]);
     $repo->shouldReceive('update')->once()->with($mockRegistered)->andReturn($mockRegistered);
     $instance = new Factory($auth, $routes, $repo);
     $instance->register('instance', 'plugin.dummy', $grant);
 }
Пример #10
0
 /**
  * returns current attributes
  *
  * @return array
  */
 public function getAttributes()
 {
     $this->attributes['grants'] = json_encode($this->grant->getAttributes());
     return $this->attributes;
 }
Пример #11
0
 /**
  * grant 를 생성해서 반환
  *
  * @param Grant  $grant       grant instance
  * @param string $action      action name
  * @param array  $permissions permissions
  * @return Grant
  */
 public function createGrant(Grant $grant, $action, $permissions)
 {
     foreach ($permissions as $type => $value) {
         $grant->add($action, $type, $value);
     }
     return $grant;
 }