Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ module('Integration | Preprint | Component | Institution Manager', hooks => {
singular: 'Test Preprint Word',
},
},
isEditFlow: true,
preprint,
resetAffiliatedInstitutions: (): void => {
this.set('affiliatedInstitutions', []);
},
isElementDisabled(): boolean {
return !(this.preprint.currentUserPermissions).includes(Permission.Admin);
},
updateAffiliatedInstitution: (affiliatedIinstitution: InstitutionModel): void => {
const affiliatedInstitutions = this.get('affiliatedInstitutions');
if (managerMock.isInstitutionAffiliated(affiliatedIinstitution.id)) {
Expand Down Expand Up @@ -128,7 +130,6 @@ module('Integration | Preprint | Component | Institution Manager', hooks => {
async function(assert) {
// When the component is rendered
const managerMock = this.get('managerMock');
managerMock.isEditFlow = true;

const affiliatedInstitutions = [] as any[];
managerMock.preprint.affiliatedInstitutions.map((institution: InstitutionModel) => {
Expand Down Expand Up @@ -231,7 +232,6 @@ module('Integration | Preprint | Component | Institution Manager', hooks => {
async function(assert) {
const managerMock = this.get('managerMock');
managerMock.preprint.currentUserPermissions = [Permission.Write, Permission.Read];
managerMock.isEditFlow = false;
this.set('managerMock', managerMock);

// When the component is rendered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Store from '@ember-data/store';
import CurrentUser from 'ember-osf-web/services/current-user';
import InstitutionModel from 'ember-osf-web/models/institution';
import PreprintStateMachine from 'ember-osf-web/preprints/-components/submit/preprint-state-machine/component';
import { Permission } from 'ember-osf-web/models/osf-model';


interface PreprintInstitutionModel extends InstitutionModel {
Expand Down Expand Up @@ -95,7 +94,7 @@ export default class InstitutionsManagerComponent extends Component<InstitutionA
this.manager.updateAffiliatedInstitution(institution);
}

public get disableWriteAccess(): boolean {
return !(this.manager.preprint.currentUserPermissions).includes(Permission.Admin);
public get isElementDisabled(): boolean {
return this.manager.isElementDisabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
institutions=this.institutions
toggleInstitution=this.toggleInstitution
preprintWord=this.preprintWord
disableWriteAccess=this.disableWriteAccess
isElementDisabled=this.isElementDisabled
)}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Input
data-test-institution-input={{index}}
@type='checkbox'
@disabled={{@manager.disableWriteAccess}}
@disabled={{@manager.isElementDisabled}}
@checked={{institution.isSelected}}
{{on 'change' (fn @manager.toggleInstitution institution)}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ const AuthorAssertionsFormValidation: ValidationObject<AuthorAssertionsForm> = {
export default class PublicData extends Component<AuthorAssertionsArgs>{
@service intl!: Intl;
@tracked isConflictOfInterestStatementDisabled = true;
@tracked isPublicDataStatementDisabled = true;
authorAssertionFormChangeset = buildChangeset(
this.args.manager.preprint,
AuthorAssertionsFormValidation,
Expand Down Expand Up @@ -169,15 +168,15 @@ export default class PublicData extends Component<AuthorAssertionsArgs>{
this.intl.t('preprints.submit.step-assertions.conflict-of-interest-none'));
this.isConflictOfInterestStatementDisabled = true;
} else {
this.isConflictOfInterestStatementDisabled = false;
this.isConflictOfInterestStatementDisabled = false || !this.args.manager.isAdmin();
}
}

@action
public updateCoi(): void {
if (this.authorAssertionFormChangeset.get('hasCoi')) {
this.authorAssertionFormChangeset.set('conflictOfInterestStatement', null);
this.isConflictOfInterestStatementDisabled = false;
this.isConflictOfInterestStatementDisabled = false || !this.args.manager.isAdmin();
} else {
this.authorAssertionFormChangeset.set('conflictOfInterestStatement',
this.intl.t('preprints.submit.step-assertions.conflict-of-interest-none'));
Expand All @@ -198,4 +197,8 @@ export default class PublicData extends Component<AuthorAssertionsArgs>{
this.authorAssertionFormChangeset.execute();
this.args.manager.validateAuthorAssertions(true);
}

public get isElementDisabled(): boolean {
return this.args.manager.isElementDisabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { tracked } from '@glimmer/tracking';
*/
interface LinkWidgetArgs {
update: (_: string[]) => {};
disabled: boolean;
links: string[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { tracked } from '@glimmer/tracking';
interface LinkArgs {
remove: (__:number) => {};
update: (_: string, __:number) => {};
disabled: boolean;
value: string;
placeholder: string;
index: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<form.text
data-test-link-input
@isRequired={{true}}
@disabled={{@disabled}}
{{on 'change' this.onUpdate}}
@placeholder={{ @placeholder }}
@valuePath={{'value'}}
Expand All @@ -20,17 +21,19 @@

</div>
<div local-class='delete-container'>
<Button
data-test-remove-link
aria-label={{t 'preprints.submit.step-assertions.public-link-remove-button'}}
@layout='fake-link'
{{on 'click' this.removeLink}}
>
<FaIcon @icon='times' local-class='delete' />
<EmberTooltip>
{{t 'preprints.submit.step-assertions.public-link-remove-button'}}
</EmberTooltip>
</Button>
{{#unless @disabled}}
Comment on lines 23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Super minor nit, could add this {{#unless}} outside of the <div> here

<Button
data-test-remove-link
aria-label={{t 'preprints.submit.step-assertions.public-link-remove-button'}}
@layout='fake-link'
{{on 'click' this.removeLink}}
>
<FaIcon @icon='times' local-class='delete' />
<EmberTooltip>
{{t 'preprints.submit.step-assertions.public-link-remove-button'}}
</EmberTooltip>
</Button>
{{/unless}}
</div>
</FormControls>
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
@value={{link}}
@index={{index}}
@placeholder={{@placeholder}}
@disabled={{@disabled}}
/>
</div>
{{/each}}

<Button
data-test-add-another-link
aria-label={{t 'preprints.submit.step-assertions.public-link-add-button'}}
local-class='add-another-link'
@layout='fake-link'
{{on 'click' this.addLink}}
>
<FaIcon @icon='plus' local-class='plus-icon' />
{{t 'preprints.submit.step-assertions.public-link-add-button'}}
</Button>
</div>
{{#unless @disabled}}
<Button
data-test-add-another-link
aria-label={{t 'preprints.submit.step-assertions.public-link-add-button'}}
local-class='add-another-link'
@layout='fake-link'
{{on 'click' this.addLink}}
>
<FaIcon @icon='plus' local-class='plus-icon' />
{{t 'preprints.submit.step-assertions.public-link-add-button'}}
</Button>
{{/unless}}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface PublicDataArgs {
manager: PreprintStateMachine;
changeSet: BufferedChangeset;
preprintWord: string;
disabled: boolean;
validate: () => {};
}

Expand Down Expand Up @@ -64,11 +65,11 @@ export default class PublicData extends Component<PublicDataArgs>{
public updatePublicDataOptions(): void {
if (this.args.changeSet.get('hasDataLinks') === PreprintDataLinksEnum.AVAILABLE) {
this.args.changeSet.set('whyNoData', null);
this.isPublicDataWhyNoStatementDisabled = false;
this.isPublicDataWhyNoStatementDisabled = false || !this.args.manager.isAdmin();
} else if (this.args.changeSet.get('hasDataLinks') === PreprintDataLinksEnum.NO) {
this.args.changeSet.set('dataLinks', []);
this.args.changeSet.set('whyNoData', null);
this.isPublicDataWhyNoStatementDisabled = false;
this.isPublicDataWhyNoStatementDisabled = false || !this.args.manager.isAdmin();
this.placeholder = this.intl.t('preprints.submit.step-assertions.public-data-no-placeholder');
} else {
this.args.changeSet.set('dataLinks', []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@valuePath={{'hasDataLinks'}}
@class='radio-group {{if (is-mobile) 'mobile'}}'
@isRequired={{true}}
@disabled={{@disabled}}
@options={{this.publicDataOptions}}
@onchange={{this.updatePublicDataOptions}}
as |radioGroup|
Expand All @@ -33,6 +34,7 @@
<Preprints::-Components::Submit::AuthorAssertions::LinkWidget
@update={{this.updatePublicDataLinks}}
@placeholder={{t 'preprints.submit.step-assertions.public-data-link-placeholder'}}
@disabled={{@disabled}}
@links={{@manager.preprint.dataLinks}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface PublicPreregistrationArgs {
manager: PreprintStateMachine;
changeSet: BufferedChangeset;
preprintWord: string;
disabled: boolean;
validate: () => {};
}

Expand Down Expand Up @@ -96,11 +97,11 @@ export default class PublicPreregistration extends Component<PublicPreregistrati
public updatePublicPreregistrationOptions(): void {
if (this.args.changeSet.get('hasPreregLinks') === PreprintPreregLinksEnum.AVAILABLE) {
this.args.changeSet.set('whyNoPrereg', null);
this.isPublicPreregistrationWhyNoStatementDisabled = false;
this.isPublicPreregistrationWhyNoStatementDisabled = false || !this.args.manager.isAdmin();
} else if (this.args.changeSet.get('hasPreregLinks') === PreprintPreregLinksEnum.NO) {
this.args.changeSet.set('preregLinks', []);
this.args.changeSet.set('whyNoPrereg', null);
this.isPublicPreregistrationWhyNoStatementDisabled = false;
this.isPublicPreregistrationWhyNoStatementDisabled = false || !this.args.manager.isAdmin();
this.placeholder = this.intl.t('preprints.submit.step-assertions.public-preregistration-no-placeholder');
} else {
this.isPublicPreregistrationWhyNoStatementDisabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@valuePath={{'hasPreregLinks'}}
@class='radio-group {{if (is-mobile) 'mobile'}}'
@isRequired={{true}}
@disabled={{@disabled}}
@options={{this.publicPreregistrationOptions}}
@onchange={{this.updatePublicPreregistrationOptions}}
as |radioGroup|
Expand All @@ -33,6 +34,7 @@
<select
onchange={{action 'updatePreregistrationLinkInfo' value='target.value'}}
local-class='select'
disabled={{@disabled}}
class='form-control'
>
{{#each this.publicPreregLinkInfoOptions as |infoOption|}}
Expand All @@ -54,6 +56,7 @@
<div local-class='input-container'>
<Preprints::-Components::Submit::AuthorAssertions::LinkWidget
@update={{this.updatePublicPreregistrationLinks}}
@disabled={{@disabled}}
@placeholder={{t 'preprints.submit.step-assertions.public-preregistration-link-placeholder'}}
@links={{@manager.preprint.preregLinks}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@class='radio-group {{if (is-mobile) 'mobile'}}'
@isRequired={{true}}
@options={{this.coiOptions}}
@disabled={{this.isElementDisabled}}
@onchange={{this.updateCoi}}
as |radioGroup|
>
Expand All @@ -52,6 +53,7 @@
@changeSet={{this.authorAssertionFormChangeset}}
@preprintWord={{@manager.provider.documentType.singular}}
@validate={{this.validate}}
@disabled={{this.isElementDisabled}}
@manager={{@manager}}
/>
</div>
Expand All @@ -61,6 +63,7 @@
@changeSet={{this.authorAssertionFormChangeset}}
@preprintWord={{@manager.provider.documentType.singular}}
@validate={{this.validate}}
@disabled={{this.isElementDisabled}}
@manager={{@manager}}
/>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/preprints/-components/submit/metadata/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,8 @@ export default class Metadata extends Component<MetadataArgs>{
this.metadataFormChangeset.execute();
this.args.manager.validateMetadata(true);
}

public get widgetMode(): string {
return this.args.manager.isAdmin() ? 'editable' : 'readonly';
}
}
2 changes: 1 addition & 1 deletion app/preprints/-components/submit/metadata/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@preprint={{@manager.preprint}}
@shouldShowAdd={{this.showAddContributorWidget}}
@toggleAddContributorWidget={{this.toggleAddContributorWidget}}
@widgetMode={{'editable'}}
@widgetMode={{this.widgetMode}}
@displayPermissionWarning={{this.displayPermissionWarning}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class PreprintStateMachine extends Component<StateMachineArgs>{
}
}

this.isWithdrawalButtonDisplayed = this.preprint.currentUserPermissions.includes(Permission.Admin) &&
this.isWithdrawalButtonDisplayed = this.isAdmin() &&
(this.preprint.reviewsState === ReviewsState.ACCEPTED ||
this.preprint.reviewsState === ReviewsState.PENDING) && !isWithdrawalRejected;

Expand Down Expand Up @@ -253,17 +253,20 @@ export default class PreprintStateMachine extends Component<StateMachineArgs>{
) {
await this.saveOnStep();

try {
await this.preprint.updateM2MRelationship(
'affiliatedInstitutions',
this.affiliatedInstitutions,
);
await this.preprint.reload();
} catch (e) {
const errorMessage = this.intl.t('preprints.submit.step-metadata.institutions.save-institutions-error');
captureException(e, { errorMessage });
this.toast.error(getApiErrorMessage(e), errorMessage);
throw e;
if (this.isAdmin()) {
try {
await this.preprint.updateM2MRelationship(
'affiliatedInstitutions',
this.affiliatedInstitutions,
);
await this.preprint.reload();
} catch (e) {
// eslint-disable-next-line max-len
const errorMessage = this.intl.t('preprints.submit.step-metadata.institutions.save-institutions-error');
captureException(e, { errorMessage });
this.toast.error(getApiErrorMessage(e), errorMessage);
throw e;
}
}

if (this.displayAuthorAssertions) {
Expand Down Expand Up @@ -657,4 +660,12 @@ export default class PreprintStateMachine extends Component<StateMachineArgs>{
public resetAffiliatedInstitutions(): void {
this.affiliatedInstitutions.length = 0;
}

public isAdmin(): boolean {
return this.preprint.currentUserPermissions.includes(Permission.Admin);
}

public isElementDisabled(): boolean {
return !this.isAdmin();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@

updateAffiliatedInstitution=this.updateAffiliatedInstitution
resetAffiliatedInstitutions=this.resetAffiliatedInstitutions

isElementDisabled=this.isElementDisabled
isAdmin=this.isAdmin
)}}