public function store() { $Input = Request::all(); $objUser = \App\User::findOrFail($Input['UserID']); if (!$this->objLoggedInUser->HasPermission("Edit/{$objUser->role}")) { abort('404'); } $objUser->name = Request::get('Name'); $objUser->email = Request::get('Email'); $objUser->company_name = Request::get('CompanyName'); $objUser->role = Request::get('Role'); $objUser->phone = Request::get('Phone'); $objUser->account_number = Request::get('AccountNumber'); $tPermissions = Request::get('Permissions'); $objUser->permissions()->delete(); foreach ((array) $tPermissions as $Permission => $State) { if ($State == 'on') { $NewPermission = new \App\Permission(); $NewPermission->user_id = $objUser->id; $NewPermission->permission = $Permission; $NewPermission->save(); } } $objUser->save(); if (Request::get('Submit') == 'Save') { $Path = $Input['ReturnTo'] == 'Dashboard' ? '' : '/users'; } else { $Path = "/users/edit/{$objUser->id}"; } return redirect("/admin{$Path}")->with('FormResponse', ['ResponseType' => static::MESSAGE_SUCCESS, 'Content' => 'User saved successfully']); }
public function setupFoundorAndBaseRolsPermission() { // Create Roles $founder = new App\Role(); $founder->name = 'Founder'; $founder->save(); $admin = new App\Role(); $admin->name = 'Admin'; $admin->save(); // Create User $user = App\User::create(['github_id' => 1, 'github_url' => 'goodgoto.com', 'name' => 'summerblue']); // Attach Roles to user $user->roles()->attach($founder->id); // Create Permissions $manageTopics = new App\Permission(); $manageTopics->name = 'manage_topics'; $manageTopics->display_name = 'Manage Topics'; $manageTopics->save(); $manageUsers = new App\Permission(); $manageUsers->name = 'manage_users'; $manageUsers->display_name = 'Manage Users'; $manageUsers->save(); // Assign Permission to Role $founder->perms()->sync([$manageTopics->id, $manageUsers->id]); $admin->perms()->sync([$manageTopics->id]); }
/** * Run the database seeds. * * @return void */ public function run() { foreach (Config('predefined.roles-and-perms.Permissions') as $method => $perms) { foreach ($perms as $name => $label) { $permission = new \App\Permission(); switch (is_numeric($name)) { case false: $permission->name = $method . '-' . $name; $permission->label = $label; break; case true: $permission->name = $method . '-' . $label; break; } $permission->created_at = \Carbon\Carbon::now(); $permission->save(); } } }
/** * Run the database seeds. * * @return void */ public function run() { // truncating the permissions table DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('permissions')->truncate(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $scheduleShifts = new App\Permission(); $scheduleShifts->name = 'schedule-shifts'; $scheduleShifts->display_name = 'Schedule Shifts'; // optional // Allow a user to... $scheduleShifts->description = 'can schedule shifts'; // optional $scheduleShifts->save(); $makeShifts = new App\Permission(); $makeShifts->name = 'make-shifts'; $makeShifts->display_name = 'Make Shifts'; // optional // Allow a user to... $makeShifts->description = 'can create shifts'; // optional $makeShifts->save(); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); // create role $member = new App\Role(); $member->name = 'member'; $member->display_name = 'Member'; // optional $member->save(); $admin = new App\Role(); $admin->name = 'admin'; $admin->display_name = 'Administrator'; // optional $admin->save(); // create permission $memberPlaylist = new App\Permission(); $memberPlaylist->name = 'member-playlist'; $memberPlaylist->display_name = 'Manage Playlist by Member (self)'; $memberPlaylist->save(); $adminPlaylist = new App\Permission(); $adminPlaylist->name = 'admin-playlist'; $adminPlaylist->display_name = 'Manage Playlist by Admin'; $adminPlaylist->save(); // Assign permisson to role $member->attachPermissions([$memberPlaylist]); $admin->attachPermissions([$adminPlaylist]); // create admin $user = App\User::create(['name' => 'administrator', 'email' => '*****@*****.**', 'password' => bcrypt('password')]); // role attach alias $user->attachRole($admin); // create editor foreach (range(1, 3) as $i) { $user = App\User::create(['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('password')]); // role attach alias $user->attachRole($member); } }
/** * Run the database seeds. * * @return void */ public function run() { // roles $admin = new \App\Role(); $admin->name = 'admin'; $admin->display_name = 'User Administrator'; $admin->description = 'User is allowed to manage and edit other users'; $admin->save(); $librarian = new \App\Role(); $librarian->name = 'librarian'; $librarian->display_name = 'User Librarian'; $librarian->description = 'User is allowed to manage the library'; $librarian->save(); $employee = new \App\Role(); $employee->name = 'employee'; $employee->display_name = 'User Employee'; $employee->description = 'User is allowed to rent, to reserve and to return the library copies'; $employee->save(); $teacher = new \App\Role(); $teacher->name = 'teacher'; $teacher->display_name = 'User Teacher'; $teacher->description = 'User is allowed to rent, to reserve and to return the library copies'; $teacher->save(); $student = new \App\Role(); $student->name = 'student'; $student->display_name = 'User Student'; $student->description = 'User is allowed to rent, to reserve and to return the library copies'; $student->save(); // permissions $toLoan = new \App\Permission(); $toLoan->name = 'to-loan'; $toLoan->display_name = 'To Loan'; $toLoan->description = 'To loan copies of works for students, teacher and employees'; $toLoan->save(); $librarian->attachPermission($toLoan); $toReserve = new \App\Permission(); $toReserve->name = 'to-reserve'; $toReserve->display_name = 'To Reserve'; $toReserve->description = 'To reserve copies of works for students, teacher and employees'; $toReserve->save(); $librarian->attachPermission($toReserve); $toReturn = new \App\Permission(); $toReturn->name = 'to-return'; $toReturn->display_name = 'To Return'; $toReturn->description = 'To return copies of works for students, teacher and employees'; $toReturn->save(); $librarian->attachPermission($toReturn); $toRenew = new \App\Permission(); $toRenew->name = 'to-renew'; $toRenew->display_name = 'To Renew'; $toRenew->description = 'To renew copies of works for students, teacher and employees'; $toRenew->save(); $librarian->attachPermission($toRenew); $addLibrarian = new \App\Permission(); $addLibrarian->name = 'add-librarian'; $addLibrarian->display_name = 'Add Librarian'; $addLibrarian->description = 'Can add librarian user'; $addLibrarian->save(); $admin->attachPermission($addLibrarian); $addEmployee = new \App\Permission(); $addEmployee->name = 'add-employee'; $addEmployee->display_name = 'Add Employee'; $addEmployee->description = 'Can add employee user'; $addEmployee->save(); $admin->attachPermission($addEmployee); $AddTeacher = new \App\Permission(); $AddTeacher->name = 'add-teacher'; $AddTeacher->display_name = 'Add Teacher'; $AddTeacher->description = 'Can add teacher user'; $AddTeacher->save(); $admin->attachPermission($AddTeacher); $addStudent = new \App\Permission(); $addStudent->name = 'add-student'; $addStudent->display_name = 'Add Student'; $addStudent->description = 'Can add student user'; $addStudent->save(); $admin->attachPermission($addStudent); $librarian->attachPermission($addStudent); $editLibrarian = new \App\Permission(); $editLibrarian->name = 'edit-librarian'; $editLibrarian->display_name = 'Edit Librarian'; $editLibrarian->description = 'Can edit librarian user'; $editLibrarian->save(); $admin->attachPermission($editLibrarian); $editEmployee = new \App\Permission(); $editEmployee->name = 'edit-employee'; $editEmployee->display_name = 'Edit Employee'; $editEmployee->description = 'Can edit employee user'; $editEmployee->save(); $admin->attachPermission($editEmployee); $editTeacher = new \App\Permission(); $editTeacher->name = 'edit-teacher'; $editTeacher->display_name = 'Edit Teacher'; $editTeacher->description = 'Can edit teacher user'; $editTeacher->save(); $admin->attachPermission($editTeacher); $editStudent = new \App\Permission(); $editStudent->name = 'edit-student'; $editStudent->display_name = 'Edit Student'; $editStudent->description = 'Can edit student user'; $editStudent->save(); $admin->attachPermission($editStudent); $librarian->attachPermission($editStudent); $editProfile = new \App\Permission(); $editProfile->name = 'edit-profile'; $editProfile->display_name = 'Edit Profile'; $editProfile->description = 'Can edit your user profile'; $editProfile->save(); $admin->attachPermission($editProfile); $librarian->attachPermission($editProfile); $employee->attachPermission($editProfile); $teacher->attachPermission($editProfile); $student->attachPermission($editProfile); $maxThreeCopies = new \App\Permission(); $maxThreeCopies->name = 'max-three-copies'; $maxThreeCopies->display_name = 'Max Three Copies'; $maxThreeCopies->description = 'Can catch loaned a maximum of three copies'; $maxThreeCopies->save(); $employee->attachPermission($maxThreeCopies); $student->attachPermission($maxThreeCopies); $maxFiveCopies = new \App\Permission(); $maxFiveCopies->name = 'max-five-copies'; $maxFiveCopies->display_name = 'Max Copies Five'; $maxFiveCopies->description = 'Can catch loaned a maximum of five copies'; $maxFiveCopies->save(); $teacher->attachPermission($maxFiveCopies); $maxTenDays = new \App\Permission(); $maxTenDays->name = 'max-ten-days'; $maxTenDays->display_name = 'Max Ten Days'; $maxTenDays->description = 'Can catch loaned by a maximum ten days'; $maxTenDays->save(); $employee->attachPermission($maxTenDays); $student->attachPermission($maxTenDays); $maxFifteenDays = new \App\Permission(); $maxFifteenDays->name = 'max-fifteen-days'; $maxFifteenDays->display_name = 'Max Fifteen Days'; $maxFifteenDays->description = 'Can catch loaned by a maximum fifteen days'; $maxFifteenDays->save(); $teacher->attachPermission($maxFifteenDays); $requestRenewal = new \App\Permission(); $requestRenewal->name = 'request-renewal'; $requestRenewal->display_name = 'Request Renewal'; $requestRenewal->description = 'Can request renewal of copies of works'; $requestRenewal->save(); $employee->attachPermission($requestRenewal); $teacher->attachPermission($requestRenewal); $student->attachPermission($requestRenewal); $requestReserve = new \App\Permission(); $requestReserve->name = 'request-reserve'; $requestReserve->display_name = 'Request Reserve'; $requestReserve->description = 'Can request reserve of works'; $requestReserve->save(); $employee->attachPermission($requestReserve); $teacher->attachPermission($requestReserve); $student->attachPermission($requestReserve); }
public function setupFounderAndBaseRolesPermission() { $founder = new App\Role(); $founder->name = 'founder'; $founder->display_name = 'Project founder'; $founder->description = 'User is the founder of a given project'; $founder->save(); $admin = new App\Role(); $admin->name = 'admin'; $admin->display_name = 'User Administrator'; $admin->description = 'User is allowed to manage and edit other users'; $admin->save(); $user = new App\User(); $user->username = '******'; $user->email = '*****@*****.**'; $user->password = bcrypt('admin'); $user->is_admin = '1'; $user->save(); if (!$user->save()) { Log::info('Unable to create user ' . $user->username, (array) $user->errors()); } else { Log::info('Create user ' . $user->username . '<' . $user->email . '>'); } $user->attachRole($founder); $createPost = new App\Permission(); $createPost->name = 'manage_contents'; $createPost->display_name = 'Manage contents'; $createPost->description = 'Manage site all contents and post'; $createPost->save(); $editUser = new App\Permission(); $editUser->name = "edit_users"; $editUser->display_name = "Edit user"; $editUser->description = "edit user info"; $editUser->save(); $founder->attachPermission($createPost, $editUser); $admin->attachPermission($createPost); }