Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $superAdmin = new Role();
     $superAdmin->name = 'super admin';
     $superAdmin->display_name = 'Super admin';
     $superAdmin->description = 'This role holder has right to everything on the application.';
     $superAdmin->save();
     $authUser = new Role();
     $authUser->name = 'auth user';
     $authUser->display_name = 'Authenticated User';
     $authUser->description = 'This is the basic role which every registered user will get by default.';
     $authUser->save();
     /**
      * Manage Role Permissions
      */
     $manageRolePermission = new Permission();
     $manageRolePermission->name = 'manage-role-perm';
     $manageRolePermission->display_name = 'Manage Role & Permissions';
     $manageRolePermission->description = 'Manage roles and give permissions to role holders.';
     $manageRolePermission->save();
     $superAdmin->attachPermission($manageRolePermission);
     /**
      * Manage User Permission
      */
     $manageUserPermission = new Permission();
     $manageUserPermission->name = 'manage-users';
     $manageUserPermission->display_name = 'Manage Users';
     $manageUserPermission->description = 'Manage Users';
     $manageUserPermission->save();
     $superAdmin->attachPermission($manageUserPermission);
     /**
      * Manage Permission to see Activity
      */
     $manageActivityViewPermission = new Permission();
     $manageActivityViewPermission->name = 'view-activity';
     $manageActivityViewPermission->display_name = 'View Activity';
     $manageActivityViewPermission->description = 'View the different user activity in the system.';
     $manageActivityViewPermission->save();
     $superAdmin->attachPermission($manageActivityViewPermission);
     /**
      * Manage settings for application
      */
     $manageSettingsPermission = new Permission();
     $manageSettingsPermission->name = 'manage-settings';
     $manageSettingsPermission->display_name = 'Manage Settings';
     $manageSettingsPermission->description = 'Manage Settings for the application. User can change settings.';
     $manageSettingsPermission->save();
     $superAdmin->attachPermission($manageSettingsPermission);
     $user = User::create(['name' => 'Amitav Roy', 'email' => '*****@*****.**', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Amitav', 'last_name' => 'Roy', 'status' => 1]);
     $authUser = User::create(['name' => 'Jhon Doe', 'email' => '*****@*****.**', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Jhon', 'last_name' => 'Doe', 'status' => 1]);
     $authUser->attachRole($authUser);
     $user->attachRole($superAdmin);
 }
Пример #2
0
 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function createdummies()
 {
     $wizard = new Role();
     $wizard->name = 'Wizard';
     $wizard->save();
     $muggle = new Role();
     $muggle->name = 'Muggle';
     $muggle->save();
     $castspells = new Permission();
     $castspells->name = 'can_castspells';
     $castspells->display_name = 'Can Cast Spells';
     $castspells->description = 'Enables you to cast awesome spells';
     $castspells->save();
     $bestupid = new Permission();
     $bestupid->name = 'can_bestupid';
     $bestupid->display_name = 'Be stupid';
     $bestupid->description = 'Enables you to be stupid and not see the magic around you';
     $bestupid->save();
     $wizard->attachPermission($castspells);
     $muggle->attachPermission($bestupid);
     $wiz_role = DB::Table('roles')->where('name', '=', 'Wizard')->pluck('id');
     $mug_role = DB::Table('roles')->where('name', '=', 'Muggle')->pluck('id');
     $harryPotter = User::where('username', '=', 'HarryPotter')->first();
     $harryPotter->roles()->attach($wiz_role);
     $smithwee = User::where('username', '=', 'SmithWee')->first();
     $smithwee->roles()->attach($mug_role);
     return 'Abracadabra!';
 }
Пример #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $admin = new Role();
     $admin->name = "administrator";
     $admin->display_name = "Administrator";
     $admin->description = "An administrator gains access to everything.";
     $admin->power = 1000;
     $admin->save();
     $dashboardAccess = new Permission();
     $dashboardAccess->name = "dashboard.access";
     $dashboardAccess->display_name = "Dashboard access";
     $dashboardAccess->description = "Grant's a user access to the dashboard.";
     $dashboardAccess->save();
     $admin->attachPermission($dashboardAccess);
 }
Пример #4
0
 public function run()
 {
     $admin = new \App\Role();
     $admin->name = 'admin';
     $admin->display_name = 'Administrador de usuarios';
     // opcional
     $admin->description = 'Se permite al usuario gestionar y editar otros usuarios';
     // opcional
     $admin->save();
     /**
      * Creamos un Usuario
      */
     $user = new \App\User();
     $user->nom_usuario = 'Juan Sebastian';
     $user->ape_usuario = 'Maya Narvaez';
     $user->num_identificacion = '1085293173';
     $user->tel_usuario = '7363301';
     $user->cel_usuario = '3147708366';
     $user->user_login = '******';
     $user->email = '*****@*****.**';
     $user->password = bcrypt('12345');
     $user->estado_user = '******';
     $user->id_municipio = '1';
     $user->id_tipo_secretaria = '1';
     $user->id_tipo_identificacion = '1';
     $user->id_cargo_usuario = '1';
     $user->save();
     /**
      * Asignamos el Rol admin al usuario
      * Usando el alias del paquete
      */
     // $user->attachRole($admin);// podemos enviar el Rol o el id del Rol
     /**
      * O usamos Eloquent
      */
     $user->roles()->attach($admin->id);
     //usamos solamente el id del Rol
     /**
      * Creamos permisos
      */
     $createPost = new \App\Permission();
     $createPost->name = 'gestion_gene';
     $createPost->display_name = 'Gestion General';
     // opcional
     // Allow a user to...
     $createPost->description = 'Menú de Gestion General';
     // opcional
     $createPost->save();
     $editUser = new \App\Permission();
     $editUser->name = 'gestion_not';
     $editUser->display_name = 'Gestion de Notificaciones';
     // opcional
     // Allow a user to...
     $editUser->description = 'Menú de Notificaciones';
     // opcional
     $editUser->save();
     /**
      * Al Rol admin le asignamos los permisos
      */
     $admin->attachPermission($createPost);
     //esto es equivalente a $admin->perms()->sync(array($createPost->id));
     // $admin->attachPermissions([$createPost, $editUser]); //esto es equivalente a $admin->perms()->sync(array($createPost->id, $editUser->id));
 }
Пример #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /**
      * Creating Roles
      */
     $admin = new Role();
     $admin->name = 'admin';
     $admin->display_name = 'Administrator';
     $admin->description = 'Administration of the System';
     $admin->save();
     $registered = new Role();
     $registered->name = 'registered';
     $registered->display_name = 'Registered User';
     $registered->description = 'Registered User of the System';
     $registered->save();
     $moderator = new Role();
     $moderator->name = 'moderator';
     $moderator->display_name = 'Moderator';
     $moderator->description = 'Moderator of the System';
     $moderator->save();
     /**
      * Creating Permissions
      */
     /**
      * Subject
      */
     $permission = new Permission();
     $permission->name = 'create-subject';
     $permission->display_name = 'Create Subject';
     // optional
     $permission->description = 'Create new Subject in The system';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Papers
      */
     $permission = new Permission();
     $permission->name = 'create-papers';
     $permission->display_name = 'Create Papers';
     // optional
     $permission->description = 'Creating Papers in The System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-papers';
     $permission->display_name = 'Update Papers';
     // optional
     $permission->description = 'Updating Papers in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-papers';
     $permission->display_name = 'Delete Papers';
     // optional
     $permission->description = 'Deleting Papers from the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Questions
      */
     $permission = new Permission();
     $permission->name = 'create-question';
     $permission->display_name = 'Create Question';
     // optional
     $permission->description = 'Create Question in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-question';
     $permission->display_name = 'Update Question';
     // optional
     $permission->description = 'Update Questions in the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-question';
     $permission->display_name = 'Delete Question';
     // optional
     $permission->description = 'Deleting Question from the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Answers
      */
     $permission = new Permission();
     $permission->name = 'create-answer';
     $permission->display_name = 'Create Answers';
     // optional
     $permission->description = 'Create answers in the system';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $moderator->attachPermission($permission);
     $registered->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-answer';
     $permission->display_name = 'Update Answers';
     // optional
     $permission->description = 'Updating answers in the system';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-answer';
     $permission->display_name = 'Delete Answers';
     // optional
     $permission->description = 'Deleting Answers from the System';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * Discussions
      */
     $permission = new Permission();
     $permission->name = 'create-discussion';
     $permission->display_name = 'Create Discussion';
     // optional
     $permission->description = 'Creating Discussions on Papers,Questions ';
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-discussion';
     $permission->display_name = 'Update Discussion';
     // optional
     $permission->description = 'Updating Discussions on Papers,System';
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-discussion';
     $permission->display_name = 'Delete Discussion';
     // optional
     $permission->description = 'Deleting Discussions';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'create-discussion-post';
     $permission->display_name = 'Create Discussion Post';
     // optional
     $permission->description = 'Creating Discussions Post';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'update-discussion-post';
     $permission->display_name = 'Update Discussion';
     // optional
     $permission->description = 'Updating Discussions on Papers,System';
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     $permission = new Permission();
     $permission->name = 'delete-discussion-post';
     $permission->display_name = 'Delete Discussion';
     // optional
     $permission->description = 'Deleting Discussions';
     // optional
     $permission->save();
     $admin->attachPermission($permission);
     $registered->attachPermission($permission);
     $moderator->attachPermission($permission);
     /**
      * User Creations
      */
     $user = User::create(['name' => 'Gnanakeethan Balasubramaniam', 'email' => '*****@*****.**', 'password' => bcrypt('password')]);
     $user->attachRole($admin);
     $user = User::create(['name' => 'Moderator', 'email' => '*****@*****.**', 'password' => bcrypt('password')]);
     $user->attachRole($moderator);
     $user = User::create(['name' => 'Registered', 'email' => '*****@*****.**', 'password' => bcrypt('password')]);
     $user->attachRole($registered);
 }
 /**
  * Reset Role, Permissions & Users
  *
  * @param  $role
  * @return void
  */
 public function reset($role)
 {
     $commandBullet = '  -> ';
     // The Old Role
     $originalRole = Role::where('name', $role['name'])->first();
     if ($originalRole) {
         Role::where('id', $originalRole->id)->update(['name' => $role['name'] . '__remove']);
     }
     // The New Role
     $newRole = new Role();
     $newRole->name = $role['name'];
     if (isset($role['display_name'])) {
         $newRole->display_name = $role['display_name'];
     }
     // optional
     if (isset($role['description'])) {
         $newRole->description = $role['description'];
     }
     // optional
     $newRole->save();
     $this->command->info($commandBullet . "Created {$role['name']} role");
     // Set the Permissions (if they exist)
     $pcount = 0;
     if (!empty($role['permissions'])) {
         foreach ($role['permissions'] as $permission_name) {
             $permission = $this->permissions($permission_name);
             if ($permission === false || !$permission_name) {
                 $this->command->error($commandBullet . "Failed to attach permission '{$permission_name}'. It does not exist");
                 continue;
             }
             $newPermission = Permission::where('name', $permission_name)->first();
             if (!$newPermission) {
                 $newPermission = new Permission();
                 $newPermission->name = key($permission);
                 if (isset($permission['display_name'])) {
                     $newPermission->display_name = $permission['display_name'];
                 }
                 // optional
                 if (isset($permission['description'])) {
                     $newPermission->description = $permission['description'];
                 }
                 // optional
                 $newPermission->save();
             }
             $newRole->attachPermission($newPermission);
             $pcount++;
         }
     }
     $this->command->info($commandBullet . "Attached {$pcount} permissions to {$role['name']} role");
     // Update old records
     if ($originalRole) {
         $userCount = 0;
         $RoleUsers = DB::table(Config::get('entrust.role_user_table'))->where('role_id', $originalRole->id)->get();
         foreach ($RoleUsers as $user) {
             $u = User::where('id', $user->user_id)->first();
             $u->attachRole($newRole);
             $userCount++;
         }
         $this->command->info($commandBullet . "Updated role attachment for {$userCount} users");
         Role::where('id', $originalRole->id)->delete();
         // will also remove old role_user records
         $this->command->info($commandBullet . "Removed the original {$role['name']} role");
     }
 }