-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathregistry.js
45 lines (40 loc) · 1.37 KB
/
registry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import _ from "lodash";
import { Meteor } from "meteor/meteor";
import { check } from "meteor/check";
import { Packages } from "/lib/collections";
import { Reaction } from "/server/api";
import { mergeDeep } from "/lib/api";
export const methods = {
"registry/update": function (packageId, name, fields) {
check(packageId, String);
check(name, String);
check(fields, Array);
// settings use just the last name from full name so that schemas don't need to define overly complex names based with
// x/x/x formatting.
// TODO name could be optional, just use package name as default
const setting = name.split("/").splice(-1);
let dataToSave = {};
dataToSave[setting] = {};
const currentPackage = Packages.findOne(packageId);
_.each(fields, function (field) {
dataToSave[setting][field.property] = field.value;
});
if (currentPackage && currentPackage.settings) {
dataToSave = mergeDeep(currentPackage.settings, dataToSave);
}
// user must have permission to package to update settings
if (Reaction.hasPermission([currentPackage.name])) {
return Packages.upsert({
_id: packageId,
name: currentPackage.name,
enabled: currentPackage.enabled
}, {
$set: {
settings: dataToSave
}
}, { upsert: true });
}
return false;
}
};
Meteor.methods(methods);