Exemplo n.º 1
0
 public static function getPageAction($module_id, $page_id)
 {
     $where = array('group_id' => User::find(Auth::id())->group->group_id, 'module_id' => $module_id, 'page_id' => $page_id);
     $permission = Permission::where($where)->get()->toArray();
     if (count($permission) == 0) {
         App::abort(403, 'Unauthorized action.');
     }
     return $permission[0]['action_value'];
 }
 /**
  * @covers ::deletePermission
  * @covers ::createPermission
  */
 public function testDeletePermissionsByActions()
 {
     $this->repository->createPermission('area1', 'permission1', ['action1', 'action2', 'action3', 'action4']);
     $this->repository->deletePermission('area1', 'permission1', ['action2', 'action4']);
     $actions = Permission::where('area', '=', 'area1')->where('permission', '=', 'permission1')->first()->getActions();
     $this->assertCount(2, $actions);
     $this->assertContains('action1', $actions);
     $this->assertContains('action3', $actions);
 }
Exemplo n.º 3
0
 public static function checkUserPages($module_id, $page_id)
 {
     $page_ids = Permission::where('module_id', $module_id)->lists('page_id');
     return in_array($page_id, $page_ids);
 }
Exemplo n.º 4
0
 public function detachPerm($section, $permission)
 {
     if (is_object($permission)) {
         $permission = $permission->getKey();
     } elseif (is_array($permission)) {
         $permission = $permission['id'];
     } elseif (is_string($permission)) {
         $permission = Permission::where('code', $permission)->first()->id;
     }
     if (is_object($section)) {
         $section = $section->getKey();
     } elseif (is_array($section)) {
         $section = $section['id'];
     } elseif (intval($permission) == 0) {
         $section = Section::where('code', $section)->first()->id;
     }
     if (!$permission || !$section) {
         return false;
     }
     $data = ['user_id' => $this->id, 'section_id' => $section, 'permission_id' => $permission];
     $permission = PermissionSectionUser::where($data);
     if ($permission->count() == 1) {
         $permission->delete();
         return true;
     }
     return false;
 }