2022-08-04 19:50:18 -05:00
import { Meteor } from 'meteor/meteor' ;
import { Mongo } from 'meteor/mongo' ;
import { check } from 'meteor/check' ;
export const SysConfig = new Mongo . Collection ( 'sysConfig' ) ;
SysConfig . allow ( {
insert : function ( userId , doc ) {
// if use id exists, allow insert
return ! ! userId ;
} ,
} ) ;
Meteor . methods ( {
2025-07-22 13:50:49 -05:00
async 'add.noSysAdminReg' ( admReg , genReg ) {
2023-06-11 12:30:08 -05:00
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.' ) ;
}
2025-06-21 07:28:59 -05:00
const currConfig = async ( ) => {
let curr = await SysConfig . findOneAsync ( { } ) ;
if ( ! curr ) {
try {
2025-07-22 13:50:49 -05:00
return await SysConfig . insertAsync ( {
2025-06-21 07:28:59 -05:00
SysAdminReg : admReg ,
dateAdded : new Date ( ) ,
allowReg : genReg ,
} ) ;
} catch ( error ) {
console . log ( " ERROR trying to insert system config:" ) ;
console . log ( error . message ) ;
console . log ( error . stack ) ;
}
} else {
try {
let configId = curr . _id ;
const addNoSys = await Meteor . callAsync ( 'edit.noSysAdminReg' , configId , admReg , genReg ) ;
if ( ! addNoSys ) {
2025-07-23 19:44:24 -05:00
// console.log(" Couldn't edit the system config.");
2023-06-11 12:30:08 -05:00
} else {
2025-07-23 19:44:24 -05:00
// console.log("Success updating sys admin reg.");
2023-06-11 12:30:08 -05:00
}
2025-06-21 07:28:59 -05:00
} catch ( error ) {
console . log ( " ERROR trying to pull current system config:" ) ;
console . log ( error . message ) ;
console . log ( error . stack ) ;
}
2023-06-11 12:30:08 -05:00
}
2025-06-21 07:28:59 -05:00
}
currConfig ( ) ;
2022-08-04 19:50:18 -05:00
} ,
2025-07-22 13:50:49 -05:00
async 'edit.noSysAdminReg' ( configId , canReg , genReg ) {
2022-08-04 19:50:18 -05:00
check ( canReg , Boolean ) ;
2023-06-11 12:30:08 -05:00
check ( configId , String ) ;
check ( genReg , Boolean ) ;
2022-08-04 19:50:18 -05:00
if ( ! this . userId ) {
throw new Meteor . Error ( 'Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.' ) ;
}
2023-06-11 12:30:08 -05:00
2025-07-22 13:50:49 -05:00
return await SysConfig . updateAsync ( { _id : configId } , {
2022-08-04 19:50:18 -05:00
$set : {
2023-06-11 12:30:08 -05:00
SysAdminReg : canReg ,
allowReg : genReg ,
2022-08-04 19:50:18 -05:00
dateUpdated : new Date ( ) ,
}
} ) ;
2023-06-11 12:30:08 -05:00
} ,
2025-07-22 13:50:49 -05:00
async 'allow.updateInfo' ( allowUpdate ) {
2024-08-21 07:01:36 -05:00
check ( allowUpdate , Boolean ) ;
if ( ! this . userId ) {
throw new Meteor . Error ( 'Not able to change system update notification settings. Make sure you are logged in with valid system administrator credentials.' ) ;
}
let curr = SysConfig . findOne ( { } ) ;
let configId = curr . _id ;
2025-07-22 13:50:49 -05:00
return await SysConfig . updateAsync ( { _id : configId } , {
2024-08-21 07:01:36 -05:00
$set : {
allowUpdates : allowUpdate ,
}
} ) ;
} ,
} ) ;