/** * Execute the console command. * * @return boolean */ public function handle() { if (!empty($this->option('filter'))) { $permissions = Permission::where('name', 'like', "%{$this->option('filter')}%")->get($this->fields); } else { $permissions = Permission::all($this->fields); } $this->table($this->headers, $permissions); return true; }
public function addDefaultPermissionRole() { // Always recreate the permissions for the system administrator DB::table('permission_role')->where('role_id', '=', '1')->delete(); // Add all permissions to the default system administrator role (1) $permission_role = []; foreach (Permission::all() as $permission) { $permission_role[] = ['permission_id' => $permission->id, 'role_id' => '1']; } DB::table('permission_role')->insert($permission_role); }
/** * Execute the console command. * * @return bool */ public function handle() { if (empty($this->option('role')) || empty($this->option('permission'))) { $this->error('Missing options for role and/or permission to select, try --help'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } /* * Detect the permission->id and lookup the name if needed */ $permission = false; if (!is_object($permission)) { $permission = Permission::where('name', $this->option('permission'))->first(); } if (!is_object($permission)) { $permission = Permission::find($this->option('permission')); } if (!is_object($permission)) { $this->error('Unable to find permission with this criteria'); return false; } $permissionRole = new PermissionRole(); $permissionRole->permission_id = $permission->id; $permissionRole->role_id = $role->id; $validation = Validator::make($permissionRole->toArray(), PermissionRole::createRules($permissionRole)); if ($validation->fails()) { $this->warn('The role has already been granted this permission'); $this->error('Failed to create the permission due to validation warnings'); return false; } if (!$permissionRole->save()) { $this->error('Failed to save the permission into the database'); return false; } $this->info("The permission {$permission->name} has been granted to role {$role->name}"); return true; }
public function run() { /* * This creates the default users for testing with a default password. Production installs should call the * CLI tool to use user:create, user:delete, user:addrole, user:deleterole to gain access to the system. */ DB::table('users')->delete(); // Add the example users $defaultAdminUsername = '******'; $defaultAdminPassword = substr(md5(rand()), 0, 8); //$defaultAdminPassword = '******'; $defaultUserUsername = '******'; $defaultUserPassword = substr(md5(rand()), 0, 8); //$defaultUserPassword = '******'; $secondAccountAdminUsername = '******'; $secondAccountAdminPassword = substr(md5(rand()), 0, 8); //$secondAccountAdminPassword = '******'; $users = [['id' => 1, 'email' => $defaultAdminUsername, 'first_name' => 'Default', 'last_name' => 'Admin', 'password' => Hash::make($defaultAdminPassword), 'account_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'email' => $defaultUserUsername, 'first_name' => 'Isp', 'last_name' => 'User', 'password' => Hash::make($defaultUserPassword), 'account_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 3, 'email' => $secondAccountAdminUsername, 'first_name' => 'Default', 'last_name' => 'Admin', 'password' => Hash::make($secondAccountAdminPassword), 'account_id' => 2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('users')->insert($users); // New role for the user $roles = [['id' => 2, 'name' => 'abuse', 'description' => 'Abuse User', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('roles')->insert($roles); // Permissions for the User role $permissions = ['login_portal', 'netblocks_view', 'netblocks_create', 'netblocks_edit', 'netblocks_delete', 'netblocks_export', 'domains_view', 'domains_create', 'domains_edit', 'domains_delete', 'domains_export', 'tickets_view', 'tickets_create', 'tickets_edit', 'tickets_delete', 'tickets_export', 'search_view', 'search_create', 'search_edit', 'search_delete', 'search_export', 'analytics_view', 'analytics_create', 'analytics_edit', 'analytics_delete', 'analytics_export', 'accounts_view', 'accounts_create', 'accounts_edit', 'accounts_delete', 'accounts_export', 'profile_manage', 'users_view', 'users_edit']; // abuseio User role permissions foreach ($permissions as $permission_name) { $permission = Permission::where('name', '=', $permission_name)->first(); $permission_role[] = ['permission_id' => $permission->id, 'role_id' => '2', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]; } DB::table('permission_role')->insert($permission_role); // Give the admin user the default role as system administrator (1) and the user the user role (2) DB::table('role_user')->delete(); $role_user = [['id' => 1, 'role_id' => 1, 'user_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'role_id' => 2, 'user_id' => 2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 3, 'role_id' => 1, 'user_id' => 3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('role_user')->insert($role_user); // Show the password in CLI that was generated when seeding the test admin user echo PHP_EOL . "Default admin user '{$defaultAdminUsername}' created with password: '******'" . PHP_EOL . PHP_EOL; // Show the password in CLI that was generated when seeding the test user echo PHP_EOL . "Default user '{$defaultUserUsername}' created with password: '******'" . PHP_EOL . PHP_EOL; // Show the password in CLI that was generated when seeding the test secondd account admin user echo PHP_EOL . "Default second account admin user '{$secondAccountAdminUsername}' created with password: '******'" . PHP_EOL . PHP_EOL; }
public function run() { /* * This creates the default users for testing with a default password. Production installs should call the * CLI tool to use user:create, user:delete, user:addrole, user:deleterole to gain access to the system. */ DB::table('users')->delete(); // Add the example users $adminPassword = app()->environment() == 'development' ? 'admin' : substr(md5(rand()), 0, 8); $userPassword = app()->environment() == 'development' ? 'user' : substr(md5(rand()), 0, 8); $users = [['id' => 1, 'email' => '*****@*****.**', 'first_name' => 'System', 'last_name' => 'Admin', 'password' => Hash::make($adminPassword), 'account_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'email' => '*****@*****.**', 'first_name' => 'Elizabeth', 'last_name' => 'Smith', 'password' => Hash::make($userPassword), 'account_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 3, 'email' => '*****@*****.**', 'first_name' => 'Warren', 'last_name' => 'King', 'password' => Hash::make($adminPassword), 'account_id' => 2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 4, 'email' => '*****@*****.**', 'first_name' => 'Sophie', 'last_name' => 'Davidson', 'password' => Hash::make($userPassword), 'account_id' => 2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 5, 'email' => '*****@*****.**', 'first_name' => 'Richard', 'last_name' => 'Paterson', 'password' => Hash::make($adminPassword), 'account_id' => 3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('users')->insert($users); // New role for the user $roles = [['id' => 2, 'name' => 'Abuse', 'description' => 'Abusedesk User', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('roles')->insert($roles); // Permissions for the User role $permissions = ['login_portal', 'netblocks_view', 'netblocks_create', 'netblocks_edit', 'netblocks_delete', 'netblocks_export', 'domains_view', 'domains_create', 'domains_edit', 'domains_delete', 'domains_export', 'tickets_view', 'tickets_create', 'tickets_edit', 'tickets_delete', 'tickets_export', 'search_view', 'search_create', 'search_edit', 'search_delete', 'search_export', 'analytics_view', 'analytics_create', 'analytics_edit', 'analytics_delete', 'analytics_export', 'accounts_view', 'accounts_create', 'accounts_edit', 'accounts_delete', 'accounts_export', 'profile_manage', 'users_view', 'users_edit', 'evidence_view']; // User role permissions foreach ($permissions as $permission_name) { $permission = Permission::where('name', '=', $permission_name)->first(); $permission_role[] = ['permission_id' => $permission->id, 'role_id' => '2', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]; } DB::table('permission_role')->insert($permission_role); // Give the admin user the default role as system administrator (1) and the user the user role (2) DB::table('role_user')->delete(); $role_user = [['id' => 1, 'role_id' => 1, 'user_id' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'role_id' => 2, 'user_id' => 2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 3, 'role_id' => 1, 'user_id' => 3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 4, 'role_id' => 2, 'user_id' => 4, 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 5, 'role_id' => 1, 'user_id' => 5, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]]; DB::table('role_user')->insert($role_user); // Show the password in CLI that was generated when seeding the test admin user echo "\nDefault admin user '{$users[0]['email']}' created with password: '******'"; // Show the password in CLI that was generated when seeding the test abusedesk user echo "\nDefault user '{$users[1]['email']}' created with password: '******'"; // Show the password in CLI that was generated when seeding the test second account admin user echo "\nSecond admin user '{$users[2]['email']}' created with password: '******'"; // Show the password in CLI that was generated when seeding the test second account abusedesk user echo "\nSecond user '{$users[3]['email']}' created with password: '******'"; // Show the password in CLI that was generated when seeding the test second account admin user echo "\nThird admin user '{$users[4]['email']}' created with password: '******'\n\n"; }
/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('permission'))) { $this->warn('no email or id argument was passed, try --help'); return false; } $permission = false; if (!is_object($permission)) { $permission = Permission::where('name', $this->option('permission'))->first(); } if (!is_object($permission)) { $permission = Permission::find($this->option('permission')); } if (!is_object($permission)) { $this->error('Unable to find permission with this criteria'); return false; } $roles = ''; foreach ($permission->roles as $role) { $roles .= $role->name . PHP_EOL; } $table = []; $counter = 0; foreach (array_combine($this->headers, $this->fields) as $header => $field) { $counter++; if ($header == 'Roles') { $table[$counter][] = $header; $table[$counter][] = chop($roles); } else { $table[$counter][] = $header; $table[$counter][] = (string) $permission->{$field}; } } $this->table(['Permission Setting', 'Permission Value'], $table); return true; }
/** * Execute the console command. * * @return bool */ public function handle() { if (empty($this->option('role')) || empty($this->option('permission'))) { $this->error('Missing options for role and/or permission to select, try --help'); return false; } /* * Detect the role->id and lookup the user if its thru a user assignment. */ $role = false; if (!empty($this->option('role'))) { if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } } if (!empty($this->option('user'))) { if (!is_object($role)) { $user = User::where('email', $this->option('user'))->first(); if (is_object($user)) { $role = $user->roles->first(); } } if (!is_object($role)) { $user = Role::find($this->option('user')); if (is_object($user)) { $role = $user->roles->first(); } } } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } /* * Detect the permission->id and lookup the name if needed */ $permission = false; if (!is_object($permission)) { $permission = Permission::where('name', $this->option('permission'))->first(); } if (!is_object($permission)) { $permission = Permission::find($this->option('permission')); } if (!is_object($permission)) { $this->error('Unable to find permission with this criteria'); return false; } $permissionRole = PermissionRole::all()->where('role_id', $role->id)->where('permission_id', $permission->id)->first(); if (!is_object($permissionRole)) { $this->error('Nothing to delete, this {$permission->name} permission is not linked to the role {$role->name}'); return false; } if (!$permissionRole->delete()) { $this->error('Failed to remove the permission into the database'); return false; } $this->info("The permission {$permission->name} has been revoked from role {$role->name}"); return true; }
/** * {@inheritdoc}. */ protected function findAll() { return Permission::all(); }
/** * {@inherit docs}. */ protected function getCollectionWithArguments() { return Permission::Where('id', $this->argument('permission')); }