53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { check } from 'meteor/check';
|
|
import SimpleSchema from 'simpl-schema';
|
|
|
|
let Settings = new Mongo.Collection('Settings');
|
|
let singletonId;
|
|
|
|
Settings.attachSchema(new SimpleSchema({
|
|
forwardEmailsTo: {
|
|
type: Array,
|
|
label: "Forward Emails To",
|
|
optional: true,
|
|
defaultValue: []
|
|
},
|
|
'forwardEmailsTo.$': {
|
|
type: String,
|
|
label: "Email",
|
|
regEx: SimpleSchema.RegEx.Email
|
|
}
|
|
}));
|
|
|
|
if(Meteor.isServer) Meteor.publish('Settings', function() {
|
|
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
|
return Settings.find({});
|
|
}
|
|
else throw new Meteor.Error(403, "Not authorized.");
|
|
});
|
|
|
|
if(Meteor.isServer) {
|
|
let singleton = Settings.findOne({});
|
|
|
|
if(!singleton) {
|
|
singletonId = Settings.insert({});
|
|
}
|
|
else {
|
|
singletonId = singleton._id;
|
|
}
|
|
|
|
Meteor.methods({
|
|
changeForwardEmailsTo: function(emails) {
|
|
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
|
check(emails, [String]);
|
|
|
|
Settings.update({_id: singletonId}, {$set: {forwardEmailsTo: emails}});
|
|
}
|
|
else throw new Meteor.Error(403, "Not authorized.");
|
|
}
|
|
});
|
|
}
|
|
|
|
export default Settings;
|