Skip to content

Commit

Permalink
refactor: migrated user page to controller (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Nov 23, 2024
1 parent 6f82d2c commit b4f0285
Show file tree
Hide file tree
Showing 17 changed files with 758 additions and 754 deletions.
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ server {
rewrite admin/api/(.*) /admin/api/index.php last;

# Administration pages
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|import|instance/edit|instance/update|instances|password|session-keep-alive|stopwords|system|update) /admin/front.php last;
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|import|instance/edit|instance/update|instances|password|session-keep-alive|stopwords|system|update|user) /admin/front.php last;

# REST API v3.0 and v3.1
rewrite ^api/v3\.[01]/(.*) /api/index.php last;
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
# Administration API
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
# Administration pages
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|import|instance/edit|instance/update|instances|password|session-keep-alive|stopwords|system|update) admin/front.php [L,QSA]
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|export|import|instance/edit|instance/update|instances|password|session-keep-alive|stopwords|system|update|user) admin/front.php [L,QSA]
# Private APIs
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
# Setup APIs
Expand Down
16 changes: 9 additions & 7 deletions phpmyfaq/admin/assets/src/user/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ const setUserData = async (userId) => {
const superAdmin = document.getElementById('is_superadmin');
superAdmin.setAttribute('checked', 'checked');
document.querySelectorAll('.permission').forEach((checkbox) => {
checkbox.setAttribute('disabled', '');
checkbox.removeAttribute('disabled');
});
document.querySelectorAll('#pmf-user-rights-save').forEach((element) => {
element.setAttribute('disabled', '');
element.removeAttribute('disabled');
});
document.getElementById('checkAll').setAttribute('disabled', '');
document.getElementById('checkAll').removeAttribute('disabled');
} else {
const superAdmin = document.getElementById('is_superadmin');
superAdmin.removeAttribute('checked');
Expand All @@ -74,6 +74,8 @@ const setUserData = async (userId) => {
}
const saveUser = document.getElementById('pmf-user-save');
saveUser.classList.remove('disabled');

window.history.pushState({}, '', `./user/edit/${userId}`);
};

const setUserRights = async (userId) => {
Expand Down Expand Up @@ -143,20 +145,20 @@ export const handleUsers = async () => {
isSuperAdmin.addEventListener('click', () => {
if (isSuperAdmin.checked) {
document.querySelectorAll('.permission').forEach((checkbox) => {
checkbox.setAttribute('disabled', '');
checkbox.removeAttribute('disabled');
});
document.querySelectorAll('#pmf-user-rights-save').forEach((element) => {
element.setAttribute('disabled', '');
element.removeAttribute('disabled');
});
document.getElementById('checkAll').setAttribute('disabled', '');
} else {
document.querySelectorAll('.permission').forEach((checkbox) => {
checkbox.removeAttribute('disabled');
});
document.querySelectorAll('#pmf-user-rights-save').forEach((element) => {
element.removeAttribute('disabled', '');
element.removeAttribute('disabled');
});
document.getElementById('checkAll').removeAttribute('disabled', '');
document.getElementById('checkAll').removeAttribute('disabled');
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
$secLevelEntries['user'] = $adminHelper->addMenuEntry(
'add_user+edit_user+delete_user',
'user',
'ad_menu_user_administration'
'ad_menu_user_administration',
'user'
);
if ($faqConfig->get('security.permLevel') !== 'basic') {
$secLevelEntries['user'] .= $adminHelper->addMenuEntry(
Expand Down
11 changes: 0 additions & 11 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use phpMyFAQ\Administration\AdminLog;
use phpMyFAQ\Attachment\AttachmentFactory;
use phpMyFAQ\Configuration;
use phpMyFAQ\Faq;
use phpMyFAQ\Filter;
use phpMyFAQ\Language;
Expand Down Expand Up @@ -242,13 +241,6 @@
//
[$currentAdminUser, $currentAdminGroups] = CurrentUser::getCurrentUserGroupId($user);

// are we running a PMF export file request?
switch ($action) {
case 'reportexport':
require 'report.export.php';
exit();
}

// Header of the admin page including the navigation
require 'header.php';

Expand All @@ -265,9 +257,6 @@
// the various sections of the admin area
switch ($action) {
// functions for user administration
case 'user':
require 'user.php';
break;
case 'group':
require 'group.php';
break;
Expand Down
191 changes: 0 additions & 191 deletions phpmyfaq/admin/user.php

This file was deleted.

2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

<!-- User -->
{% if secondLevelEntries['user'] != '' %}
<a class="nav-link {{ userPage ? '' : 'collapsed' }}" href="?action=user" data-bs-toggle="collapse"
<a class="nav-link {{ userPage ? '' : 'collapsed' }}" href="./user" data-bs-toggle="collapse"
data-bs-target="#collapseUsers" aria-expanded="false" aria-controls="collapseUsers">
<div class="pmf-admin-nav-link-icon"><i aria-hidden="true" class="bi bi-person h6"></i></div>
{{ menuUsers }}
Expand Down
8 changes: 4 additions & 4 deletions phpmyfaq/assets/templates/admin/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

<!-- User -->
{% if secondLevelEntries['user'] != '' %}
<a class="nav-link {{ userPage ? '' : 'collapsed' }}" href="?action=user" data-bs-toggle="collapse"
<a class="nav-link {{ userPage ? '' : 'collapsed' }}" href="./user" data-bs-toggle="collapse"
data-bs-target="#collapseUsers" aria-expanded="false" aria-controls="collapseUsers">
<div class="pmf-admin-nav-link-icon"><i aria-hidden="true" class="bi bi-person h6"></i></div>
{{ menuUsers }}
Expand Down Expand Up @@ -258,7 +258,7 @@
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="sessionWarningModalLabel">
{{ msgSessionExpiringSoon }}
{{ 'msgSessionExpiringSoon' | translate }}
</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
Expand All @@ -267,10 +267,10 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
{{ msgNoLogMeOut }}
{{ 'msgNoLogMeOut' | translate }}
</button>
<button type="button" class="btn btn-primary" id="pmf-button-reload-page">
{{ msgYesKeepMeLoggedIn }}
{{ 'msgYesKeepMeLoggedIn' | translate }}
</button>
</div>
</div>
Expand Down
Loading

0 comments on commit b4f0285

Please sign in to comment.