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-6815][ENG-6843] Update condition to show edit button #2460

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
5 changes: 2 additions & 3 deletions app/preprints/-components/preprint-status-banner/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ICONS[UNKNOWN] = 'exclamation-triangle';

interface InputArgs {
submission: PreprintModel;
provider: PreprintProviderModel;
}

export default class PreprintStatusBanner extends Component<InputArgs>{
Expand All @@ -78,7 +79,7 @@ export default class PreprintStatusBanner extends Component<InputArgs>{
submission = this.args.submission;
isWithdrawn = this.args.submission.isWithdrawn;

provider: PreprintProviderModel | undefined;
provider = this.args.provider;

@tracked displayComment = false;
isPendingWithdrawal = false;
Expand Down Expand Up @@ -178,8 +179,6 @@ export default class PreprintStatusBanner extends Component<InputArgs>{
@task
@waitFor
async loadPreprintState() {
this.provider = await this.submission.provider;

if (this.isWithdrawn) {
return;
}
Expand Down
34 changes: 32 additions & 2 deletions app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,41 @@ export default class PrePrintsDetailController extends Controller {
DATE_LABEL.created;
}

get showEditButton() {
const providerIsPremod = this.model.provider.reviewsWorkflow === PreprintProviderReviewsWorkFlow.PRE_MODERATION;
const preprintIsRejected = this.model.preprint.reviewsState === ReviewsState.REJECTED;
const preprintIsFirstVersion = this.model.preprint.version === 1;

if (!this.userIsContrib) {
return false;
}

if (this.model.preprint.isWithdrawn) {
return false;
}

if (this.model.preprint.isLatestVersion || this.model.preprint.reviewsState === ReviewsState.INITIAL) {
return true;
}
if (providerIsPremod) {
if (this.model.preprint.reviewsState === ReviewsState.PENDING) {
return true;
}
// Edit and resubmit
if (preprintIsFirstVersion && preprintIsRejected
&& this.model.preprint.currentUserIsAdmin) {
return true;
}
}
return false;
}
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
get editButtonLabel(): string {
const providerIsPremod = this.model.provider.reviewsWorkflow === PreprintProviderReviewsWorkFlow.PRE_MODERATION;
const preprintIsRejected = this.model.preprint.reviewsState === ReviewsState.REJECTED;

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.model.preprint.currentUserIsAdmin
const translation = providerIsPremod && preprintIsRejected && this.model.preprint.currentUserIsAdmin
? editResubmitPreprint : editPreprint;
return this.intl.t(translation, {
documentType: this.model.provider.documentType.singular,
Expand Down
7 changes: 5 additions & 2 deletions app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</dropdown.content>
</ResponsiveDropdown>
{{else}}
{{#if (and this.userIsContrib (not this.isPendingWithdrawal))}}
{{#if this.showEditButton}}
<OsfLink
data-test-edit-preprint-button
data-analytics-name='Edit preprint button'
Expand Down Expand Up @@ -97,7 +97,10 @@
/>
</div>
{{#if (or this.showStatusBanner this.isWithdrawn)}}
<Preprints::-Components::PreprintStatusBanner @submission={{this.model.preprint}} />
<Preprints::-Components::PreprintStatusBanner
@submission={{this.model.preprint}}
@provider={{this.model.provider}}
/>
{{/if}}
<div local-class='data-container'>
{{#if this.model.preprint.isWithdrawn}}
Expand Down
88 changes: 85 additions & 3 deletions tests/acceptance/preprints/detail-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { currentRouteName } from '@ember/test-helpers';
import { currentRouteName, settled } from '@ember/test-helpers';
import { ModelInstance } from 'ember-cli-mirage';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { TestContext } from 'ember-test-helpers';
Expand Down Expand Up @@ -78,8 +78,7 @@ module('Acceptance | preprints | detail', hooks => {
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-edit-preprint-button]').doesNotExist('Edit button is not displayed for prior versions');
assert.dom('[data-test-create-new-version-button]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good opportunity to add tests for the other conditions this ticket covers.

.doesNotExist('New version button is not displayed for prior versions');

Expand Down Expand Up @@ -167,4 +166,87 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-version-link]').exists({ count: 3 }, 'Link to previous version is displayed');
assert.dom('[data-test-no-other-versions]').doesNotExist('No other versions message is not displayed');
});

test('Edit button visibility', async function(this: PreprintDetailTestContext, assert) {
// Read only
this.preprint.update({
currentUserPermissions: [Permission.Read],
reviewsState: ReviewsState.ACCEPTED,
});

const preprint: PreprintModel = this.owner.lookup('service:store').findRecord('preprint', 'test');
await visit('/preprints/osf/test');
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed for read-only users');

// Non-latest
preprint.setProperties({
currentUserPermissions: Object.values(Permission),
reviewsState: ReviewsState.ACCEPTED,
isLatestVersion: false,
});
await settled();
assert.dom('[data-test-edit-preprint-button]')
.doesNotExist('Edit button is not displayed for non-latest versions');

// Not initial, pre-mod, rejected
preprint.setProperties({
reviewsState: ReviewsState.REJECTED,
version: 4,
isLatestVersion: false,
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]')
.doesNotExist('Edit button is not displayed for non-initial pre-mod rejected');

// Initial, pre-mod, rejected
preprint.setProperties({
reviewsState: ReviewsState.REJECTED,
version: 1,
isLatestVersion: false,
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed for initial pre-mod rejected');
assert.dom('[data-test-edit-preprint-button]')
.containsText('Edit and resubmit', 'Edit and resubmit option for initial pre-mod rejected');

// Pre-mod, pending
preprint.setProperties({
reviewsState: ReviewsState.PENDING,
isLatestVersion: false,
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed for pre-mod pending');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit option for pre-mod pending');

// Withdrawn
preprint.setProperties({
dateWithdrawn: new Date(),
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed for withdrawn');

// Latest
preprint.setProperties({
dateWithdrawn: null,
isLatestVersion: true,
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed for latest version');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit option for latest version');

// Inital state
preprint.setProperties({
reviewsState: ReviewsState.INITIAL,
isLatestVersion: false,
currentUserPermissions: Object.values(Permission),
});
await settled();
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed for initial state');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit option for initial state');
});
});
Loading