@@ -65,12 +65,14 @@ const findMultipart = (files) => {
65
65
} ;
66
66
const forceAuthFailed = Problem . translate ( Problem . user . insufficientRights , Problem . user . authenticationFailed ) ;
67
67
68
- module . exports = ( service , endpoint ) => {
68
+ module . exports = ( service , endpoint , anonymousEndpoint ) => {
69
69
70
70
////////////////////////////////////////////////////////////////////////////////
71
71
// SUBMISSIONS (OPENROSA)
72
72
73
73
const openRosaSubmission = ( path , draft , getForm ) => {
74
+ const endpointByTestPath = path . startsWith ( '/test/:key' ) ? anonymousEndpoint : endpoint ;
75
+
74
76
// Nonstandard REST; OpenRosa-specific API.
75
77
// This bit of silliness is to address the fact that the OpenRosa standards
76
78
// specification requires the presence of a HEAD /submission endpoint, but
@@ -81,9 +83,10 @@ module.exports = (service, endpoint) => {
81
83
// there is no body content, and the HTTP spec requires that HEAD should
82
84
// return exactly what GET would, just without a response body, the only thing
83
85
// we can possibly respond with in either case is no body and a 204 code.
84
- service . get ( path , endpoint . openRosa ( ( { Projects } , { params } ) =>
86
+ service . get ( path , endpointByTestPath . openRosa ( ( { Projects, Forms } , { params, auth } ) =>
85
87
Projects . getById ( params . projectId )
86
88
. then ( getOrNotFound )
89
+ . then ( ( ) => ( params . xmlFormId ? getForm ( auth , params , params . xmlFormId , Forms ) : resolve ( ) ) )
87
90
. then ( always ( { code : 204 , body : '' } ) ) ) ) ;
88
91
89
92
// Temporary solution to https://github.com/expressjs/multer/issues/1104
@@ -101,7 +104,7 @@ module.exports = (service, endpoint) => {
101
104
} ;
102
105
103
106
// Nonstandard REST; OpenRosa-specific API.
104
- service . post ( path , multipart . any ( ) , multerUtf , multipartErrorHandler , endpoint . openRosa ( ( { Forms, Submissions, SubmissionAttachments } , { params, files, auth, query, userAgent } ) =>
107
+ service . post ( path , multipart . any ( ) , multerUtf , multipartErrorHandler , endpointByTestPath . openRosa ( ( { Forms, Submissions, SubmissionAttachments } , { params, files, auth, query, userAgent } ) =>
105
108
Submission . fromXml ( findMultipart ( files ) . buffer )
106
109
. then ( ( partial ) => getForm ( auth , params , partial . xmlFormId , Forms , partial . def . version )
107
110
. catch ( forceAuthFailed )
@@ -267,7 +270,7 @@ module.exports = (service, endpoint) => {
267
270
) ;
268
271
269
272
// Create Submission using draftToken
270
- service . post ( `/test/:key/projects/:projectId/forms/:formId/draft/submissions` , endpoint ( ( { Forms, Submissions, SubmissionAttachments } , { params, query, userAgent } , request ) =>
273
+ service . post ( `/test/:key/projects/:projectId/forms/:formId/draft/submissions` , anonymousEndpoint ( ( { Forms, Submissions, SubmissionAttachments } , { params, query, userAgent } , request ) =>
271
274
Submission . fromXml ( request )
272
275
. then ( ( partial ) => Forms . getByProjectAndXmlFormId ( params . projectId , params . formId , false , Form . DraftVersion )
273
276
. then ( getOrNotFound )
0 commit comments