Skip to content
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

[ENG-6459][ENG-6637][ENG-6638] Add Create new preprint version button #2423

Merged
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
8 changes: 8 additions & 0 deletions app/models/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export default class PreprintModel extends AbstractNodeModel {
.replace(/({{year}})/g, year)
.replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
}

get currentUserIsAdmin(): boolean {
return this.currentUserPermissions.includes(Permission.Admin);
}

get canCreateNewVersion(): boolean {
return this.currentUserIsAdmin && this.datePublished && this.isLatestVersion;
}
}

declare module 'ember-data/types/registries/model' {
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/-components/preprint-tombstone/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
{{/if}}
<Preprints::-Components::PreprintAbstract @preprint={{@preprint}} />
<Preprints::-Components::PreprintDoi @preprint={{@preprint}} @provider={{@provider}} />
<Preprints::-Components::PreprintDoi @versions={{@versions}} @provider={{@provider}} />
<Preprints::-Components::PreprintLicense @preprint={{@preprint}} />
<Preprints::-Components::PreprintDiscipline @subjects={{@subjects}} />
<Preprints::-Components::PreprintTag @preprint={{@preprint}} />
Expand Down
13 changes: 4 additions & 9 deletions app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export default class PrePrintsDetailController extends Controller {
}

get editButtonLabel(): string {
const editPreprint = 'preprints.detail.project_button.edit_preprint';
const editResubmitPreprint = 'preprints.detail.project_button.edit_resubmit_preprint';
const editPreprint = 'preprints.detail.edit_preprint';
const editResubmitPreprint = 'preprints.detail.edit_resubmit_preprint';
const translation = this.model.provider.reviewsWorkflow === PreprintProviderReviewsWorkFlow.PRE_MODERATION
&& this.model.preprint.reviewsState === ReviewsState.REJECTED && this.isAdmin()
&& this.model.preprint.reviewsState === ReviewsState.REJECTED && this.model.preprint.currentUserIsAdmin
? editResubmitPreprint : editPreprint;
return this.intl.t(translation, {
documentType: this.model.provider.documentType.singular,
Expand All @@ -90,19 +90,14 @@ export default class PrePrintsDetailController extends Controller {
return this.model.preprint.title;
}

private isAdmin(): boolean {
// True if the current user has admin permissions for the node that contains the preprint
return (this.model.preprint.currentUserPermissions).includes(Permission.Admin);
}

private hasReadWriteAccess(): boolean {
// True if the current user has write permissions for the node that contains the preprint
return (this.model.preprint.currentUserPermissions.includes(Permission.Write));
}


get userIsContrib(): boolean {
if (this.isAdmin()) {
if (this.model.preprint.currentUserIsAdmin) {
return true;
} else if (this.model.contributors.length) {
const authorIds = [] as string[];
Expand Down
22 changes: 17 additions & 5 deletions app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<div local-class='header-container'>
<div local-class='preprint-title-container'>
<h1 data-test-preprint-title>{{this.displayTitle}}</h1>
{{#unless this.model.preprint.isWithdrawn}}
<div class='edit-preprint-button'>
<div>
{{#unless this.model.preprint.isWithdrawn}}
{{#if (and this.userIsContrib (not this.isPendingWithdrawal))}}
<OsfLink
data-test-edit-preprint-button
Expand All @@ -23,9 +23,20 @@

</OsfLink>
{{/if}}
<br>
</div>
{{/unless}}
{{/unless}}
{{#if this.model.preprint.canCreateNewVersion}}
<OsfLink
data-test-create-new-version-button
data-analytics-name='Create new version'
local-class='btn btn-primary'
{{!-- TODO: Update when new version route is implemented --}}
@route='preprints.edit'
@models={{array this.model.provider.id this.model.preprint.id}}
>
{{t 'preprints.detail.create_new_version'}}
</OsfLink>
{{/if}}
</div>
</div>
<div local-class='preprint-author-container'>
<h5 local-class='view-authors'>
Expand All @@ -52,6 +63,7 @@
{{#if this.model.preprint.isWithdrawn}}
<Preprints::-Components::PreprintTombstone
@preprint={{this.model.preprint}}
@versions={{this.model.versions}}
@provider={{this.model.provider}}
@subjects={{this.model.subjects}} />
{{else}}
Expand Down
1 change: 1 addition & 0 deletions mirage/factories/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export default Factory.extend<PreprintMirageModel & PreprintTraits>({
description: preprint.description,
provider: preprint.provider,
id: `${baseId}_v${version}`,
reviewsState: preprint.reviewsState,
preprintVersion: version,
isLatestVersion: version === 3,
});
Expand Down
152 changes: 152 additions & 0 deletions tests/acceptance/preprints/detail-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { currentRouteName } from '@ember/test-helpers';
import { ModelInstance } from 'ember-cli-mirage';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { TestContext } from 'ember-test-helpers';
import { module, test } from 'qunit';

import { setupOSFApplicationTest, visit } from 'ember-osf-web/tests/helpers';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
import PreprintModel from 'ember-osf-web/models/preprint';
import { PreprintProviderReviewsWorkFlow, ReviewsState } from 'ember-osf-web/models/provider';
import { Permission } from 'ember-osf-web/models/osf-model';

interface PreprintDetailTestContext extends TestContext {
provider: ModelInstance<PreprintProviderModel>;
preprint: ModelInstance<PreprintModel>;
}

module('Acceptance | preprints | detail', hooks => {
setupOSFApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(async function(this: PreprintDetailTestContext) {
server.loadFixtures('preprint-providers');
server.loadFixtures('citation-styles');
const provider = server.schema.preprintProviders.find('osf') as ModelInstance<PreprintProviderModel>;
provider.update({
reviewsWorkflow: PreprintProviderReviewsWorkFlow.PRE_MODERATION,
assertionsEnabled: true,
});

const preprint = server.create('preprint', {
id: 'test',
provider,
currentUserPermissions: Object.values(Permission),
title: 'Test Preprint',
description: 'This is a test preprint',
});
this.provider = provider;
this.preprint = preprint;
});

test('Accepted preprint detail page', async function(this: PreprintDetailTestContext, assert) {
this.preprint.update({
reviewsState: ReviewsState.ACCEPTED,
});
await visit('/preprints/osf/test');
assert.equal(currentRouteName(), 'preprints.detail', 'Current route is preprint detail');

// Check page title
const pageTitle = document.getElementsByTagName('title')[0].innerText;
assert.equal(pageTitle, 'OSF Preprints | Test Preprint', 'Page title is correct');

// Check preprint title
assert.dom('[data-test-preprint-title]').exists('Title is displayed');
assert.dom('[data-test-preprint-title]').hasText('Test Preprint', 'Title is correct');

// Check edit and new version buttons
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit button text is correct');
assert.dom('[data-test-create-new-version-button]').exists('New version button is displayed');

// Check preprint authors
assert.dom('[data-test-contributor-name]').exists('Authors are displayed');

// TODO: Check author assertions

// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('accepted', 'Status is correct');
});

test('Accepted preprint, prior version detail page', async function(this: PreprintDetailTestContext, assert) {
this.preprint.update({
reviewsState: ReviewsState.ACCEPTED,
isLatestVersion: false,
});
await visit('/preprints/osf/test');

// Check edit and new version buttons
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit button text is correct');
assert.dom('[data-test-create-new-version-button]')
.doesNotExist('New version button is not displayed for prior versions');

// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('accepted', 'Status is correct');
});

test('Pre-mod: Rejected preprint detail page', async function(this: PreprintDetailTestContext, assert) {
this.provider.update({
reviewsWorkflow: PreprintProviderReviewsWorkFlow.PRE_MODERATION,
});
this.preprint.update({
reviewsState: ReviewsState.REJECTED,
datePublished: null,
});
await visit('/preprints/osf/test');
assert.equal(currentRouteName(), 'preprints.detail', 'Current route is preprint detail');

// Check page title. Should be same as accepted preprint
const pageTitle = document.getElementsByTagName('title')[0].innerText;
assert.equal(pageTitle, 'OSF Preprints | Test Preprint', 'Page title is correct');

// Check preprint title. Should be same as accepted preprint
assert.dom('[data-test-preprint-title]').exists('Title is displayed');
assert.dom('[data-test-preprint-title]').hasText('Test Preprint', 'Title is correct');

// Check edit and new version buttons
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed');
assert.dom('[data-test-edit-preprint-button]')
.hasText('Edit and resubmit', 'Edit button text indicates resubmission');
assert.dom('[data-test-create-new-version-button]').doesNotExist('New version button is not displayed');

// Check preprint authors
assert.dom('[data-test-contributor-name]').exists('Authors are displayed');

// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('rejected', 'Status is correct');
});


test('Withdrawn preprint, latest version detail page', async function(this: PreprintDetailTestContext, assert) {
this.preprint.update({
dateWithdrawn: new Date(),
});
await visit('/preprints/osf/test');

// Check page title
const pageTitle = document.getElementsByTagName('title')[0].innerText;
assert.equal(pageTitle, 'OSF Preprints | Withdrawn: Test Preprint', 'Page title is correct');

// Check new version button and no edit button
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed');
assert.dom('[data-test-create-new-version-button]')
.exists('New version button is displayed for latest withdrawn preprint version');
});

test('Withdrawn preprint, prior version detail page', async function(this: PreprintDetailTestContext, assert) {
this.preprint.update({
dateWithdrawn: new Date(),
isLatestVersion: false,
});
await visit('/preprints/osf/test');

// Check no new version button and no edit button
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed');
assert.dom('[data-test-create-new-version-button]')
.doesNotExist('New version button is not displayed for prior withdrawn preprint version');
});
});
6 changes: 3 additions & 3 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1437,9 +1437,9 @@ preprints:
no_doi: 'No DOI'
preprint_pending_doi_minted: 'DOIs are minted by a third party, and may take up to 24 hours to be registered.'
private_preprint_warning: 'This {documentType} is private. Contact {supportEmail} if this is in error.'
project_button:
edit_preprint: 'Edit {documentType}'
edit_resubmit_preprint: 'Edit and resubmit'
edit_preprint: 'Edit {documentType}'
edit_resubmit_preprint: 'Edit and resubmit'
create_new_version: 'Create new version'
see_less: 'See less'
see_more: 'See more'
share:
Expand Down
Loading