add allowedSections for user

This commit is contained in:
Jacob Overgaard
2022-05-19 12:07:58 +02:00
parent e4b6c825ac
commit 958efd4dc8
7 changed files with 278 additions and 181 deletions

View File

@@ -35,53 +35,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user/login:
post:
operationId: PostUserLogin
parameters: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserLoginRequest'
required: true
responses:
'201':
description: 201 response
'403':
description: 403 response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user/logout:
post:
operationId: PostUserLogout
responses:
'201':
description: 201 response
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user:
get:
operationId: GetUser
responses:
'200':
description: 200 response
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
'403':
description: 403 response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/install:
get:
operationId: GetInstall
@@ -129,6 +82,69 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user:
get:
operationId: GetUser
responses:
'200':
description: 200 response
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
'403':
description: 403 response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user/login:
post:
operationId: PostUserLogin
parameters: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserLoginRequest'
required: true
responses:
'201':
description: 201 response
'403':
description: 403 response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user/logout:
post:
operationId: PostUserLogout
responses:
'201':
description: 201 response
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/user/sections:
get:
operationId: GetAllowedSections
responses:
'200':
description: 200 response
content:
application/json:
schema:
$ref: '#/components/schemas/AllowedSectionsResponse'
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
InitResponse:
@@ -152,29 +168,6 @@ components:
type: string
required:
- version
UserLoginRequest:
type: object
properties:
username:
type: string
password:
type: string
persist:
type: boolean
required:
- username
- password
- persist
UserResponse:
type: object
properties:
username:
type: string
role:
type: string
required:
- username
- role
ConsentLevel:
type: object
properties:
@@ -338,3 +331,35 @@ components:
- subscribeToNewsletter
- telemetryLevel
- database
UserResponse:
type: object
properties:
username:
type: string
role:
type: string
required:
- username
- role
UserLoginRequest:
type: object
properties:
username:
type: string
password:
type: string
persist:
type: boolean
required:
- username
- password
- persist
AllowedSectionsResponse:
type: object
properties:
sections:
type: array
items:
type: string
required:
- sections

View File

@@ -10,15 +10,6 @@ export interface paths {
"/version": {
get: operations["GetVersion"];
};
"/user/login": {
post: operations["PostUserLogin"];
};
"/user/logout": {
post: operations["PostUserLogout"];
};
"/user": {
get: operations["GetUser"];
};
"/install": {
get: operations["GetInstall"];
post: operations["PostInstall"];
@@ -26,6 +17,18 @@ export interface paths {
"/install/database/validate": {
post: operations["PostInstallValidateDatabase"];
};
"/user": {
get: operations["GetUser"];
};
"/user/login": {
post: operations["PostUserLogin"];
};
"/user/logout": {
post: operations["PostUserLogout"];
};
"/user/sections": {
get: operations["GetAllowedSections"];
};
}
export interface components {
@@ -39,15 +42,6 @@ export interface components {
VersionResponse: {
version: string;
};
UserLoginRequest: {
username: string;
password: string;
persist: boolean;
};
UserResponse: {
username: string;
role: string;
};
ConsentLevel: {
/** @enum {string} */
level: "Minimal" | "Basic" | "Detailed";
@@ -109,6 +103,18 @@ export interface components {
telemetryLevel: "Minimal" | "Basic" | "Detailed";
database: components["schemas"]["UmbracoInstallerDatabaseConfiguration"];
};
UserResponse: {
username: string;
role: string;
};
UserLoginRequest: {
username: string;
password: string;
persist: boolean;
};
AllowedSectionsResponse: {
sections: string[];
};
};
}
@@ -145,52 +151,6 @@ export interface operations {
};
};
};
PostUserLogin: {
parameters: {};
responses: {
/** 201 response */
201: unknown;
/** 403 response */
403: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
requestBody: {
content: {
"application/json": components["schemas"]["UserLoginRequest"];
};
};
};
PostUserLogout: {
responses: {
/** 201 response */
201: unknown;
/** default response */
default: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
};
GetUser: {
responses: {
/** 200 response */
200: {
content: {
"application/json": components["schemas"]["UserResponse"];
};
};
/** 403 response */
403: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
};
GetInstall: {
responses: {
/** 200 response */
@@ -237,6 +197,68 @@ export interface operations {
};
};
};
GetUser: {
responses: {
/** 200 response */
200: {
content: {
"application/json": components["schemas"]["UserResponse"];
};
};
/** 403 response */
403: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
};
PostUserLogin: {
parameters: {};
responses: {
/** 201 response */
201: unknown;
/** 403 response */
403: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
requestBody: {
content: {
"application/json": components["schemas"]["UserLoginRequest"];
};
};
};
PostUserLogout: {
responses: {
/** 201 response */
201: unknown;
/** default response */
default: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
};
GetAllowedSections: {
responses: {
/** 200 response */
200: {
content: {
"application/json": components["schemas"]["AllowedSectionsResponse"];
};
};
/** default response */
default: {
content: {
"application/json": components["schemas"]["ErrorResponse"];
};
};
};
};
}
export interface external {}

View File

@@ -9,7 +9,9 @@ fetcher.configure({
});
export const getInitStatus = fetcher.path('/init').method('get').create();
export const getUser = fetcher.path('/user').method('get').create();
export const postUserLogin = fetcher.path('/user/login').method('post').create();
export const postUserLogout = fetcher.path('/user/logout').method('post').create();
export const getUserSections = fetcher.path('/user/sections').method('get').create();
export const getInstall = fetcher.path('/install').method('get').create();
export const postInstall = fetcher.path('/install').method('post').create();

View File

@@ -1,6 +1,8 @@
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import { css, CSSResultGroup, html, LitElement } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import { getUserSections } from '../api/fetcher';
@customElement('umb-backoffice-header')
export class UmbBackofficeHeader extends LitElement {
@@ -78,6 +80,9 @@ export class UmbBackofficeHeader extends LitElement {
@state()
private _activeSection: string = this._sections[0];
@state()
private _availableSections: string[] = [];
@state()
private _visibleSections: Array<string> = ['Content', 'Media', 'Members'];
@@ -110,6 +115,15 @@ export class UmbBackofficeHeader extends LitElement {
this._open = false;
}
async connectedCallback(): Promise<void> {
super.connectedCallback();
const { data } = await getUserSections({});
this._availableSections = data.sections;
this._visibleSections = data.sections;
}
render() {
return html`
<div id="appHeader">
@@ -120,13 +134,13 @@ export class UmbBackofficeHeader extends LitElement {
<div id="sections">
<uui-tab-group id="tabs">
${this._visibleSections.map(
(section) => html`
(section) => html`
<uui-tab
?active="${this._activeSection === section}"
label="${section}"
@click="${this._handleTabClick}"></uui-tab>
`
)}
)}
<uui-tab id="moreTab" @click="${this._handleTabClick}">
<uui-popover .open=${this._open} placement="bottom-start" @close="${() => (this._open = false)}">
@@ -136,13 +150,13 @@ export class UmbBackofficeHeader extends LitElement {
<div slot="popover" id="dropdown">
${this._extraSections.map(
(section) => html`
(section) => html`
<uui-menu-item
?active="${this._activeSection === section}"
label="${section}"
@click-label="${this._handleLabelClick}"></uui-menu-item>
`
)}
)}
</div>
</uui-popover>
</uui-tab>

View File

@@ -58,7 +58,17 @@ export const handlers = [
ctx.status(200),
ctx.json({
username: 'admin',
})
role: 'administrator'
} as components['schemas']['UserResponse']),
);
}),
rest.get('/umbraco/backoffice/user/sections', (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
sections: ['Content', 'Media', 'Members', 'Settings', 'Packages']
} as components['schemas']['AllowedSectionsResponse']),
);
}),

View File

@@ -1,8 +1,9 @@
import './installer';
import './user';
import { api, body, defaultResponse, endpoint, request, response } from '@airtasker/spot';
import { api, body, defaultResponse, endpoint, response } from '@airtasker/spot';
import { ErrorResponse, InitResponse, UserLoginRequest, UserResponse, VersionResponse } from './models';
import { ErrorResponse, InitResponse, VersionResponse } from './models';
/* eslint-disable */
@api({ name: "umbraco-backoffice-api", version: "1.0.0" })
@@ -31,42 +32,3 @@ class GetVersion {
@defaultResponse
default(@body body: ErrorResponse) { }
}
@endpoint({
method: "POST",
path: "/user/login",
})
class PostUserLogin {
@request
request(@body body: UserLoginRequest) { }
@response({ status: 201 })
success() { }
@response({ status: 403 })
failure(@body body: ErrorResponse) { }
}
@endpoint({
method: "POST",
path: "/user/logout",
})
class PostUserLogout {
@response({ status: 201 })
success() { }
@defaultResponse
default(@body body: ErrorResponse) { }
}
@endpoint({
method: "GET",
path: "/user",
})
class GetUser {
@response({ status: 200 })
success(@body body: UserResponse) { }
@response({ status: 403 })
failure(@body body: ErrorResponse) { }
}

View File

@@ -0,0 +1,62 @@
import { body, defaultResponse, endpoint, request, response } from '@airtasker/spot';
import { ErrorResponse, UserLoginRequest, UserResponse } from './models';
@endpoint({
method: "GET",
path: "/user",
})
class GetUser {
@response({ status: 200 })
success(@body body: UserResponse) { }
@response({ status: 403 })
failure(@body body: ErrorResponse) { }
}
@endpoint({
method: "POST",
path: "/user/login",
})
class PostUserLogin {
@request
request(@body body: UserLoginRequest) { }
@response({ status: 201 })
success() { }
@response({ status: 403 })
failure(@body body: ErrorResponse) { }
}
@endpoint({
method: "POST",
path: "/user/logout",
})
class PostUserLogout {
@response({ status: 201 })
success() { }
@defaultResponse
default(@body body: ErrorResponse) { }
}
@endpoint({
method: "GET",
path: "/user/sections",
})
export class GetAllowedSections {
@response({ status: 200 })
successResponse(
@body body: AllowedSectionsResponse
) { }
@defaultResponse
defaultResponse(
@body body: ErrorResponse
) { }
}
export interface AllowedSectionsResponse {
sections: string[];
}