Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
- Datasets: Added `exportDatasetMetadata` use case, repository method, and `ExportedDatasetMetadata` response type to support exporting dataset metadata by numeric id or persistent id through Dataverse endpoint `GET /datasets/export`.
- Collections: Added `allowedDatasetTypes` field to the [Collection](./src/collections/domain/models/Collection.ts) model. This field is optional and only populated the feature is enabled on the installation and configured on the collection.
- Collections: Added theme information when retrieving a collection using `getCollection`.
- Collections: Added `getDefaultContributorRole` use case.

### Changed

Expand Down
4 changes: 4 additions & 0 deletions src/collections/domain/repositories/ICollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CollectionSummary } from '../models/CollectionSummary'
import { AllowedStorageDrivers } from '../models/AllowedStorageDrivers'
import { StorageDriver } from '../../../core/domain/models/StorageDriver'
import { LinkingObjectType } from '../useCases/GetCollectionsForLinking'
import { Role } from '../../../roles/domain/models/Role'

export interface ICollectionsRepository {
getCollection(collectionIdOrAlias: number | string): Promise<Collection>
Expand All @@ -39,6 +40,9 @@ export interface ICollectionsRepository {
getCollectionUserPermissions(
collectionIdOrAlias: number | string
): Promise<CollectionUserPermissions>
getDefaultContributorRole(
collectionIdOrAlias: number | string
): Promise<Role>
getCollectionItems(
collectionId?: string,
limit?: number,
Expand Down
25 changes: 25 additions & 0 deletions src/collections/domain/useCases/GetDefaultContributorRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'
import { ROOT_COLLECTION_ID } from '../models/Collection'
import { Role } from '../../../roles/domain/models/Role'

export class GetDefaultContributorRole implements UseCase<Role> {
private collectionsRepository: ICollectionsRepository

constructor(collectionsRepository: ICollectionsRepository) {
this.collectionsRepository = collectionsRepository
}

/**
* Returns the default Role that is assigned to contributors in the given collection.
*
* @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)
* If this parameter is not set, the default value is: ':root'
* @returns {Promise<Role>}
*/
async execute(
collectionIdOrAlias: number | string = ROOT_COLLECTION_ID
): Promise<Role> {
return await this.collectionsRepository.getDefaultContributorRole(collectionIdOrAlias)
}
}
5 changes: 4 additions & 1 deletion src/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { GetCollectionsForLinking } from './domain/useCases/GetCollectionsForLin
import { SetCollectionStorageDriver } from './domain/useCases/SetCollectionStorageDriver'
import { DeleteCollectionStorageDriver } from './domain/useCases/DeleteCollectionStorageDriver'
import { GetAllowedCollectionStorageDrivers } from './domain/useCases/GetAllowedCollectionStorageDrivers'
import { GetDefaultContributorRole } from './domain/useCases/GetDefaultContributorRole'

const collectionsRepository = new CollectionsRepository()

Expand All @@ -46,6 +47,7 @@ const deleteCollectionStorageDriver = new DeleteCollectionStorageDriver(collecti
const getAllowedCollectionStorageDrivers = new GetAllowedCollectionStorageDrivers(
collectionsRepository
)
const getDefaultContributorRole = new GetDefaultContributorRole(collectionsRepository)

export {
getCollection,
Expand All @@ -68,7 +70,8 @@ export {
getCollectionsForLinking,
setCollectionStorageDriver,
deleteCollectionStorageDriver,
getAllowedCollectionStorageDrivers
getAllowedCollectionStorageDrivers,
getDefaultContributorRole
}
export { Collection, CollectionInputLevel, CollectionTheme } from './domain/models/Collection'
export { CollectionFacet } from './domain/models/CollectionFacet'
Expand Down
19 changes: 19 additions & 0 deletions src/collections/infra/repositories/CollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import { CollectionSummary } from '../../domain/models/CollectionSummary'
import { AllowedStorageDrivers } from '../../domain/models/AllowedStorageDrivers'
import { StorageDriver } from '../../../core/domain/models/StorageDriver'
import { LinkingObjectType } from '../../domain/useCases/GetCollectionsForLinking'
import { Role } from '../../../roles/domain/models/Role'
import {
transformCollectionDefaultContributorRoleToRole
} from './transformers/collectionDefaultContributorRoleTransformers'

export interface NewCollectionRequestPayload {
alias: string
Expand Down Expand Up @@ -225,6 +229,21 @@ export class CollectionsRepository extends ApiRepository implements ICollections
})
}

public async getDefaultContributorRole(
collectionIdOrAlias: number | string
): Promise<Role> {
return this.doGet(
`/${this.collectionsResourceName}/${collectionIdOrAlias}/defaultContributorRole`,
true
)
.then((response) =>
transformCollectionDefaultContributorRoleToRole(response)
)
.catch((error) => {
throw error
})
}

public async getCollectionItems(
collectionId?: string,
limit?: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface CollectionDefaultContributorRolePayload {
alias: string
name: string
permissions: Array<string>
description: string
id: number
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AxiosResponse } from 'axios'
import { Role } from '../../../../roles/domain/models/Role'

export const transformCollectionDefaultContributorRoleToRole = (
response: AxiosResponse
): Role => {
const defaultContributorRolePayload = response.data.data
return {
alias: defaultContributorRolePayload.alias,
name: defaultContributorRolePayload.name,
permissions: defaultContributorRolePayload.permissions,
description: defaultContributorRolePayload.description,
id: defaultContributorRolePayload.id
}
}
Loading