Exemplo n.º 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $user = $this->user->findOrFail($id);
     $sections = Section::get();
     $permissions = Permission::get();
     return view('acl::users.show', compact('user', 'sections', 'permissions'));
 }
Exemplo n.º 2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $role = Role::findOrFail($id);
     $sections = Section::get();
     $permissions = Permission::get();
     return view('acl::roles.show', compact('role', 'sections', 'permissions'));
 }
Exemplo n.º 3
0
 protected function checkPageAction($page_id, $action)
 {
     $this->checkModule();
     $this->checkPage($page_id);
     if (Permission::getPageAction($this->page_module, $page_id) & $action) {
         return;
     }
     $this->diplayError();
 }
Exemplo n.º 4
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'];
 }
Exemplo n.º 5
0
 private function saveModules($data)
 {
     foreach ($data as $module) {
         Module::create(array('module_id' => $module['module_id'], 'module_name' => $module['module_name'], 'icon' => $module['icon']));
         foreach ($module['pages'] as $page) {
             Page::create(array('page_id' => $page['page_id'], 'module_id' => $module['module_id'], 'page_name' => $page['page_name'], 'page_url' => $page['page_url'], 'page_max_action' => $page['page_max_action'], 'icon' => $page['icon']));
             $permission = $page['permission'];
             Permission::create(array('group_id' => $permission['group_id'], 'module_id' => $module['module_id'], 'page_id' => $page['page_id'], 'action_value' => $page['page_max_action']));
         }
     }
 }
Exemplo n.º 6
0
 public function index()
 {
     $this->checkModule();
     $action_value = Permission::getPageAction($this->page_module, $this->page_id);
     return view('content.setting.group.group', array('action_value' => $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.º 8
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.º 9
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Permission::destroy($id);
     return redirect()->route($this->route);
 }
Exemplo n.º 10
0
 public function generateGroups($company_id)
 {
     $group_list = array('0' => 'Admin');
     $permission_list = array('0' => array('1' => array(array('page_id' => 1, 'action_value' => Action::$View | Action::$Add | Action::$Edit | Action::$Delete), array('page_id' => 2, 'action_value' => Action::$View | Action::$Add | Action::$Edit)), '2' => array(array('page_id' => 4, 'action_value' => Action::$View | Action::$Add | Action::$Edit | Action::$Delete))));
     foreach ($group_list as $key => $group) {
         $new_group = new Group();
         $new_group->fill(array('group_name' => $group, 'company_id' => $company_id));
         if ($new_group->save()) {
             foreach ($permission_list[$key] as $module_key => $pages) {
                 foreach ($pages as $page) {
                     $new_permission = new Permission();
                     $new_permission->group_id = $new_group->group_id;
                     $new_permission->module_id = $module_key;
                     $new_permission->page_id = $page['page_id'];
                     $new_permission->action_value = $page['action_value'];
                     $new_permission->save();
                 }
             }
         }
     }
 }
Exemplo n.º 11
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;
 }