Skip to content

Commit cd05e3b

Browse files
committed
Merge pull request #1210 from framp/master
Make GlobalConfig work like parse.com
2 parents d47a756 + 236c7d1 commit cd05e3b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Routers/FeaturesRouter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { version } from '../../package.json';
22
import PromiseRouter from '../PromiseRouter';
33
import * as middleware from "../middlewares";
44

5+
const isGlobalConfigEnabled = !!(process.env.PARSE_EXPERIMENTAL_CONFIG_ENABLED || process.env.TESTING)
6+
57
export class FeaturesRouter extends PromiseRouter {
68
mountRoutes() {
79
this.route('GET','/serverInfo', middleware.promiseEnforceMasterKeyAccess, req => {
810
const features = {
911
globalConfig: {
10-
create: false,
11-
read: false,
12-
update: false,
13-
delete: false,
12+
create: isGlobalConfigEnabled,
13+
read: isGlobalConfigEnabled,
14+
update: isGlobalConfigEnabled,
15+
delete: isGlobalConfigEnabled,
1416
},
1517
hooks: {
1618
create: false,

src/Routers/GlobalConfigRouter.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ export class GlobalConfigRouter extends PromiseRouter {
1818
}
1919

2020
updateGlobalConfig(req) {
21+
const params = req.body.params;
22+
const update = Object.keys(params).reduce((acc, key) => {
23+
if(params[key] && params[key].__op && params[key].__op === "Delete") {
24+
if (!acc.$unset) acc.$unset = {};
25+
acc.$unset[`params.${key}`] = "";
26+
} else {
27+
if (!acc.$set) acc.$set = {};
28+
acc.$set[`params.${key}`] = params[key];
29+
}
30+
return acc;
31+
}, {});
2132
return req.config.database.adaptiveCollection('_GlobalConfig')
22-
.then(coll => coll.upsertOne({ _id: 1 }, { $set: req.body }))
33+
.then(coll => coll.upsertOne({ _id: 1 }, update))
2334
.then(() => ({ response: { result: true } }));
2435
}
2536

0 commit comments

Comments
 (0)