diff --git a/CHANGELOG.md b/CHANGELOG.md index c1a2cbb..d85bc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Version 1.5.0 +Another major update on seat-groups. Containing many demanded features such as: +* Dispatching update job via web interface. +* Seat-Groups jobs are now dispatched on `high` queue (thanks @mmolitor87 for the suggestion). +* Clicking multiple times on `Add new SeAT Group` does not append multiple sets of roles anymore (thank you @MoucceuWildfire for reporting). +* SeAT-Groups now only logs attached and detached role events instead of every successful run (thank you @warlof for the idea). +* Deactivated users don't raise `MissingRefreshTokenExceptions` anymore +* `MissingRefreshTokenExceptions` are now more verbose. + +As you can see many of the implemented features are based from your valuable input. Please don't hesitate to contact me IG or via [slack](https://eveseat-slack.herokuapp.com/) (join plugin channel) with anything you'd like to discuss. + # Version 1.4.2 * Fixxed a bug causing to show all hidden-groups, instead of only the hidden-groups where a user is a member of. Thank you @jediefe for reporting this. * Removed raw:db statements from migrations (preparation for testing). diff --git a/src/Commands/SeatGroupsUsersUpdate.php b/src/Commands/SeatGroupsUsersUpdate.php index 184a9cd..64fc8ca 100644 --- a/src/Commands/SeatGroupsUsersUpdate.php +++ b/src/Commands/SeatGroupsUsersUpdate.php @@ -38,13 +38,13 @@ public function handle() return $users_group->main_character_id != '0'; }) ->each(function ($group) { - dispatch(new GroupSync($group)); + dispatch(new GroupSync($group))->onQueue('high'); $this->info(sprintf('A synchronization job has been queued in order to update %s (%s) roles.', $group->main_character->name, $group->users->map(function ($user) { return $user->name; })->implode(', '))); }); } else { - GroupDispatcher::dispatch(); + GroupDispatcher::dispatch()->onQueue('high'); $this->info('A synchronization job has been queued in order to update all SeAT Group roles.'); } diff --git a/src/Exceptions/MissingRefreshTokenException.php b/src/Exceptions/MissingRefreshTokenException.php index bce634c..42bab1a 100644 --- a/src/Exceptions/MissingRefreshTokenException.php +++ b/src/Exceptions/MissingRefreshTokenException.php @@ -9,8 +9,15 @@ namespace Herpaderpaldent\Seat\SeatGroups\Exceptions; use Exception; +use Seat\Web\Models\User; class MissingRefreshTokenException extends Exception { + public function __construct(User $user) + { + $message = sprintf('The user group with ID %d is missing a refresh_token from %s (%d) ' . + 'therefore the user group loses all its roles and permissions. To fix this: ask the user to login to SeAT again.', $user->group_id, $user->name, $user->id); + parent::__construct($message, 0, null); + } } diff --git a/src/Http/Controllers/SeatGroupsController.php b/src/Http/Controllers/SeatGroupsController.php index 4b204db..72b0962 100644 --- a/src/Http/Controllers/SeatGroupsController.php +++ b/src/Http/Controllers/SeatGroupsController.php @@ -11,6 +11,7 @@ use Herpaderpaldent\Seat\SeatGroups\Http\Validation\DeleteSeatGroupRequest; use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Artisan; use Seat\Services\Repositories\Character\Character; use Seat\Services\Repositories\Corporation\Corporation; use Seat\Web\Http\Controllers\Controller; @@ -167,4 +168,14 @@ public function about(GetChangelog $action) return view('seatgroups::about', compact('changelog')); } + + public function dispatchUpdate() + { + + Artisan::queue('seat-groups:users:update')->onQueue('high'); + + return redirect()->back() + ->with('success', 'SeAT Group update scheduled. Check back in a few moments'); + + } } diff --git a/src/Http/routes.php b/src/Http/routes.php index 58489f4..96e3241 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -53,6 +53,10 @@ 'as' => 'seatgroupuser.remove.manager', 'uses' => 'SeatGroupUserController@removeManager', ]); + Route::get('/update', [ + 'as' => 'seatgroup.user.update', + 'uses' => 'SeatGroupsController@dispatchUpdate', + ]); }); diff --git a/src/Jobs/GroupDispatcher.php b/src/Jobs/GroupDispatcher.php index b0627a0..ff7c5c2 100644 --- a/src/Jobs/GroupDispatcher.php +++ b/src/Jobs/GroupDispatcher.php @@ -31,7 +31,7 @@ public function handle() { $job = new GroupSync($users_group); - dispatch($job); + dispatch($job)->onQueue('high'); }); }, function () diff --git a/src/Jobs/GroupSync.php b/src/Jobs/GroupSync.php index a9ba19a..aad06b3 100644 --- a/src/Jobs/GroupSync.php +++ b/src/Jobs/GroupSync.php @@ -12,6 +12,7 @@ use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup; use Herpaderpaldent\Seat\SeatGroups\Models\SeatgroupLog; use Illuminate\Support\Facades\Redis; +use Seat\Web\Models\Acl\Role; use Seat\Web\Models\Group; class GroupSync extends SeatGroupsJobBase @@ -43,6 +44,7 @@ class GroupSync extends SeatGroupsJobBase */ public function __construct(Group $group) { + $this->group = $group; $this->main_character = $group->main_character; if (is_null($group->main_character)) { @@ -64,23 +66,27 @@ public function __construct(Group $group) public function handle() { + // in case no main character has been set, throw an exception and abort the process if (is_null($this->main_character)) throw new MissingMainCharacterException($this->group); - Redis::funnel('seat-groups:jobs.group_sync_' . $this->group->id)->limit(1)->then(function () - { + Redis::funnel('seat-groups:jobs.group_sync_' . $this->group->id)->limit(1)->then(function () { + $this->beforeStart(); try { $roles = collect(); $group = $this->group; - //Catch Superuser + //Catch superuser permissions foreach ($group->roles as $role) { - if ($role->title === 'Superuser') { - $roles->push($role->id); + foreach ($role->permissions as $permission) { + if ($permission->title === 'superuser') { + $roles->push($role->id); + } } + } Seatgroup::all()->each(function ($seat_group) use ($roles, $group) { @@ -91,7 +97,7 @@ public function handle() foreach ($seat_group->role as $role) { $roles->push($role->id); } - if(! in_array($group->id, $seat_group->group->pluck('id')->toArray())){ + if (! in_array($group->id, $seat_group->group->pluck('id')->toArray())) { // add user_group to seat_group as member if no member yet. $seat_group->member()->attach($group->id); } @@ -107,14 +113,14 @@ public function handle() } break; } - } elseif(in_array($group->id, $seat_group->group->pluck('id')->toArray())) { + } elseif (in_array($group->id, $seat_group->group->pluck('id')->toArray())) { $seat_group->member()->detach($group->id); } }); - $group->roles()->sync($roles->unique()); + $sync = $group->roles()->sync($roles->unique()); - $this->onFinish(); + $this->onFinish($sync); logger()->debug('Group has beend synced for ' . $this->main_character->name); @@ -124,8 +130,8 @@ public function handle() } - }, function () - { + }, function () { + logger()->warning('A GroupSync job is already running for ' . $this->main_character->name . ' Removing the job from the queue.'); $this->delete(); @@ -138,25 +144,34 @@ public function beforeStart() foreach ($this->group->users as $user) { + //If user is deactivated skip the refresh_token check + if (! $user->active) + continue; + // If a RefreshToken is missing if (is_null($user->refresh_token)) { // take away all roles $this->group->roles()->sync([]); Seatgroup::all()->each(function ($seatgroup) { + $seatgroup->member()->detach($this->group->id); }); SeatgroupLog::create([ - 'event' => 'warning', - 'message' => sprintf('The RefreshToken of %s is missing, therefore user group of %s (%s) loses all permissions.', - $user->name, $this->main_character->name, $this->group->users->map(function ($user) { return $user->name; })->implode(', ')), - + 'event' => 'error', + 'message' => sprintf('The RefreshToken of %s is missing, therefore user group of %s (%s) loses all permissions.' . + 'Ask the owner of this user group to login again with this user, in order to provide a new RefreshToken. ', + $user->name, $this->main_character->name, $this->group->users->map(function ($user) {return $user->name; })->implode(', ')), ]); // throw exception - throw new MissingRefreshTokenException(); + $this->fail(new MissingRefreshTokenException($user)); } } + + // If deactivated user is alone in a group delete this job + if (! $this->group->users->first()->active && $this->group->users->count() === 1) + $this->delete(); } public function onFail($exception) @@ -165,21 +180,46 @@ public function onFail($exception) report($exception); SeatgroupLog::create([ - 'event' => 'error', + 'event' => 'error', 'message' => sprintf('An error occurred while syncing user group of %s (%s). Please check the logs.', - $this->main_character->name, $this->group->users->map(function ($user) { return $user->name; })->implode(', ')), - + $this->main_character->name, $this->group->users->map(function ($user) {return $user->name; })->implode(', ')), ]); + $this->fail($exception); + } - public function onFinish() + public function onFinish($sync) { - SeatgroupLog::create([ - 'event' => 'success', - 'message' => sprintf('The user group of %s (%s) has successfully been synced.', - $this->main_character->name, $this->group->users->map(function ($user) { return $user->name; })->implode(', ')), - ]); + if (! empty($sync['attached'])) { + + SeatgroupLog::create([ + 'event' => 'attached', + 'message' => sprintf('The user group of %s (%s) has successfully been attached to the following roles: %s.', + $this->main_character->name, + $this->group->users->map(function ($user) { + + return $user->name; + })->implode(', '), + Role::whereIn('id', $sync['attached'])->pluck('title')->implode(', ') + ), + ]); + } + + if (! empty($sync['detached'])) { + + SeatgroupLog::create([ + 'event' => 'detached', + 'message' => sprintf('The user group of %s (%s) has been detached from the following roles: %s.', + $this->main_character->name, + $this->group->users->map(function ($user) { + + return $user->name; + })->implode(', '), + Role::whereIn('id', $sync['detached'])->pluck('title')->implode(', ') + ), + ]); + } } } diff --git a/src/config/seatgroups.config.php b/src/config/seatgroups.config.php index 9717d0e..c651c70 100644 --- a/src/config/seatgroups.config.php +++ b/src/config/seatgroups.config.php @@ -6,7 +6,7 @@ * Time: 10:24. */ return [ - 'version' => '1.4.2', + 'version' => '1.5.0', ]; //TODO: Update Version diff --git a/src/lang/en/seat.php b/src/lang/en/seat.php index 62c0a82..61b0eb8 100644 --- a/src/lang/en/seat.php +++ b/src/lang/en/seat.php @@ -52,4 +52,7 @@ 'available_alliances' => 'Available Alliances', 'add_alliance' => 'Add Alliance', + //Event Log + 'event' => 'Event', + ]; diff --git a/src/resources/views/about.blade.php b/src/resources/views/about.blade.php index cdff3a4..98cf10a 100644 --- a/src/resources/views/about.blade.php +++ b/src/resources/views/about.blade.php @@ -36,29 +36,46 @@ -
If you find something is not working as expectected, please don't hesitate and contact me. Either use SeAT-Slack or submit an issue on Github
+If you find something is not working as expected, please don't hesitate and contact me. Either use SeAT-Slack or submit an issue on Github
@if(auth()->user()->hasRole('seatgroups.create')) -