Skip to content

Commit

Permalink
for superuser, add /django-admin to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrembecky committed Dec 21, 2024
1 parent 55c0e2d commit 6085041
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/PageLayout/MenuMain/MenuMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {BottomButtons} from './BottomButtons'
export const MenuMain: FC = () => {
const {seminar, seminarId} = useSeminarInfo()

const {hasPermissions} = useHasPermissions()
const {hasPermissions, isSuperuser} = useHasPermissions()

const [isVisible, setIsVisible] = useState(false)
const toggleMenu = () => setIsVisible((currentIsVisible) => !currentIsVisible)
Expand Down Expand Up @@ -125,6 +125,7 @@ export const MenuMain: FC = () => {
<Stack>
<MenuMainItem caption="Opravovanie" url={`/${seminar}/admin/opravovanie/`} />
<MenuMainItem caption="Admin" url="/admin" />
{isSuperuser && <MenuMainItem caption="Django Admin" url="/django-admin" />}
</Stack>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/types/api/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface Profile {

export interface MyPermissions {
is_staff: boolean
is_superuser: boolean
competition_permissions: number[]
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/useHasPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export const useHasPermissions = () => {
})

const permissions = data?.data.competition_permissions
const isSuperuser = data?.data.is_superuser ?? false

const {seminarId} = useSeminarInfo()

const hasPermissions = !permissions ? false : permissions.includes(seminarId)

return {hasPermissions, permissionsIsLoading}
return {hasPermissions, isSuperuser, permissionsIsLoading}
}

0 comments on commit 6085041

Please sign in to comment.