From 959af275d89b4400b247eff40b496f7396920beb Mon Sep 17 00:00:00 2001 From: kunw Date: Mon, 13 Mar 2017 19:34:30 +0800 Subject: [PATCH] Updates for verfied tags deletion. --- .../app/repository/mock-verfied-signature.ts | 10 ---- .../src/app/repository/repository.service.ts | 36 ++++++-------- .../tag-repository.component.html | 2 +- .../tag-repository.component.ts | 49 +++++++++++++------ src/ui_ng/src/ng/i18n/lang/en-lang.json | 2 + src/ui_ng/src/ng/i18n/lang/zh-lang.json | 2 + 6 files changed, 54 insertions(+), 47 deletions(-) delete mode 100644 src/ui_ng/src/app/repository/mock-verfied-signature.ts diff --git a/src/ui_ng/src/app/repository/mock-verfied-signature.ts b/src/ui_ng/src/app/repository/mock-verfied-signature.ts deleted file mode 100644 index 498eac491..000000000 --- a/src/ui_ng/src/app/repository/mock-verfied-signature.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { VerifiedSignature } from './verified-signature'; - -export const verifiedSignatures: VerifiedSignature[] = [ - { - "tag": "latest", - "hashes": { - "sha256": "E1lggRW5RZnlZBY4usWu8d36p5u5YFfr9B68jTOs+Kc=" - } - } -]; \ No newline at end of file diff --git a/src/ui_ng/src/app/repository/repository.service.ts b/src/ui_ng/src/app/repository/repository.service.ts index ecf7c4cef..028e2e5f1 100644 --- a/src/ui_ng/src/app/repository/repository.service.ts +++ b/src/ui_ng/src/app/repository/repository.service.ts @@ -5,8 +5,6 @@ import { Repository } from './repository'; import { Tag } from './tag'; import { VerifiedSignature } from './verified-signature'; -import { verifiedSignatures } from './mock-verfied-signature'; - import { Observable } from 'rxjs/Observable' import 'rxjs/add/observable/of'; import 'rxjs/add/operator/mergeMap'; @@ -43,25 +41,23 @@ export class RepositoryService { listTagsWithVerifiedSignatures(repoName: string): Observable { return this.http - .get(`/api/repositories/tags?repo_name=${repoName}&detail=1`) - .map(response=>response.json()) - .catch(error=>Observable.throw(error)) - .flatMap((tags: Tag[])=> - this.http - .get(`/api/repositories/signatures?repo_name=${repoName}`) - .map(res=>{ - let signatures = res.json(); - tags.forEach(t=>{ - for(let i = 0; i < signatures.length; i++) { - if(signatures[i].tag === t.tag) { - t.verified = true; - break; - } + .get(`/api/repositories/signatures?repo_name=${repoName}`) + .map(response=>response) + .flatMap(res=> + this.listTags(repoName) + .map((tags: Tag[])=>{ + let signatures = res.json(); + tags.forEach(t=>{ + for(let i = 0; i < signatures.length; i++) { + if(signatures[i].tag === t.tag) { + t.verified = true; + break; } - }); - return tags; - }) - .catch(error=>Observable.throw(error)) + } + }); + return tags; + }) + .catch(error=>Observable.throw(error)) ) .catch(error=>Observable.throw(error)); } diff --git a/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.html b/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.html index 0da162479..2488f44d8 100644 --- a/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.html +++ b/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.html @@ -22,7 +22,7 @@ {{t.architecture}} {{t.os}} - {{'REPOSITORY.DELETE' | translate}} + {{'REPOSITORY.DELETE' | translate}} diff --git a/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.ts b/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.ts index d2e9316f4..ea77ac520 100644 --- a/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.ts +++ b/src/ui_ng/src/app/repository/tag-repository/tag-repository.component.ts @@ -32,16 +32,24 @@ export class TagRepositoryComponent implements OnInit, OnDestroy { private repositoryService: RepositoryService) { this.subscription = this.deletionDialogService.deletionConfirm$.subscribe( message=>{ - let tagName = message.data; - this.repositoryService - .deleteRepoByTag(this.repoName, tagName) - .subscribe( - response=>{ - this.retrieve(); - console.log('Deleted repo:' + this.repoName + ' with tag:' + tagName); - }, - error=>this.messageService.announceMessage(error.status, 'Failed to delete tag:' + tagName + ' under repo:' + this.repoName, AlertType.DANGER) - ); + let tag = message.data; + if(tag) { + if(tag.verified) { + return; + } else { + let tagName = tag.tag; + this.repositoryService + .deleteRepoByTag(this.repoName, tagName) + .subscribe( + response=>{ + this.retrieve(); + console.log('Deleted repo:' + this.repoName + ' with tag:' + tagName); + }, + error=>this.messageService.announceMessage(error.status, 'Failed to delete tag:' + tagName + ' under repo:' + this.repoName, AlertType.DANGER) + ); + } + } + } ) } @@ -58,8 +66,9 @@ export class TagRepositoryComponent implements OnInit, OnDestroy { this.subscription.unsubscribe(); } } - + retrieve() { + this.tags = []; this.repositoryService .listTagsWithVerifiedSignatures(this.repoName) .subscribe( @@ -81,11 +90,19 @@ export class TagRepositoryComponent implements OnInit, OnDestroy { error=>this.messageService.announceMessage(error.status, 'Failed to list tags with repo:' + this.repoName, AlertType.DANGER)); } - deleteTag(tagName: string) { - let message = new DeletionMessage( - 'REPOSITORY.DELETION_TITLE_TAG', 'REPOSITORY.DELETION_SUMMARY_TAG', - tagName, tagName, DeletionTargets.TAG); - this.deletionDialogService.openComfirmDialog(message); + deleteTag(tag: TagView) { + if(tag) { + let titleKey: string, summaryKey: string; + if (tag.verified) { + titleKey = 'REPOSITORY.DELETION_TITLE_TAG_DENIED'; + summaryKey = 'REPOSITORY.DELETION_SUMMARY_TAG_DENIED'; + } else { + titleKey = 'REPOSITORY.DELETION_TITLE_TAG'; + summaryKey = 'REPOSITORY.DELETION_SUMMARY_TAG'; + } + let message = new DeletionMessage(titleKey, summaryKey, tag.tag, tag, DeletionTargets.TAG); + this.deletionDialogService.openComfirmDialog(message); + } } } \ No newline at end of file diff --git a/src/ui_ng/src/ng/i18n/lang/en-lang.json b/src/ui_ng/src/ng/i18n/lang/en-lang.json index c4ba08b65..10f1020b7 100644 --- a/src/ui_ng/src/ng/i18n/lang/en-lang.json +++ b/src/ui_ng/src/ng/i18n/lang/en-lang.json @@ -256,6 +256,8 @@ "DELETION_SUMMARY_REPO": "Do you want to delete repository {{param}}?", "DELETION_TITLE_TAG": "Confirm Tag Deletion", "DELETION_SUMMARY_TAG": "Do you want to delete tag {{param}}?", + "DELETION_TITLE_TAG_DENIED": "Signed Tag can't be deleted", + "DELETION_SUMMARY_TAG_DENIED": "The tag must be removed from Notary before they can be deleted.", "FILTER_FOR_REPOSITORIES": "Filter for repositories", "TAG": "Tag", "VERIFIED": "Verified", diff --git a/src/ui_ng/src/ng/i18n/lang/zh-lang.json b/src/ui_ng/src/ng/i18n/lang/zh-lang.json index cc96fb19d..7585a4079 100644 --- a/src/ui_ng/src/ng/i18n/lang/zh-lang.json +++ b/src/ui_ng/src/ng/i18n/lang/zh-lang.json @@ -256,6 +256,8 @@ "DELETION_SUMMARY_REPO": "确认删除镜像仓库 {{param}}?", "DELETION_TITLE_TAG": "删除镜像标签确认", "DELETION_SUMMARY_TAG": "确认删除镜像标签 {{param}}?", + "DELETION_TITLE_TAG_DENIED": "已签名的镜像不能被删除", + "DELETION_SUMMARY_TAG_DENIED": "要删除此镜像标签必须首先从Notary中删除。", "FILTER_FOR_REPOSITORIES": "过滤镜像仓库", "TAG": "标签", "VERIFIED": "已验证",