diff --git a/backend/src/collections/apikey-db/apikey-db.service.ts b/backend/src/collections/apikey-db/apikey-db.service.ts index 59266ad..ff9b0e4 100644 --- a/backend/src/collections/apikey-db/apikey-db.service.ts +++ b/backend/src/collections/apikey-db/apikey-db.service.ts @@ -19,6 +19,7 @@ export class ApiKeyDbService { async createApiKey(userid: string): AsyncFailable> { const apikey = new EApiKeyBackend(); apikey.user = userid; + apikey.created = new Date(); apikey.key = generateRandomString(32); // Might collide, probably not /* diff --git a/backend/src/database/entities/apikey.entity.ts b/backend/src/database/entities/apikey.entity.ts index c289eb3..06fee42 100644 --- a/backend/src/database/entities/apikey.entity.ts +++ b/backend/src/database/entities/apikey.entity.ts @@ -1,8 +1,6 @@ import { EApiKeySchema } from 'picsur-shared/dist/entities/apikey.entity'; import { - Column, - CreateDateColumn, - Entity, + Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm'; @@ -33,7 +31,7 @@ export class EApiKeyBackend< }) user: T; - @CreateDateColumn({ + @Column({ nullable: false, }) created: Date; diff --git a/backend/src/models/constants/roles.const.ts b/backend/src/models/constants/roles.const.ts index eb2d730..ce0cee5 100644 --- a/backend/src/models/constants/roles.const.ts +++ b/backend/src/models/constants/roles.const.ts @@ -35,6 +35,7 @@ const SystemRoleDefaultsTyped: { Permission.UserLogin, Permission.Settings, Permission.ImageUpload, + Permission.ApiKey, ], // Grant all permissions to admin admin: PermissionsList, diff --git a/frontend/src/app/components/copy-field/copy-field.component.html b/frontend/src/app/components/copy-field/copy-field.component.html index 8136edb..d8a0dca 100644 --- a/frontend/src/app/components/copy-field/copy-field.component.html +++ b/frontend/src/app/components/copy-field/copy-field.component.html @@ -1,6 +1,20 @@ {{ label }} - + + diff --git a/frontend/src/app/components/copy-field/copy-field.component.ts b/frontend/src/app/components/copy-field/copy-field.component.ts index 8dbe683..094780d 100644 --- a/frontend/src/app/components/copy-field/copy-field.component.ts +++ b/frontend/src/app/components/copy-field/copy-field.component.ts @@ -1,5 +1,5 @@ import { Clipboard } from '@angular/cdk/clipboard'; -import { Component, Input } from '@angular/core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { SnackBarType } from 'src/app/models/dto/snack-bar-type.dto'; import { UtilService } from 'src/app/util/util-module/util.service'; @@ -13,6 +13,12 @@ export class CopyFieldComponent { @Input() label: string = 'Loading...'; @Input() value: string = 'Loading...'; + @Input() showHideButton: boolean = false; + @Input() hidden: boolean = false; + + @Output('copy') onCopy = new EventEmitter(); + @Output('hide') onHide = new EventEmitter(); + constructor( private readonly utilService: UtilService, private readonly clipboard: Clipboard, @@ -21,6 +27,7 @@ export class CopyFieldComponent { public copy() { if (this.clipboard.copy(this.value)) { this.utilService.showSnackBar(`Copied ${this.label}!`, SnackBarType.Info); + this.onCopy.emit(this.value); return; } @@ -29,4 +36,9 @@ export class CopyFieldComponent { SnackBarType.Error, ); } + + public toggleHide() { + this.hidden = !this.hidden; + this.onHide.emit(this.hidden); + } } diff --git a/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.html b/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.html index 13a1b77..a9f1a90 100644 --- a/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.html +++ b/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.html @@ -4,24 +4,31 @@ Key - + - + Created - {{ - apikey.created | amTimeAgo - }} + + {{ apikey.created | amTimeAgo }} + - Last Used - {{ - apikey.last_used === null ? 'Never' : (apikey.last_used | amTimeAgo) - }} + + Last Used + + + {{ apikey.last_used === null ? 'Never' : (apikey.last_used | amTimeAgo) }} + diff --git a/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.scss b/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.scss index b5f4c1e..aa9f15c 100644 --- a/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.scss +++ b/frontend/src/app/routes/settings/apikeys/settings-apikeys.component.scss @@ -4,6 +4,7 @@ mat-table { .mat-column-actions { justify-content: end; + flex-grow: .5; } .mat-column-key { @@ -11,7 +12,7 @@ mat-table { } .mat-column-last_used { - flex-grow: .5; + flex-grow: 0.5; } .icon-red { @@ -20,4 +21,7 @@ mat-table { copy-field { margin-top: 1rem; + width: 100%; + margin-right: 1rem; + padding-right: 1rem; }