/** * @param string $path * @param array $filters * * @return bool */ public function isAllowed(string $path, array $filters = []) : bool { $keys = explode('/', $path); $findFilters = []; $permissions = $this->permissions; foreach ($keys as $key) { if ($key == '*') { break; } /** @var Permission $permission */ $permission = Permission::find($key, Permission::class, $permissions); if (!$permission) { return false; } $findFilters = array_merge($findFilters, $permission->getFilters()); $permissions = $permission->getPermissions(); } if (sizeof($filters)) { foreach ($filters as $key => $value) { /** @var Filter $filter */ $filter = Permission::find($key, Filter::class, $findFilters); if ($filter) { if (array_search($value, $filter->getFilters()) === false) { return false; } } } } return true; }
public function run() { $admin = Role::find(1); $read = Permission::find(1); $admin->attachPermission($read); $user1 = User::find(1); $user1->attachRole($admin); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { if (ACL::checkUserPermission('permission.edit') == false) { return Redirect::action('dashboard'); } $permissionInfo = Permission::find($id); if (!empty($permissionInfo)) { $title = Lang::get('Edit Permission'); $formOpen = Form::open(array('method' => 'post', 'id' => 'form-permission', 'class' => 'smart-form', 'route' => array('permission.update', $id))); $formClose = Form::close(); return View::make('permission/edit', array('formOpen' => $formOpen, 'formClose' => $formClose, 'permissionInfo' => $permissionInfo, 'title' => $title)); } else { $message = 'Cannot find PermissionInfo'; return Redirect::action('settings.permission')->with('error', $message); } }
public function testStore() { echo "\n\nPERMISSION CONTROLLER TEST\n\n"; $this->action('POST', 'PermissionController@store', $this->permissionRolesMapping); $permission1 = Permission::find(1); $permission2 = Permission::find(2); $permission3 = Permission::find(3); $role1 = Role::find(1); $role2 = Role::find(2); $this->assertTrue($permission1->hasRole($role1->name)); $this->assertTrue($permission2->hasRole($role2->name)); $this->assertTrue($permission3->hasRole($role2->name)); $this->assertFalse($permission3->hasRole($role1->name)); $this->assertFalse($permission1->hasRole($role2->name)); $this->assertRedirectedToRoute('permission.index'); }
public function getSingle(Request $request) { $data = $request->all(); $response = ['errors' => [], 'entry' => null]; if ($data['id']) { $permission = Permission::find($data['id']); if ($permission) { $response['entry'] = $permission->toArray(); $response['entry']['roles'] = []; foreach ($permission->roles as $role) { array_push($response['entry']['roles'], $role->id); } } } return $response; }
public function updatePermission(Request $request, $id) { $this->check_auth('edit_all'); if (!isset($id)) { if ($request->id == null) { return back()->withInput()->with('status', 'form yang anda kirim tidak melalui prosedur'); } else { $id = $request->id; } } $validator = Validator::make($request->all(), self::validator()['management']['permission']); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } else { $perm = Permission::find($id)->update(['name' => strtolower($request->permissionName), 'label' => $request->permissionLabel]); return redirect('admin/management')->with('status', 'update Permission Berhasil'); } }
/** * Show the form for editing the specified permission. * * @param int $id * @return Response */ public function edit($id) { $permission = Permission::find($id); return View::make('permissions.edit', compact('permission')); }
public function sort() { $sort = explode(',', Input::get('sort')); if ($sort) { foreach ($sort as $key => $id) { $permission = Permission::find($id); $permission->sort = $key + 1; $permission->save(); } } }
/** * Show the form for editing the specified permission. * * @param int $id * @return Response */ public function edit($id) { $permission = Permission::find($id); if (Request::ajax()) { return _ajax_denied(); } if (!$permission->canUpdate()) { return _access_denied(); } return View::make('permissions.edit', compact('permission')); }
public function run() { /* Permissions table */ $permissions = array(array("name" => "view_names", "display_name" => "Can view patient names"), array("name" => "manage_patients", "display_name" => "Can add patients"), array("name" => "receive_external_test", "display_name" => "Can receive test requests"), array("name" => "request_test", "display_name" => "Can request new test"), array("name" => "accept_test_specimen", "display_name" => "Can accept test specimen"), array("name" => "reject_test_specimen", "display_name" => "Can reject test specimen"), array("name" => "change_test_specimen", "display_name" => "Can change test specimen"), array("name" => "start_test", "display_name" => "Can start tests"), array("name" => "enter_test_results", "display_name" => "Can enter tests results"), array("name" => "edit_test_results", "display_name" => "Can edit test results"), array("name" => "verify_test_results", "display_name" => "Can verify test results"), array("name" => "send_results_to_external_system", "display_name" => "Can send test results to external systems"), array("name" => "refer_specimens", "display_name" => "Can refer specimens"), array("name" => "manage_users", "display_name" => "Can manage users"), array("name" => "manage_test_catalog", "display_name" => "Can manage test catalog"), array("name" => "manage_lab_configurations", "display_name" => "Can manage lab configurations"), array("name" => "view_reports", "display_name" => "Can view reports")); foreach ($permissions as $permission) { Permission::create($permission); } $this->command->info('Permissions table seeded'); /* Roles table */ $roles = array(array("name" => "Superadmin"), array("name" => "Technologist"), array("name" => "Receptionist")); foreach ($roles as $role) { Role::create($role); } $this->command->info('Roles table seeded'); $role1 = Role::find(1); $permissions = Permission::all(); //Assign all permissions to role administrator foreach ($permissions as $permission) { $role1->attachPermission($permission); } //Assign role Administrator to administrators User::find(1)->attachRole($role1); User::find(8)->attachRole($role1); User::find(10)->attachRole($role1); $role2 = Role::find(2); //Technologist //Assign technologist's permissions to role technologist $role2->attachPermission(Permission::find(1)); $role2->attachPermission(Permission::find(2)); $role2->attachPermission(Permission::find(3)); $role2->attachPermission(Permission::find(4)); $role2->attachPermission(Permission::find(5)); $role2->attachPermission(Permission::find(6)); $role2->attachPermission(Permission::find(7)); $role2->attachPermission(Permission::find(8)); $role2->attachPermission(Permission::find(9)); $role2->attachPermission(Permission::find(10)); $role2->attachPermission(Permission::find(11)); $role2->attachPermission(Permission::find(12)); $role2->attachPermission(Permission::find(13)); $role2->attachPermission(Permission::find(17)); //Assign role Technologist to the other users User::find(2)->attachRole($role2); User::find(5)->attachRole($role2); User::find(12)->attachRole($role2); User::find(18)->attachRole($role2); User::find(23)->attachRole($role2); User::find(24)->attachRole($role2); User::find(26)->attachRole($role2); User::find(29)->attachRole($role2); User::find(43)->attachRole($role2); User::find(76)->attachRole($role2); User::find(136)->attachRole($role2); User::find(159)->attachRole($role2); User::find(161)->attachRole($role2); User::find(162)->attachRole($role2); User::find(163)->attachRole($role2); User::find(164)->attachRole($role2); /* Instruments table */ $instrumentsData = array("name" => "Celltac F Mek 8222", "description" => "Automatic analyzer with 22 parameters and WBC 5 part diff Hematology Analyzer", "driver_name" => "KBLIS\\Plugins\\CelltacFMachine", "ip" => "192.168.1.12", "hostname" => "HEMASERVER"); $instrument = Instrument::create($instrumentsData); $instrument->testTypes()->attach(array(176)); $this->command->info('Instruments table seeded'); }
/** * Remove the specified resource from storage. * DELETE /permissions/{id} * * @param int $id * @return Response */ public function destroy($id) { $permission = Permission::find($id); if ($permission->delete()) { return $this->respondNoContent(); } return $this->respondServerError(); }
public static function GetByName($permissionName) { return Permission::find(array('name' => $permissionName)); }
public function run() { /* Users table */ $usersData = array(array("username" => "administrator", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "kBLIS Administrator", "designation" => "Administrator"), array("username" => "external", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "External System User", "designation" => "Administrator", "image" => "/i/users/user-2.jpg")); foreach ($usersData as $user) { $users[] = User::create($user); } $this->command->info('users seeded'); /* Permissions table */ $permissions = array(array("name" => "view_names", "display_name" => "Can view patient names"), array("name" => "manage_patients", "display_name" => "Can add patients"), array("name" => "receive_external_test", "display_name" => "Can receive test requests"), array("name" => "request_test", "display_name" => "Can request new test"), array("name" => "accept_test_specimen", "display_name" => "Can accept test specimen"), array("name" => "reject_test_specimen", "display_name" => "Can reject test specimen"), array("name" => "change_test_specimen", "display_name" => "Can change test specimen"), array("name" => "start_test", "display_name" => "Can start tests"), array("name" => "enter_test_results", "display_name" => "Can enter tests results"), array("name" => "edit_test_results", "display_name" => "Can edit test results"), array("name" => "verify_test_results", "display_name" => "Can verify test results"), array("name" => "send_results_to_external_system", "display_name" => "Can send test results to external systems"), array("name" => "refer_specimens", "display_name" => "Can refer specimens"), array("name" => "manage_users", "display_name" => "Can manage users"), array("name" => "manage_test_catalog", "display_name" => "Can manage test catalog"), array("name" => "manage_lab_configurations", "display_name" => "Can manage lab configurations"), array("name" => "view_reports", "display_name" => "Can view reports"), array("name" => "manage_inventory", "display_name" => "Can manage inventory"), array("name" => "request_topup", "display_name" => "Can request top-up"), array("name" => "manage_qc", "display_name" => "Can manage Quality Control")); foreach ($permissions as $permission) { Permission::create($permission); } $this->command->info('Permissions table seeded'); /* Roles table */ $roles = array(array("name" => "Superadmin"), array("name" => "Technologist"), array("name" => "Receptionist")); foreach ($roles as $role) { Role::create($role); } $this->command->info('Roles table seeded'); $role1 = Role::find(1); $permissions = Permission::all(); //Assign all permissions to role administrator foreach ($permissions as $permission) { $role1->attachPermission($permission); } //Assign role Administrator to administrators User::find(1)->attachRole($role1); //User::find(8)->attachRole($role1); //User::find(10)->attachRole($role1); $role2 = Role::find(2); //Technologist //Assign technologist's permissions to role technologist $role2->attachPermission(Permission::find(1)); $role2->attachPermission(Permission::find(2)); $role2->attachPermission(Permission::find(3)); $role2->attachPermission(Permission::find(4)); $role2->attachPermission(Permission::find(5)); $role2->attachPermission(Permission::find(6)); $role2->attachPermission(Permission::find(7)); $role2->attachPermission(Permission::find(8)); $role2->attachPermission(Permission::find(9)); $role2->attachPermission(Permission::find(10)); $role2->attachPermission(Permission::find(11)); $role2->attachPermission(Permission::find(12)); $role2->attachPermission(Permission::find(13)); $role2->attachPermission(Permission::find(17)); //Assign role Technologist to the other users User::find(2)->attachRole($role2); /* User::find(5)->attachRole($role2); User::find(12)->attachRole($role2); User::find(18)->attachRole($role2); User::find(23)->attachRole($role2); User::find(24)->attachRole($role2); User::find(26)->attachRole($role2); User::find(29)->attachRole($role2); User::find(43)->attachRole($role2); User::find(76)->attachRole($role2); User::find(136)->attachRole($role2); User::find(159)->attachRole($role2); User::find(161)->attachRole($role2); User::find(162)->attachRole($role2); User::find(163)->attachRole($role2); User::find(164)->attachRole($role2);*/ /* Instruments table $instrumentsData = array( "name" => "Celltac F Mek 8222", "description" => "Automatic analyzer with 22 parameters and WBC 5 part diff Hematology Analyzer", "driver_name" => "KBLIS\\Plugins\\CelltacFMachine", "ip" => "192.168.1.12", "hostname" => "HEMASERVER" );*/ //$instrument = Instrument::create($instrumentsData); //$instrument->testTypes()->attach(array(176)); XXX ZEEK there is no test type can't attach due to foreign key constraint // $this->command->info('Instruments table seeded'); /* Measure Types */ $measureTypes = array(array("id" => "1", "name" => "Numeric Range"), array("id" => "2", "name" => "Alphanumeric Values"), array("id" => "3", "name" => "Autocomplete"), array("id" => "4", "name" => "Free Text")); foreach ($measureTypes as $measureType) { MeasureType::create($measureType); } $this->command->info('measure_types seeded'); /* Specimen Status table */ $specimen_statuses = array(array("id" => "1", "name" => "specimen-not-collected"), array("id" => "2", "name" => "specimen-accepted"), array("id" => "3", "name" => "specimen-rejected")); foreach ($specimen_statuses as $specimen_status) { SpecimenStatus::create($specimen_status); } $this->command->info('specimen_statuses seeded'); /* Rejection Reasons table */ $rejection_reasons_array = array(array("reason" => "Poorly labelled"), array("reason" => "Over saturation"), array("reason" => "Insufficient Sample"), array("reason" => "Scattered"), array("reason" => "Clotted Blood"), array("reason" => "Two layered spots"), array("reason" => "Serum rings"), array("reason" => "Scratched"), array("reason" => "Haemolysis"), array("reason" => "Spots that cannot elute"), array("reason" => "Leaking"), array("reason" => "Broken Sample Container"), array("reason" => "Mismatched sample and form labelling"), array("reason" => "Missing Labels on container and tracking form"), array("reason" => "Empty Container"), array("reason" => "Samples without tracking forms"), array("reason" => "Poor transport"), array("reason" => "Lipaemic"), array("reason" => "Wrong container/Anticoagulant"), array("reason" => "Request form without samples"), array("reason" => "Missing collection date on specimen / request form."), array("reason" => "Name and signature of requester missing"), array("reason" => "Mismatched information on request form and specimen container."), array("reason" => "Request form contaminated with specimen"), array("reason" => "Duplicate specimen received"), array("reason" => "Delay between specimen collection and arrival in the laboratory"), array("reason" => "Inappropriate specimen packing"), array("reason" => "Inappropriate specimen for the test"), array("reason" => "Inappropriate test for the clinical condition"), array("reason" => "No Label"), array("reason" => "No Sample in the Container"), array("reason" => "No Request Form"), array("reason" => "Missing Information Required")); foreach ($rejection_reasons_array as $rejection_reason) { $rejection_reasons[] = RejectionReason::create($rejection_reason); } $this->command->info('rejection_reasons seeded'); /* Test Phase table */ $test_phases = array(array("id" => "1", "name" => "Pre-Analytical"), array("id" => "2", "name" => "Analytical"), array("id" => "3", "name" => "Post-Analytical")); foreach ($test_phases as $test_phase) { TestPhase::create($test_phase); } $this->command->info('test_phases seeded'); /* Test Status table */ $test_statuses = array(array("id" => "1", "name" => "not-received", "test_phase_id" => "1"), array("id" => "2", "name" => "pending", "test_phase_id" => "1"), array("id" => "3", "name" => "started", "test_phase_id" => "2"), array("id" => "4", "name" => "completed", "test_phase_id" => "3"), array("id" => "5", "name" => "verified", "test_phase_id" => "3")); foreach ($test_statuses as $test_status) { TestStatus::create($test_status); } $this->command->info('test_statuses seeded'); }
/** * @param array|$this[] $sources * @param array|$this[] $merge * * @return array */ public static function listMerge(array $sources, array $merge) : array { foreach ($merge as $permission) { /** @var Permission $find */ $find = Permission::find($permission->getKey(), Permission::class, $sources); if (!$find) { $sources[] = $permission; } else { $find->merge($permission); } } return $sources; }
/** * Update the specified resource in storage. * PUT /admin.permissions/{id} * * @param int $id * @return Response */ public function update($id) { //Buscamos el permiso original, lo poblamos y lo asignamos a la instancia $permission = Permission::find($id); $permission->fill(Input::all()); $this->permission = $permission; //Si no es posible guardar la instancia mandamos errores if (!$this->permission->updateUniques()) { return Redirect::back()->withErrors($this->permission->errors()); } //Se han actualizado los valores, expresamos al usuario nuestro gran regocijo al respecto. return Redirect::to('admin/permission/' . $this->permission->id . '/edit')->with('success', '¡Se ha actualizado correctamente el permiso: ' . $this->permission->display_name . " !"); }
/** * @param string $sourceName * @param int $sourceId * @param string $targetName * @param int $targetId * @param $permission */ protected function isAllowedExplicit($sourceName, $sourceId, $targetName, $targetId, $permission) { return Permission::find()->where(['source_model' => $sourceName, 'source_id' => $sourceId, 'target_model' => $targetName, 'target_id' => $targetId, 'permission' => $permission])->exists(); }
public function actionDelete() { $request = Yii::app()->getRequest(); $id = trim($request->getParam("id")); if ($id) { try { $rs = new Role(); $rrow = $rs->find('rid=:rid', array(':rid' => $id)); $rrow->delete(); $pm = new Permission(); $prow = $pm->find('rid=:rid', array(':rid' => $id)); $prow->delete(); $this->redirect(array('list')); } catch (CDbException $e) { throw CDbException($e); } } }