Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #47 from herpaderpaldent/version-1-5-0
Browse files Browse the repository at this point in the history
Version 1.5.0
  • Loading branch information
herpaderpaldent authored Nov 10, 2018
2 parents 5242543 + af274d7 commit 404ad6d
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 47 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/SeatGroupsUsersUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down
7 changes: 7 additions & 0 deletions src/Exceptions/MissingRefreshTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/Http/Controllers/SeatGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');

}
}
4 changes: 4 additions & 0 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
'as' => 'seatgroupuser.remove.manager',
'uses' => 'SeatGroupUserController@removeManager',
]);
Route::get('/update', [
'as' => 'seatgroup.user.update',
'uses' => 'SeatGroupsController@dispatchUpdate',
]);

});

Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/GroupDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle()
{
$job = new GroupSync($users_group);

dispatch($job);
dispatch($job)->onQueue('high');
});

}, function ()
Expand Down
90 changes: 65 additions & 25 deletions src/Jobs/GroupSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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(', ')
),
]);
}
}
}
2 changes: 1 addition & 1 deletion src/config/seatgroups.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 10:24.
*/
return [
'version' => '1.4.2',
'version' => '1.5.0',
];

//TODO: Update Version
3 changes: 3 additions & 0 deletions src/lang/en/seat.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@
'available_alliances' => 'Available Alliances',
'add_alliance' => 'Add Alliance',

//Event Log
'event' => 'Event',

];
37 changes: 27 additions & 10 deletions src/resources/views/about.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,46 @@

<legend>Bugs and issues</legend>

<p>If you find something is not working as expectected, please don't hesitate and contact me. Either use SeAT-Slack or submit an <a href="https://github.com/herpaderpaldent/seat-groups/issues/new">issue on Github</a></p>
<p>If you find something is not working as expected, please don't hesitate and contact me. Either use SeAT-Slack or submit an <a href="https://github.com/herpaderpaldent/seat-groups/issues/new">issue on Github</a></p>

</div>
</div>

@if(auth()->user()->hasRole('seatgroups.create'))
<div class="box box-default">
<div class="box-header with-border">
<i class="fa fa-archive"></i>
<div class="box box-default">
<div class="box-header with-border">
<i class="fa fa-refresh"></i>

<h3 class="box-title">Last Event log</h3>
<h3 class="box-title">{{ trans('web::seat.update') }} {{ trans('seatgroups::seat.seat_groups') }}</h3>

<span class="log-clear-button"></span>

</div>
<!-- /.box-header -->
<div class="box-body">
<a href="{{route('seatgroup.user.update')}}" class="btn btn-block btn-primary" role="button">{{ trans('seatgroups::seat.seat_groups') }} {{ trans_choice('web::seat.user',2) }} {{ trans('web::seat.update') }}</a>

</div>
<!-- /.box-body -->
</div>
<!-- /.box-header -->
<div class="box-body">

<div class="box box-default">
<div class="box-header with-border">
<i class="fa fa-archive"></i>

<h3 class="box-title">Last {{trans('seatgroups::seat.event')}} Log</h3>

<span class="log-clear-button"></span>


</div>
<!-- /.box-header -->
<div class="box-body">

@include('seatgroups::logs.list')

</div>
<!-- /.box-body -->
</div>
<!-- /.box-body -->
</div>
@endif

@stop
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/logs/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<thead>
<tr>
<th>{{ trans('web::seat.date') }}</th>
<th>{{ trans('web::seat.category') }}</th>
<th>{{ trans('seatgroups::seat.event') }}</th>
<th>{{ trans('web::seat.message') }}</th>
</tr>
</thead>
Expand Down
6 changes: 4 additions & 2 deletions src/resources/views/logs/partials/event.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@switch($row->event)
@case('success')
@case('attached')
<span class="label label-success"> {{$row->event}} </span>
@break
@case('warning')
@case('detached')
<span class="label label-warning"> {{$row->event}} </span>
@break
@case('error')
<span class="label label-danger"> {{$row->event}} </span>
@default
<span class="label label-default"> {{$row->event}} </span>
@endswitch
15 changes: 10 additions & 5 deletions src/resources/views/partials/create-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@

<script type="text/javascript">
$(document).ready(function(){
$(document).ready(function () {
$("#SeATGroupCreate").on('show.bs.modal', function () {
$("#available_roles").select2({
placeholder: "{{ trans('web::seat.select_item_add') }}"
});
$.ajax({
type: 'GET',
url: '{{ route('seatgroups.create') }}',
success: function(data){
type : 'GET',
url : '{{ route('seatgroups.create') }}',
success: function (data) {
var select = $('#available_roles');
select.empty();
for (var i = 0; i < data.length; i++) {
$('#available_roles').append($('<option></option>').attr('value', data[i].id).text(data[i].title));
select.append($('<option></option>').attr('value', data[i].id).text(data[i].title));
}
},
error : function (xhr, textStatus, errorThrown) {
Expand Down

0 comments on commit 404ad6d

Please sign in to comment.