add currentSetting to ReactiveCache

This commit is contained in:
Martin Filser 2022-12-13 23:20:04 +01:00
parent c6ee58ef88
commit b7dbeba7de
13 changed files with 59 additions and 55 deletions

View file

@ -3,9 +3,6 @@ import { TAPi18n } from '/imports/i18n';
const subManager = new SubsManager();
Template.boardList.helpers({
currentSetting() {
return Settings.findOne();
},
hideCardCounterList() {
/* Bug Board icons random dance https://github.com/wekan/wekan/issues/4214
return Utils.isMiniScreen() && Session.get('currentBoard'); */

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
Meteor.subscribe('user-admin');
Meteor.subscribe('boards');
Meteor.subscribe('setting');
@ -9,7 +11,7 @@ Template.header.onCreated(function(){
Meteor.subscribe('setting', {
onReady() {
templateInstance.currentSetting.set(Settings.findOne());
templateInstance.currentSetting.set(ReactiveCache.getCurrentSetting());
let currSetting = templateInstance.currentSetting.curValue;
if(currSetting && currSetting !== undefined && currSetting.customLoginLogoImageUrl !== undefined && document.getElementById("headerIsSettingDatabaseCallDone") != null)
document.getElementById("headerIsSettingDatabaseCallDone").style.display = 'none';
@ -24,10 +26,6 @@ Template.header.helpers({
return !Session.get('currentBoard');
},
currentSetting() {
return Settings.findOne();
},
hideLogo() {
return Utils.isMiniScreen() && Session.get('currentBoard');
},

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
BlazeLayout.setRoot('body');
@ -28,7 +29,7 @@ Template.userFormsLayout.onCreated(function () {
Meteor.subscribe('setting', {
onReady() {
templateInstance.currentSetting.set(Settings.findOne());
templateInstance.currentSetting.set(ReactiveCache.getCurrentSetting());
let currSetting = templateInstance.currentSetting.curValue;
let oidcBtnElt = $("#at-oidc");
if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
@ -85,10 +86,6 @@ Template.userFormsLayout.onRendered(() => {
});
Template.userFormsLayout.helpers({
currentSetting() {
return Template.instance().currentSetting.get();
},
// isSettingDatabaseCallDone(){
// return isSettingDatabaseFctCallDone;
// },
@ -164,7 +161,7 @@ Template.userFormsLayout.events({
},
'DOMSubtreeModified #at-oidc'(event) {
if (alreadyCheck <= 2) {
let currSetting = Settings.findOne();
let currSetting = Utils.getCurrentSetting();
let oidcBtnElt = $("#at-oidc");
if (currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined) {
let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
@ -185,7 +182,7 @@ Template.userFormsLayout.events({
'DOMSubtreeModified .at-form'(event) {
if (alreadyCheck <= 2 && !isCheckDone) {
if (document.getElementById("at-oidc") != null) {
let currSetting = Settings.findOne();
let currSetting = Utils.getCurrentSetting();
let oidcBtnElt = $("#at-oidc");
if (currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined) {
let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;

View file

@ -1,7 +1,7 @@
Template.invitationCode.onRendered(function() {
Meteor.subscribe('setting', {
onReady() {
const setting = Settings.findOne();
const setting = Utils.getCurrentSetting();
if (!setting || !setting.disableRegistration) {
$('#invitationcode').hide();

View file

@ -42,10 +42,6 @@ BlazeComponent.extendComponent({
}
},
currentSetting() {
return Settings.findOne();
},
boards() {
return Boards.find(
{
@ -60,16 +56,16 @@ BlazeComponent.extendComponent({
},
toggleForgotPassword() {
this.setLoading(true);
const forgotPasswordClosed = this.currentSetting().disableForgotPassword;
Settings.update(Settings.findOne()._id, {
const forgotPasswordClosed = Utils.getCurrentSetting().disableForgotPassword;
Settings.update(Utils.getCurrentSetting()._id, {
$set: { disableForgotPassword: !forgotPasswordClosed },
});
this.setLoading(false);
},
toggleRegistration() {
this.setLoading(true);
const registrationClosed = this.currentSetting().disableRegistration;
Settings.update(Settings.findOne()._id, {
const registrationClosed = Utils.getCurrentSetting().disableRegistration;
Settings.update(Utils.getCurrentSetting()._id, {
$set: { disableRegistration: !registrationClosed },
});
this.setLoading(false);
@ -165,7 +161,7 @@ BlazeComponent.extendComponent({
.trim();
const from = this.checkField('#mail-server-from');
const tls = $('#mail-server-tls.is-checked').length > 0;
Settings.update(Settings.findOne()._id, {
Settings.update(Utils.getCurrentSetting()._id, {
$set: {
'mailServer.host': host,
'mailServer.port': port,
@ -245,7 +241,7 @@ BlazeComponent.extendComponent({
const spinnerName = $('#spinnerName').val();
try {
Settings.update(Settings.findOne()._id, {
Settings.update(Utils.getCurrentSetting()._id, {
$set: {
productName,
hideLogo: hideLogoChange,

View file

@ -149,9 +149,6 @@ Template.homeSidebar.helpers({
});
Template.boardInfoOnMyBoardsPopup.helpers({
currentSetting() {
return Settings.findOne();
},
hideCardCounterList() {
return Utils.isMiniScreen() && Session.get('currentBoard');
},

View file

@ -31,7 +31,7 @@ Template.memberMenuPopup.helpers({
}
},
isSameDomainNameSettingValue(){
const currSett = Settings.findOne();
const currSett = Utils.getCurrentSetting();
if(currSett && currSett != undefined && currSett.disableRegistration && currSett.mailDomainName !== undefined && currSett.mailDomainName != ""){
currentUser = Meteor.user();
if (currentUser) {
@ -140,12 +140,6 @@ Template.invitePeoplePopup.events({
},
});
Template.invitePeoplePopup.helpers({
currentSetting() {
return Settings.findOne();
},
});
Template.editProfilePopup.helpers({
allowEmailChange() {
Meteor.call('AccountSettings.allowEmailChange', (_, result) => {

View file

@ -17,6 +17,11 @@ Blaze.registerHelper('currentList', () => {
return ret;
});
Blaze.registerHelper('currentSetting', () => {
const ret = Utils.getCurrentSetting();
return ret;
});
Blaze.registerHelper('getUser', userId => Users.findOne(userId));
Blaze.registerHelper('concat', (...args) => args.slice(0, -1).join(''));

View file

@ -3,17 +3,13 @@ Meteor.subscribe('setting');
import { ALLOWED_WAIT_SPINNERS } from '/config/const';
export class Spinner extends BlazeComponent {
currentSettings() {
return Settings.findOne();
}
getSpinnerName() {
let ret = 'Bounce';
let defaultWaitSpinner = Meteor.settings.public.WAIT_SPINNER;
if (defaultWaitSpinner && ALLOWED_WAIT_SPINNERS.includes(defaultWaitSpinner)) {
ret = defaultWaitSpinner;
}
let settings = this.currentSettings();
let settings = Utils.getCurrentSetting();
if (settings && settings.spinnerName) {
ret = settings.spinnerName;

View file

@ -58,6 +58,10 @@ Utils = {
}
return ret;
},
getCurrentSetting() {
const ret = ReactiveCache.getCurrentSetting();
return ret;
},
getPopupCard() {
const cardId = Utils.getPopupCardId();
const ret = ReactiveCache.getCard(cardId);

View file

@ -31,6 +31,10 @@ ReactiveCacheServer = {
const ret = CustomFields.find(selector).fetch();
return ret;
},
getCurrentSetting() {
const ret = Settings.findOne();
return ret;
},
}
// only the Client is reactive
@ -106,6 +110,16 @@ ReactiveCacheClient = {
}
const ret = this.__customFields.get(Jsons.stringify(selector));
return ret;
},
getCurrentSetting() {
if (!this.__currentSetting || !this.__currentSetting.get()) {
this.__currentSetting = new DataCache(() => {
const _ret = Settings.findOne();
return _ret;
});
}
const ret = this.__currentSetting.get();
return ret;
}
}
@ -179,6 +193,15 @@ ReactiveCache = {
}
return ret;
},
getCurrentSetting() {
let ret;
if (Meteor.isServer) {
ret = ReactiveCacheServer.getCurrentSetting();
} else {
ret = ReactiveCacheClient.getCurrentSetting();
}
return ret;
},
}
export { ReactiveCache };

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
//var nodemailer = require('nodemailer');
@ -167,7 +168,7 @@ Settings.allow({
if (Meteor.isServer) {
Meteor.startup(() => {
Settings._collection.createIndex({ modifiedAt: -1 });
const setting = Settings.findOne({});
const setting = ReactiveCache.getCurrentSetting();
if (!setting) {
const now = new Date();
const domain = process.env.ROOT_URL.match(
@ -193,7 +194,7 @@ if (Meteor.isServer) {
}
if (isSandstorm) {
// At Sandstorm, Admin Panel has SMTP settings
const newSetting = Settings.findOne();
const newSetting = ReactiveCache.getCurrentSetting();
if (!process.env.MAIL_URL && newSetting.mailUrl())
process.env.MAIL_URL = newSetting.mailUrl();
Accounts.emailTemplates.from = process.env.MAIL_FROM
@ -301,7 +302,7 @@ if (Meteor.isServer) {
}
function isNonAdminAllowedToSendMail(currentUser){
const currSett = Settings.findOne({});
const currSett = ReactiveCache.getCurrentSetting();
let isAllowed = false;
if(currSett && currSett != undefined && currSett.disableRegistration && currSett.mailDomainName !== undefined && currSett.mailDomainName != ""){
for(let i = 0; i < currentUser.emails.length; i++) {
@ -449,7 +450,7 @@ if (Meteor.isServer) {
},
getCustomUI() {
const setting = Settings.findOne({});
const setting = ReactiveCache.getCurrentSetting();
if (!setting.productName) {
return {
productName: '',
@ -462,7 +463,7 @@ if (Meteor.isServer) {
},
isDisableRegistration() {
const setting = Settings.findOne({});
const setting = ReactiveCache.getCurrentSetting();
if (setting.disableRegistration === true) {
return true;
} else {
@ -471,7 +472,7 @@ if (Meteor.isServer) {
},
isDisableForgotPassword() {
const setting = Settings.findOne({});
const setting = ReactiveCache.getCurrentSetting();
if (setting.disableForgotPassword === true) {
return true;
} else {

View file

@ -1,4 +1,4 @@
//var nodemailer = require('nodemailer');
import { ReactiveCache } from '/imports/reactiveCache';
import { SyncedCron } from 'meteor/percolate:synced-cron';
import { TAPi18n } from '/imports/i18n';
import ImpersonatedUsers from './impersonatedUsers';
@ -1425,11 +1425,7 @@ if (Meteor.isServer) {
throw new Meteor.Error('error-user-notAllowSelf');
} else {
if (posAt <= 0) throw new Meteor.Error('error-user-doesNotExist');
if (
Settings.findOne({
disableRegistration: true,
})
) {
if (ReactiveCache.getCurrentSetting().disableRegistration) {
throw new Meteor.Error('error-user-notCreated');
}
// Set in lowercase email before creating account
@ -1667,7 +1663,7 @@ if (Meteor.isServer) {
return user;
}
const disableRegistration = Settings.findOne().disableRegistration;
const disableRegistration = ReactiveCache.getCurrentSetting().disableRegistration;
// If this is the first Authentication by the ldap and self registration disabled
if (disableRegistration && options && options.ldap) {
user.authenticationMethod = 'ldap';
@ -1972,7 +1968,7 @@ if (Meteor.isServer) {
}
//invite user to corresponding boards
const disableRegistration = Settings.findOne().disableRegistration;
const disableRegistration = Utils.getCurrentSetting().disableRegistration;
// If ldap, bypass the inviation code if the self registration isn't allowed.
// TODO : pay attention if ldap field in the user model change to another content ex : ldap field to connection_type
if (doc.authenticationMethod !== 'ldap' && disableRegistration) {