disable create, edit for several routes using AdminOnly wrapper

This commit is contained in:
maxim 2025-04-03 17:25:28 +03:00
parent c1a788b4e5
commit 739bbe4e28
8 changed files with 109 additions and 18 deletions

View File

@ -188,15 +188,43 @@ function App() {
<Route path="/country">
<Route index element={<CountryList />} />
<Route path="create" element={<CountryCreate />} />
<Route path="edit/:id" element={<CountryEdit />} />
<Route
path="create"
element={
<AdminOnly>
<CountryCreate />
</AdminOnly>
}
/>
<Route
path="edit/:id"
element={
<AdminOnly>
<CountryEdit />
</AdminOnly>
}
/>
<Route path="show/:id" element={<CountryShow />} />
</Route>
<Route path="/city">
<Route index element={<CityList />} />
<Route path="create" element={<CityCreate />} />
<Route path="edit/:id" element={<CityEdit />} />
<Route
path="create"
element={
<AdminOnly>
<CityCreate />
</AdminOnly>
}
/>
<Route
path="edit/:id"
element={
<AdminOnly>
<CityEdit />
</AdminOnly>
}
/>
<Route path="show/:id" element={<CityShow />} />
</Route>
@ -230,8 +258,22 @@ function App() {
<Route path="/station">
<Route index element={<StationList />} />
<Route path="create" element={<StationCreate />} />
<Route path="edit/:id" element={<StationEdit />} />
<Route
path="create"
element={
<AdminOnly>
<StationCreate />
</AdminOnly>
}
/>
<Route
path="edit/:id"
element={
<AdminOnly>
<StationEdit />
</AdminOnly>
}
/>
<Route path="show/:id" element={<StationShow />} />
</Route>
@ -244,8 +286,22 @@ function App() {
<Route path="/route">
<Route index element={<RouteList />} />
<Route path="create" element={<RouteCreate />} />
<Route path="edit/:id" element={<RouteEdit />} />
<Route
path="create"
element={
<AdminOnly>
<RouteCreate />
</AdminOnly>
}
/>
<Route
path="edit/:id"
element={
<AdminOnly>
<RouteEdit />
</AdminOnly>
}
/>
<Route path="show/:id" element={<RouteShow />} />
</Route>

View File

@ -1,4 +1,5 @@
@import './stylesheets/hidden-functionality.css';
@import './stylesheets/roles-functionality.css';
.limited-text {
overflow: hidden;

View File

@ -42,6 +42,7 @@ export const CityList = () => {
{
field: 'actions',
headerName: 'Действия',
cellClassName: 'city-actions',
minWidth: 120,
display: 'flex',
align: 'right',

View File

@ -26,6 +26,7 @@ export const CountryList = () => {
{
field: 'actions',
headerName: 'Действия',
cellClassName: 'country-actions',
minWidth: 120,
display: 'flex',
align: 'right',

View File

@ -62,6 +62,7 @@ export const RouteList = () => {
{
field: 'actions',
headerName: 'Действия',
cellClassName: 'route-actions',
align: 'right',
headerAlign: 'center',
minWidth: 120,

View File

@ -67,6 +67,7 @@ export const StationList = () => {
{
field: 'actions',
headerName: 'Действия',
cellClassName: 'station-actions',
align: 'right',
headerAlign: 'center',
minWidth: 120,

View File

@ -37,13 +37,3 @@
.MuiBox-root div .css-1enbsbt-MuiButtonBase-root-MuiButton-root {
display: none !important;
}
/* Hide users menu item by default */
a[aria-label='Пользователи'] {
display: none !important;
}
/* Show for admin users - this class will be added to body */
body.is-admin a[aria-label='Пользователи'] {
display: flex !important;
}

View File

@ -0,0 +1,40 @@
/* Прячем секцию Пользователи из сайдбара по умолчанию */
a[aria-label='Пользователи'] {
display: none !important;
}
/* показываем только если админ */
body.is-admin a[aria-label='Пользователи'] {
display: flex !important;
}
/* Скрываем кнопки "Редактировать", "Удалить" и "Просмотр" в таблицах городов, стран, маршрутов и станций
для пользователей, у которых нет класса is-admin на <body>.
Работает только в колонке с действиями (например, .city-actions), не затрагивая другие кнопки на странице. */
body:not(.is-admin) .city-actions .refine-edit-button,
body:not(.is-admin) .city-actions .refine-delete-button,
body:not(.is-admin) .country-actions .refine-edit-button,
body:not(.is-admin) .country-actions .refine-delete-button,
body:not(.is-admin) .route-actions .refine-edit-button,
body:not(.is-admin) .route-actions .refine-delete-button,
body:not(.is-admin) .station-actions .refine-edit-button,
body:not(.is-admin) .station-actions .refine-delete-button {
display: none !important;
}
/* Скрываем "Редактировать" на show-странице, если нет класса is-admin */
body:not(.is-admin) a[href^='/country/edit'] .refine-edit-button,
body:not(.is-admin) a[href^='/city/edit'] .refine-edit-button,
body:not(.is-admin) a[href^='/route/edit'] .refine-edit-button,
body:not(.is-admin) a[href^='/station/edit'] .refine-edit-button {
display: none !important;
}
/* Скрываем "Создать" на list-странице, если нет класса is-admin */
body:not(.is-admin) a[href^='/country/create'] .refine-create-button,
body:not(.is-admin) a[href^='/city/create'] .refine-create-button,
body:not(.is-admin) a[href^='/route/create'] .refine-create-button,
body:not(.is-admin) a[href^='/station/create'] .refine-create-button {
display: none !important;
}