From 8aaf6f4523559d80b3bf35c5f08eb085758dcfe7 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Thu, 6 Jun 2024 03:01:51 +0800 Subject: [PATCH] Update ManageUserApiKeys.mjs --- .../Account/Manage/ManageUserApiKeys.mjs | 27 ++++++++++++++----- MyApp/wwwroot/pages/Account/Manage/dtos.mjs | 14 +++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/MyApp/wwwroot/pages/Account/Manage/ManageUserApiKeys.mjs b/MyApp/wwwroot/pages/Account/Manage/ManageUserApiKeys.mjs index 5023df3..650a691 100644 --- a/MyApp/wwwroot/pages/Account/Manage/ManageUserApiKeys.mjs +++ b/MyApp/wwwroot/pages/Account/Manage/ManageUserApiKeys.mjs @@ -4,6 +4,7 @@ import { useClient, useUtils, useFormatters, useMetadata, css } from "@servicest import { QueryUserApiKeys, CreateUserApiKey, UpdateUserApiKey, DeleteUserApiKey } from "./dtos.mjs" function arraysAreEqual(a, b) { + if (!a || !b) return false return a.length === b.length && a.every((v, i) => v === b[i]) } @@ -72,6 +73,9 @@ const CreateApiKeyForm = {
+
+ +
@@ -126,6 +130,7 @@ const CreateApiKeyForm = { const features = ref({}) const api = ref(new ApiResult()) const errorSummary = computed(() => api.value.summaryMessage()) + const apiKeyApis = computed(() => props.info.requestTypes) async function submit(e) { e.preventDefault() @@ -157,7 +162,7 @@ const CreateApiKeyForm = { emit('done') } - return { request, expiresIn, scopes, features, api, errorSummary, submit, css, apiKey, done } + return { request, expiresIn, scopes, features, api, errorSummary, css, apiKey, apiKeyApis, done, submit } } } @@ -180,6 +185,9 @@ const EditApiKeyForm = {
+
+ +
@@ -240,6 +248,7 @@ const EditApiKeyForm = { const features = ref({}) const api = ref(new ApiResult()) const errorSummary = computed(() => api.value.summaryMessage()) + const apiKeyApis = computed(() => props.info.requestTypes) async function submit(e) { e.preventDefault() @@ -259,16 +268,22 @@ const EditApiKeyForm = { } }) - ;['name','expiryDate','scopes','features','notes'].forEach(k => { + ;['name','expiryDate','scopes','features','restrictTo','notes'].forEach(k => { const value = request.value[k] const origValue = origValues[k] + console.log(k, value, origValue, Array.isArray(value) ? arraysAreEqual(value, origValue) : -1) if (value === origValue) return if (Array.isArray(value)) { if (!origValue || !arraysAreEqual(value, origValue)) { - update[k] = value + if (value.length === 0) { + update.reset ??= [] + update.reset.push(k) + } else { + update[k] = value + } } } - if (value) { + else if (value) { update[k] = value } else { update.reset ??= [] @@ -319,11 +334,11 @@ const EditApiKeyForm = { request.value.expiryDate = request.value.expiryDate ? dateInputFormat(toDate(request.value.expiryDate)) : null - origValues = { ...request.value } + origValues = { ...result } } }) - return { css, request, scopes, features, errorSummary, formatDate, + return { css, request, scopes, features, errorSummary, formatDate, apiKeyApis, submit, submitDelete, submitDisable, submitEnable } } } diff --git a/MyApp/wwwroot/pages/Account/Manage/dtos.mjs b/MyApp/wwwroot/pages/Account/Manage/dtos.mjs index c6714bc..06be974 100644 --- a/MyApp/wwwroot/pages/Account/Manage/dtos.mjs +++ b/MyApp/wwwroot/pages/Account/Manage/dtos.mjs @@ -1,5 +1,5 @@ /* Options: -Date: 2024-06-02 00:36:50 +Date: 2024-06-06 02:20:36 Version: 8.23 Tip: To override a DTO option, remove "//" prefix before updating BaseUrl: https://localhost:5001 @@ -40,7 +40,7 @@ export class ResponseStatus { meta; } export class PartialApiKey { - /** @param {{id?:number,name?:string,userId?:string,userName?:string,visibleKey?:string,environment?:string,createdDate?:string,expiryDate?:string,cancelledDate?:string,lastUsedDate?:string,scopes?:string[],features?:string[],notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; },active?:boolean}} [init] */ + /** @param {{id?:number,name?:string,userId?:string,userName?:string,visibleKey?:string,environment?:string,createdDate?:string,expiryDate?:string,cancelledDate?:string,lastUsedDate?:string,scopes?:string[],features?:string[],restrictTo?:string[],notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; },active?:boolean}} [init] */ constructor(init) { Object.assign(this, init) } /** @type {number} */ id; @@ -66,6 +66,8 @@ export class PartialApiKey { scopes; /** @type {string[]} */ features; + /** @type {string[]} */ + restrictTo; /** @type {string} */ notes; /** @type {?number} */ @@ -117,7 +119,7 @@ export class QueryUserApiKeys { createResponse() { return new UserApiKeysResponse() } } export class CreateUserApiKey { - /** @param {{name?:string,scopes?:string[],features?:string[],expiryDate?:string,notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; }}} [init] */ + /** @param {{name?:string,scopes?:string[],features?:string[],restrictTo?:string[],expiryDate?:string,notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; }}} [init] */ constructor(init) { Object.assign(this, init) } /** @type {string} */ name; @@ -125,6 +127,8 @@ export class CreateUserApiKey { scopes; /** @type {string[]} */ features; + /** @type {string[]} */ + restrictTo; /** @type {?string} */ expiryDate; /** @type {string} */ @@ -140,7 +144,7 @@ export class CreateUserApiKey { createResponse() { return new UserApiKeyResponse() } } export class UpdateUserApiKey { - /** @param {{id?:number,name?:string,scopes?:string[],features?:string[],expiryDate?:string,cancelledDate?:string,notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; },reset?:string[]}} [init] */ + /** @param {{id?:number,name?:string,scopes?:string[],features?:string[],restrictTo?:string[],expiryDate?:string,cancelledDate?:string,notes?:string,refId?:number,refIdStr?:string,meta?:{ [index: string]: string; },reset?:string[]}} [init] */ constructor(init) { Object.assign(this, init) } /** @type {number} */ id; @@ -150,6 +154,8 @@ export class UpdateUserApiKey { scopes; /** @type {string[]} */ features; + /** @type {string[]} */ + restrictTo; /** @type {?string} */ expiryDate; /** @type {?string} */