Skip to content

Commit

Permalink
fix: add 'privateUrl' to Dataset domain model
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Oct 23, 2023
1 parent 20f0ecf commit 57b57a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
28 changes: 14 additions & 14 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ export class Dataset {
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean
public readonly isReleased: boolean,
public readonly privateUrl?: string
) {}

public getTitle(): string {
Expand Down Expand Up @@ -334,6 +335,7 @@ export class Dataset {
public readonly hasValidTermsOfAccess: boolean,
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly privateUrl?: string,
public readonly privateUrlToken?: string
) {
this.withLabels()
Expand Down Expand Up @@ -386,6 +388,9 @@ export class Dataset {
}

private withAlerts(): void {
console.log(
'withAlerts, privateUrl ' + this.privateUrl + ' privateUrlToken: ' + this.privateUrlToken
)
if (
this.version.publishingStatus === DatasetPublishingStatus.DRAFT &&
this.permissions.canPublishDataset
Expand Down Expand Up @@ -418,20 +423,15 @@ export class Dataset {
)
}
}
if (this.privateUrl && !this.privateUrlToken) {
const dynamicFields = { privateUrl: this.privateUrl }
this.alerts.push(
new DatasetAlert('info', DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET, dynamicFields)
)
}

if (this.privateUrlToken) {
if (this.permissions.canUpdateDataset) {
// TODO: set the whole Url, not just the token
const dynamicFields = { privateUrl: this.privateUrlToken }
this.alerts.push(
new DatasetAlert(
'info',
DatasetAlertMessageKey.SHARE_UNPUBLISHED_DATASET,
dynamicFields
)
)
} else {
this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET))
}
this.alerts.push(new DatasetAlert('warning', DatasetAlertMessageKey.UNPUBLISHED_DATASET))
}
}

Expand Down
31 changes: 15 additions & 16 deletions src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,20 @@ export const VersionNotFoundShowDraft: Story = {
}
export const SharePrivateUrl: Story = {
render: () => {
const dataset = DatasetMother.createWithPrivateUrlToken(
'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb',
{
version: new DatasetVersion(
1,
DatasetPublishingStatus.RELEASED,
true,
false,
DatasetPublishingStatus.DRAFT,
1,
0
),
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed()
}
)
const dataset = DatasetMother.createRealistic({
version: new DatasetVersion(
1,
DatasetPublishingStatus.RELEASED,
true,
false,
DatasetPublishingStatus.DRAFT,
1,
0
),
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(),
privateUrl:
'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb'
})

return (
<div>
Expand All @@ -110,7 +109,7 @@ export const SharePrivateUrl: Story = {
export const UsePrivateUrl: Story = {
render: () => {
const dataset = DatasetMother.createWithPrivateUrlToken(
'http://localhost:8080/privateurl.xhtml?token=cd943c75-1cc7-4c1d-9717-98141d65d5cb',
'cd943c75-1cc7-4c1d-9717-98141d65d5cb',
{
version: new DatasetVersion(
1,
Expand Down
1 change: 1 addition & 0 deletions tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class DatasetMother {
dataset.hasValidTermsOfAccess,
dataset.isValid,
dataset.isReleased,
dataset.privateUrl,
privateUrlToken
).build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const expectedDataset = {
locks: [],
hasValidTermsOfAccess: true,
isValid: true,
isReleased: false
isReleased: false,
privateUrl: undefined
}
const expectedDatasetAlternateVersion = {
persistentId: 'doi:10.5072/FK2/B4B2MJ',
Expand All @@ -137,6 +138,7 @@ const expectedDatasetAlternateVersion = {
hasValidTermsOfAccess: true,
isReleased: false,
isValid: true,
privateUrl: undefined,
labels: [
{ semanticMeaning: 'dataset', value: 'Draft' },
{ semanticMeaning: 'warning', value: 'Unpublished' }
Expand Down

0 comments on commit 57b57a3

Please sign in to comment.