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:
Wynne Crisman
2020-01-16 09:32:59 -08:00
parent 3b1c57e47e
commit 9d243850db
15 changed files with 364 additions and 30 deletions

52
imports/api/Settings.js Normal file
View 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;