1- import { computed } from '@ember/object' ;
21import { buildValidations , validator } from 'ember-cp-validations' ;
32import DS from 'ember-data' ;
43
54import DraftRegistrationModel from 'ember-osf-web/models/draft-registration' ;
5+ import ReviewActionModel , { ReviewActionTrigger } from 'ember-osf-web/models/review-action' ;
66import { RegistrationResponse } from 'ember-osf-web/packages/registration-schema' ;
77
88import CommentModel from './comment' ;
@@ -15,16 +15,33 @@ import UserModel from './user';
1515
1616const { attr, belongsTo, hasMany } = DS ;
1717
18- export enum RegistrationState {
19- Embargoed = 'Embargoed' ,
20- Public = 'Public' ,
21- Withdrawn = 'Withdrawn' ,
22- PendingRegistration = 'PendingRegistration' ,
23- PendingWithdrawal = 'PendingWithdrawal' ,
24- PendingEmbargo = 'PendingEmbargo' ,
25- PendingEmbargoTermination = 'PendingEmbargoTermination' ,
18+ export enum RegistrationReviewStates {
19+ Initial = 'initial' ,
20+ Pending = 'pending' ,
21+ Accepted = 'accepted' ,
22+ Rejected = 'rejected' ,
23+ Withdrawn = 'withdrawn' ,
24+ Embargo = 'embargo' ,
25+ PendingEmbargoTermination = 'pending_embargo_termination' ,
26+ PendingWithdrawRequest = 'pending_withdraw_request' ,
27+ PendingWithdraw = 'pending_withdraw' ,
2628}
2729
30+ type NonActionableStates = RegistrationReviewStates . Initial
31+ | RegistrationReviewStates . Withdrawn | RegistrationReviewStates . Rejected ;
32+
33+ export type ReviewsStateToDecisionMap = Exclude < RegistrationReviewStates , NonActionableStates > ;
34+ export const reviewsStateToDecisionMap : { [ index in ReviewsStateToDecisionMap ] : ReviewActionTrigger [ ] } = {
35+ [ RegistrationReviewStates . Accepted ] : [ ReviewActionTrigger . ForceWithdraw ] ,
36+ [ RegistrationReviewStates . Embargo ] : [ ReviewActionTrigger . ForceWithdraw ] ,
37+ [ RegistrationReviewStates . Pending ] :
38+ [ ReviewActionTrigger . AcceptSubmission , ReviewActionTrigger . RejectSubmission ] ,
39+ [ RegistrationReviewStates . PendingWithdraw ] :
40+ [ ReviewActionTrigger . AcceptWithdrawal , ReviewActionTrigger . RejectWithdrawal ] ,
41+ [ RegistrationReviewStates . PendingWithdrawRequest ] : [ ReviewActionTrigger . ForceWithdraw ] ,
42+ [ RegistrationReviewStates . PendingEmbargoTermination ] : [ ReviewActionTrigger . ForceWithdraw ] ,
43+ } ;
44+
2845const Validations = buildValidations ( {
2946 license : [
3047 validator ( 'presence' , {
@@ -57,26 +74,13 @@ export default class RegistrationModel extends NodeModel.extend(Validations) {
5774 @attr ( 'fixstring' ) articleDoi ! : string | null ;
5875 @attr ( 'object' ) registeredMeta ! : RegistrationMetadata ;
5976 @attr ( 'registration-responses' ) registrationResponses ! : RegistrationResponse ;
77+ @attr ( 'fixstring' ) reviewsState ! : RegistrationReviewStates ;
6078
6179 // Write-only attributes
6280 @attr ( 'array' ) includedNodeIds ?: string [ ] ;
6381 @attr ( 'boolean' ) createDoi ?: boolean ;
6482 @attr ( 'fixstring' ) draftRegistrationId ?: string ;
6583
66- @computed (
67- 'withdrawn' , 'embargoed' , 'public' , 'pendingRegistrationApproval' ,
68- 'pendingEmbargoApproval' , 'pendingEmbargoTerminationApproval' ,
69- 'pendingWithdrawal' ,
70- )
71- get state ( ) : RegistrationState {
72- const stateMap : any = this . registrationStateMap ( ) ;
73- const currentState : RegistrationState = Object . keys ( stateMap )
74- . filter ( active => stateMap [ active ] )
75- . map ( key => RegistrationState [ key as keyof typeof RegistrationState ] ) [ 0 ] ;
76-
77- return currentState || RegistrationState . Public ;
78- }
79-
8084 @belongsTo ( 'node' , { inverse : 'registrations' } )
8185 registeredFrom ! : DS . PromiseObject < NodeModel > & NodeModel ;
8286
@@ -107,31 +111,12 @@ export default class RegistrationModel extends NodeModel.extend(Validations) {
107111 @hasMany ( 'institution' , { inverse : 'registrations' } )
108112 affiliatedInstitutions ! : DS . PromiseManyArray < InstitutionModel > | InstitutionModel [ ] ;
109113
114+ @hasMany ( 'review-action' , { inverse : 'target' } )
115+ reviewActions ! : DS . PromiseManyArray < ReviewActionModel > | ReviewActionModel [ ] ;
116+
110117 // Write-only relationships
111118 @belongsTo ( 'draft-registration' , { inverse : null } )
112119 draftRegistration ! : DraftRegistrationModel ;
113-
114- registrationStateMap ( ) : Record < RegistrationState , boolean > {
115- const {
116- pendingRegistrationApproval,
117- pendingEmbargoApproval,
118- pendingEmbargoTerminationApproval,
119- pendingWithdrawal,
120- withdrawn,
121- embargoed,
122- } = this ;
123- const embargo = embargoed && ! pendingEmbargoTerminationApproval ;
124-
125- return {
126- PendingRegistration : pendingRegistrationApproval ,
127- PendingEmbargo : pendingEmbargoApproval ,
128- PendingEmbargoTermination : pendingEmbargoTerminationApproval ,
129- PendingWithdrawal : pendingWithdrawal ,
130- Withdrawn : withdrawn ,
131- Embargoed : embargo ,
132- Public : ! pendingWithdrawal ,
133- } ;
134- }
135120}
136121
137122declare module 'ember-data/types/registries/model' {
0 commit comments