wiki helper

This commit is contained in:
2019-12-19 01:31:22 -06:00
parent 499a0dfbd8
commit 0721e41d5a
2 changed files with 138 additions and 18 deletions

View File

@@ -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.

View File

@@ -0,0 +1,115 @@
<?php
namespace App\Library\Wiki;
//Internal Library
use Carbon\Carbon;
//Library
use App\Library\Lookups\LookupHelper;
//Models
use App\Models\User\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
use App\Models\Doku\DokuGroupNames;
use App\Models\Doku\DokuMember;
use App\Models\Doku\DokuUser;
use App\Models\Admin\AllowedLogin;
class WikiHelper {
/**
* Check whether the user is allwoed or not allowed
*/
public function AllowedUser($user) {
//Declare some variables
$purge = true;
//Declare helper class
$lookup = new LookupHelper;
//Get the allowed logins list from the database
$legacy = AllowedLogin::where(['login_type' => '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();
}
}