示例#1
0
 public function fire()
 {
     $name = $this->argument('name');
     $permission = Permission::where('name', '=', $name)->first();
     if (is_null($permission)) {
         $permission = new Permission();
         $permission->name = $name;
         try {
             $permission->save();
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
         $this->info("{$name} permission added.");
     } else {
         $this->comment("{$name} permission exists.");
     }
 }
示例#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);
         }
     }
 }
示例#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.');
 }
示例#4
0
 public function fire()
 {
     $name = $this->argument('name');
     $permission = Permission::where('name', '=', $name)->first();
     if (!is_null($permission)) {
         try {
             $permission->users()->detach();
             $permission->groups()->detach();
             $permission->delete();
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
         $this->info("{$name} permission removed.");
     } else {
         $this->comment("{$name} permission does not exist.");
     }
 }