From 0721e41d5ac8d11366611d58f49850be313c07e0 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Thu, 19 Dec 2019 01:31:22 -0600 Subject: [PATCH] wiki helper --- app/Http/Controllers/Wiki/WikiController.php | 41 ++++--- app/Library/Wiki/WikiHelper.php | 115 +++++++++++++++++++ 2 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 app/Library/Wiki/WikiHelper.php diff --git a/app/Http/Controllers/Wiki/WikiController.php b/app/Http/Controllers/Wiki/WikiController.php index 5073c455a..99fbb20b3 100644 --- a/app/Http/Controllers/Wiki/WikiController.php +++ b/app/Http/Controllers/Wiki/WikiController.php @@ -10,6 +10,7 @@ use Auth; //User Libraries use App\Library\Lookups\LookupHelper; +use App\Library\Wiki\WikiHelper; //Models use App\Models\Doku\DokuGroupNames; @@ -28,6 +29,7 @@ class WikiController extends Controller public function purgeUsers() { //Declare helper classes $lookup = new LookupHelper; + $wikiHelper = new WikiHelper; //Get all the users from the database $users = DokuUser::pluck('name')->all(); @@ -42,29 +44,13 @@ class WikiController extends Controller //If no name is found, then delete the user and have them start over with the wiki permissions $count = User::where(['name' => $user])->count(); if($count > 0) { - //Get the user from the database - $charIdTemp = User::where(['name' => $user])->get(['character_id']); - - //Set the character id - $charId = $charIdTemp[0]->character_id; - - //Set the corp id - $char = $lookup->GetCharacterInfo($charId); - $corpId = $char->corporation_id; - - //Set the alliance id - $corp = $lookup->LookupCorporation($corpId, null); - $allianceId = $corp->alliance_id; - - if(in_array($allianceId, $legacy) || in_array($allianceId, $renter) || $allianceId == 99004116) { - //Do nothing - } else { + //If the user is not allowed, then delete the user, otherwise, leave the user untouched + if(!$wikiHelper->AllowedUser($user)) { $this->DeleteWikiUser($user); } } else { $this->DeleteWikiUser($user); } - } return redirect('/admin/dashboard')->with('success', 'Wiki has been purged.'); @@ -188,6 +174,25 @@ class WikiController extends Controller return redirect('/dashboard')->with('success', 'User added to the group: ' . $gid . ' with name of ' . $gname); } + /** + * Display the modify user group page + */ + public function displayModifyWikiUser() { + $this->middleware('role:Admin'); + + return view('wiki.display.modifyuser'); + } + + /** + * Modify the user's group(s) in the database for the wiki + */ + public function modifyWikiUser(Request $request) { + $this->validate($request, [ + 'user' => 'required', + 'group' => 'required', + ]); + } + private function DeleteWikiUser($user) { //Get the uid of the user as we will need to purge them from the member table as well. //the member table holds their permissions. diff --git a/app/Library/Wiki/WikiHelper.php b/app/Library/Wiki/WikiHelper.php new file mode 100644 index 000000000..c65217a53 --- /dev/null +++ b/app/Library/Wiki/WikiHelper.php @@ -0,0 +1,115 @@ + 'Legacy'])->pluck('entity_id')->toArray(); + $renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray(); + + $charIdTemp = User::where(['name' => $user])->get(['character_id']); + + //Set the character id + $charId = $charIdTemp[0]->character_id; + + //Set the corp id + $char = $lookup->GetCharacterInfo($charId); + $corpId = $char->corporation_id; + + //Set the alliance id + $corp = $lookup->GetCorporationInfo($corpId); + $allianceId = $corp->alliance_id; + + if(in_array($allianceId, $legacy) || in_array($allianceId, $renter) || $allianceId == 99004116) { + $purge = false; + } else { + $purge = true; + } + + return $purge; + } + + /** + * Add a user to a particular group + */ + public function AddUserToGroup($name, $groupName) { + //Get the group information + $groups = DokuGroupNames::all(); + + //Check if the user already belongs to the group + $userGroups = DokuMember::where(['groupname' => $groupName])->count(); + if($count > 0) { + //If the count is greater than zero then we don't need to do anything, + //just return false to indicate nothing was changed + return false; + } else { + //If the person is not part of the group, then we need to add them to the group + + //Get the uid from the user + $user = DokuUser::where(['name' => $name])->first(); + + //Get the group the person needs to be added to. + $newGroup = DokuGroupNames::where(['groupname' => $groupName])->first(); + //Add the user to the group + DokuMember::insert([ + 'uid' => $user->id, + 'gid' => $newGroup->id, + ]); + + //Return true saying we have inserted the user into the group + return true; + } + } + + /** + * Remove a user from a particular group + */ + public function RemoveUserFromGroup($name, $groupName) { + + $user = DokuUser::where(['name' => $name])->first(); + + $group = DokuGroupNames::where(['groupname' => $groupName])->first(); + + DokuMember::where([ + 'uid' => $user->id, + 'gid' => $group->gid, + ])->delete(); + } + + /** + * Remove a user from all groups + */ + public function RemoveUserFromAllGroups($name) { + $user = DokuUser::where(['name' => $name])->first(); + + DokuMember::where([ + 'uid' => $user->id, + ])->delete(); + } +} \ No newline at end of file