From 958efd4dc88595b3b42f423bc022cf97e3bf0567 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Thu, 19 May 2022 12:07:58 +0200 Subject: [PATCH] add allowedSections for user --- src/Umbraco.Web.UI.Client/schemas/api/api.yml | 165 ++++++++++-------- .../schemas/generated-schema.ts | 150 +++++++++------- src/Umbraco.Web.UI.Client/src/api/fetcher.ts | 2 + .../umb-backoffice-header.element.ts | 24 ++- .../src/mocks/handlers.ts | 12 +- .../temp-schema-generator/api.ts | 44 +---- .../temp-schema-generator/user.ts | 62 +++++++ 7 files changed, 278 insertions(+), 181 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/temp-schema-generator/user.ts diff --git a/src/Umbraco.Web.UI.Client/schemas/api/api.yml b/src/Umbraco.Web.UI.Client/schemas/api/api.yml index dba85c3812..fc84b12195 100644 --- a/src/Umbraco.Web.UI.Client/schemas/api/api.yml +++ b/src/Umbraco.Web.UI.Client/schemas/api/api.yml @@ -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 diff --git a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts index cc4a3370ec..84027fe4e7 100644 --- a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts +++ b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts @@ -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 {} diff --git a/src/Umbraco.Web.UI.Client/src/api/fetcher.ts b/src/Umbraco.Web.UI.Client/src/api/fetcher.ts index 743d4729fc..81701702f8 100644 --- a/src/Umbraco.Web.UI.Client/src/api/fetcher.ts +++ b/src/Umbraco.Web.UI.Client/src/api/fetcher.ts @@ -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(); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/umb-backoffice-header.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/umb-backoffice-header.element.ts index 402b63f70a..afca13b0cc 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/umb-backoffice-header.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/umb-backoffice-header.element.ts @@ -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 = ['Content', 'Media', 'Members']; @@ -110,6 +115,15 @@ export class UmbBackofficeHeader extends LitElement { this._open = false; } + async connectedCallback(): Promise { + super.connectedCallback(); + + const { data } = await getUserSections({}); + + this._availableSections = data.sections; + this._visibleSections = data.sections; + } + render() { return html`
@@ -120,13 +134,13 @@ export class UmbBackofficeHeader extends LitElement {
${this._visibleSections.map( - (section) => html` + (section) => html` ` - )} + )} @@ -136,13 +150,13 @@ export class UmbBackofficeHeader extends LitElement { diff --git a/src/Umbraco.Web.UI.Client/src/mocks/handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/handlers.ts index 684bb9b82b..758e28925d 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/handlers.ts @@ -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']), ); }), diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/api.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/api.ts index f2b4069f86..810d29f265 100644 --- a/src/Umbraco.Web.UI.Client/temp-schema-generator/api.ts +++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/api.ts @@ -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) { } -} diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/user.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/user.ts new file mode 100644 index 0000000000..c31043d491 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/user.ts @@ -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[]; +} \ No newline at end of file