Skip to content

Commit e6eb3e5

Browse files
committed
feat: add use case for unassigning role on collection
1 parent 1575036 commit e6eb3e5

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/collections/domain/repositories/ICollectionsRepository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export interface ICollectionsRepository {
3030
roleAssignee: string,
3131
roleAlias: string
3232
): Promise<void>
33+
unassignRoleOnCollection(
34+
collectionIdOrAlias: number | string,
35+
roleAssignmentId: number
36+
): Promise<void>
3337
getCollectionItems(
3438
collectionId?: string,
3539
limit?: number,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'
3+
import { ROOT_COLLECTION_ID } from '../models/Collection'
4+
5+
export class UnassignRoleOnCollection implements UseCase<void> {
6+
private collectionsRepository: ICollectionsRepository
7+
8+
constructor(collectionsRepository: ICollectionsRepository) {
9+
this.collectionsRepository = collectionsRepository
10+
}
11+
12+
/**
13+
* Deletes the given role assignment on the given Dataverse collection.
14+
*
15+
* @param {number | string} [collectionIdOrAlias = ':root'] - A generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId)
16+
* If this parameter is not set, the default value is: ':root'
17+
* @param {number} [roleAssignmentId] - To numeric identifier of the role assignment
18+
* @returns {Promise<void>}
19+
*/
20+
async execute(
21+
collectionIdOrAlias: number | string = ROOT_COLLECTION_ID,
22+
roleAssignmentId: number
23+
): Promise<void> {
24+
return await this.collectionsRepository.unassignRoleOnCollection(collectionIdOrAlias, roleAssignmentId)
25+
}
26+
}

src/collections/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { UnlinkCollection } from './domain/useCases/UnlinkCollection'
1717
import { GetCollectionLinks } from './domain/useCases/GetCollectionLinks'
1818
import { GetCollectionsForLinking } from './domain/useCases/GetCollectionsForLinking'
1919
import { AssignRoleOnCollection } from './domain/useCases/AssignRoleOnCollection'
20+
import { UnassignRoleOnCollection } from './domain/useCases/UnassignRoleOnCollection'
2021

2122
const collectionsRepository = new CollectionsRepository()
2223

@@ -38,6 +39,7 @@ const unlinkCollection = new UnlinkCollection(collectionsRepository)
3839
const getCollectionLinks = new GetCollectionLinks(collectionsRepository)
3940
const getCollectionsForLinking = new GetCollectionsForLinking(collectionsRepository)
4041
const assignRoleOnCollection = new AssignRoleOnCollection(collectionsRepository)
42+
const unassignRoleOnCollection = new UnassignRoleOnCollection(collectionsRepository)
4143

4244
export {
4345
getCollection,
@@ -57,7 +59,8 @@ export {
5759
unlinkCollection,
5860
getCollectionLinks,
5961
getCollectionsForLinking,
60-
assignRoleOnCollection
62+
assignRoleOnCollection,
63+
unassignRoleOnCollection
6164
}
6265
export { Collection, CollectionInputLevel } from './domain/models/Collection'
6366
export { CollectionFacet } from './domain/models/CollectionFacet'

src/collections/infra/repositories/CollectionsRepository.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ export class CollectionsRepository extends ApiRepository implements ICollections
182182
})
183183
}
184184

185+
public async unassignRoleOnCollection(
186+
collectionIdOrAlias: number | string,
187+
roleAssignmentId: number
188+
): Promise<void> {
189+
return this.doDelete(`/${this.collectionsResourceName}/${collectionIdOrAlias}/assignments/${roleAssignmentId}`)
190+
.then(() => undefined)
191+
.catch((error) => {
192+
throw error
193+
})
194+
}
195+
185196
public async getCollectionItems(
186197
collectionId?: string,
187198
limit?: number,

0 commit comments

Comments
 (0)