Esempio n. 1
0
 public function fire()
 {
     $name = $this->argument('name');
     $group = Group::where('name', '=', $name)->first();
     if (is_null($group)) {
         $this->comment("{$name} is not a valid group.");
         exit;
     }
     if ($username = $this->option('user')) {
         $user = User::where('username', '=', $username)->first();
         if (is_null($user)) {
             $this->comment("{$username} is not a valid user.");
             exit;
         }
         $already_joined = $user->groups()->where('name', '=', $name)->first();
         if (!is_null($already_joined)) {
             try {
                 $user->groups()->detach($group);
             } catch (\Exception $e) {
                 $this->error($e->getMessage());
             }
             $this->info("{$username} removed from {$name}.");
         } else {
             $this->comment("{$username} is not a member of {$name}.");
         }
         return;
     }
     $this->comment('Please use the user option.');
 }
Esempio n. 2
0
 public function fire()
 {
     if ($username = $this->option('user')) {
         $user = User::where('username', '=', $username)->first();
         if (is_null($user)) {
             $this->comment("{$username} is not a valid user.");
             exit;
         }
         $this->comment("{$username} user permissions:");
         $permissions = $user->permissions()->orderBy('name')->get();
         if ($permissions->isEmpty()) {
             $this->comment("{$username} has no user permissions.");
         } else {
             foreach ($permissions as $permission) {
                 $this->info($permission->name);
             }
         }
         if ($user->groups->isEmpty()) {
             $this->comment("{$username} has no group permissions.");
         } else {
             foreach ($user->groups as $group) {
                 foreach ($group->permissions as $permission) {
                     $this->info("{$permission->name} <comment>({$group->name})</comment>");
                 }
             }
         }
         return;
     }
     if ($groupname = $this->option('group')) {
         $group = Group::where('name', '=', $groupname)->first();
         if (is_null($group)) {
             $this->comment("{$groupname} is not a valid group.");
             exit;
         }
         $this->comment("{$groupname} group permissions:");
         $permissions = $group->permissions()->orderBy('name')->get();
         if ($permissions->isEmpty()) {
             $this->comment("{$groupname} has no permissions.");
         } else {
             foreach ($permissions as $permission) {
                 $this->info($permission->name);
             }
         }
         return;
     }
     $this->comment('All system permissions:');
     $permissions = Permission::orderBy('name')->get();
     if ($permissions->isEmpty()) {
         $this->comment('There are no system permissions.');
     } else {
         foreach ($permissions as $permission) {
             $this->info($permission->name);
         }
     }
 }
Esempio n. 3
0
 public function fire()
 {
     $name = $this->argument('name');
     $permission = Permission::where('name', '=', $name)->first();
     if (is_null($permission)) {
         $this->comment("{$name} is not a valid permission.");
         exit;
     }
     if ($username = $this->option('user')) {
         $user = User::where('username', '=', $username)->first();
         if (is_null($user)) {
             $this->comment("{$username} is not a valid user.");
             exit;
         }
         $already_granted = $permission->users()->where('username', '=', $username)->first();
         if (is_null($already_granted)) {
             try {
                 $permission->user()->attach($user);
             } catch (\Exception $e) {
                 $this->error($e->getMessage());
             }
             $this->info("{$name} granted to {$username}.");
         } else {
             $this->comment("{$name} is already granted to {$username}.");
         }
         return;
     }
     if ($groupname = $this->option('group')) {
         $group = Group::where('name', '=', $groupname)->first();
         if (is_null($group)) {
             $this->comment("{$groupname} is not a valid group.");
             exit;
         }
         $already_granted = $permission->groups()->where('name', '=', $groupname)->first();
         if (is_null($already_granted)) {
             try {
                 $permission->groups()->attach($group);
             } catch (\Exception $e) {
                 $this->error($e->getMessage());
             }
             $this->info("{$name} granted to {$groupname}.");
         } else {
             $this->comment("{$name} is already granted to {$groupname}.");
         }
         return;
     }
     $this->comment('Please use the group or user option.');
 }
Esempio n. 4
0
 public function fire()
 {
     $name = $this->argument('name');
     $group = Group::where('name', '=', $name)->first();
     if (is_null($group)) {
         $group = new Group();
         $group->name = $name;
         try {
             $group->save();
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
         $this->info("{$name} group added.");
     } else {
         $this->comment("{$name} group exists.");
     }
 }