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:
@@ -1,6 +1,7 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { Email } from 'meteor/email';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let ContactUsMessages = new Mongo.Collection('ContactUsMessages');
|
||||
@@ -32,7 +33,10 @@ ContactUsMessages.attachSchema(new SimpleSchema({
|
||||
}));
|
||||
|
||||
if(Meteor.isServer) Meteor.publish('contactUsMessages', function() {
|
||||
return ContactUsMessages.find({});
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
return ContactUsMessages.find({});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
});
|
||||
|
||||
if(Meteor.isServer) {
|
||||
@@ -42,10 +46,18 @@ if(Meteor.isServer) {
|
||||
check(email, String);
|
||||
check(message, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
ContactUsMessages.insert({name, email, message, createdAt: new Date()});
|
||||
ContactUsMessages.insert({name, email, message, createdAt: new Date()});
|
||||
|
||||
try {
|
||||
let settings = Meteor.collections.Settings.findOne();
|
||||
|
||||
if(settings && settings.forwardEmailsTo && settings.forwardEmailsTo.length > 0) {
|
||||
Email.send({to: settings.forwardEmailsTo, from: "Do Not Reply <no-reply@andersonvalleyeducation.org>", subject: "Contact Us Message", text: "Email: " + email + "\n\n" + message});
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
console.log(err);
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -6,9 +6,10 @@ import ImageUploads from "./Images.js";
|
||||
import Slideshow from "./Slideshow.js";
|
||||
import Internship from "./Internship.js";
|
||||
import ContactUsMessages from "./ContactUsMessages.js";
|
||||
import Settings from "./Settings.js";
|
||||
|
||||
//Save the collections in the Meteor.collections property for easy access without name conflicts.
|
||||
Meteor.collections = {Users, UserRoles, Pages, Slideshow, Internship, ContactUsMessages, ImageUploads};
|
||||
Meteor.collections = {Users, UserRoles, Pages, Slideshow, Internship, ContactUsMessages, ImageUploads, Settings};
|
||||
|
||||
//If this is the server then setup the default admin user if none exist.
|
||||
if(Meteor.isServer) {
|
||||
|
||||
Reference in New Issue
Block a user