From bc8df4838911b456fd9fbe2def803f9b2c34a217 Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Sun, 11 Jun 2023 12:30:08 -0500 Subject: [PATCH] Added ability for ystem admin to disable registration. --- client/Accounts/Login/login.html | 8 ++-- client/Accounts/Login/login.js | 12 ++++- client/Accounts/Login/reg.html | 5 +++ client/Accounts/Login/reg.js | 11 ++++- client/AdminMgmt/MgmtPage/mgmtPage.html | 1 + client/AdminMgmt/SystemAdmin/systemAdmin.html | 32 ++++++++++++++ client/AdminMgmt/SystemAdmin/systemAdmin.js | 40 +++++++++++++++++ imports/api/systemConfig.js | 44 ++++++++++++++----- imports/api/userConfigOptions.js | 17 ------- lib/routes.js | 7 +++ 10 files changed, 145 insertions(+), 32 deletions(-) create mode 100644 client/AdminMgmt/SystemAdmin/systemAdmin.html create mode 100644 client/AdminMgmt/SystemAdmin/systemAdmin.js diff --git a/client/Accounts/Login/login.html b/client/Accounts/Login/login.html index 0324616..9303eee 100644 --- a/client/Accounts/Login/login.html +++ b/client/Accounts/Login/login.html @@ -32,9 +32,11 @@ -
- Register -
+ {{#if $eq canReg true}} +
+ Register +
+ {{/if}} diff --git a/client/Accounts/Login/login.js b/client/Accounts/Login/login.js index 77b653b..7f3c38a 100644 --- a/client/Accounts/Login/login.js +++ b/client/Accounts/Login/login.js @@ -1,5 +1,7 @@ -Template.login.onCreated(function() { +import { SysConfig } from '../../../imports/api/systemConfig.js'; +Template.login.onCreated(function() { + this.subscribe("SystemConfig"); }); Template.login.onRendered(function() { @@ -9,6 +11,14 @@ Template.login.onRendered(function() { Template.login.helpers({ areFilled: function() { return Session.get("filledFields"); + }, + canReg: function() { + let conf = SysConfig.findOne(); + if (typeof conf != 'undefined') { + return conf.allowReg; + } else { + return true; + } } }); diff --git a/client/Accounts/Login/reg.html b/client/Accounts/Login/reg.html index 2a932a7..8c24b5d 100644 --- a/client/Accounts/Login/reg.html +++ b/client/Accounts/Login/reg.html @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/client/Accounts/Login/reg.js b/client/Accounts/Login/reg.js index f2cfbe9..ef5c80e 100644 --- a/client/Accounts/Login/reg.js +++ b/client/Accounts/Login/reg.js @@ -1,6 +1,7 @@ +import { SysConfig } from "../../../imports/api/systemConfig.js"; Template.reg.onCreated(function() { - + this.subscribe("SystemConfig"); }); Template.reg.onRendered(function() { @@ -27,6 +28,14 @@ Template.reg.helpers({ }, misReq: function() { return Session.get("missingReq"); + }, + allowReg: function() { + let conf = SysConfig.findOne(); + if (typeof conf != 'undefined') { + return conf.allowReg; + } else { + return true + } } }); diff --git a/client/AdminMgmt/MgmtPage/mgmtPage.html b/client/AdminMgmt/MgmtPage/mgmtPage.html index ebb2637..8281562 100644 --- a/client/AdminMgmt/MgmtPage/mgmtPage.html +++ b/client/AdminMgmt/MgmtPage/mgmtPage.html @@ -12,6 +12,7 @@
  • Location
  • Store
  • Tasks
  • +
  • System Admin
  • diff --git a/client/AdminMgmt/SystemAdmin/systemAdmin.html b/client/AdminMgmt/SystemAdmin/systemAdmin.html new file mode 100644 index 0000000..c568bb5 --- /dev/null +++ b/client/AdminMgmt/SystemAdmin/systemAdmin.html @@ -0,0 +1,32 @@ + \ No newline at end of file diff --git a/client/AdminMgmt/SystemAdmin/systemAdmin.js b/client/AdminMgmt/SystemAdmin/systemAdmin.js new file mode 100644 index 0000000..95f6e1d --- /dev/null +++ b/client/AdminMgmt/SystemAdmin/systemAdmin.js @@ -0,0 +1,40 @@ +import { SysConfig } from '../../../imports/api/systemConfig.js'; + +Template.systemAdmin.onCreated(function() { + this.subscribe("SystemConfig"); +}); + +Template.systemAdmin.onRendered(function() { + this.autorun(() => { + let curr = SysConfig.findOne({}); + if (typeof curr != 'undefined') { + $("#allowGenReg").prop('checked', curr.allowReg); + $("#allAdmReg").prop('checked', curr.SysAdminReg); + } else { + console.log(" ---- unable to find current system configuration."); + } + }); +}); + +Template.systemAdmin.helpers({ + currConfigs: function() { + + } +}); + +Template.systemAdmin.events({ + 'change #allowGenReg, change #allowAdmReg' (evnnt) { + let genReg = $("#allowGenReg").prop('checked'); + let admReg = $("#allowAdmReg").prop('checked'); + // console.log("General Reg set to: " + genReg); + Meteor.call("add.noSysAdminReg", admReg, genReg, function(err, result) { + if (err) { + console.log(" ERROR updating permission to allow general registration: " + err); + showSnackbar("Registration Permission Change Failed.", "red"); + } else { + console.log(" Successfully updated permission to allow general registration."); + showSnackbar("Registration Permission Successfully Changed.", "green") + } + }); + } +}); \ No newline at end of file diff --git a/imports/api/systemConfig.js b/imports/api/systemConfig.js index e55921c..82108a8 100644 --- a/imports/api/systemConfig.js +++ b/imports/api/systemConfig.js @@ -12,23 +12,47 @@ SysConfig.allow({ }); Meteor.methods({ - 'add.noSysAdminReg' () { - return SysConfig.insert({ - canReg: false, - dateAdded: new Date(), - }); - }, - 'edit.noSysAdminReg' (canReg) { - check(canReg, Boolean); + 'add.noSysAdminReg' (admReg, genReg) { + check(admReg, Boolean); + check(genReg, Boolean); if (!this.userId) { throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.'); } + + let curr = SysConfig.findOne({}); + if (typeof curr != 'undefined') { + let configId = curr._id; + Meteor.call('edit.noSysAdminReg', configId, admReg, genReg, function(err, result) { + if (err) { + console.log(" ERROR updating sys admin reg: " + err); + } else { + console.log("Success updating sys admin reg."); + } + }); + } else { + return SysConfig.insert({ + SysAdminReg: admReg, + dateAdded: new Date(), + allowReg: genReg, + }); + } + }, + 'edit.noSysAdminReg' (configId, canReg, genReg) { + check(canReg, Boolean); + check(configId, String); + check(genReg, Boolean); + + if (!this.userId) { + throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.'); + } + return SysConfig.update({ _id: configId }, { $set: { - canReg: canReg, + SysAdminReg: canReg, + allowReg: genReg, dateUpdated: new Date(), } }); - } + }, }); \ No newline at end of file diff --git a/imports/api/userConfigOptions.js b/imports/api/userConfigOptions.js index f20d37b..d7b59c3 100644 --- a/imports/api/userConfigOptions.js +++ b/imports/api/userConfigOptions.js @@ -12,23 +12,6 @@ UserConfigOptions.allow({ }); Meteor.methods({ - 'add.darkPref' (darkPref) { - check(darkPref, Boolean); - - return UserConfigOptions.insert({ - darkPref: darkPref, - owner: this.userId - }); - }, - 'edit.darkPref' (darkPref) { - check(darkPref, Boolean); - - return UserConfigOptions.update({ owner: this.userId }, { - $set: { - darkPref: darkPref - } - }); - }, 'change.userPass' (usersId, password) { check(usersId, String); check(password, String); diff --git a/lib/routes.js b/lib/routes.js index b633974..0c3c7fd 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -122,4 +122,11 @@ FlowRouter.route('/myTasks', { action() { BlazeLayout.render('MainLayout', { main: 'myTasks' }); } +}); + +FlowRouter.route('/systemAdmin', { + name: 'systemAdmin', + action() { + BlazeLayout.render('MainLayout', { main: 'systemAdmin' }); + } }); \ No newline at end of file