wiki dashboard testing

This commit is contained in:
2019-12-21 20:33:45 -06:00
parent b2fb22a890
commit 9fb6ce40ba
2 changed files with 21 additions and 58 deletions

View File

@@ -376,14 +376,10 @@ class AdminController extends Controller
*/ */
public function addWikiUserGroup(Request $request) { public function addWikiUserGroup(Request $request) {
$this->validate($request, [ $this->validate($request, [
'user' => 'required', 'user' => 'required', //User Id number
'groupname' => 'required', 'groupname' => 'required', //Group Id number
]); ]);
var_dump($request->user);
var_dump($request->groupname);
dd();
//Declare some helper variables //Declare some helper variables
$wikiHelper = new WikiHelper; $wikiHelper = new WikiHelper;
@@ -406,8 +402,6 @@ class AdminController extends Controller
'user' => 'required', 'user' => 'required',
'groupname' => 'required', 'groupname' => 'required',
]); ]);
var_dump($request->user);
dd($request->groupname);
//Declare some helper variables //Declare some helper variables
$wikiHelper = new WikiHelper; $wikiHelper = new WikiHelper;
@@ -430,7 +424,6 @@ class AdminController extends Controller
$this->validate($request, [ $this->validate($request, [
'user' => 'required', 'user' => 'required',
]); ]);
dd($request->user);
//Declare variable //Declare variable
$wikiHelper = new WikiHelper; $wikiHelper = new WikiHelper;
@@ -448,8 +441,6 @@ class AdminController extends Controller
'group' => 'required', 'group' => 'required',
'description' => 'required', 'description' => 'required',
]); ]);
var_dump($request->group);
dd($request->description);
//Declare variable //Declare variable
$wikiHelper = new WikiHelper; $wikiHelper = new WikiHelper;
@@ -463,18 +454,11 @@ class AdminController extends Controller
$this->validate($request, [ $this->validate($request, [
'admin' => 'required', 'admin' => 'required',
]); ]);
dd($request->admin);
//Declare helper classes //Declare helper classes
$lookup = new LookupHelper; $lookup = new LookupHelper;
$wikiHelper = new WikiHelper; $wikiHelper = new WikiHelper;
//Get all the users from the database
$users = DokuUser::pluck('name')->all();
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
//Search the names and verify against the lookup table //Search the names and verify against the lookup table
//to find the corporation and / or alliance they belong to. //to find the corporation and / or alliance they belong to.
foreach($users as $user) { foreach($users as $user) {

View File

@@ -58,28 +58,23 @@ class WikiHelper {
/** /**
* Add a user to a particular group * Add a user to a particular group
*/ */
public function AddUserToGroup($name, $groupName) { public function AddUserToGroup($userId, $groupId) {
//Get the group information //Get the group information
$groups = DokuGroupNames::all(); $groups = DokuGroupNames::all();
//Check if the user already belongs to the group //Check if the user already belongs to the group
$userGroups = DokuMember::where(['groupname' => $groupName])->count(); $userGroups = DokuMember::where(['gid' => $groupId])->count();
if($count > 0) { if($count > 0) {
//If the count is greater than zero then we don't need to do anything, //If the count is greater than zero then we don't need to do anything,
//just return false to indicate nothing was changed //just return false to indicate nothing was changed
return false; return false;
} else { } 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. //Get the group the person needs to be added to.
$newGroup = DokuGroupNames::where(['groupname' => $groupName])->first(); $newGroup = DokuGroupNames::where(['id' => $groupId])->first();
//Add the user to the group //Add the user to the group
DokuMember::insert([ DokuMember::insert([
'uid' => $user->id, 'uid' => $userId,
'gid' => $newGroup->id, 'gid' => $groupId,
'groupname' => $newGroup->gname, 'groupname' => $newGroup->gname,
]); ]);
@@ -91,51 +86,40 @@ class WikiHelper {
/** /**
* Remove a user from a particular group * Remove a user from a particular group
*/ */
public function RemoveUserFromGroup($name, $groupName) { public function RemoveUserFromGroup($userId, $groupId) {
//Remove the user from any groups he is associated with
$user = DokuUser::where(['name' => $name])->first();
$group = DokuGroupNames::where(['groupname' => $groupName])->first();
DokuMember::where([ DokuMember::where([
'uid' => $user->id, 'uid' => $userId,
'gid' => $group->gid, 'gid' => $groupId,
])->delete(); ])->delete();
} }
/** /**
* Remove a user from all groups * Remove a user from all groups
*/ */
public function RemoveUserFromAllGroups($name) { public function RemoveUserFromAllGroups($userId) {
$user = DokuUser::where(['name' => $name])->first(); //Remove the user from all groups
DokuMember::where([ DokuMember::where([
'uid' => $user->id, 'uid' => $userId,
])->delete(); ])->delete();
} }
/** /**
* Check to see if a user is already in a group * Check to see if a user is already in a group
*/ */
public function UserHasGroup($user, $groupname) { public function UserHasGroup($userId, $groupId) {
//Get the user information //Get the user information
$user = DokuUser::where(['name' => $user])->first(); $user = DokuUser::where(['id' => $userId])->first();
//Get the groups the user is a part of
$groups = DokuMember::where(['uid' => $user->id])->get();
//Get all of the groups //Get all of the groups
$allGroups = DokuGroupNames::all(); $allGroups = DokuGroupNames::all();
//cycle through all of the groups, and all of the user's groups to see if the user //cycle through all of the groups, and all of the user's groups to see if the user
//is part of the group we are seeking //is part of the group we are seeking
foreach($allGroups as $all) { foreach($allGroups as $all) {
foreach($groups as $group) { if($groupId === $all->id) {
//If the group is found, then send back the group has been found
if($group->gid === $all->id) {
return true; return true;
} }
} }
}
//If we have made it here, then the user does not have the group, therefore, //If we have made it here, then the user does not have the group, therefore,
//return the user doesn't have the group //return the user doesn't have the group
@@ -160,18 +144,13 @@ class WikiHelper {
/** /**
* Delete all traces of a wiki user * Delete all traces of a wiki user
*/ */
public function DeleteWikiUser($user) { public function DeleteWikiUser($userId) {
//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.
$uid = DokuUser::where([
'name' => $user,
])->value('id');
//Delete the permissions of the user first. //Delete the permissions of the user first.
DokuMember::where([ DokuMember::where([
'uid' => $uid, 'uid' => $userId,
])->delete(); ])->delete();
//Delete the user from the user table //Delete the user from the user table
DokuUser::where(['name' => $user])->delete(); DokuUser::where(['id' => $userId])->delete();
} }
} }