@@ -5,14 +5,7 @@ var express = require('express'),
5
5
Schema = require ( '../Schema' ) ;
6
6
7
7
import PromiseRouter from '../PromiseRouter' ;
8
-
9
- // TODO: refactor in a SchemaController at one point...
10
- function masterKeyRequiredResponse ( ) {
11
- return Promise . resolve ( {
12
- status : 401 ,
13
- response : { error : 'master key not specified' } ,
14
- } )
15
- }
8
+ import * as middleware from "../middlewares" ;
16
9
17
10
function classNameMismatchResponse ( bodyClass , pathClass ) {
18
11
return Promise . resolve ( {
@@ -45,9 +38,6 @@ function mongoSchemaToSchemaAPIResponse(schema) {
45
38
}
46
39
47
40
function getAllSchemas ( req ) {
48
- if ( ! req . auth . isMaster ) {
49
- return masterKeyRequiredResponse ( ) ;
50
- }
51
41
return req . config . database . collection ( '_SCHEMA' )
52
42
. then ( coll => coll . find ( { } ) . toArray ( ) )
53
43
. then ( schemas => ( { response : {
@@ -56,9 +46,6 @@ function getAllSchemas(req) {
56
46
}
57
47
58
48
function getOneSchema ( req ) {
59
- if ( ! req . auth . isMaster ) {
60
- return masterKeyRequiredResponse ( ) ;
61
- }
62
49
return req . config . database . collection ( '_SCHEMA' )
63
50
. then ( coll => coll . findOne ( { '_id' : req . params . className } ) )
64
51
. then ( schema => ( { response : mongoSchemaToSchemaAPIResponse ( schema ) } ) )
@@ -72,9 +59,6 @@ function getOneSchema(req) {
72
59
}
73
60
74
61
function createSchema ( req ) {
75
- if ( ! req . auth . isMaster ) {
76
- return masterKeyRequiredResponse ( ) ;
77
- }
78
62
if ( req . params . className && req . body . className ) {
79
63
if ( req . params . className != req . body . className ) {
80
64
return classNameMismatchResponse ( req . body . className , req . params . className ) ;
@@ -100,10 +84,6 @@ function createSchema(req) {
100
84
}
101
85
102
86
function modifySchema ( req ) {
103
- if ( ! req . auth . isMaster ) {
104
- return masterKeyRequiredResponse ( ) ;
105
- }
106
-
107
87
if ( req . body . className && req . body . className != req . params . className ) {
108
88
return classNameMismatchResponse ( req . body . className , req . params . className ) ;
109
89
}
@@ -168,10 +148,6 @@ var removeJoinTables = (database, mongoSchema) => {
168
148
} ;
169
149
170
150
function deleteSchema ( req ) {
171
- if ( ! req . auth . isMaster ) {
172
- return masterKeyRequiredResponse ( ) ;
173
- }
174
-
175
151
if ( ! Schema . classNameIsValid ( req . params . className ) ) {
176
152
throw new Parse . Error ( Parse . Error . INVALID_CLASS_NAME , Schema . invalidClassNameMessage ( req . params . className ) ) ;
177
153
}
@@ -214,11 +190,11 @@ function deleteSchema(req) {
214
190
215
191
export class SchemasRouter extends PromiseRouter {
216
192
mountRoutes ( ) {
217
- this . route ( 'GET' , '/schemas' , getAllSchemas ) ;
218
- this . route ( 'GET' , '/schemas/:className' , getOneSchema ) ;
219
- this . route ( 'POST' , '/schemas' , createSchema ) ;
220
- this . route ( 'POST' , '/schemas/:className' , createSchema ) ;
221
- this . route ( 'PUT' , '/schemas/:className' , modifySchema ) ;
222
- this . route ( 'DELETE' , '/schemas/:className' , deleteSchema ) ;
193
+ this . route ( 'GET' , '/schemas' , middleware . promiseEnforceMasterKeyAccess , getAllSchemas ) ;
194
+ this . route ( 'GET' , '/schemas/:className' , middleware . promiseEnforceMasterKeyAccess , getOneSchema ) ;
195
+ this . route ( 'POST' , '/schemas' , middleware . promiseEnforceMasterKeyAccess , createSchema ) ;
196
+ this . route ( 'POST' , '/schemas/:className' , middleware . promiseEnforceMasterKeyAccess , createSchema ) ;
197
+ this . route ( 'PUT' , '/schemas/:className' , middleware . promiseEnforceMasterKeyAccess , modifySchema ) ;
198
+ this . route ( 'DELETE' , '/schemas/:className' , middleware . promiseEnforceMasterKeyAccess , deleteSchema ) ;
223
199
}
224
200
}
0 commit comments