Skip to content

Commit

Permalink
Update ManageUserApiKeys.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jun 5, 2024
1 parent ec009e4 commit b58a308
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
27 changes: 21 additions & 6 deletions MyApp/wwwroot/pages/Account/Manage/ManageUserApiKeys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down Expand Up @@ -72,6 +73,9 @@ const CreateApiKeyForm = {
<div class="col-span-6 sm:col-span-3">
<SelectInput id="expiresIn" v-model="expiresIn" :entries="info.expiresIn" />
</div>
<div class="col-span-6">
<TagInput id="restrictTo" label="Restrict to APIs" v-model="request.restrictTo" :allowableValues="apiKeyApis" />
</div>
<div v-if="info.scopes.length" class="col-span-6">
<div class="mb-2">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Scopes</label>
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 }
}
}

Expand All @@ -180,6 +185,9 @@ const EditApiKeyForm = {
<div class="col-span-6 sm:col-span-3">
<TextInput id="expiryDate" type="date" v-model="request.expiryDate" />
</div>
<div class="col-span-6">
<TagInput id="restrictTo" label="Restrict to APIs" v-model="request.restrictTo" :allowableValues="apiKeyApis" />
</div>
<div v-if="info.scopes.length" class="col-span-6">
<div class="mb-2">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Scopes</label>
Expand Down Expand Up @@ -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()
Expand All @@ -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 ??= []
Expand Down Expand Up @@ -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 }
}
}
Expand Down
14 changes: 10 additions & 4 deletions MyApp/wwwroot/pages/Account/Manage/dtos.mjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -66,6 +66,8 @@ export class PartialApiKey {
scopes;
/** @type {string[]} */
features;
/** @type {string[]} */
restrictTo;
/** @type {string} */
notes;
/** @type {?number} */
Expand Down Expand Up @@ -117,14 +119,16 @@ 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;
/** @type {string[]} */
scopes;
/** @type {string[]} */
features;
/** @type {string[]} */
restrictTo;
/** @type {?string} */
expiryDate;
/** @type {string} */
Expand All @@ -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;
Expand All @@ -150,6 +154,8 @@ export class UpdateUserApiKey {
scopes;
/** @type {string[]} */
features;
/** @type {string[]} */
restrictTo;
/** @type {?string} */
expiryDate;
/** @type {?string} */
Expand Down

0 comments on commit b58a308

Please sign in to comment.