Initial commit
This commit is contained in:
commit
35745a89ec
44 changed files with 3342 additions and 0 deletions
95
server/main.js
Normal file
95
server/main.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Roles } from 'meteor/roles';
|
||||
import { SysConfig } from '../imports/api/systemConfig.js';
|
||||
import { MScripts } from '../imports/api/mScripts.js';
|
||||
import { UpdateInfo } from '../imports/api/updateInfo.js'
|
||||
|
||||
|
||||
Meteor.startup(async () => {
|
||||
// code to run on server at startup
|
||||
await Roles.createRoleAsync("user", { unlessExists: true });
|
||||
await Roles.createRoleAsync("systemadmin", { unlessExists: true });
|
||||
await Roles.createRoleAsync("tenantadmin", { unlessExists: true });
|
||||
await Roles.createRoleAsync("shareadmin", { unlessExists: true });
|
||||
|
||||
// set the systemconfig defaults for registration
|
||||
// check if this has already been run
|
||||
let regPolRun = await MScripts.findOneAsync({ scriptName: "DefaultRegPolicy", scriptRun: true });
|
||||
if (!regPolRun) {
|
||||
try {
|
||||
let regPolicy = await SysConfig.findOneAsync({});
|
||||
if (!regPolicy) {
|
||||
SysConfig.insertAsync({
|
||||
SysAdminReg: false,
|
||||
dateAdded: new Date(),
|
||||
allowReg: true,
|
||||
allowUpdates: true,
|
||||
});
|
||||
markScriptRun("DefaultRegPolicy");
|
||||
} else {
|
||||
// console.log("Registration policy already set.");
|
||||
markScriptRun("DefaultRegPolicy");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR trying to check if registration policy was set.");
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var startCronForUpdates = function(feedurl) {
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('*/30 * * * *', () => {
|
||||
getUpdateInfoNow(feedurl);
|
||||
});
|
||||
}
|
||||
|
||||
var markScriptRun = async function(scriptName) {
|
||||
// check if this is already set
|
||||
let scriptRun = await MScripts.findOneAsync({ scriptName: scriptName });
|
||||
if (!scriptRun) {
|
||||
try {
|
||||
return MScripts.insertAsync({
|
||||
scriptName: scriptName,
|
||||
scriptRun: true,
|
||||
runOn: new Date()
|
||||
});
|
||||
} catch(error) {
|
||||
console.log(" ERROR inserting the script run log: " + error);
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
} else {
|
||||
// console.log(scriptName + " already set as run on " + scriptRun.runOn);
|
||||
}
|
||||
}
|
||||
|
||||
var getUpdateInfoNow = async function(feedurl) {
|
||||
const parser = require('rss-url-parser')
|
||||
|
||||
const data = await parser(feedurl)
|
||||
let dataLength = data.length;
|
||||
// console.dir(data[0].title);
|
||||
|
||||
// check if this title already exists in db
|
||||
let updatesExist = await UpdateInfo.findOneAsync({ title: data[0].title });
|
||||
try {
|
||||
if (!updatesExist) {
|
||||
UpdateInfo.insertAsync({
|
||||
title: data[0].title,
|
||||
description: data[0].description,
|
||||
dateRelease: data[0].date,
|
||||
releaseLink: data[0].link,
|
||||
viewed: false
|
||||
});
|
||||
} else {
|
||||
console.log("No new updates available at this time.");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR checking for update: " + error);
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
71
server/methods.js
Normal file
71
server/methods.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { Roles } from 'meteor/roles';
|
||||
|
||||
Meteor.methods({
|
||||
'addToRole' (role) {
|
||||
const getUserInfo = async() => {
|
||||
try {
|
||||
let countOfUsers = await Meteor.users.find().countAsync();
|
||||
const user = await Meteor.userAsync();
|
||||
if (user) {
|
||||
let userId = user._id;
|
||||
if (countOfUsers > 1) {
|
||||
Roles.addUsersToRolesAysnc(userId, role);
|
||||
} else if (countOfUsers == 1) {
|
||||
Roles.addUsersToRolesAsync(userId, "systemadmin");
|
||||
} else {
|
||||
console.log("The count of users didn't seem to work when adding a new user.");
|
||||
}
|
||||
} else {
|
||||
console.log(" ---- No user info found.")
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user info on server: " + error);
|
||||
}
|
||||
}
|
||||
getUserInfo();
|
||||
},
|
||||
'edit.userPass' (userId, newPassword) {
|
||||
check(userId, String);
|
||||
check(newPassword, String);
|
||||
|
||||
const setUsersPassword = async() => {
|
||||
try {
|
||||
const setPass = await Accounts.setPasswordAsync(userId, newPassword);
|
||||
if (setPass) {
|
||||
return setPass;
|
||||
} else {
|
||||
console.log(" Error seeting user password, await returned nothing.");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR setting user's password: " + error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
'delete.userFromSys' (userId) {
|
||||
check(userId, String);
|
||||
|
||||
return Meteor.users.remove({ _id: userId });
|
||||
},
|
||||
'update.userEmail' (userId, email) {
|
||||
check(userId, String);
|
||||
check(email, String);
|
||||
|
||||
return Meteor.users.update({ _id: userId }, {
|
||||
$set: {
|
||||
'emails.0.address': email,
|
||||
}
|
||||
});
|
||||
},
|
||||
'edit.userRole' (userId, role) {
|
||||
check(userId, String);
|
||||
check(role, String);
|
||||
|
||||
return Roles.setUserRoles(userId, role);
|
||||
},
|
||||
});
|
||||
36
server/publish.js
Normal file
36
server/publish.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { SysConfig } from "../imports/api/systemConfig";
|
||||
import { UpdateInfo } from "../imports/api/updateInfo";
|
||||
import { MScripts } from "../imports/api/mScripts";
|
||||
import { UserInfo } from "../imports/api/userInfo";
|
||||
import { Roels } from "meteor/roles";
|
||||
|
||||
Meteor.publish("SystemConfig", function() {
|
||||
try {
|
||||
return SysConfig.find({});
|
||||
} catch (error) {
|
||||
console.log(" ERROR pulling system config data: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish("UpdateVersion", function() {
|
||||
try {
|
||||
return UpdateInfo.find({ viewed: false });
|
||||
} catch(error) {
|
||||
console.log(" ERROR pulling updated version info: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish("UserInfo", function() {
|
||||
try {
|
||||
return this.userId;
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user Id: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.publish(null, function () {
|
||||
if (this.userId) {
|
||||
return Meteor.roleAssignment.find({ "user._id": this.userId });
|
||||
}
|
||||
this.ready();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue