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
4 changes: 3 additions & 1 deletion app/decorators/check-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export default function checkAuth<T extends ConcreteSubclass<Route>>(
// Need to handle view-only links before checking auth, and this is the only reasonable place to do it.
// This limitation points toward replacing this decorator with a service method meant to be
// called in Route.beforeModel. Decorator mixins should probably be considered an anti-pattern.
const { viewOnlyToken = '' } = this.paramsFor('application') as Record<string, string>;
let { viewOnlyToken = '' } = this.paramsFor('application') as Record<string, string>;

try {
if (!this.session.isAuthenticated || this.currentUser.viewOnlyToken !== viewOnlyToken) {
// This is for ENG-8174 where occasionally a %2F or / is at the end of the viewOnlyToken
viewOnlyToken = viewOnlyToken.replace(/(%2[fF]|\/)$/g, '');
this.currentUser.setProperties({ viewOnlyToken });

// Check whether user is actually logged in.
Expand Down
48 changes: 48 additions & 0 deletions app/preprints/-components/preprint-metrics/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { taskFor } from 'ember-concurrency-ts';
import Store from '@ember-data/store';
import config from 'ember-osf-web/config/environment';
import { BaseMeta } from 'osf-api';


interface InputArgs {
guid: string;
}

export default class PreprintMetrics extends Component<InputArgs> {
@service store!: Store;
@tracked apiMeta!: BaseMeta;

metricsStartDate = config.OSF.metricsStartDate;

constructor(owner: unknown, args: InputArgs) {
super(owner, args);

taskFor(this.loadPreprintMetrics).perform();
}

@task
@waitFor
private async loadPreprintMetrics() {
try {
const adapterOptions = Object({
query: {
'metrics[views]': 'total',
'metrics[downloads]': 'total',
},
});

const preprintMetrics = await this.store.findRecord('preprint', this.args.guid, {
reload: true,
adapterOptions,
});

this.apiMeta = preprintMetrics.apiMeta;
// eslint-disable-next-line
} catch (_){ }
}
}
17 changes: 17 additions & 0 deletions app/preprints/-components/preprint-metrics/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div>
{{#if this.loadPreprintMetrics.isRunning}}
<LoadingIndicator data-test-loading-indicator @dark={{true}} />
{{else}}
<span data-test-view-count-label>
{{t 'preprints.detail.share.views'}}:
</span>
<span data-test-view-count> {{this.apiMeta.metrics.views}} </span> |
<span data-test-download-count-label>
{{t 'preprints.detail.share.downloads'}}:
</span>
<span data-test-download-count>{{this.apiMeta.metrics.downloads}}</span>
<EmberTooltip>
{{t 'preprints.detail.share.metrics_disclaimer'}} {{moment-format this.metricsStartDate 'YYYY-MM-DD'}}
</EmberTooltip>
{{/if}}
</div>
16 changes: 14 additions & 2 deletions app/preprints/-components/preprint-status-banner/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const WITHDRAWN = 'withdrawn';
const PRE_MODERATION = 'pre-moderation';
const POST_MODERATION = 'post-moderation';

const PROVIDER_OSF = 'provider-osf';

const STATUS = Object({});
STATUS[PENDING]= 'preprints.detail.status_banner.pending';
STATUS[ACCEPTED]= 'preprints.detail.status_banner.accepted';
Expand All @@ -30,6 +32,7 @@ STATUS[PENDING_WITHDRAWAL]= 'preprints.detail.status_banner.pending_withdrawal';
STATUS[WITHDRAWAL_REJECTED]= 'preprints.detail.status_banner.withdrawal_rejected';

const MESSAGE = Object({});
MESSAGE[PROVIDER_OSF] = 'preprints.detail.status_banner.message.provider_osf';
MESSAGE[PRE_MODERATION] = 'preprints.detail.status_banner.message.pending_pre';
MESSAGE[POST_MODERATION] = 'preprints.detail.status_banner.message.pending_post';
MESSAGE[ACCEPTED] = 'preprints.detail.status_banner.message.accepted';
Expand All @@ -45,6 +48,7 @@ WORKFLOW[POST_MODERATION] = 'preprints.detail.status_banner.post_moderation';
WORKFLOW[UNKNOWN] = 'preprints.detail.status_banner.post_moderation';

const CLASS_NAMES = Object({});
CLASS_NAMES[PROVIDER_OSF] = 'preprint-status-pending-pre';
CLASS_NAMES[PRE_MODERATION] = 'preprint-status-pending-pre';
CLASS_NAMES[POST_MODERATION] = 'preprint-status-pending-post';
CLASS_NAMES[ACCEPTED] = 'preprint-status-accepted';
Expand All @@ -68,6 +72,7 @@ interface InputArgs {
provider: PreprintProviderModel;
latestWithdrawalRequest: PreprintRequestModel | null;
latestAction: PreprintRequestActionModel | ReviewActionModel | null;
isOSFBanner: boolean | null;
}

export default class PreprintStatusBanner extends Component<InputArgs>{
Expand Down Expand Up @@ -104,7 +109,9 @@ export default class PreprintStatusBanner extends Component<InputArgs>{
}

public get getClassName(): string {
if (this.isPendingWithdrawal) {
if (this.args.isOSFBanner) {
return CLASS_NAMES[PROVIDER_OSF];
} else if (this.isPendingWithdrawal) {
return CLASS_NAMES[PENDING_WITHDRAWAL];
} else if (this.isWithdrawn) {
return CLASS_NAMES[WITHDRAWN];
Expand All @@ -119,7 +126,12 @@ export default class PreprintStatusBanner extends Component<InputArgs>{

public get bannerContent(): string {
const { provider } = this.args;
if (this.isPendingWithdrawal) {
if (this.args.isOSFBanner) {
return this.intl.t(MESSAGE[PROVIDER_OSF], {
name: 'OSF',
documentType: provider.documentType.plural,
});
} else if (this.isPendingWithdrawal) {
return this.intl.t(this.statusExplanation, { documentType: provider.documentType.singular });
} else if (this.isWithdrawn) {
return this.intl.t(MESSAGE[WITHDRAWN], { documentType: provider.documentType.singular });
Expand Down
8 changes: 6 additions & 2 deletions app/preprints/-components/preprint-status-banner/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
{{else}}
<div local-class='preprint-banner-status {{this.getClassName}}'>
<div local-class='display-container'>
{{#if this.isWithdrawn}}
{{#if @isOSFBanner}}
<div>
<strong>{{this.bannerContent}}</strong>
</div>
{{else if this.isWithdrawn}}
<div>
<FaIcon @icon='{{this.icon}}' @prefix='fas' local-class='status-icon' aria-hidden='true'/>
<span local-class='banner-content'>{{this.bannerContent}}</span>
<span>{{this.bannerContent}}</span>
</div>
{{else}}
<div>
Expand Down
1 change: 0 additions & 1 deletion app/preprints/-components/submit/file/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
@manager={{@manager}}
@preprint={{@manager.preprint}}
@clickableElementId={{id}}
@enable={{true}}
@dragEnter={{fn (mut this.dragging) true}}
@dragOver={{fn (mut this.dragging) true}}
@dragLeave={{fn (mut this.dragging) false}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class PreprintUpload extends Component<PreprintUploadArgs> {
rootFolder?: FileModel;
primaryFile: FileModel | undefined;
@tracked isUploadFileDisplayed = false;
@tracked isEnabled = false;

constructor(owner: unknown, args: any) {
super(owner, args);
Expand Down Expand Up @@ -75,6 +76,7 @@ export default class PreprintUpload extends Component<PreprintUploadArgs> {

this.url = new URL( urlString );
this.rootFolder = rootFolder;
this.isEnabled = true;
}

@action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@dragleave={{@dragLeave}}
@dragover={{@dragOver}}
@drop={{@drop}}
@enable={{@enable}}
@enable={{this.isEnabled}}
@id={{id}}
@clickable={{this.clickableElementSelectors}}
@preUpload={{perform this.preUpload}}
Expand Down
5 changes: 3 additions & 2 deletions app/preprints/-components/submit/supplements/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class Supplements extends Component<SupplementsArgs>{
@waitFor
public async removeSelectedProject(): Promise<void> {
try {
this.validate(false);
await this.args.manager.preprint.removeM2MRelationship('node'); // Remove relationship
// Remove relationship on the node side, this only clears the cache locally
this.args.manager.preprint.node.get('preprints')
Expand All @@ -89,7 +90,7 @@ export default class Supplements extends Component<SupplementsArgs>{
}

@action
public validate(): void {
this.args.manager.validateSupplements(true);
public validate(isValid = true): void {
this.args.manager.validateSupplements(isValid);
}
}
5 changes: 4 additions & 1 deletion app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class PrePrintsDetailController extends Controller {
@tracked fullScreenMFR = false;
@tracked plauditIsReady = false;

metricsStartDate = config.OSF.metricsStartDate;
reviewStateLabelKeyMap = VersionStatusSimpleLabelKey;

get hyperlink(): string {
Expand Down Expand Up @@ -152,6 +151,10 @@ export default class PrePrintsDetailController extends Controller {
return false;
}

get showOSFBanner(): boolean {
return this.model.provider.id === config.defaultProvider;
}

get showStatusBanner(): boolean {
return (
this.model.provider.reviewsWorkflow
Expand Down
9 changes: 3 additions & 6 deletions app/preprints/detail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@ export default class PreprintsDetail extends Route {
'contributors',
'identifiers',
];


const preprint = await this.store.findRecord('preprint', guid, {
reload: true,
include: embeddableFields,
adapterOptions: {
query: {
'metrics[views]': 'total',
'metrics[downloads]': 'total',
},
},
});

const provider = await preprint?.get('provider');
Expand Down Expand Up @@ -119,6 +115,7 @@ export default class PreprintsDetail extends Route {
&& !isWithdrawalRejected && !hasPendingWithdrawal;

return {
guid,
preprint,
brand: provider.brand.content,
contributors,
Expand Down
21 changes: 10 additions & 11 deletions app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
@latestAction={{this.model.latestAction}}
/>
{{/if}}
{{#if this.showOSFBanner}}
<Preprints::-Components::PreprintStatusBanner
@submission={{this.model.preprint}}
@provider={{this.model.provider}}
@isOSFBanner={{true}}
/>
{{/if}}
<div local-class='data-container'>
{{#if this.model.preprint.isWithdrawn}}
<Preprints::-Components::PreprintTombstone
Expand Down Expand Up @@ -187,17 +194,9 @@
</OsfLink>
</div>
<div>
<span data-test-view-count-label>
{{t 'preprints.detail.share.views'}}:
</span>
<span data-test-view-count> {{this.model.preprint.apiMeta.metrics.views}} </span> |
<span data-test-download-count-label>
{{t 'preprints.detail.share.downloads'}}:
</span>
<span data-test-download-count>{{this.model.preprint.apiMeta.metrics.downloads}}</span>
<EmberTooltip>
{{t 'preprints.detail.share.metrics_disclaimer'}} {{moment-format this.metricsStartDate 'YYYY-MM-DD'}}
</EmberTooltip>
<Preprints::-Components::PreprintMetrics
@guid={{this.model.guid}}
></Preprints::-Components::PreprintMetrics>
</div>
</div>
<div local-class='plaudit-container'>
Expand Down
6 changes: 4 additions & 2 deletions app/serializers/collection-submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ export default class CollectionSubmissionSerializer extends OsfSerializer {
*/
serialize(snapshot: DS.Snapshot, options: {}) {
const serialized = super.serialize(snapshot, options);
const { data, data: { attributes, relationships } } = serialized;
const { data, data: { relationships } } = serialized;
data.attributes = data.attributes || { };

data.type = 'collection-submissions';

if (relationships && 'guid' in relationships) {
const { guid } = relationships;
if ('data' in guid) {
const { data: guidData } = guid;

if (guidData && 'id' in guidData) {
attributes!.guid = guidData.id;
data.attributes!.guid = guidData.id;
delete relationships.guid;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mirage/views/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function fakeCheckCredentials(
async function emulateUserDoingOAuthFlow(authorizedAccount: ModelInstance<AllAuthorizedAccountTypes>, schema: Schema) {
await timeout(1000);
// eslint-disable-next-line no-console
console.log('Mirage addons view: emulateUserDoingOAuthFlow done');
console.info('Mirage addons view: emulateUserDoingOAuthFlow done');
const currentUser = schema.roots.first().currentUser;
authorizedAccount.update({
credentialsAvailable: true,
Expand Down
1 change: 1 addition & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ preprints:
close: 'Close'
message:
base: '{name} uses {reviewsWorkflow}. This {documentType}'
provider_osf: '{name} {documentType} are not peer-reviewed and acceptance is not an indicator of scholarly merit.'
pending_pre: 'is not publicly available or searchable until approved by a moderator.'
pending_post: 'is publicly available and searchable but is subject to removal by a moderator.'
accepted: 'has been accepted by a moderator and is publicly available and searchable.'
Expand Down