static: show admin categories only when user is superuser
This commit is contained in:
parent
eb9df38e92
commit
bc2113a935
|
@ -1,6 +1,9 @@
|
||||||
"""User API Views"""
|
"""User API Views"""
|
||||||
from rest_framework.serializers import BooleanField, ModelSerializer
|
from rest_framework.serializers import BooleanField, ModelSerializer
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from passbook.core.models import User
|
from passbook.core.models import User
|
||||||
|
|
||||||
|
@ -21,3 +24,8 @@ class UserViewSet(ModelViewSet):
|
||||||
|
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
|
@action(detail=False)
|
||||||
|
def me(self, request: Request) -> Response:
|
||||||
|
"""Get information about current user"""
|
||||||
|
return Response(UserSerializer(request.user).data)
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,9 @@
|
||||||
|
export interface User {
|
||||||
|
|
||||||
|
pk: number;
|
||||||
|
username: string;
|
||||||
|
name: string;
|
||||||
|
is_superuser: boolean;
|
||||||
|
email: boolean;
|
||||||
|
|
||||||
|
}
|
|
@ -12,54 +12,51 @@ import PageStyle from "@patternfly/patternfly/components/Page/page.css";
|
||||||
import NavStyle from "@patternfly/patternfly/components/Nav/nav.css";
|
import NavStyle from "@patternfly/patternfly/components/Nav/nav.css";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import GlobalsStyle from "@patternfly/patternfly/base/patternfly-globals.css";
|
import GlobalsStyle from "@patternfly/patternfly/base/patternfly-globals.css";
|
||||||
|
import { User } from "../api/user";
|
||||||
|
|
||||||
export interface SidebarItem {
|
export interface SidebarItem {
|
||||||
name: string;
|
name: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
children?: SidebarItem[];
|
children?: SidebarItem[];
|
||||||
|
condition?: (sb: SideBar) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SIDEBAR_ITEMS: SidebarItem[] = [
|
export const SIDEBAR_ITEMS: SidebarItem[] = [
|
||||||
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
path: "",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "General",
|
name: "General",
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: "Overview",
|
name: "Overview",
|
||||||
path: "overview",
|
path: "administration/overview",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "System Tasks",
|
name: "System Tasks",
|
||||||
path: "tasks",
|
path: "administration/tasks",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Applications",
|
name: "Applications",
|
||||||
path: "applications",
|
path: "administration/applications",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Sources",
|
name: "Sources",
|
||||||
path: "sources",
|
path: "administration/sources",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Providers",
|
name: "Providers",
|
||||||
path: "providers",
|
path: "administration/providers",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "User Management",
|
name: "User Management",
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: "User",
|
name: "User",
|
||||||
path: "users",
|
path: "administration/users",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Groups",
|
name: "Groups",
|
||||||
path: "groups",
|
path: "administration/groups",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -68,50 +65,50 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: "Outposts",
|
name: "Outposts",
|
||||||
path: "outposts",
|
path: "administration/outposts",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Service Connections",
|
name: "Service Connections",
|
||||||
path: "outposts/service_connections",
|
path: "administration/outposts/service_connections",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Policies",
|
name: "Policies",
|
||||||
path: "policies",
|
path: "administration/policies",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Property Mappings",
|
name: "Property Mappings",
|
||||||
path: "property_mappings",
|
path: "administration/property_mappings",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Flows",
|
name: "Flows",
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: "Flows",
|
name: "Flows",
|
||||||
path: "flows",
|
path: "administration/flows",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Stages",
|
name: "Stages",
|
||||||
path: "stages",
|
path: "administration/stages",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Prompts",
|
name: "Prompts",
|
||||||
path: "stages/prompts",
|
path: "administration/stages/prompts",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invitations",
|
name: "Invitations",
|
||||||
path: "stages/invitations",
|
path: "administration/stages/invitations",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Certificates",
|
name: "Certificates",
|
||||||
path: "crypto/certificates",
|
path: "administration/crypto/certificates",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Tokens",
|
name: "Tokens",
|
||||||
path: "tokens",
|
path: "administration/tokens",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -123,10 +120,16 @@ export const ROOT_ITEMS: SidebarItem[] = [
|
||||||
{
|
{
|
||||||
name: "Monitor",
|
name: "Monitor",
|
||||||
path: "/audit/audit/",
|
path: "/audit/audit/",
|
||||||
|
condition: (sb: SideBar) => {
|
||||||
|
return sb.user?.is_superuser!;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Administration",
|
name: "Administration",
|
||||||
children: SIDEBAR_ITEMS
|
children: SIDEBAR_ITEMS,
|
||||||
|
condition: (sb: SideBar) => {
|
||||||
|
return sb.user?.is_superuser!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -141,6 +144,9 @@ export class SideBar extends LitElement {
|
||||||
@property()
|
@property()
|
||||||
brandTitle?: string;
|
brandTitle?: string;
|
||||||
|
|
||||||
|
@property()
|
||||||
|
user?: User;
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return [
|
||||||
GlobalsStyle,
|
GlobalsStyle,
|
||||||
|
@ -176,6 +182,9 @@ export class SideBar extends LitElement {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
fetch("/api/v2beta/core/users/me/")
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(r => this.user = <User>r);
|
||||||
this.activePath = window.location.hash.slice(1, Infinity);
|
this.activePath = window.location.hash.slice(1, Infinity);
|
||||||
window.addEventListener("hashchange", (e) => {
|
window.addEventListener("hashchange", (e) => {
|
||||||
this.activePath = window.location.hash.slice(1, Infinity);
|
this.activePath = window.location.hash.slice(1, Infinity);
|
||||||
|
@ -194,6 +203,12 @@ export class SideBar extends LitElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItem(item: SidebarItem): TemplateResult {
|
renderItem(item: SidebarItem): TemplateResult {
|
||||||
|
if (item.condition) {
|
||||||
|
const result = item.condition(this);
|
||||||
|
if (!result) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
}
|
||||||
return html` <li
|
return html` <li
|
||||||
class="pf-c-nav__item ${item.children
|
class="pf-c-nav__item ${item.children
|
||||||
? "pf-m-expandable pf-m-expanded"
|
? "pf-m-expandable pf-m-expanded"
|
||||||
|
|
Reference in New Issue