/**
  * Handle the form.
  *
  * @param PermissionFormBuilder   $builder
  * @param RoleRepositoryInterface $roles
  * @param Redirector              $redirect
  */
 public function handle(PermissionFormBuilder $builder, RoleRepositoryInterface $roles, Redirector $redirect)
 {
     /* @var RoleInterface|EloquentModel $role */
     $role = $builder->getEntry();
     $roles->save($role->setAttribute('permissions', array_filter(array_flatten($builder->getFormInput()))));
     $builder->setFormResponse($redirect->refresh());
 }
Esempio n. 2
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     $this->roles->truncate();
     $this->roles->create(['en' => ['name' => 'Admin', 'description' => 'The super admin role.'], 'slug' => 'admin']);
     $this->roles->create(['en' => ['name' => 'User', 'description' => 'The default user role.'], 'slug' => 'user']);
     $this->roles->create(['en' => ['name' => 'Guest', 'description' => 'The fallback role for non-users.'], 'slug' => 'guest']);
 }
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  * @param UserRepositoryInterface $users
  */
 public function handle(RoleRepositoryInterface $roles, UserRepositoryInterface $users)
 {
     $user = $users->findByUsername(env('ADMIN_USERNAME'));
     if (!($role = $roles->findBySlug('admin'))) {
         $role = $roles->create(['en' => ['name' => 'Admin'], 'slug' => 'admin']);
     }
     $user->roles()->attach($role);
 }
 /**
  * Handle the form.
  *
  * @param PermissionFormBuilder   $builder
  * @param RoleRepositoryInterface $roles
  * @param Redirector              $redirect
  */
 public function handle(PermissionFormBuilder $builder, RoleRepositoryInterface $roles, Redirector $redirect)
 {
     /* @var RoleInterface $role */
     $role = $builder->getEntry();
     $roles->save($role->setPermissions(array_keys(array_dot(array_map(function ($values) {
         return array_combine(array_values($values), array_pad([], count($values), true));
     }, array_filter($builder->getFormInput()))))));
     $builder->setFormResponse($redirect->refresh());
 }
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  */
 public function handle(RoleRepositoryInterface $roles)
 {
     if (!$this->query->getQuery()->joins && ($permission = array_get($this->fieldType->getConfig(), 'permission'))) {
         $accessible = $roles->findByPermission($permission);
         if (!$accessible->isEmpty()) {
             $this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->whereIn('users_users_roles.related_id', $accessible->lists('id'));
         }
     }
 }
Esempio n. 6
0
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  * @return \Anomaly\Streams\Platform\Model\EloquentModel|\Anomaly\UsersModule\Role\Contract\RoleInterface|null
  */
 public function handle(RoleRepositoryInterface $roles)
 {
     if (is_numeric($this->identifier)) {
         return $roles->find($this->identifier);
     }
     if (!is_numeric($this->identifier)) {
         return $roles->findBySlug($this->identifier);
     }
     return null;
 }
 /**
  * Fired when builder is ready to build.
  *
  * @param RoleRepositoryInterface $roles
  * @param BreadcrumbCollection    $breadcrumbs
  * @param MessageBag              $messages
  * @param Redirector              $redirect
  * @return \Illuminate\Http\RedirectResponse
  */
 public function onReady(RoleRepositoryInterface $roles, BreadcrumbCollection $breadcrumbs, MessageBag $messages, Redirector $redirect)
 {
     $this->setEntry($role = $roles->find($this->getEntry()));
     if ($role->getSlug() === 'admin') {
         $messages->warning('anomaly.module.users::warning.modify_admin_role');
         $this->setFormResponse($redirect->to('admin/users/roles'));
         return;
     }
     $breadcrumbs->add($role->getName(), 'admin/users/roles/edit/' . $role->getId());
     $breadcrumbs->add('anomaly.module.users::breadcrumb.permissions', 'admin/users/roles/permissions/' . $role->getId());
 }
 /**
  * Fired when builder is ready to build.
  *
  * @param UserRepositoryInterface $users
  * @param BreadcrumbCollection    $breadcrumbs
  * @param MessageBag              $messages
  * @param Redirector              $redirect
  * @return \Illuminate\Http\RedirectResponse
  */
 public function onReady(UserRepositoryInterface $users, RoleRepositoryInterface $roles, BreadcrumbCollection $breadcrumbs, MessageBag $messages, Redirector $redirect)
 {
     $this->setEntry($user = $users->find($this->getEntry()));
     if ($user->hasRole($roles->findBySlug('admin'))) {
         $messages->warning('anomaly.module.users::warning.modify_admin_user');
         $this->setFormResponse($redirect->to('admin/users'));
         return;
     }
     $breadcrumbs->add($user->getDisplayName(), 'admin/users/edit/' . $user->getId());
     $breadcrumbs->add('anomaly.module.users::breadcrumb.permissions', 'admin/users/permissions/' . $user->getId());
 }
Esempio n. 9
0
 /**
  * @param StreamsHasInstalled $event
  */
 public function handle(StreamsHasInstalled $event)
 {
     $installers = $event->getInstallers();
     $installers->add(new Installer('Creating the user role.', function () {
         $user = $this->users->findByUsername(env('ADMIN_USERNAME'));
         if (!($role = $this->roles->findBySlug('user'))) {
             $role = $this->roles->create(['en' => ['name' => 'User'], 'slug' => 'user']);
         }
         if (!$user->hasRole($role)) {
             $user->roles()->attach($role);
         }
     }));
 }
Esempio n. 10
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     $this->users->truncate();
     $admin = $this->roles->findBySlug('admin');
     $user = $this->roles->findBySlug('user');
     /* @var UserInterface $administrator */
     $administrator = $this->users->create(['display_name' => 'Administrator', 'email' => env('ADMIN_EMAIL'), 'username' => env('ADMIN_USERNAME'), 'password' => env('ADMIN_PASSWORD')]);
     /* @var UserInterface $demo */
     $demo = $this->users->create(['display_name' => 'Demo User', 'email' => '*****@*****.**', 'password' => 'password', 'username' => 'demo']);
     $demo->roles()->sync([$user->getId()]);
     $administrator->roles()->sync([$admin->getId()]);
     $this->activator->force($demo);
     $this->activator->force($administrator);
 }
Esempio n. 11
0
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  */
 public function handle(RoleRepositoryInterface $roles)
 {
     if ($role = array_get($this->fieldType->getConfig(), 'role')) {
         if (is_numeric($role)) {
             $role = $roles->find($role);
         }
         if (is_string($role)) {
             $role = $roles->findBySlug($role);
         }
         if ($role) {
             // The role exists so join and limit results to that role's ID.
             $this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->where('users_users_roles.related_id', $role->getId());
         } else {
             // The role doesn't exist so don't return anything.
             $this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->where('users_users_roles.related_id', false);
         }
     }
 }
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  */
 public function handle(RoleRepositoryInterface $roles)
 {
     if (!$roles->findBySlug('user')) {
         $roles->create(['en' => ['name' => 'User'], 'slug' => 'user']);
     }
 }
 /**
  * If nothing is posted then
  * the role gets no permissions.
  *
  * @param RoleRepositoryInterface $roles
  */
 public function onPost(RoleRepositoryInterface $roles)
 {
     if (!$this->hasPostData() && ($entry = $this->getEntry())) {
         $roles->save($entry->setAttribute('permissions', []));
     }
 }
Esempio n. 14
0
 /**
  * Handle the command.
  *
  * @param RoleRepositoryInterface $roles
  * @param Authorizer              $authorizer
  */
 public function handle(RoleRepositoryInterface $roles, Authorizer $authorizer)
 {
     if ($guest = $roles->findBySlug('guest')) {
         $authorizer->setGuest($guest);
     }
 }