Admin Wiki Dashboard

This commit is contained in:
2019-12-20 23:20:42 -06:00
parent 472fd7f49f
commit 00513e1eef
6 changed files with 287 additions and 60 deletions

View File

@@ -322,13 +322,6 @@ class AdminController extends Controller
return redirect('/admin/dashboard')->with('success', 'Entity removed from allowed login list.');
}
/**
* Displays the purge wiki page. This will be removed in favor of the wiki dashboard.
*/
public function displayPurgeWiki() {
return view('admin.dashboards.purge_wiki');
}
/**
* Display the wiki dashboard for wiki functions
*/
@@ -342,45 +335,128 @@ class AdminController extends Controller
->with('wikiMembership', $wikiMembership);
}
/**
* Modify a user's wiki group
*/
public function modifyWikiUser(Request $request) {
}
/**
* Delete a wiki user
*/
public function deleteWikiUser(Request $request) {
$this->validate($request, [
'user' => 'required',
]);
//Declare helper variable
$wikiHelper = new WikiHelper;
$wikiHelper->DeleteWikiUser($request->user);
redirect('/admin/wiki/dashboard')->with('success', 'User: ' . $request->user . ' has been deleted.');
}
/**
* Add a group to a wiki user
*/
public function addWikiUserGroup(Request $request) {
$this->validate($request, [
'user' => 'required',
'groupname' => 'required',
]);
//Declare some helper variables
$wikiHelper = new WikiHelper;
//Check to see if the user has the group we are going to add first
if($wikiHelper->UserHasGroup($request->user, $request->groupname)) {
return redirect('/admin/wiki/dashboard')->with('error', 'User already has the group.');
}
//Add the user to the wiki group
$wikiHelper->AddUserToGroup($request->user, $request->groupname);
return redirect('/admin/wiki/dashboard')->with('success', 'User added to group for the wiki.');
}
/**
* Remove a group from a wiki user
*/
public function removeWikiUserGroup(Request $request) {
$this->validate($request, [
'user' => 'required',
'groupname' => 'required',
]);
//Declare some helper variables
$wikiHelper = new WikiHelper;
//Check to see if the user has the group we are going to remove them from
if(!$wikiHelper->UserHasGroup($request->user, $request->groupname)) {
return redirect('/admin/wiki/dashboard')->with('error', 'User does not have the group to remove.');
}
//Remove the user from the wiki group
$wikiHelper->RemoveUserFromGroup($request->user, $request->groupname);
return redirect('/admin/wiki/dashboard')->with('success', 'Removed user from group ' . $request->grouopname);
}
/**
* Remove a user from all wiki groups
*/
public function removeWikiUserAllGroups(Request $request) {
$this->validate($request, [
'user' => 'required',
]);
//Declare variable
$wikiHelper = new WikiHelper;
$wikiHelper->RemoveUserFromAllGroups($request->user);
return redirect('/admin/wiki/dashboard')->with('success', 'User successfully removed from all groups.');
}
/**
* Insert a new group for wiki user's to be added to
*/
public function insertNewWikiUserGroup(Request $request) {
$this->validate($request, [
'group' => 'required',
'description' => 'required',
]);
//Declare variable
$wikiHelper = new WikiHelper;
$wikiHelper->AddNewUserGroup($request->group, $request->description);
return redirect('/admin/wiki/dashboard')->with('success', 'Added new user group.');
}
public function purgeWikiUsers() {
//Declare helper classes
$lookup = new LookupHelper;
$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
//to find the corporation and / or alliance they belong to.
foreach($users as $user) {
//Let's look up the character in the user table by their name.
//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) {
//If the user is not allowed, then delete the user, otherwise, leave the user untouched
if(!$wikiHelper->AllowedUser($user)) {
$wikiHelper->DeleteWikiUser($user);
}
} else {
$wikiHelper->DeleteWikiUser($user);
}
}
return redirect('/admin/wiki/dashboard')->with('success', 'Wiki has been purged.');
}
}

View File

@@ -25,36 +25,6 @@ class WikiController extends Controller
$this->middleware('auth');
$this->middleware('role:Renter');
}
public function purgeUsers() {
//Declare helper classes
$lookup = new LookupHelper;
$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
//to find the corporation and / or alliance they belong to.
foreach($users as $user) {
//Let's look up the character in the user table by their name.
//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) {
//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.');
}
public function displayRegister() {
//make user name syntax like we want it.
@@ -157,19 +127,4 @@ class WikiController extends Controller
return redirect('/dashboard')->with('success', 'Password changed successfully. Your username is: ' . $name);
}
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.
$uid = DokuUser::where([
'name' => $user,
])->value('id');
//Delete the permissions of the user first.
DokuMember::where([
'uid' => $uid,
])->delete();
//Delete the user from the user table
DokuUser::where(['name' => $user])->delete();
}
}

View File

@@ -113,4 +113,65 @@ class WikiHelper {
'uid' => $user->id,
])->delete();
}
/**
* Check to see if a user is already in a group
*/
public function UserHasGroup($user, $groupname) {
//Get the user information
$user = DokuUser::where(['name' => $user])->first();
//Get the groups the user is a part of
$groups = DokuMember::where(['uid' => $user->id])->get();
//Get all of the groups
$allGroups = DokuGroupNames::all();
//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
foreach($allGroups as $all) {
foreach($groups as $group) {
//If the group is found, then send back the group has been found
if($group->gid === $all->id) {
return true;
}
}
}
//If we have made it here, then the user does not have the group, therefore,
//return the user doesn't have the group
return false;
}
/**
* Add a new user group
*/
public function AddNewUserGroup($groupName, $description) {
//Check if the user group already exists
DokuGroupNames::where(['gname' => $groupName])->count();
if($count == 0) {
DokuGroupNames::insert([
'gname' => $groupName,
'description' => $description,
]);
}
}
/**
* Delete all traces of a wiki user
*/
public 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.
$uid = DokuUser::where([
'name' => $user,
])->value('id');
//Delete the permissions of the user first.
DokuMember::where([
'uid' => $uid,
])->delete();
//Delete the user from the user table
DokuUser::where(['name' => $user])->delete();
}
}

View File

@@ -13,5 +13,6 @@ class DokuGroupNames extends Model
protected $fillable = [
'gname',
'description',
];
}

View File

@@ -0,0 +1,126 @@
@extends('admin.layouts.b4')
@section('content')
<div class="container">
<div class="row justify-content-center">
<h2>Wiki Admin Dashboard</h2>
</div>
</div>
<br>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Add User to Group</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@addWikiUserGroup', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('user', 'Select a User') }}
{{ Form::select('user', $wikiUsers, null, ['placeholder' => 'Pick A User']) }}
</div>
<div class="form-group">
{{ Form::label('groupname', 'Group') }}
{{ Form::select('groupname', $wikiGroups, null, ['placeholder' => 'Pick A Group']) }}
</div>
{{ Form::submit('Add User To Grouop', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="card-header">
<h2>Create New User Group</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@insertNewWikiUserGroup', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('group', 'New Group Name') }}
{{ Form::text('group', '', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::lable('description', 'Group Description') }}
{{ Form::text('description', '', ['class' => 'form-control']) }}
</div>
{{ Form::submit('Add New Group', ['class' => 'btn btn-success']) }}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Remove User From Group</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@removeWikiUserGroup', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('user', 'Select a User') }}
{{ Form::select('user', $wikiUsers, null, ['placeholder' => 'Pick A User']) }}
</div>
<div class="form-group">
{{ Form::label('groupname', 'Group') }}
{{ Form::select('groupname', $wikiGroup, null, ['placeholder' => 'Pick A Group']) }}
</div>
{{ Form::submit('Remove User From Group', ['class' => 'btn btn-warning']) }}
{!! Form::close() !!}
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="card-header">
<h2>Remove User From All Groups</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@removeWikiUserAllGroups', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('user', 'Select User') }}
{{ Form::select('user', $wikiUsers, null, ['placeholder' => 'Select User']) }}
</div>
{{ Form::submit('Remove User From All Groups', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Remove Wiki User</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@deleteWikiUser', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('user', 'Select User') }}
{{ Form::select('user', $user, null, ['placeholder' => 'Select User to Delete']) }}
</div>
{{ Form::submit('Delete User', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="card-header">
<h2>Purge Wiki</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Dashboard\AdminController@purgeUsers', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('admin', 'This action will log the administrator who peformed the action.') }}
{{ Form::hidden('admin', auth()->user()->character_id) }}
</div>
{{ Form::submit('Purge Wiki', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@@ -44,6 +44,14 @@ Route::group(['middleware' => ['auth']], function(){
Route::post('/admin/add/allowedlogin', 'Dashboard\AdminController@addAllowedLogin');
Route::post('/admin/rmoeve/allowedlogin', 'Dashboard\AdminController@removeAllowedLogin');
Route::get('/admin/dashboard/journal', 'Dashboard\AdminController@showJournalEntries');
Route::get('/admin/dashboard/wiki', 'Dashboard\AdminController@displayWikiDashboard');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@deleteWikiUser');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@addWikiUserGroup');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@removeWikiUserGroup');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@removeWikiUserAllGroups');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@insertNewWikiUserGroup');
Route::post('/admin/dashboard/wiki', 'Dashboard\AdminController@purgeWikiUseres');
/**
* AJAX Test pages