-
Notifications
You must be signed in to change notification settings - Fork 11
Set Dataset License and Custom Terms Use Case #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChengShi-1
merged 4 commits into
develop
from
365-set-dataset-license-and-custom-terms-use-case
Nov 5, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { CustomTerms } from '../../domain/models/Dataset' | ||
|
|
||
| export interface DatasetLicenseUpdateRequest { | ||
| name?: string | ||
| customTerms?: CustomTerms | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
| import { DatasetLicenseUpdateRequest } from '../dtos/DatasetLicenseUpdateRequest' | ||
|
|
||
| export class UpdateDatasetLicense implements UseCase<void> { | ||
| private readonly datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Updates the license of a dataset by applying it to the draft version. If no draft exists, a new one is created by the API. | ||
| * Supports either predefined license by name or custom terms of use and access. | ||
| * | ||
| * @param {number | string} datasetId - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @param {DatasetLicenseUpdateRequest} payload - The payload containing the license name or custom terms of use and access. | ||
| * @returns {Promise<void>} - This method does not return anything upon successful completion. | ||
| */ | ||
| async execute(datasetId: number | string, payload: DatasetLicenseUpdateRequest): Promise<void> { | ||
| return this.datasetsRepository.updateDatasetLicense(datasetId, payload) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { | ||
| ApiConfig, | ||
| createDataset, | ||
| getDataset, | ||
| publishDataset, | ||
| updateDatasetLicense, | ||
| DatasetLicenseUpdateRequest | ||
| } from '../../../src' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { | ||
| waitForNoLocks, | ||
| deleteUnpublishedDatasetViaApi, | ||
| deletePublishedDatasetViaApi | ||
| } from '../../testHelpers/datasets/datasetHelper' | ||
| import { DatasetNotNumberedVersion, VersionUpdateType } from '../../../src/datasets' | ||
|
|
||
| describe('execute', () => { | ||
| beforeEach(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| }) | ||
|
|
||
| test('should update the license of a draft dataset (predefined by name)', async () => { | ||
| const created = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO) | ||
|
|
||
| const payload: DatasetLicenseUpdateRequest = { name: 'CC BY 4.0' } | ||
| const response = await updateDatasetLicense.execute(created.numericId, payload) | ||
|
|
||
| expect(response).toBeUndefined() | ||
|
|
||
| const after = await getDataset.execute( | ||
| created.numericId, | ||
| DatasetNotNumberedVersion.DRAFT, | ||
| false, | ||
| false | ||
| ) | ||
| expect(after.license?.name).toBe('CC BY 4.0') | ||
|
|
||
| await deleteUnpublishedDatasetViaApi(created.numericId) | ||
| }) | ||
|
|
||
| test('should update the license of a published dataset (custom terms creates draft)', async () => { | ||
| const created = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO) | ||
|
|
||
| await publishDataset.execute(created.numericId, VersionUpdateType.MAJOR) | ||
| await waitForNoLocks(created.numericId, 10) | ||
|
|
||
| const payload: DatasetLicenseUpdateRequest = { | ||
| customTerms: { | ||
| termsOfUse: 'Updated terms of use (functional test)' | ||
| } | ||
| } | ||
| const response = await updateDatasetLicense.execute(created.numericId, payload) | ||
|
|
||
| expect(response).toBeUndefined() | ||
|
|
||
| const draft = await getDataset.execute( | ||
| created.numericId, | ||
| DatasetNotNumberedVersion.DRAFT, | ||
| false, | ||
| false | ||
| ) | ||
| expect(draft.license).toBeUndefined() | ||
| expect(draft.termsOfUse.customTerms?.termsOfUse).toBe('Updated terms of use (functional test)') | ||
|
|
||
| await deletePublishedDatasetViaApi(created.persistentId) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.