disable create, edit
for several routes using AdminOnly
wrapper
This commit is contained in:
parent
c1a788b4e5
commit
739bbe4e28
72
src/App.tsx
72
src/App.tsx
@ -188,15 +188,43 @@ function App() {
|
|||||||
|
|
||||||
<Route path="/country">
|
<Route path="/country">
|
||||||
<Route index element={<CountryList />} />
|
<Route index element={<CountryList />} />
|
||||||
<Route path="create" element={<CountryCreate />} />
|
<Route
|
||||||
<Route path="edit/:id" element={<CountryEdit />} />
|
path="create"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<CountryCreate />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="edit/:id"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<CountryEdit />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="show/:id" element={<CountryShow />} />
|
<Route path="show/:id" element={<CountryShow />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="/city">
|
<Route path="/city">
|
||||||
<Route index element={<CityList />} />
|
<Route index element={<CityList />} />
|
||||||
<Route path="create" element={<CityCreate />} />
|
<Route
|
||||||
<Route path="edit/:id" element={<CityEdit />} />
|
path="create"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<CityCreate />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="edit/:id"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<CityEdit />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="show/:id" element={<CityShow />} />
|
<Route path="show/:id" element={<CityShow />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
@ -230,8 +258,22 @@ function App() {
|
|||||||
|
|
||||||
<Route path="/station">
|
<Route path="/station">
|
||||||
<Route index element={<StationList />} />
|
<Route index element={<StationList />} />
|
||||||
<Route path="create" element={<StationCreate />} />
|
<Route
|
||||||
<Route path="edit/:id" element={<StationEdit />} />
|
path="create"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<StationCreate />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="edit/:id"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<StationEdit />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="show/:id" element={<StationShow />} />
|
<Route path="show/:id" element={<StationShow />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
@ -244,8 +286,22 @@ function App() {
|
|||||||
|
|
||||||
<Route path="/route">
|
<Route path="/route">
|
||||||
<Route index element={<RouteList />} />
|
<Route index element={<RouteList />} />
|
||||||
<Route path="create" element={<RouteCreate />} />
|
<Route
|
||||||
<Route path="edit/:id" element={<RouteEdit />} />
|
path="create"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<RouteCreate />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="edit/:id"
|
||||||
|
element={
|
||||||
|
<AdminOnly>
|
||||||
|
<RouteEdit />
|
||||||
|
</AdminOnly>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="show/:id" element={<RouteShow />} />
|
<Route path="show/:id" element={<RouteShow />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@import './stylesheets/hidden-functionality.css';
|
@import './stylesheets/hidden-functionality.css';
|
||||||
|
@import './stylesheets/roles-functionality.css';
|
||||||
|
|
||||||
.limited-text {
|
.limited-text {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -42,6 +42,7 @@ export const CityList = () => {
|
|||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
headerName: 'Действия',
|
headerName: 'Действия',
|
||||||
|
cellClassName: 'city-actions',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
@ -26,6 +26,7 @@ export const CountryList = () => {
|
|||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
headerName: 'Действия',
|
headerName: 'Действия',
|
||||||
|
cellClassName: 'country-actions',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
@ -62,6 +62,7 @@ export const RouteList = () => {
|
|||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
headerName: 'Действия',
|
headerName: 'Действия',
|
||||||
|
cellClassName: 'route-actions',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
headerAlign: 'center',
|
headerAlign: 'center',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
|
@ -67,6 +67,7 @@ export const StationList = () => {
|
|||||||
{
|
{
|
||||||
field: 'actions',
|
field: 'actions',
|
||||||
headerName: 'Действия',
|
headerName: 'Действия',
|
||||||
|
cellClassName: 'station-actions',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
headerAlign: 'center',
|
headerAlign: 'center',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
|
@ -37,13 +37,3 @@
|
|||||||
.MuiBox-root div .css-1enbsbt-MuiButtonBase-root-MuiButton-root {
|
.MuiBox-root div .css-1enbsbt-MuiButtonBase-root-MuiButton-root {
|
||||||
display: none !important;
|
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;
|
|
||||||
}
|
|
||||||
|
40
src/stylesheets/roles-functionality.css
Normal file
40
src/stylesheets/roles-functionality.css
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user