• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CenterForOpenScience / ember-osf-web / 13206780108

07 Feb 2025 07:33PM UTC coverage: 66.63% (-0.2%) from 66.833%
13206780108

Pull #2490

github

web-flow
Merge f400645ac into 7005478ea
Pull Request #2490: [wip][ENG-6953][ENG-6954][ENG-6955] send usage metrics to datacite

3113 of 5101 branches covered (61.03%)

Branch coverage included in aggregate %.

18 of 53 new or added lines in 4 files covered. (33.96%)

13 existing lines in 2 files now uncovered.

7915 of 11450 relevant lines covered (69.13%)

189.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.62
/app/models/preprint.ts
1
import { attr, belongsTo, hasMany, AsyncBelongsTo, AsyncHasMany } from '@ember-data/model';
2
import { computed } from '@ember/object';
3
import { alias } from '@ember/object/computed';
4
import AbstractNodeModel from 'ember-osf-web/models/abstract-node';
5
import CitationModel from 'ember-osf-web/models/citation';
6
import PreprintRequestModel from 'ember-osf-web/models/preprint-request';
7
import { ReviewsState } from 'ember-osf-web/models/provider';
8
import ReviewActionModel from 'ember-osf-web/models/review-action';
9
import InstitutionModel from 'ember-osf-web/models/institution';
10
import { extractDoi } from 'ember-osf-web/utils/doi';
11

12
import ContributorModel from './contributor';
13
import FileModel from './file';
14
import IdentifierModel from './identifier';
15
import LicenseModel from './license';
16
import NodeModel from './node';
17
import { Permission } from './osf-model';
18
import PreprintProviderModel from './preprint-provider';
19
import SubjectModel from './subject';
20

21
export enum PreprintDataLinksEnum {
22
    AVAILABLE = 'available',
23
    NO = 'no',
24
    NOT_APPLICABLE = 'not_applicable',
25
}
26

27
export enum PreprintPreregLinksEnum {
28
    AVAILABLE = 'available',
29
    NO = 'no',
30
    NOT_APPLICABLE = 'not_applicable',
31
}
32

33
export enum PreprintPreregLinkInfoEnum {
34
    PREREG_EMPTY = '',
35
    PREREG_DESIGNS = 'prereg_designs',
36
    PREREG_ANALYSIS = 'prereg_analysis',
37
    PREREG_BOTH = 'prereg_both',
38
}
39

40
export const VersionStatusSimpleLabelKey = {
1✔
41
    [ReviewsState.PENDING]: 'preprints.detail.version_status.pending',
42
    [ReviewsState.REJECTED]: 'preprints.detail.version_status.rejected',
43
    [ReviewsState.WITHDRAWN]: 'preprints.detail.version_status.withdrawn',
44
};
45

46
export interface PreprintLicenseRecordModel {
47
    copyright_holders: string[];
48
    year: string;
49
}
50

51
export default class PreprintModel extends AbstractNodeModel {
52
    @attr('fixstring') title!: string;
53
    @attr('date') dateCreated!: Date;
54
    @attr('date') datePublished!: Date;
55
    @attr('date') dateWithdrawn!: Date;
56
    @attr('date') originalPublicationDate!: Date | null;
57
    @attr('fixstring') customPublicationCitation!: string | null;
58
    @attr('date') dateModified!: Date;
59
    @attr('fixstring') doi!: string | null;
60
    @attr('boolean') public!: boolean;
61
    @attr('boolean') isPublished!: boolean;
62
    @attr('boolean') isPreprintOrphan!: boolean;
63
    @attr('object') licenseRecord!: PreprintLicenseRecordModel;
64
    @attr('string') reviewsState!: ReviewsState;
65
    @attr('string') description!: string;
66
    @attr('date') dateLastTransitioned!: Date;
67
    @attr('date') preprintDoiCreated!: Date;
68
    @attr('array') currentUserPermissions!: Permission[];
69
    @attr('fixstringarray') tags!: string[];
70
    @attr('fixstring') withdrawalJustification!: string;
71
    @attr('boolean') hasCoi!: boolean;
72
    @attr('string') hasDataLinks!: PreprintDataLinksEnum;
73
    @attr('string') hasPreregLinks!: PreprintPreregLinksEnum;
74
    @attr('string') conflictOfInterestStatement!: string | null;
75
    @attr('array') dataLinks!: string[];
76
    @attr('array') preregLinks!: string[];
77
    @attr('string') whyNoData!: string | null;
78
    @attr('string') whyNoPrereg!: string | null;
79
    @attr('string') preregLinkInfo!: PreprintPreregLinkInfoEnum;
80
    @attr('number') version!: number;
81
    @attr('boolean') isLatestVersion!: boolean;
82

83
    @belongsTo('node', { inverse: 'preprints' })
84
    node!: AsyncBelongsTo<NodeModel> & NodeModel;
85

86
    @belongsTo('license', { inverse: null })
87
    license!: AsyncBelongsTo<LicenseModel> & LicenseModel;
88

89
    @belongsTo('file', { inverse: null })
90
    primaryFile?: AsyncBelongsTo<FileModel> & FileModel;
91

92
    @belongsTo('preprint-provider', { inverse: 'preprints' })
93
    provider!: AsyncBelongsTo<PreprintProviderModel> & PreprintProviderModel;
94

95
    @hasMany('institution')
96
    affiliatedInstitutions!: AsyncHasMany<InstitutionModel>;
97

98
    @hasMany('review-action')
99
    reviewActions!: AsyncHasMany<ReviewActionModel>;
100

101
    @hasMany('contributors', { inverse: 'preprint'})
102
    contributors!: AsyncHasMany<ContributorModel> & ContributorModel;
103

104
    @hasMany('contributor', { inverse: null })
105
    bibliographicContributors!: AsyncHasMany<ContributorModel>;
106

107
    @belongsTo('citation', { inverse: null })
108
    citation!: AsyncBelongsTo<CitationModel>;
109

110
    @hasMany('subject', { inverse: null})
111
    subjects!: AsyncHasMany<SubjectModel>;
112

113
    @hasMany('preprint-request', { inverse: 'target'})
114
    requests!: AsyncHasMany<PreprintRequestModel>;
115

116
    @hasMany('identifiers')
117
    identifiers!: AsyncHasMany<IdentifierModel>;
118

119
    @hasMany('preprint', { inverse: null })
120
    versions!: AsyncHasMany<PreprintModel>;
121

122
    @alias('links.doi') articleDoiUrl!: string | null;
123
    @alias('links.preprint_doi') preprintDoiUrl!: string;
124

125
    get isWithdrawn(): boolean{
126
        return this.dateWithdrawn !== null;
80✔
127
    }
128

129
    get verifiedDoi(): string {
130
        if (this.preprintDoiCreated) {
4!
NEW
131
            return extractDoi(this.preprintDoiUrl) || '';
×
132
        }
133
        return '';
4✔
134
    }
135

136
    @computed('license', 'licenseRecord')
137
    get licenseText(): string {
138
        const text = this.license.get('text') || '';
×
139
        const { year = '', copyright_holders = [] } = this.licenseRecord;
×
140

141
        return text
×
142
            .replace(/({{year}})/g, year)
143
            .replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
144
    }
145

146
    get currentUserIsAdmin(): boolean {
147
        return this.currentUserPermissions.includes(Permission.Admin);
48✔
148
    }
149

150
    get canCreateNewVersion(): boolean {
151
        return this.currentUserIsAdmin && this.datePublished && this.isLatestVersion;
13✔
152
    }
153
}
154

155
declare module 'ember-data/types/registries/model' {
156
    export default interface ModelRegistry {
157
        preprint: PreprintModel;
158
    } // eslint-disable-line semi
159
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc