feat(manager): staff permission editor, signed-in sessions, approvals log (platform-v2 2.6e)
- Staff: the 13 perm_* tick columns become one Permissions column (count, "changed from role") opening an editor grouped by module, from /api/waiters/permission-catalog: switches labelled per key, keys you don't hold are disabled with the reason, reset to role defaults (names what it can't give), save the whole set; access.cannot_grant explained by label. - "Signed in now" (/management/sessions): who, where (app or device), since, last active, your own session marked; end session; show ended + reason. - "Manager approvals" (/management/approvals): the override audit with action label, asked by, approved by, device, used/not used, order link. - Backend: sessions list adds device_name/device_app/current/expires_at; overrides list adds device_name/expires_at. - Permission labels for every key in modules.json (en/el), guarded by test_module_texts; manager unit tests for the editor logic; e2e 66 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,9 @@ import toast from 'react-hot-toast'
|
||||
import client from '../api/client'
|
||||
import { ConfirmModal } from '../ui/Modal'
|
||||
import Button from '../ui/Button'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import PermissionEditor from './staff/PermissionEditor'
|
||||
import { differsFromRole } from './staff/permissionsLogic'
|
||||
|
||||
// ── Role definitions (mirrors backend roles.py) ───────────────────────────────
|
||||
export const ALL_ROLES = [
|
||||
@@ -22,26 +25,6 @@ export const ALL_ROLES = [
|
||||
|
||||
const ROLE_MAP = Object.fromEntries(ALL_ROLES.map(r => [r.value, r]))
|
||||
|
||||
// Permission column definitions — grouped for the table header
|
||||
export const PERM_COLUMNS = [
|
||||
// Access
|
||||
{ key: 'perm_access_dashboard', label: 'Dashboard', group: 'Πρόσβαση' },
|
||||
{ key: 'perm_access_waiter_app', label: 'POS App', group: 'Πρόσβαση' },
|
||||
{ key: 'perm_access_kds', label: 'KDS', group: 'Πρόσβαση' },
|
||||
// Orders
|
||||
{ key: 'perm_open_orders', label: 'Άνοιγμα', group: 'Παραγγελίες' },
|
||||
{ key: 'perm_close_orders', label: 'Κλείσιμο', group: 'Παραγγελίες' },
|
||||
{ key: 'perm_cancel_orders', label: 'Ακύρωση', group: 'Παραγγελίες' },
|
||||
{ key: 'perm_apply_discounts', label: 'Εκπτώσεις', group: 'Παραγγελίες' },
|
||||
{ key: 'perm_modify_prices', label: 'Τιμές', group: 'Παραγγελίες' },
|
||||
// Management
|
||||
{ key: 'perm_view_reports', label: 'Αναφορές', group: 'Διαχείριση' },
|
||||
{ key: 'perm_manage_staff', label: 'Προσωπικό', group: 'Διαχείριση' },
|
||||
{ key: 'perm_manage_menu', label: 'Μενού', group: 'Διαχείριση' },
|
||||
{ key: 'perm_manage_tables', label: 'Τραπέζια', group: 'Διαχείριση' },
|
||||
{ key: 'perm_manage_settings', label: 'Ρυθμίσεις', group: 'Διαχείριση' },
|
||||
]
|
||||
|
||||
// ── Avatar helpers ─────────────────────────────────────────────────────────────
|
||||
function avatarColor(name) {
|
||||
const palette = ['#3758c9', '#7a44c9', '#2f9e5e', '#d94b26', '#8a6d2b', '#0d7a8a', '#c93775']
|
||||
@@ -110,59 +93,8 @@ function PinInput({ value, onChange }) {
|
||||
)
|
||||
}
|
||||
|
||||
// ── Permission toggle cell ─────────────────────────────────────────────────────
|
||||
function PermToggle({ staffId, permKey, value, disabled, onToggle }) {
|
||||
const [optimistic, setOptimistic] = useState(value)
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
useEffect(() => { setOptimistic(value) }, [value])
|
||||
|
||||
async function handleClick() {
|
||||
if (disabled || saving) return
|
||||
const next = !optimistic
|
||||
setOptimistic(next)
|
||||
setSaving(true)
|
||||
try {
|
||||
await onToggle(staffId, permKey, next)
|
||||
} catch {
|
||||
setOptimistic(!next) // revert on error
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const on = optimistic
|
||||
return (
|
||||
<button
|
||||
onClick={handleClick}
|
||||
disabled={disabled}
|
||||
title={disabled ? 'Ο superadmin έχει πάντα αυτό το δικαίωμα' : undefined}
|
||||
style={{
|
||||
width: 26, height: 26, borderRadius: 6, border: 'none',
|
||||
background: disabled ? '#e5e7eb' : on ? '#22c55e' : '#f3f4f6',
|
||||
color: disabled ? '#9ca3af' : on ? '#fff' : '#d1d5db',
|
||||
cursor: disabled ? 'not-allowed' : 'pointer',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
transition: 'all 120ms',
|
||||
opacity: saving ? 0.6 : 1,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
{on ? (
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
|
||||
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Actions dropdown ───────────────────────────────────────────────────────────
|
||||
function ActionsMenu({ member, onEdit, onZones, onResetPin, onBlock, onDelete, onResetPerms, isSuperadmin }) {
|
||||
function ActionsMenu({ member, onEdit, onZones, onResetPin, onBlock, onDelete, onPermissions, permissionsLabel, isSuperadmin }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef(null)
|
||||
|
||||
@@ -177,7 +109,7 @@ function ActionsMenu({ member, onEdit, onZones, onResetPin, onBlock, onDelete, o
|
||||
{ label: 'Επεξεργασία', icon: editIcon, onClick: onEdit },
|
||||
{ label: 'Πρόσβαση σε Ζώνες', icon: zonesIcon, onClick: onZones },
|
||||
{ label: 'Επαναφορά PIN', icon: pinIcon, onClick: onResetPin },
|
||||
!isSuperadmin && { label: 'Επαναφορά Δικαιωμάτων', icon: resetIcon, onClick: onResetPerms },
|
||||
{ label: permissionsLabel, icon: resetIcon, onClick: onPermissions },
|
||||
!isSuperadmin && { label: member.is_active ? 'Μπλοκάρισμα' : 'Ξεμπλοκάρισμα', icon: blockIcon, onClick: onBlock, color: member.is_active ? '#f97316' : '#22c55e' },
|
||||
!isSuperadmin && { label: 'Διαγραφή', icon: trashIcon, onClick: onDelete, color: '#ef4444' },
|
||||
].filter(Boolean)
|
||||
@@ -331,6 +263,8 @@ export default function StaffPage() {
|
||||
const [editModal, setEditModal] = useState(null)
|
||||
const [editForm, setEditForm] = useState({ username: '', full_name: '', nickname: '', mobile_phone: '', email: '', note: '', role: 'waiter', hourly_rate: '' })
|
||||
const [filterRole, setFilterRole] = useState('all')
|
||||
const [permEditor, setPermEditor] = useState(null)
|
||||
const { t } = useTranslation('manager')
|
||||
const avatarInputRef = useRef(null)
|
||||
const newAvatarInputRef = useRef(null)
|
||||
|
||||
@@ -338,6 +272,10 @@ export default function StaffPage() {
|
||||
queryKey: ['staff'],
|
||||
queryFn: () => client.get('/api/waiters/').then(r => r.data),
|
||||
})
|
||||
const { data: catalog } = useQuery({
|
||||
queryKey: ['permission-catalog'],
|
||||
queryFn: () => client.get('/api/waiters/permission-catalog').then(r => r.data),
|
||||
})
|
||||
const { data: groups = [] } = useQuery({
|
||||
queryKey: ['table-groups'],
|
||||
queryFn: () => client.get('/api/tables/groups').then(r => r.data),
|
||||
@@ -402,17 +340,6 @@ export default function StaffPage() {
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
const resetPerms = useMutation({
|
||||
mutationFn: (id) => client.put(`/api/waiters/${id}/reset-permissions`),
|
||||
onSuccess: () => { toast.success('Δικαιώματα επαναφέρθηκαν'); invalidate() },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
async function togglePermission(memberId, permKey, value) {
|
||||
await client.put(`/api/waiters/${memberId}/permission`, { permission: permKey, value })
|
||||
invalidate()
|
||||
}
|
||||
|
||||
if (isLoading) return <div className="flex items-center justify-center h-64 text-gray-400">Φόρτωση…</div>
|
||||
|
||||
function openEdit(m) {
|
||||
@@ -436,13 +363,6 @@ export default function StaffPage() {
|
||||
|
||||
const filtered = filterRole === 'all' ? staff : staff.filter(m => m.role === filterRole)
|
||||
|
||||
// Build column group spans for the table header
|
||||
const groups2 = [
|
||||
{ label: 'Πρόσβαση', cols: PERM_COLUMNS.filter(c => c.group === 'Πρόσβαση') },
|
||||
{ label: 'Παραγγελίες', cols: PERM_COLUMNS.filter(c => c.group === 'Παραγγελίες') },
|
||||
{ label: 'Διαχείριση', cols: PERM_COLUMNS.filter(c => c.group === 'Διαχείριση') },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
{/* ── Header bar ── */}
|
||||
@@ -487,47 +407,19 @@ export default function StaffPage() {
|
||||
<colgroup>
|
||||
<col style={{ width: 220, minWidth: 220 }} />
|
||||
<col style={{ width: 90, minWidth: 90 }} />
|
||||
{PERM_COLUMNS.map(c => (
|
||||
<col key={c.key} style={{ width: 58, minWidth: 54 }} />
|
||||
))}
|
||||
<col style={{ width: 260, minWidth: 200 }} />
|
||||
<col style={{ width: 120, minWidth: 110 }} />
|
||||
</colgroup>
|
||||
<thead>
|
||||
{/* Group header row */}
|
||||
<tr style={{ borderBottom: '1px solid #e5e7eb', background: '#f9fafb' }}>
|
||||
<th style={thBase} />
|
||||
<th style={thBase} />
|
||||
{groups2.map(g => (
|
||||
<th key={g.label} colSpan={g.cols.length} style={{
|
||||
...thBase,
|
||||
borderLeft: '1px solid #e5e7eb',
|
||||
color: '#374151', fontWeight: 700, fontSize: 10,
|
||||
textTransform: 'uppercase', letterSpacing: '0.06em',
|
||||
textAlign: 'center', padding: '6px 0',
|
||||
}}>
|
||||
{g.label}
|
||||
</th>
|
||||
))}
|
||||
<th style={thBase} />
|
||||
</tr>
|
||||
{/* Column label row */}
|
||||
<tr style={{ borderBottom: '2px solid #e5e7eb', background: '#f9fafb' }}>
|
||||
<th style={{ ...thBase, textAlign: 'left', padding: '6px 16px', fontWeight: 600, color: '#374151' }}>
|
||||
Εργαζόμενος
|
||||
</th>
|
||||
<th style={{ ...thBase, textAlign: 'center', color: '#6b7280', fontWeight: 500 }}>Κατάσταση</th>
|
||||
{PERM_COLUMNS.map((c, i) => (
|
||||
<th key={c.key} style={{
|
||||
...thBase,
|
||||
textAlign: 'center', color: '#6b7280', fontWeight: 500,
|
||||
borderLeft: i === 0 || PERM_COLUMNS[i - 1]?.group !== c.group ? '1px solid #e5e7eb' : undefined,
|
||||
writingMode: 'vertical-rl', transform: 'rotate(180deg)',
|
||||
height: 72, padding: '4px 0',
|
||||
fontSize: 11,
|
||||
}}>
|
||||
{c.label}
|
||||
</th>
|
||||
))}
|
||||
<th style={{ ...thBase, textAlign: 'left', padding: '6px 12px', color: '#6b7280', fontWeight: 500 }}>
|
||||
{t('permissions.column')}
|
||||
</th>
|
||||
<th style={{ ...thBase, textAlign: 'right', padding: '6px 12px', color: '#6b7280', fontWeight: 500 }}>
|
||||
Ενέργειες
|
||||
</th>
|
||||
@@ -582,23 +474,18 @@ export default function StaffPage() {
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Permission toggle cells */}
|
||||
{PERM_COLUMNS.map((col, i) => (
|
||||
<td key={col.key} style={{
|
||||
textAlign: 'center', verticalAlign: 'middle', padding: '0 4px',
|
||||
borderLeft: i === 0 || PERM_COLUMNS[i - 1]?.group !== col.group ? '1px solid #f3f4f6' : undefined,
|
||||
}}>
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
<PermToggle
|
||||
staffId={member.id}
|
||||
permKey={col.key}
|
||||
value={isSuperadmin ? true : !!member[col.key]}
|
||||
disabled={isSuperadmin}
|
||||
onToggle={togglePermission}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
))}
|
||||
{/* Permissions (2.6e): count + "custom" when they differ from the role */}
|
||||
<td style={{ padding: '0 12px', verticalAlign: 'middle' }} data-testid={`staff-perms-${member.id}`}>
|
||||
<button type="button" onClick={() => setPermEditor(member)}
|
||||
className="text-left text-label text-ink-2 hover:text-accent-ink inline-flex items-center gap-2">
|
||||
{isSuperadmin
|
||||
? t('permissions.all')
|
||||
: t('permissions.count', { count: member.permissions?.length || 0 })}
|
||||
{!isSuperadmin && catalog && differsFromRole(member.permissions || [], catalog.role_templates[member.role] || []) && (
|
||||
<span className="rounded-full px-2 py-0.5 text-caption font-medium bg-warning-soft text-warning-ink">{t('permissions.custom')}</span>
|
||||
)}
|
||||
</button>
|
||||
</td>
|
||||
|
||||
{/* Actions cell */}
|
||||
<td style={{ textAlign: 'right', padding: '0 12px', verticalAlign: 'middle' }}>
|
||||
@@ -610,7 +497,8 @@ export default function StaffPage() {
|
||||
onResetPin={() => setPinModal(member.id)}
|
||||
onBlock={() => toggleBlock.mutate(member.id)}
|
||||
onDelete={() => setConfirmDelete(member.id)}
|
||||
onResetPerms={() => resetPerms.mutate(member.id)}
|
||||
onPermissions={() => setPermEditor(member)}
|
||||
permissionsLabel={t('permissions.open')}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -687,6 +575,8 @@ export default function StaffPage() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{permEditor && <PermissionEditor member={permEditor} onClose={() => setPermEditor(null)} />}
|
||||
|
||||
{zoneModal && (
|
||||
<ZoneModal member={zoneModal} groups={groups} onClose={() => setZoneModal(null)} />
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user