From 6f542628897ecdee4bae5454d4e0fd14dc9ede87 Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Fri, 17 Apr 2020 12:12:16 +0800 Subject: [PATCH] [feat] Add pop up command when delete signed tag Signed-off-by: Yogi_Wang --- .../artifact-tag.component.spec.ts | 6 ++++- .../artifact-tag/artifact-tag.component.ts | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts index ba904319f..635f72a4d 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.spec.ts @@ -10,7 +10,7 @@ import { ErrorHandler } from "../../../../../lib/utils/error-handler"; import { ArtifactService } from '../../../../../../ng-swagger-gen/services/artifact.service'; import { OperationService } from "../../../../../lib/components/operation/operation.service"; import { CURRENT_BASE_HREF } from "../../../../../lib/utils/utils"; -import { USERSTATICPERMISSION, UserPermissionService, UserPermissionDefaultService } from '../../../../../lib/services'; +import { USERSTATICPERMISSION, UserPermissionService, UserPermissionDefaultService, SystemInfoService } from '../../../../../lib/services'; import { delay } from 'rxjs/operators'; import { AppConfigService } from "../../../../services/app-config.service"; @@ -29,6 +29,9 @@ describe('ArtifactTagComponent', () => { const config: IServiceConfig = { repositoryBaseEndpoint: CURRENT_BASE_HREF + "/repositories/testing" }; + const mockSystemInfoService = { + getSystemInfo: () => of( false ) + }; const mockAppConfigService = { getConfig: () => { return { @@ -64,6 +67,7 @@ describe('ArtifactTagComponent', () => { { provide: mockErrorHandler, useValue: ErrorHandler }, { provide: ArtifactService, useValue: mockArtifactService }, { provide: AppConfigService, useValue: mockAppConfigService }, + { provide: SystemInfoService, useValue: mockSystemInfoService }, { provide: UserPermissionService, useClass: UserPermissionDefaultService }, { provide: OperationService }, ] diff --git a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts index 40a3e7722..b726cf67c 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-tag/artifact-tag.component.ts @@ -18,7 +18,7 @@ import { ArtifactFront as Artifact } from "../artifact"; import { ArtifactService } from '../../../../../../ng-swagger-gen/services/artifact.service'; import { Tag } from '../../../../../../ng-swagger-gen/models/tag'; import { - UserPermissionService, USERSTATICPERMISSION + UserPermissionService, USERSTATICPERMISSION, SystemInfoService, SystemInfo } from "../../../../../lib/services"; import { ClrDatagridStateInterface } from '@clr/angular'; import { @@ -33,12 +33,13 @@ import { AppConfigService } from "../../../../services/app-config.service"; class InitTag { name = ""; } +const DeleteTagWithNotoryCommand1 = 'notary -s https://'; +const DeleteTagWithNotoryCommand2 = ':4443 -d ~/.docker/trust remove -p '; @Component({ selector: 'artifact-tag', templateUrl: './artifact-tag.component.html', styleUrls: ['./artifact-tag.component.scss'] }) - export class ArtifactTagComponent implements OnInit, OnDestroy { @Input() artifactDetails: Artifact; @Input() projectName: string; @@ -66,11 +67,13 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { tagNameChecker: Subject = new Subject(); tagNameCheckSub: Subscription; tagNameCheckOnGoing = false; + systemInfo: SystemInfo; constructor( private operationService: OperationService, private artifactService: ArtifactService, private translateService: TranslateService, private userPermissionService: UserPermissionService, + private systemInfoService: SystemInfoService, private appConfigService: AppConfigService, private errorHandlerService: ErrorHandler @@ -78,6 +81,8 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { ngOnInit() { this.getImagePermissionRule(this.projectId); this.invalidCreateTag(); + this.systemInfoService.getSystemInfo() + .subscribe(systemInfo => this.systemInfo = systemInfo, error => this.errorHandlerService.error(error)); } checkTagName(name) { let listArtifactParams: ArtifactService.ListArtifactsParams = { @@ -258,6 +263,18 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { operMessage.state = OperationState.progressing; operMessage.data.name = tag.name; this.operationService.publishInfo(operMessage); + + if (tag.signature) { + forkJoin(this.translateService.get("BATCH.DELETED_FAILURE"), + this.translateService.get("REPOSITORY.DELETION_SUMMARY_TAG_DENIED")).subscribe(res => { + let wrongInfo: string = res[1] + DeleteTagWithNotoryCommand1 + this.registryUrl + + DeleteTagWithNotoryCommand2 + + this.registryUrl + "/" + this.repositoryName + + " " + name; + operateChanges(operMessage, OperationState.failure, wrongInfo); + }); + return of(null); + } else { const deleteTagParams: ArtifactService.DeleteTagParams = { projectName: this.projectName, repositoryName: dbEncodeURIComponent(this.repositoryName), @@ -278,6 +295,7 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { ); return of(error); })); + } } existValid(name) { @@ -306,4 +324,7 @@ export class ArtifactTagComponent implements OnInit, OnDestroy { get withNotary(): boolean { return this.appConfigService.getConfig().with_notary; } + public get registryUrl(): string { + return this.systemInfo ? this.systemInfo.registry_url : ''; + } }