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

CenterForOpenScience / ember-osf-web / 13249070322

10 Feb 2025 07:40PM UTC coverage: 66.764%. First build
13249070322

Pull #2506

github

web-flow
Merge 52576f0d1 into 571e129de
Pull Request #2506: [ENG-7174] Update Preprint versions to be a relationship

3110 of 5081 branches covered (61.21%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

7900 of 11410 relevant lines covered (69.24%)

189.77 hits per line

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

43.75
/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

5
import getRelatedHref from 'ember-osf-web/utils/get-related-href';
6

7
import AbstractNodeModel from 'ember-osf-web/models/abstract-node';
8
import CitationModel from 'ember-osf-web/models/citation';
9
import PreprintRequestModel from 'ember-osf-web/models/preprint-request';
10
import { ReviewsState } from 'ember-osf-web/models/provider';
11
import ReviewActionModel from 'ember-osf-web/models/review-action';
12
import InstitutionModel from 'ember-osf-web/models/institution';
13

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

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

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

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

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

48
export interface PreprintLicenseRecordModel {
49
    copyright_holders: string[];
50
    year: string;
51
}
52

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

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

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

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

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

97
    @hasMany('institution')
98
    affiliatedInstitutions!: AsyncHasMany<InstitutionModel>;
99

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

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

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

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

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

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

118
    @hasMany('identifiers')
119
    identifiers!: AsyncHasMany<IdentifierModel>;
120

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

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

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

131
    @computed('license', 'licenseRecord')
132
    get licenseText(): string {
133
        const text = this.license.get('text') || '';
×
134
        const { year = '', copyright_holders = [] } = this.licenseRecord;
×
135

136
        return text
×
137
            .replace(/({{year}})/g, year)
138
            .replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
139
    }
140

141
    get currentUserIsAdmin(): boolean {
142
        return this.currentUserPermissions.includes(Permission.Admin);
48✔
143
    }
144

145
    get canCreateNewVersion(): boolean {
146
        return this.currentUserIsAdmin && this.datePublished && this.isLatestVersion;
13✔
147
    }
148

149
    makeNewVersion(): Promise<PreprintModel> {
NEW
150
        const url = getRelatedHref(this.links.relationships!.versions);
×
NEW
151
        return this.currentUser.authenticatedAJAX({
×
152
            url,
153
            type: 'POST',
154
        });
155
    }
156
}
157

158
declare module 'ember-data/types/registries/model' {
159
    export default interface ModelRegistry {
160
        preprint: PreprintModel;
161
    } // eslint-disable-line semi
162
}
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