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

Commit

Permalink
Version 1.3.0 (#24)
Browse files Browse the repository at this point in the history
This update is brought to you because and thanks to mmolitor87 & Vojax. Both had very valuable input on how to make SeAT-Groups even better. Thank you for being patient with me, and keep your feedback flowing.

* Now respecting all users in a user_group in `isQualified()` method
* You are able to setup a whole SeAT Group as manager of another SeAT Group
* Refactored edit-view for managed groups
* Refactored index-view for managed groups
* refactored `isManager()` method
* being more strict on membership 
* Changing Log from STRING to TEXT to accommodate longer messages.
* Attempting to modify LogController to resolve an issue with too large DBs
* `onFail` now correctly reports to log what went wrong

ATTENTION: Managers need now to be extra careful when purging members and make sure they purge all characters from a user_group, whereas before everything was bound to the main_character.
If a user lacks of at least 1 character in his user_group which qualifies in respective to your configured affiliation he will get removed from the SeAT group. This means the user will lose every role bound to this SeAT Group and needs to apply/opt-in again.
  • Loading branch information
herpaderpaldent authored Sep 12, 2018
1 parent ee9496c commit 0a493b9
Show file tree
Hide file tree
Showing 24 changed files with 528 additions and 183 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Version 1.3.0
This update is brought to you because and thanks to mmolitor87 & Vojax. Both had very valuable input on how to make SeAT-Groups even better. Thank you for being patient with me, and keep your feedback flowing.

* Now respecting all users in a user_group in `isQualified()` method
* You are able to setup a whole SeAT Group as manager of another SeAT Group
* Refactored edit-view for managed groups
* Refactored index-view for managed groups
* refactored `isManager()` method
* being more strict on membership
* Changing Log from STRING to TEXT to accommodate longer messages.
* Attempting to modify LogController to resolve an issue with too large DBs
* `onFail` now correctly reports to log what went wrong

ATTENTION: Managers need now to be extra careful when pruging members and make sure they purge all characters from a user_group, whereas before everything was bound to the main_character.
If a user lacks of at least 1 character in his user_group which qualifies in respective to your configurated affiliation he will get removed from the SeAT group. This means the user will lose every role bound to this SeAT Group and needs to apply/opt-in again.


# Version 1.2.0
This is a major update to SeAT-Groups as it introduces many asked features and refactoring lots of front end mistakes i made. This is just an initial working release. I will continue to improve SeAT Groups and refactor even classes i have introuced with this release and i see room for improvement.

Expand Down
49 changes: 49 additions & 0 deletions src/Actions/Managers/AddManagerAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Created by PhpStorm.
* User: fehu
* Date: 10.09.18
* Time: 15:31
*/

namespace Herpaderpaldent\Seat\SeatGroups\Actions\Managers;


use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup;

class AddManagerAction
{
public function execute (array $data)
{
$seatgroup = Seatgroup::find($data['seatgroup_id']);

if(isset($data['groups'])){
$groups = $data['groups'];

foreach ($groups as $group) {
if (in_array($group, $seatgroup->waitlist->map(function($group) { return $group->id; })->toArray())) {
return redirect()->back()->with('warning', 'User must be first member before made manager');
}
elseif (in_array($group, $seatgroup->member->map(function($group) { return $group->id; })->toArray())) {
$seatgroup->group()->updateExistingPivot($group, [
'is_manager' => 1,
]);
} else {
$seatgroup->group()->attach($group, [
'is_manager' => 1,
]);
}
}
}

if(isset($data['seatgroups'])){

$seatgroup->children()->attach($data['seatgroups']);

}


return redirect()->back()->with('success', 'Updated');
}

}
41 changes: 41 additions & 0 deletions src/Actions/Managers/RemoveManagerAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: fehu
* Date: 11.09.18
* Time: 15:43
*/

namespace Herpaderpaldent\Seat\SeatGroups\Actions\Managers;


use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup;

class RemoveManagerAction
{
public function execute (array $data)
{
$seatgroup = Seatgroup::find($data['seatgroup_id']);
$group_id = $data['group_id'];
$children_id = $data['children_id'];


if(isset($group_id)){

$seatgroup->group()->updateExistingPivot($group_id, [
'is_manager' => 0,
]);

}

if(isset($children_id)){

$seatgroup->children()->detach($data['children_id']);

}
return redirect()->back()->with('success', 'SeAT Group removed');


}

}
2 changes: 1 addition & 1 deletion src/Http/Controllers/Logs/SeatGroupLogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getSeatGroupDeleteButton()

public function getSeatGroupLogs()
{
$logs = SeatgroupLog::all();
$logs = SeatgroupLog::query();

return Datatables::of($logs)
->editColumn('created_at', function($row){
Expand Down
46 changes: 15 additions & 31 deletions src/Http/Controllers/SeatGroupUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Herpaderpaldent\Seat\SeatGroups\Http\Controllers;

use Herpaderpaldent\Seat\SeatGroups\Actions\Managers\AddManagerAction;
use Herpaderpaldent\Seat\SeatGroups\Actions\Managers\RemoveManagerAction;
use Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\AddManagerRequest;
use Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\RemoveManagerRequest;
use Herpaderpaldent\Seat\SeatGroups\Jobs\GroupSync;
use Herpaderpaldent\Seat\SeatGroups\Models\Seatgroup;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -71,53 +75,33 @@ public function removeMember($seat_group_id, $group_id)
/**
* Display the specified resource.
*
* @param int $id
*
* @param \Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\RemoveManagerRequest $request
* @param \Herpaderpaldent\Seat\SeatGroups\Actions\Managers\RemoveManagerAction $action
*
* @return \Illuminate\Http\Response
*/
public function removeManager($seat_group_id, $group_id)
public function removeManager(RemoveManagerRequest $request, RemoveManagerAction $action)
{
$seatgroup = Seatgroup::find($seat_group_id);

$seatgroup->group()->updateExistingPivot($group_id, [
'is_manager' => 0,
]);
return $action->execute($request->all());

return redirect()->back()->with('success', 'Manager removed');

}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @param \Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager\AddManagerRequest $request
* @param \Herpaderpaldent\Seat\SeatGroups\Actions\Managers\AddManagerAction $action
*
* @return \Illuminate\Http\Response
*/
public function addManager(Request $request, $id)
public function addManager(AddManagerRequest $request, AddManagerAction $action)
{
//
$seatgroup = Seatgroup::find($id);

$this->validate(request(),[
'groups' => 'required'
]);
return $action->execute($request->all());

$groups = $request->get('groups');
foreach ($groups as $group) {
if (in_array($group, $seatgroup->waitlist->map(function($group) { return $group->id; })->toArray())) {
redirect()->back()->with('warning', 'User must be first member before made manager');
}
elseif (in_array($group, $seatgroup->member->map(function($group) { return $group->id; })->toArray())) {
$seatgroup->group()->updateExistingPivot($group, [
'is_manager' => 1,
]);
} else {
$seatgroup->group()->attach($group, [
'is_manager' => 1,
]);
}
}

return redirect()->back()->with('success', 'Updated');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/SeatGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public function show($id)
*/
public function edit($id, GetCorporationListAction $action)
{
// TODO refactor this to $seatgroup->corporation->pluck blabla
$all_corporations = $action->execute([
'seatgroup_id' =>$id,
'origin' => 'SeatGroupsController'
Expand All @@ -99,9 +98,10 @@ public function edit($id, GetCorporationListAction $action)
]);
$roles = Role::all();
$seatgroup = Seatgroup::find($id);
$available_seatgroups = Seatgroup::whereNotIn('id',$seatgroup->children->pluck('id')->push($id)->toArray())->get();
$all_groups = Group::all();

return view('seatgroups::edit', compact('seatgroup', 'id', 'all_corporations', 'roles', 'corporations', 'all_groups','all_corporations_for_title'));
return view('seatgroups::edit', compact('seatgroup', 'id', 'all_corporations', 'roles', 'corporations', 'all_groups','all_corporations_for_title', 'available_seatgroups'));
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/Http/Validation/Manager/AddManagerRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: fehu
* Date: 10.09.18
* Time: 15:18
*/

namespace Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager;


use Illuminate\Foundation\Http\FormRequest;

class AddManagerRequest extends FormRequest
{
/**
* Authorize the request by default.
*
* @return bool
*/
public function authorize()
{

return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{

return [
'seatgroup_id'=>'required',
'groups' => 'required_if:seatgroups,""',
'seatgroups' => 'required_if:groups,""',
];
}

}
42 changes: 42 additions & 0 deletions src/Http/Validation/Manager/RemoveManagerRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: fehu
* Date: 11.09.18
* Time: 15:44
*/

namespace Herpaderpaldent\Seat\SeatGroups\Http\Validation\Manager;


use Illuminate\Foundation\Http\FormRequest;

class RemoveManagerRequest extends FormRequest
{
/**
* Authorize the request by default.
*
* @return bool
*/
public function authorize()
{

return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{

return [
'seatgroup_id'=>'required',
'group_id' => 'required_if:children_id,""',
'children_id' => 'required_if:group_id,""',
];
}

}
16 changes: 8 additions & 8 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
'as' => 'seatgroups.create',
'uses' => 'SeatGroupsController@create',
]);
Route::post('/manager/add', [
'as' => 'seatgroupuser.addmanager',
'uses' => 'SeatGroupUserController@addManager',
]);
Route::post('/manager/remove', [
'as' => 'seatgroupuser.remove.manager',
'uses' => 'SeatGroupUserController@removeManager',
]);

});

Expand Down Expand Up @@ -150,14 +158,6 @@
'middleware' => 'bouncer:seatgroups.create',
'uses' => 'SeatGroupUserController@removeGroupFromSeatGroup',
]);
Route::post('/{group_id}/manager', [
'as' => 'seatgroupuser.addmanager',
'uses' => 'SeatGroupUserController@addManager',
]);
Route::delete('/{seat_group_id}/manager/{group_id}', [
'as' => 'seatgroupuser.removemanager',
'uses' => 'SeatGroupUserController@removeManager',
]);
Route::delete('/{seat_group_id}/member/{group_id}', [
'as' => 'seatgroupuser.removemember',
'uses' => 'SeatGroupUserController@removeMember',
Expand Down
17 changes: 14 additions & 3 deletions src/Jobs/GroupSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function handle()
foreach ($seat_group->role as $role) {
$roles->push($role->id);
}
if(!in_array($group->id,$seat_group->member->pluck('id')->toArray())){
// add user_group to seat_group as member if no member yet.
$seat_group->member()->attach($group->id);
}
break;
case 'open':
case 'managed':
Expand All @@ -82,8 +86,9 @@ public function handle()
}
break;
}
} else if(in_array($group->id,$seat_group->member->pluck('id')->toArray())) {
$seat_group->member()->detach($group->id);
}

});

$group->roles()->sync($roles->unique());
Expand Down Expand Up @@ -117,6 +122,9 @@ public function beforeStart()
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',
Expand All @@ -134,19 +142,22 @@ public function beforeStart()
public function onFail($exception)
{

report($exception);

SeatgroupLog::create([
'event' => 'error',
'message' => sprintf('An error occurred while syncing user group of %s (%s)',
'message' => sprintf('An error occurred while syncing user group of %s (%s). Please check the logs.',
$this->group->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))

]);

}

public function onFinish()
{
SeatgroupLog::create([
'event' => 'success',
'message' => sprintf('The user group of %s (%s) has successfully been synced',
'message' => sprintf('The user group of %s (%s) has successfully been synced.',
$this->group->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))

]);
Expand Down
Loading

0 comments on commit 0a493b9

Please sign in to comment.