Added settings and messages to manage sending web inquiries to one or more email addresses specified via the web management interface.
This commit is contained in:
52
imports/api/Settings.js
Normal file
52
imports/api/Settings.js
Normal file
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user