From 25d85c78906de9fa52616c84ff5788c29349e061 Mon Sep 17 00:00:00 2001 From: Nikita Maliarchuk <84377976+nikita-web-ua@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:38:57 +0100 Subject: [PATCH] [ACS-4331] Add deleteTag method to tag service (#8126) * ACS-4331 - added deleteTag method to tag service * ACS-4331 - docs + unit test * ACS-4331 - docs correction * ACS-4331 - docs alignment fix * ACS-4331 - applied small fixes * ACS-4331 - updated docs * [ACS-4331] removed extra spaces --- docs/content-services/services/tag.service.md | 4 ++++ .../src/lib/tag/services/tag.service.spec.ts | 14 +++++++++++--- .../src/lib/tag/services/tag.service.ts | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/content-services/services/tag.service.md b/docs/content-services/services/tag.service.md index 0611186e93..5ad49b779f 100644 --- a/docs/content-services/services/tag.service.md +++ b/docs/content-services/services/tag.service.md @@ -31,6 +31,10 @@ Manages tags in Content Services. - _nodeId:_ `string` - ID of the target node - _tag:_ `string` - Name of the tag to remove - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - Null object when the operation completes +- **deleteTag**(tagId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)``
+ Completely deletes a tag, this will cause the tag to be removed from all the nodes. + - _tagId:_ `string` - ID of the tag to remove + - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - Null object when the operation completes - **createTags**(tags: `TagBody[]`): [`Observable`](http://reactivex.io/documentation/observable.html)``
Creates tags. - _tags:_ `TagBody[]` - List of tags to create. diff --git a/lib/content-services/src/lib/tag/services/tag.service.spec.ts b/lib/content-services/src/lib/tag/services/tag.service.spec.ts index 42a577122c..e6a204d11e 100644 --- a/lib/content-services/src/lib/tag/services/tag.service.spec.ts +++ b/lib/content-services/src/lib/tag/services/tag.service.spec.ts @@ -66,7 +66,7 @@ describe('TagService', () => { describe('Content tests', () => { - it('getTagsByNodeId catch errors call', async () => { + it('should catch errors on getTagsByNodeId call', async () => { spyOn(service, 'getTagsByNodeId').and.returnValue(throwError({error : 'error'})); await service.getTagsByNodeId('fake-node-id').subscribe(() => { throwError('This call should fail'); @@ -75,7 +75,7 @@ describe('TagService', () => { }); }); - it('delete tag should trigger a refresh event', async () => { + it('should trigger a refresh event on removeTag() call', async () => { await service.refresh.subscribe((res) => { expect(res).toBeDefined(); }); @@ -83,7 +83,7 @@ describe('TagService', () => { service.removeTag('fake-node-id', 'fake-tag'); }); - it('add tag should trigger a refresh event', async () => { + it('should trigger a refresh event on addTag() call', async () => { await service.refresh.subscribe((res) => { expect(res).toBeDefined(); }); @@ -91,6 +91,14 @@ describe('TagService', () => { service.addTag('fake-node-id', 'fake-tag'); }); + it('should trigger a refresh event on deleteTag() call', async () => { + await service.refresh.subscribe((res) => { + expect(res).toBeDefined(); + }); + + service.deleteTag('fake-tag-id'); + }); + describe('createTags', () => { it('should call createTags on tagsApi', () => { spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([])); diff --git a/lib/content-services/src/lib/tag/services/tag.service.ts b/lib/content-services/src/lib/tag/services/tag.service.ts index 816c250783..c93a8a6fb7 100644 --- a/lib/content-services/src/lib/tag/services/tag.service.ts +++ b/lib/content-services/src/lib/tag/services/tag.service.ts @@ -18,7 +18,7 @@ import { AlfrescoApiService, LogService, UserPreferencesService } from '@alfresco/adf-core'; import { EventEmitter, Injectable, Output } from '@angular/core'; import { from, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; +import { catchError, map, tap } from 'rxjs/operators'; import { RequestQuery, RequestSortDefinitionInner, @@ -227,6 +227,20 @@ export class TagService { ); } + /** + * Deletes a tag with tagId. + * This will cause the tag to be removed from all nodes. + * You must have admin rights to delete a tag. + * + * @param tagId of the tag to be deleted + * @returns Null object when the operation completes + */ + deleteTag(tagId: string): Observable { + return from(this.tagsApi.deleteTag(tagId)).pipe( + tap((data) => this.refresh.emit(data)) + ); + } + private handleError(error: any) { this.logService.error(error); return throwError(error || 'Server error');