Skip to content

Commit c861f70

Browse files
committed
feat: add use case for assigning role on collection
1 parent 9c7e9d8 commit c861f70

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/collections/domain/repositories/ICollectionsRepository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface ICollectionsRepository {
2525
getCollectionUserPermissions(
2626
collectionIdOrAlias: number | string
2727
): Promise<CollectionUserPermissions>
28+
assignRoleOnCollection(
29+
collectionIdOrAlias: number | string,
30+
roleAssignee: string,
31+
roleAlias: string
32+
): Promise<void>
2833
getCollectionItems(
2934
collectionId?: string,
3035
limit?: number,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 AssignRoleOnCollection implements UseCase<void> {
6+
private collectionsRepository: ICollectionsRepository
7+
8+
constructor(collectionsRepository: ICollectionsRepository) {
9+
this.collectionsRepository = collectionsRepository
10+
}
11+
12+
/**
13+
* Assigns a new role to someone 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 {string} [roleAssignee] - To whom the role should be assigned
18+
* @param {string} [roleAlias] - The alias of the role to be assigned
19+
* @returns {Promise<void>}
20+
*/
21+
async execute(
22+
collectionIdOrAlias: number | string = ROOT_COLLECTION_ID,
23+
roleAssignee: string,
24+
roleAlias: string
25+
): Promise<void> {
26+
return await this.collectionsRepository.assignRoleOnCollection(collectionIdOrAlias, roleAssignee, roleAlias)
27+
}
28+
}

src/collections/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { LinkCollection } from './domain/useCases/LinkCollection'
1616
import { UnlinkCollection } from './domain/useCases/UnlinkCollection'
1717
import { GetCollectionLinks } from './domain/useCases/GetCollectionLinks'
1818
import { GetCollectionsForLinking } from './domain/useCases/GetCollectionsForLinking'
19+
import { AssignRoleOnCollection } from './domain/useCases/AssignRoleOnCollection'
1920

2021
const collectionsRepository = new CollectionsRepository()
2122

@@ -36,6 +37,7 @@ const linkCollection = new LinkCollection(collectionsRepository)
3637
const unlinkCollection = new UnlinkCollection(collectionsRepository)
3738
const getCollectionLinks = new GetCollectionLinks(collectionsRepository)
3839
const getCollectionsForLinking = new GetCollectionsForLinking(collectionsRepository)
40+
const assignRoleOnCollection = new AssignRoleOnCollection(collectionsRepository)
3941

4042
export {
4143
getCollection,
@@ -54,7 +56,8 @@ export {
5456
linkCollection,
5557
unlinkCollection,
5658
getCollectionLinks,
57-
getCollectionsForLinking
59+
getCollectionsForLinking,
60+
assignRoleOnCollection
5861
}
5962
export { Collection, CollectionInputLevel } from './domain/models/Collection'
6063
export { CollectionFacet } from './domain/models/CollectionFacet'

src/collections/infra/repositories/CollectionsRepository.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ export class CollectionsRepository extends ApiRepository implements ICollections
167167
})
168168
}
169169

170+
public async assignRoleOnCollection(
171+
collectionIdOrAlias: number | string,
172+
roleAssignee: string,
173+
roleAlias: string
174+
): Promise<void> {
175+
return this.doPost(`/${this.collectionsResourceName}/${collectionIdOrAlias}/assignments`, {
176+
assignee: roleAssignee,
177+
role: roleAlias
178+
})
179+
.then(() => undefined)
180+
.catch((error) => {
181+
throw error
182+
})
183+
}
184+
170185
public async getCollectionItems(
171186
collectionId?: string,
172187
limit?: number,

0 commit comments

Comments
 (0)