/** * Display a listing of permissions * * @return Response */ public function index() { if (!Permission::canList()) { return $this->_access_denied(); } if (Request::ajax()) { $permissions = Permission::select(['id', 'group_name', 'name', 'display_name']); return Datatables::of($permissions)->add_column('actions', function ($data) { $actions = []; $actions[] = $data->canShow() ? link_to_action('permissions.show', 'Show', $data->id, ['class' => 'btn btn-xs btn-primary']) : ''; $actions[] = $data->canUpdate() ? link_to_action('permissions.edit', 'Update', $data->id, ['class' => 'btn btn-xs btn-default']) : ''; $actions[] = $data->canDelete() ? Former::open(action('permissions.destroy', $data->id))->class('form-inline') . Former::hidden('_method', 'DELETE') . '<button type="button" class="btn btn-danger btn-xs confirm-delete">Delete</button>' . Former::close() : ''; return implode(' ', $actions); })->remove_column('id')->make(); } Asset::push('js', 'datatables'); return View::make('permissions.index'); }
public function updateRole() { $prevURL = Request::header('referer'); if (!Request::isMethod('post')) { return App::abort(404); } if (Input::has('id')) { try { $role = Role::findorFail((int) Input::get('id')); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { return App::abort(404); } $create = false; $message = 'has been updated successful'; } else { $create = true; $role = new Role(); $message = 'has been added successful'; } $role->name = Input::has('name') ? Input::get('name') : ''; $pass = $role->valid(); if ($pass->passes()) { Permission::generatePermission(); $role->save(); if (Input::has('permission')) { $arrAssignedPermission = []; $arrPermission = Input::get('permission'); foreach ($arrPermission as $controller => $permission) { foreach ($permission as $action => $type) { $currentPerrmission = Permission::select('id')->where('name', 'like', "%{$controller}_{$action}_%")->where('name', '<>', "{$controller}_{$action}_{$type}")->get(); if (!$currentPerrmission->isEmpty()) { $arrId = []; foreach ($currentPerrmission as $id) { $arrId[] = $id->id; } DB::table('permission_role')->where('role_id', $role->id)->whereIn('permission_id', $arrId)->delete(); unset($currentPerrmission, $arrId); } if ($type != 'none') { $permission_id = Permission::where('name', "{$controller}_{$action}_{$type}")->pluck('id'); if (is_null($permission_id)) { continue; } $arrAssignedPermission[] = $permission_id; } } } if (!empty($arrAssignedPermission)) { $role->perms()->sync($arrAssignedPermission); } Cache::tags('menu', 'frontend')->flush(); Cache::tags('menu', 'backend')->flush(); } if (Input::has('continue')) { if ($create) { $prevURL = URL . '/admin/roles/edit-role/' . $role->id; } return Redirect::to($prevURL)->with('flash_success', "<b>{$role->name}</b> {$message}."); } return Redirect::to(URL . '/admin/roles')->with(['flash_success' => "{$role->name} {$message}."]); } return Redirect::to($prevURL)->with(['flash_error' => $pass->messages()->all()])->withInput(); }
function checkPermisssions($id) { # select p.ID_CATEGORIAS, p.ID_SUBCATEGORIAS # from permissoes p # left join usuarios g on (p.TIPO = 'G') and (g.ID_GRUPO_USUARIOS = p.ID_ESTRANGEIRO ) # left join usuarios u on (p.TIPO = 'U') and (u.ID = p.ID_ESTRANGEIRO ) # where ( p.ID_ESTRANGEIRO = 1 ) $p = Permission::select('permissions.id_category', 'permissions.id_subcategory')->leftJoin('users AS g', function ($join) { $join->on('g.id_usergroup', '=', 'permissions.id_fk')->where('permissions.type', '=', "'G'"); })->leftJoin('users AS u', function ($join) { $join->on('u.id', '=', 'permissions.id_fk')->where('permissions.type', '=', "'U'"); })->where("permissions.id_fk", '=', $id)->get(); $error = false; $mensagem = ''; if (count($p) < 1) { $error = true; $mensagem = 'Nenhum registro encontrado'; } return $p; }
/** * * @param array $input * @return string|null */ public function getErrorOrSync($input) { if (!is_array($input)) { return "Wrong input"; } //provjera postojanja nužnih podataka $ime = $this->ime; if (!$ime && !isset($input['ime'])) { return 'Ime je obvezno'; } if (isset($input['ime'])) { $ime = $input['ime']; } if (isset($input['allowed'])) { $allowed = $input['allowed']; } else { $allowed = array(); } if (!$allowed || !is_array($allowed)) { $allowed = array(); } //kraj provjere nužnih podataka //provjera zauzetosti imena $query = Role::where('ime', '=', $ime); if ($this->id > 0) { $query = $query->where('id', '!=', $this->id); } if ($query->count() > 0) { return 'Već postoji uloga s imenom ' . $ime . '.'; } //kraj provjere zauzetosti imena //odabir postojećih dozvola if (count($allowed) > 0) { $allowed = Permission::select('id')->whereIn('id', $allowed)->get()->lists('id'); } //pohrana podataka $this->ime = $ime; if (isset($input['opis'])) { $this->opis = $input['opis']; } $this->save(); //pohrana dozvola if (count($allowed) > 0) { $this->permissions()->sync($allowed); } else { $this->permissions()->detach(); } }
public static function getById($id) { $q = Permission::select()->where('id = ?', $id); return $q->fetch(); }