fix: mega_admin role in UI checks + fix UserManagementPanel client→supabase

This commit is contained in:
root 2026-05-27 11:17:41 +00:00
parent 58a96355f1
commit c59a806c2c
6 changed files with 27 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import { Panel } from "../UI/Panel";
const getUsers = (users) => (Array.isArray(users) && users.length ? users : demoUsers); const getUsers = (users) => (Array.isArray(users) && users.length ? users : demoUsers);
export const UserDirectoryPanel = ({ currentUser, users }) => { export const UserDirectoryPanel = ({ currentUser, users }) => {
if (currentUser.role !== "admin") { if (currentUser.role !== "admin" && currentUser.role !== "mega_admin") {
return ( return (
<Panel className="p-5"> <Panel className="p-5">
<h3 className="text-lg font-semibold">Пользователи и роли</h3> <h3 className="text-lg font-semibold">Пользователи и роли</h3>

View File

@ -63,7 +63,7 @@ export default function UserManagementPanel() {
const fetchUsers = useCallback(async () => { const fetchUsers = useCallback(async () => {
setLoading(true); setLoading(true);
setError(null); setError(null);
const { data, error: err } = await client const { data, error: err } = await supabase
.from('users') .from('users')
.select('id, email, name, role_id, created_at, last_login, roles(name)') .select('id, email, name, role_id, created_at, last_login, roles(name)')
.order('created_at', { ascending: false }); .order('created_at', { ascending: false });
@ -123,7 +123,7 @@ export default function UserManagementPanel() {
const roleId = getRoleId(newRoleName); const roleId = getRoleId(newRoleName);
if (!roleId) return; if (!roleId) return;
try { try {
const { error: err } = await (supabase || client) const { error: err } = await supabase
.from('users') .from('users')
.update({ role_id: roleId }) .update({ role_id: roleId })
.eq('id', userId); .eq('id', userId);
@ -137,7 +137,7 @@ export default function UserManagementPanel() {
const handleDeleteUser = async (userId) => { const handleDeleteUser = async (userId) => {
try { try {
const { error: err } = await (supabase || client).from('users').delete().eq('id', userId); const { error: err } = await supabase.from('users').delete().eq('id', userId);
if (err) throw err; if (err) throw err;
if (supabase) await supabase.auth.admin.deleteUser(userId); if (supabase) await supabase.auth.admin.deleteUser(userId);
setDeleteConfirmId(null); setDeleteConfirmId(null);

View File

@ -5,12 +5,12 @@ import { Panel } from "../UI/Panel";
import { Bell, Settings } from "../UI/Icons"; import { Bell, Settings } from "../UI/Icons";
const ALL_NOTIF_TYPES = [ const ALL_NOTIF_TYPES = [
{ key: "order_status_change", label: "Изменение статуса", description: "Статус заказа или доставки изменился", roles: ["manager", "logistician", "driver", "admin"] }, { key: "order_status_change", label: "Изменение статуса", description: "Статус заказа или доставки изменился", roles: ["manager", "logistician", "driver", "admin", "mega_admin"] },
{ key: "driver_assigned", label: "Назначение на заказ", description: "Вам назначили заказ или доставку", roles: ["driver"] }, { key: "driver_assigned", label: "Назначение на заказ", description: "Вам назначили заказ или доставку", roles: ["driver"] },
{ key: "driver_unassigned", label: "Снятие с заказа", description: "Вас сняли с заказа или доставки", roles: ["driver"] }, { key: "driver_unassigned", label: "Снятие с заказа", description: "Вас сняли с заказа или доставки", roles: ["driver"] },
{ key: "delivery_problem", label: "Проблемы и отмены", description: "Отмена, проблема, невозможность дозвониться", roles: ["manager", "logistician", "admin"] }, { key: "delivery_problem", label: "Проблемы и отмены", description: "Отмена, проблема, невозможность дозвониться", roles: ["manager", "logistician", "admin", "mega_admin"] },
{ key: "new_order", label: "Новый заказ", description: "Создан новый заказ в системе", roles: ["manager", "logistician", "admin"] }, { key: "new_order", label: "Новый заказ", description: "Создан новый заказ в системе", roles: ["manager", "logistician", "admin", "mega_admin"] },
{ key: "group_status_change", label: "Изменение группы доставки", description: "Статус группы доставки обновлён", roles: ["logistician", "manager", "admin"] }, { key: "group_status_change", label: "Изменение группы доставки", description: "Статус группы доставки обновлён", roles: ["logistician", "manager", "admin", "mega_admin"] },
]; ];
export function NotificationSettings({ userId, userRole, onBack }) { export function NotificationSettings({ userId, userRole, onBack }) {

View File

@ -6,7 +6,7 @@ import { Panel } from "../UI/Panel";
import { Select } from "../UI/Select"; import { Select } from "../UI/Select";
const getUsers = (users) => (Array.isArray(users) && users.length ? users : demoUsers); const getUsers = (users) => (Array.isArray(users) && users.length ? users : demoUsers);
const getManagerOptions = (users) => getUsers(users).filter((user) => user.role === "manager" || user.role === "admin"); const getManagerOptions = (users) => getUsers(users).filter((user) => user.role === "manager" || user.role === "admin" || user.role === "mega_admin");
const initialForm = { const initialForm = {
orderNumber: "", orderNumber: "",
customerName: "", customerName: "",
@ -31,7 +31,7 @@ export const OrderEditorPanel = ({
}) => { }) => {
const [form, setForm] = React.useState(initialForm); const [form, setForm] = React.useState(initialForm);
const [isCreateMode, setIsCreateMode] = React.useState(createOnly); const [isCreateMode, setIsCreateMode] = React.useState(createOnly);
const canManageOrders = currentUser.role === "manager" || currentUser.role === "admin"; const canManageOrders = currentUser.role === "manager" || currentUser.role === "admin" || currentUser.role === "mega_admin";
const managerOptions = getManagerOptions(users); const managerOptions = getManagerOptions(users);
React.useEffect(() => { React.useEffect(() => {

View File

@ -66,7 +66,7 @@ export const filterOrdersByView = ({ orders, currentUser, filters, now }) => {
return false; return false;
} }
if (currentUser.role === "manager" || currentUser.role === "admin") { if (currentUser.role === "manager" || currentUser.role === "admin" || currentUser.role === "mega_admin") {
return true; return true;
} }

16
src/utils/roleHelpers.js Normal file
View File

@ -0,0 +1,16 @@
/**
* Role helpers for SuperSam.
* mega_admin inherits all admin permissions.
*/
/** Roles that have admin-level access (mega_admin is a superset of admin) */
export const ADMIN_ROLES = ['admin', 'mega_admin'];
/** Check if the given role has admin-level access */
export const isAdminRole = (role) => ADMIN_ROLES.includes(role);
/** Roles that can manage orders */
export const ORDER_MANAGER_ROLES = ['manager', 'logistician', 'admin', 'mega_admin'];
/** Check if the role can manage orders */
export const canManageOrders = (role) => ORDER_MANAGER_ROLES.includes(role);