Skip to content

Commit

Permalink
wip: clenup of legacy self admin edit ui
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Dec 9, 2023
1 parent 5043d43 commit 0ebabd5
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 234 deletions.
22 changes: 12 additions & 10 deletions core/webroutes/adminManager/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,19 @@ async function handleEdit(ctx: AuthedCtx) {
const name = ctx.request.body.name.trim();
const citizenfxID = ctx.request.body.citizenfxID.trim();
const discordID = ctx.request.body.discordID.trim();
const editingSelf = (ctx.admin.name.toLowerCase() === name.toLowerCase());

//Check if editing himself
if (ctx.admin.name.toLowerCase() === name.toLowerCase()) {
return ctx.send({type: 'danger', message: '(ERR0) You cannot edit yourself.'});
}

//Validate & translate permissions
let permissions;
if (!editingSelf) {
if (Array.isArray(ctx.request.body.permissions)) {
permissions = ctx.request.body.permissions.filter((x: unknown) => typeof x === 'string');
if (permissions.includes('all_permissions')) permissions = ['all_permissions'];
} else {
permissions = [];
}
if (Array.isArray(ctx.request.body.permissions)) {
permissions = ctx.request.body.permissions.filter((x: unknown) => typeof x === 'string');
if (permissions.includes('all_permissions')) permissions = ['all_permissions'];
} else {
permissions = undefined;
permissions = [];
}

//Validate & translate FiveM ID
Expand Down Expand Up @@ -256,7 +258,7 @@ async function handleDelete(ctx: AuthedCtx) {
}
const name = ctx.request.body.name.trim();

//Check if editing himself
//Check if deleting himself
if (ctx.admin.name.toLowerCase() === name.toLowerCase()) {
return ctx.send({type: 'danger', message: "You can't delete yourself."});
}
Expand Down
2 changes: 0 additions & 2 deletions core/webroutes/adminManager/getModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default async function AdminManagerGetModal(ctx: AuthedCtx) {
const [permsGeneral, permsMenu] = getPerms([], allPermissions);
const renderData = {
isNewAdmin: true,
editingSelf: false,
username: '',
citizenfx_id: '',
discord_id: '',
Expand Down Expand Up @@ -98,7 +97,6 @@ export default async function AdminManagerGetModal(ctx: AuthedCtx) {
username: admin.name,
citizenfx_id: (admin.providers.citizenfx) ? admin.providers.citizenfx.id : '',
discord_id: (admin.providers.discord) ? admin.providers.discord.id : '',
editingSelf: (ctx.admin.name.toLowerCase() === name.toLowerCase()),
permsGeneral,
permsMenu,
};
Expand Down
4 changes: 3 additions & 1 deletion core/webroutes/adminManager/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ export default async function AdminManagerPage(ctx: AuthedCtx) {
} else {
perms = '1 permission';
}
const isSelf = ctx.admin.name.toLowerCase() === admin.name.toLowerCase();

return {
hasCitizenFX: (admin.providers.includes('citizenfx')),
hasDiscord: (admin.providers.includes('discord')),
name: admin.name,
perms: perms,
isSelf,
disableEdit: !ctx.admin.isMaster && admin.master,
disableDelete: (admin.master || ctx.admin.name.toLowerCase() === admin.name.toLowerCase()),
disableDelete: (admin.master || isSelf),
};
});

Expand Down
4 changes: 2 additions & 2 deletions docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Processo:
- [ ][3d] "your account" modal
- [x] if isTempPassword change message and disallows closing before changing the password
- [ ] give the chance to change modifiers
- [ ] remove legacy header + change password code
- [ ] admin manager should open "my account" when trying to edit self
- [x] remove legacy header + change password code
- [x] admin manager should open "my account" when trying to edit self
- [ ] maybe separate the backend routes
- [ ][3d] playerlist
- [ ][1d] add the new logos to shell+auth pages
Expand Down
9 changes: 9 additions & 0 deletions panel/src/hooks/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export const useAccountModal = () => {
}
}

export const useOpenAccountModal = () => {
const setAccountModalOpen = useSetAtom(accountModalOpenAtom);
const setAccountModalTab = useSetAtom(accountModalTabAtom);
return (tab?: string) => {
setAccountModalOpen(true);
if (tab) setAccountModalTab(tab);
}
}



/**
Expand Down
8 changes: 4 additions & 4 deletions panel/src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ function AuthedHeaderFragment() {
/>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
{/* <DropdownMenuLabel>Your Account</DropdownMenuLabel>
<DropdownMenuSeparator /> */}

<DropdownMenuItem className="cursor-pointer" onClick={switchTheme}>
<span className="hidden dark:flex items-center">
Expand Down Expand Up @@ -175,8 +175,8 @@ export function Header() {
<div className="flex flex-row items-center flex-grow gap-5 mr-5">
<div className="w-sidebar hidden xl:flex justify-center">
<span
className="h-7 w-36 bg-accent text-accent-foreground rounded text-center p-0.5 font-bold tracking-widest"
title={`tx: v${window.txConsts.txaVersion} | fx: b${window.txConsts.fxsVersion}`}
className="h-7 w-36 bg-accent text-accent-foreground rounded text-center p-0.5 font-bold tracking-widest"
title={`tx: v${window.txConsts.txaVersion} | fx: b${window.txConsts.fxsVersion}`}
>FULL LOGO</span>
</div>
<div className="h-8 w-8 lg:h-10 lg:w-10 rounded hidden sm:max-xl:block bg-accent text-accent-foreground text-center">
Expand Down
4 changes: 4 additions & 0 deletions panel/src/layout/MainShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import ConfirmDialog from '@/components/ConfirmDialog';
import PromptDialog from '@/components/PromptDialog';
import TxToaster, { txToast } from '../components/TxToaster';
import AccountDialog from '@/components/AccountDialog';
import { useOpenAccountModal } from '@/hooks/dialogs';


export default function MainShell() {
useAtomValue(pageTitleWatcher);
const expireSession = useExpireAuthData();
const openAccountModal = useOpenAccountModal();
useEventListener('message', (e: MessageEventFromIframe) => {
if (e.data.type === 'logoutNotice') {
expireSession('child iframe');
} else if (e.data.type === 'openYourAccountModal') {
openAccountModal();
}
});

Expand Down
46 changes: 29 additions & 17 deletions web/main/adminManager.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,33 @@
</td>
<td><%= admin.perms %></td>
<td class="tableActions">
<% if (admin.disableEdit) { %>
<button class="btn btn-sm btn-outline-secondary" disabled>
<i class="icon-pencil"></i> Edit
</button>
<% } else { %>
<% if (admin.isSelf) { %>
<button class="btn btn-sm btn-outline-primary"
onclick="getAdminModal('<%= admin.name %>')">
<i class="icon-pencil"></i> Edit
</button>
<% } %>
&nbsp;
<% if (admin.disableDelete) { %>
<button class="btn btn-sm btn-outline-secondary" disabled>
<i class="icon-trash"></i> Delete
onclick="openYourAccountModal()">
<i class="icon-pencil"></i> Your Account
</button>
<% } else { %>
<button class="btn btn-sm btn-outline-danger"
onclick="deleteAdmin('<%= admin.name %>')">
<i class="icon-trash"></i> Delete
</button>
<% if (admin.disableEdit) { %>
<button class="btn btn-sm btn-outline-secondary" disabled>
<i class="icon-pencil"></i> Edit
</button>
<% } else { %>
<button class="btn btn-sm btn-outline-primary"
onclick="getAdminModal('<%= admin.name %>')">
<i class="icon-pencil"></i> Edit
</button>
<% } %>
&nbsp;
<% if (admin.disableDelete) { %>
<button class="btn btn-sm btn-outline-secondary" disabled>
<i class="icon-trash"></i> Delete
</button>
<% } else { %>
<button class="btn btn-sm btn-outline-danger"
onclick="deleteAdmin('<%= admin.name %>')">
<i class="icon-trash"></i> Delete
</button>
<% } %>
<% } %>
</td>
</tr>
Expand Down Expand Up @@ -194,6 +201,11 @@
}
//============================================== Show Your Account Modal
function openYourAccountModal() {
window.parent.postMessage({ type: 'openYourAccountModal' });
}
//============================================== Show Admin Modal
function getAdminModal(name){
let modalType, data;
Expand Down
44 changes: 19 additions & 25 deletions web/parts/adminModal.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,27 @@
<h5>Permissions</h5>
</div>
<div class="form-group row">
<% if (editingSelf) { %>
<div class="col-sm-12 text-center pt-2">
<h5 class="text-secondary">you cannot edit your own permissions</h5>
<div class="col-sm-6">
<% for (const [key, perm] of permsMenu.entries()) { %>
<div class="form-check checkbox">
<input class="form-check-input permsCheckbox" id="modAdmin-permsMenu-<%= perm.id %>-<%= key %>"
type="checkbox" name="modAdmin-permissions[]" value="<%= perm.id %>" <%= perm.checked %>>
<label class="form-check-label <%= perm.dangerous ? 'text-danger' : '' %>"
for="modAdmin-permsMenu-<%= perm.id %>-<%= key %>" alt="sdfsdf sdf sdfsdfs">
<%= perm.desc %>
</label>
</div>
<% } else { %>
<div class="col-sm-6">
<% for (const [key, perm] of permsMenu.entries()) { %>
<div class="form-check checkbox">
<input class="form-check-input permsCheckbox" id="modAdmin-permsMenu-<%= perm.id %>-<%= key %>"
type="checkbox" name="modAdmin-permissions[]" value="<%= perm.id %>" <%= perm.checked %>>
<label class="form-check-label <%= perm.dangerous ? 'text-danger' : '' %>"
for="modAdmin-permsMenu-<%= perm.id %>-<%= key %>" alt="sdfsdf sdf sdfsdfs">
<%= perm.desc %>
</label>
</div>
<% } %>
</div>
<div class="col-sm-6">
<% for (const [key, perm] of permsGeneral.entries()) { %>
<div class="form-check checkbox">
<input class="form-check-input permsCheckbox" id="modAdmin-permsGeneral-<%= perm.id %>-<%= key %>" type="checkbox" name="modAdmin-permissions[]"
value="<%= perm.id %>" <%= perm.checked %>>
<label class="form-check-label <%= perm.dangerous ? 'text-danger' : '' %>" for="modAdmin-permsGeneral-<%= perm.id %>-<%= key %>"><%= perm.desc %></label>
</div>
<% } %>
<% } %>
</div>
<div class="col-sm-6">
<% for (const [key, perm] of permsGeneral.entries()) { %>
<div class="form-check checkbox">
<input class="form-check-input permsCheckbox" id="modAdmin-permsGeneral-<%= perm.id %>-<%= key %>" type="checkbox" name="modAdmin-permissions[]"
value="<%= perm.id %>" <%= perm.checked %>>
<label class="form-check-label <%= perm.dangerous ? 'text-danger' : '' %>" for="modAdmin-permsGeneral-<%= perm.id %>-<%= key %>"><%= perm.desc %></label>
</div>
<% } %>
<% } %>
</div>
</div>

<!-- Just signaling for the save action -->
Expand Down
65 changes: 0 additions & 65 deletions web/parts/changePasswordModal.ejs

This file was deleted.

1 change: 0 additions & 1 deletion web/parts/footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


<%- await include('parts/playerInfoModal.ejs', locals) %>
<%- await include('parts/changePasswordModal.ejs', locals) %>

<!-- CoreUI and necessary plugins-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
Expand Down
37 changes: 0 additions & 37 deletions web/parts/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,6 @@

<!-- Center Content -->
<div class="c-wrapper c-fixed-components">
<!-- Header -->
<% if (isWebInterface) { %>
<header class="c-header c-header-light c-header-fixed c-header-with-subheader">
<ul class="c-header-nav ml-auto mr-4">
<li class="c-header-nav-item dropdown">
<a class="c-header-nav-link" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
aria-expanded="false">
<span class="d-md-down-none pr-2"><%= adminUsername %> </span>
<div class="c-avatar">
<img class="c-avatar-img profile-pic" src="<%= profilePicture %>" alt="<%= adminUsername %>">
</div>
</a>
<div class="dropdown-menu dropdown-menu-right pt-0">
<div class="dropdown-header py-2">
<strong>Account</strong>
</div>
<a class="dropdown-item" href="" onclick="changeOwnPasswordModal(); return false;">
<svg class="c-icon mr-2">
<use href="img/coreui_icons.svg#cil-lock-locked"></use>
</svg> Change password
</a>
<a class="dropdown-item" href="auth?logout">
<svg class="c-icon mr-2">
<use href="img/coreui_icons.svg#cil-account-logout"></use>
</svg> Logout
</a>
</div>
</li>
</ul>
<button class="c-header-toggler c-class-toggler d-xl-none" type="button" data-target="#plist"
data-class="playerlist-sidebar-max">
<svg class="c-icon c-icon-lg">
<use href="img/coreui_icons.svg#cil-menu"></use>
</svg>
</button>
</header>
<% } %> <%# end if(isWebInterface) %>

<!-- Actual Body -->
<div class="c-body">
Expand Down

0 comments on commit 0ebabd5

Please sign in to comment.