Commit d190e334 authored by Curtis Adam's avatar Curtis Adam

Hide notification settings in the frontend if they got disabled by the server

parent e84cfc1f
import {Cardsets} from "./cardsets"; import {Cardsets} from "./cardsets";
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {Workload} from "./learned"; import {Workload} from "./learned";
import {ServerSettings} from "./settings";
export let Bonus = class Bonus { export let Bonus = class Bonus {
static isInBonus (cardset_id, user_id = undefined) { static isInBonus (cardset_id, user_id = undefined) {
...@@ -33,14 +34,14 @@ export let Bonus = class Bonus { ...@@ -33,14 +34,14 @@ export let Bonus = class Bonus {
static getNotificationStatus (user, isCSVExport = false) { static getNotificationStatus (user, isCSVExport = false) {
let notifications = ""; let notifications = "";
if (user.mailNotification) { if (ServerSettings.isMailEnabled() && user.mailNotification) {
if (isCSVExport) { if (isCSVExport) {
notifications += TAPi18n.__('leitnerProgress.notification.mail', {}, "de"); notifications += TAPi18n.__('leitnerProgress.notification.mail', {}, "de");
} else { } else {
notifications += "<i class='fa fa-envelope'> " + TAPi18n.__('leitnerProgress.notification.mail') + "</i>"; notifications += "<i class='fa fa-envelope'> " + TAPi18n.__('leitnerProgress.notification.mail') + "</i>";
} }
} }
if (user.webNotification) { if (ServerSettings.isPushEnabled() && user.webNotification) {
if (notifications !== "") { if (notifications !== "") {
notifications += " & "; notifications += " & ";
} }
......
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {AdminSettings} from "./adminSettings";
export const Categories = new TAPi18n.Collection("settings"); export const Categories = new TAPi18n.Collection("settings");
...@@ -7,3 +8,13 @@ if (Meteor.isServer) { ...@@ -7,3 +8,13 @@ if (Meteor.isServer) {
return Categories.find(); return Categories.find();
}); });
} }
export let ServerSettings = class ServerSettings {
static isMailEnabled () {
return AdminSettings.findOne({name: "mailSettings"}).enabled;
}
static isPushEnabled () {
return AdminSettings.findOne({name: "pushSettings"}).enabled;
}
};
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {Mongo} from "meteor/mongo"; import {Mongo} from "meteor/mongo";
import webPush from 'web-push'; import webPush from 'web-push';
import {AdminSettings} from "./adminSettings"; import {ServerSettings} from "./settings";
export const WebPushSubscriptions = new Mongo.Collection("webPushSubscriptions"); export const WebPushSubscriptions = new Mongo.Collection("webPushSubscriptions");
...@@ -13,7 +13,7 @@ export let WebPushNotifications = class WebPushNotifications { ...@@ -13,7 +13,7 @@ export let WebPushNotifications = class WebPushNotifications {
* Meteor-method addWebPushSubscription. * Meteor-method addWebPushSubscription.
*/ */
static subscribeForPushNotification () { static subscribeForPushNotification () {
if (this.isPushEnabled()) { if (ServerSettings.isPushEnabled()) {
try { try {
if (navigator.serviceWorker !== undefined) { if (navigator.serviceWorker !== undefined) {
navigator.serviceWorker.getRegistration() navigator.serviceWorker.getRegistration()
...@@ -48,10 +48,6 @@ export let WebPushNotifications = class WebPushNotifications { ...@@ -48,10 +48,6 @@ export let WebPushNotifications = class WebPushNotifications {
} }
} }
} }
static isPushEnabled () {
return AdminSettings.findOne({name: "pushSettings"}).enabled;
}
}; };
Meteor.methods({ Meteor.methods({
......
...@@ -29,6 +29,7 @@ import {MainNavigation} from "../../api/mainNavigation"; ...@@ -29,6 +29,7 @@ import {MainNavigation} from "../../api/mainNavigation";
import {BarfyStarsConfig} from "../../api/barfyStars.js"; import {BarfyStarsConfig} from "../../api/barfyStars.js";
import {Utilities} from "../../api/utilities"; import {Utilities} from "../../api/utilities";
import {TranscriptBonus} from "../../api/transcriptBonus"; import {TranscriptBonus} from "../../api/transcriptBonus";
import {ServerSettings} from "../../api/settings";
Meteor.subscribe("collegesCourses"); Meteor.subscribe("collegesCourses");
...@@ -196,6 +197,22 @@ Template.registerHelper('getNavigationName', function (name = undefined) { ...@@ -196,6 +197,22 @@ Template.registerHelper('getNavigationName', function (name = undefined) {
} }
}); });
Template.registerHelper('isNotificationEnabled', function () {
return ServerSettings.isPushEnabled() || ServerSettings.isMailEnabled();
});
Template.registerHelper('isNotificationEnabled', function () {
return ServerSettings.isPushEnabled() || ServerSettings.isMailEnabled();
});
Template.registerHelper('isMailEnabled', function () {
return ServerSettings.isMailEnabled();
});
Template.registerHelper('isPushEnabled', function () {
return ServerSettings.isPushEnabled();
});
Template.registerHelper('isPublicRoute', function () { Template.registerHelper('isPublicRoute', function () {
return Route.isPublic(); return Route.isPublic();
}); });
......
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {AdminSettings} from "../../../api/adminSettings.js"; import {AdminSettings} from "../../../api/adminSettings.js";
import "./settings.html"; import "./settings.html";
import {ServerSettings} from "../../../api/settings";
Template.admin_settings.events({ Template.admin_settings.events({
'click #enableWordcloudPomodoro': function () { 'click #enableWordcloudPomodoro': function () {
...@@ -73,10 +74,10 @@ Template.admin_settings.helpers({ ...@@ -73,10 +74,10 @@ Template.admin_settings.helpers({
return AdminSettings.findOne({name: "wordcloudPomodoroSettings"}).enabled; return AdminSettings.findOne({name: "wordcloudPomodoroSettings"}).enabled;
}, },
isMailEnabled: function () { isMailEnabled: function () {
return AdminSettings.findOne({name: "mailSettings"}).enabled; return ServerSettings.isMailEnabled();
}, },
isPushEnabled: function () { isPushEnabled: function () {
return AdminSettings.findOne({name: "pushSettings"}).enabled; return ServerSettings.isPushEnabled();
}, },
getNotificationTargetText: function () { getNotificationTargetText: function () {
let user = Meteor.users.findOne({_id: AdminSettings.findOne({name: "testNotifications"}).target}); let user = Meteor.users.findOne({_id: AdminSettings.findOne({name: "testNotifications"}).target});
......
...@@ -33,8 +33,10 @@ ...@@ -33,8 +33,10 @@
<th>{{_ "panel-body.givenname"}}</th> <th>{{_ "panel-body.givenname"}}</th>
<th>{{_ "panel-body.email"}} <th>{{_ "panel-body.email"}}
</th> </th>
<th>{{_ "confirmLearn-form.notification"}} {{#if isNotificationEnabled}}
</th> <th>{{_ "confirmLearn-form.notification"}}
</th>
{{/if}}
<th>{{_ "leitnerProgress.box" number=1}} [{{this.learningInterval.[0]}}] <th>{{_ "leitnerProgress.box" number=1}} [{{this.learningInterval.[0]}}]
</th> </th>
<th>{{_ "leitnerProgress.box" number=2}} [{{this.learningInterval.[1]}}] <th>{{_ "leitnerProgress.box" number=2}} [{{this.learningInterval.[1]}}]
...@@ -54,7 +56,9 @@ ...@@ -54,7 +56,9 @@
<td>{{this.birthname}}</td> <td>{{this.birthname}}</td>
<td>{{this.givenname}}</td> <td>{{this.givenname}}</td>
<td><a href="mailto:{{this.email}}">{{this.email}}</a></td> <td><a href="mailto:{{this.email}}">{{this.email}}</a></td>
<td>{{{getNotificationStatus this}}}</td> {{#if isNotificationEnabled}}
<td>{{{getNotificationStatus this}}}</td>
{{/if}}
<td>{{this.box1}}</td> <td>{{this.box1}}</td>
<td>{{this.box2}}</td> <td>{{this.box2}}</td>
<td>{{this.box3}}</td> <td>{{this.box3}}</td>
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
<th>{{_ "panel-body.birthname"}}</th> <th>{{_ "panel-body.birthname"}}</th>
<th>{{_ "panel-body.givenname"}}</th> <th>{{_ "panel-body.givenname"}}</th>
<th>{{_ "panel-body.email"}}</th> <th>{{_ "panel-body.email"}}</th>
<th>{{_ "confirmLearn-form.notification"}}</th> {{#if isNotificationEnabled}}
<th>{{_ "confirmLearn-form.notification"}}</th>
{{/if}}
<th>{{_ "leitnerProgress.box" number=1}}</th> <th>{{_ "leitnerProgress.box" number=1}}</th>
<th>{{_ "leitnerProgress.box" number=2}}</th> <th>{{_ "leitnerProgress.box" number=2}}</th>
<th>{{_ "leitnerProgress.box" number=3}}</th> <th>{{_ "leitnerProgress.box" number=3}}</th>
...@@ -38,9 +40,11 @@ ...@@ -38,9 +40,11 @@
<td> <td>
{{this.email}} {{this.email}}
</td> </td>
<td> {{#if isNotificationEnabled}}
{{{getNotificationStatus this}}} <td>
</td> {{{getNotificationStatus this}}}
</td>
{{/if}}
<td> <td>
{{this.box1}} {{this.box1}}
</td> </td>
......
...@@ -74,30 +74,40 @@ ...@@ -74,30 +74,40 @@
<span id="errorGivenName" class="help-block name"></span> <span id="errorGivenName" class="help-block name"></span>
</div> </div>
</div> </div>
<div class="form-group"> {{#if isNotificationEnabled}}
<label class="col-md-4 control-label">{{_ "confirmLearn-form.notification"}}</label> <div class="form-group">
<form> <label class="col-md-4 control-label">{{_ "confirmLearn-form.notification"}}</label>
<fieldset> <form>
<div class="col-md-9 form-group notifications-form-group"> <fieldset>
<div class="col-sm-6" style="{{#if isSocialLogin}}display: none;{{/if}}"> <div class="col-md-9 form-group notifications-form-group">
<label class="checkbox-inline" for="mailNotificationCheckbox"> {{#if isMailEnabled}}
<input type="checkbox" name="notification" <div class="col-sm-6"
id="mailNotificationCheckbox" style="{{#if isSocialLogin}}display: none;{{/if}}">
{{getMailNotifications}}> <label class="checkbox-inline" for="mailNotificationCheckbox">
{{_ "confirmLearn-form.mailNotificationCheckbox"}} <input type="checkbox" name="notification"
</label> id="mailNotificationCheckbox"
</div> {{getMailNotifications}}>
<div class="col-sm-6"> {{_ "confirmLearn-form.mailNotificationCheckbox"}}
<label class="checkbox-inline" for="webNotificationCheckbox"> </label>
<input type="checkbox" name="notification" id="webNotificationCheckbox" </div>
{{getWebNotifications}}> {{/if}}
{{_ "confirmLearn-form.webNotificationCheckbox"}} {{#if isPushEnabled}}
</label> <div class="col-sm-6">
<label class="checkbox-inline" for="webNotificationCheckbox">
<input type="checkbox" name="notification"
id="webNotificationCheckbox"
{{getWebNotifications}}>
{{_ "confirmLearn-form.webNotificationCheckbox"}}
</label>
</div>
{{/if}}
</div> </div>
</div> </fieldset>
</fieldset> </form>
</form> </div>
</div> {{else}}
<br>
{{/if}}
<button id="profileCancel" type="button" <button id="profileCancel" type="button"
class="btn btn-default btn-raised profileSave" class="btn btn-default btn-raised profileSave"
data-id="disabled">{{_ data-id="disabled">{{_
......
...@@ -6,6 +6,7 @@ import {Session} from "meteor/session"; ...@@ -6,6 +6,7 @@ import {Session} from "meteor/session";
import {ColorThemes} from "../../../api/theme"; import {ColorThemes} from "../../../api/theme";
import {BertAlertVisuals} from "../../../api/bertAlertVisuals"; import {BertAlertVisuals} from "../../../api/bertAlertVisuals";
import "./settings.html"; import "./settings.html";
import {ServerSettings} from "../../../api/settings";
/* /*
* ############################################################################ * ############################################################################
...@@ -229,8 +230,14 @@ Template.profileSettings.events({ ...@@ -229,8 +230,14 @@ Template.profileSettings.events({
// Name validation // Name validation
let user_id = Meteor.userId(); let user_id = Meteor.userId();
if (validEmail && validBirthName && validGivenName) { if (validEmail && validBirthName && validGivenName) {
let mailNotification = document.getElementById('mailNotificationCheckbox').checked; let mailNotification = Meteor.user().mailNotification;
let webNotification = document.getElementById('webNotificationCheckbox').checked; if (ServerSettings.isMailEnabled()) {
mailNotification = document.getElementById('mailNotificationCheckbox').checked;
}
let webNotification = Meteor.user().webNotification;
if (ServerSettings.isPushEnabled()) {
webNotification = document.getElementById('webNotificationCheckbox').checked;
}
$('#inputEmailValidation').val(''); $('#inputEmailValidation').val('');
$('#inputEmailValidationForm').addClass("hidden"); $('#inputEmailValidationForm').addClass("hidden");
Session.set("profileSettingsSave", true); Session.set("profileSettingsSave", true);
......
...@@ -4,20 +4,8 @@ import {Cardsets} from "../imports/api/cardsets"; ...@@ -4,20 +4,8 @@ import {Cardsets} from "../imports/api/cardsets";
import {MailNotifier} from "./sendmail.js"; import {MailNotifier} from "./sendmail.js";
import {WebNotifier} from "./sendwebpush.js"; import {WebNotifier} from "./sendwebpush.js";
import {Bonus} from "../imports/api/bonus"; import {Bonus} from "../imports/api/bonus";
import {AdminSettings} from "../imports/api/adminSettings.js";
import {LeitnerUtilities} from "../imports/api/leitner"; import {LeitnerUtilities} from "../imports/api/leitner";
import {WebPushSubscriptions} from "../imports/api/webPushSubscriptions"; import {ServerSettings} from "../imports/api/settings";
/** Function checks if mail notifications are globally disabled by the admin
* @returns {boolean} - Mail notifications are globally enabled / disabled
* */
function mailsEnabled() {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
return AdminSettings.findOne({name: "mailSettings"}).enabled;
}
}
/** Function gets called when the learning-phase ended and excludes the cardset from the leitner algorithm /** Function gets called when the learning-phase ended and excludes the cardset from the leitner algorithm
* @param {Object} cardset - The cardset from the active learning-phase * @param {Object} cardset - The cardset from the active learning-phase
...@@ -132,7 +120,7 @@ Meteor.methods({ ...@@ -132,7 +120,7 @@ Meteor.methods({
}, },
prepareMail: function (cardset, user, isReset = false, isNewcomer = false) { prepareMail: function (cardset, user, isReset = false, isNewcomer = false) {
if (Meteor.isServer) { if (Meteor.isServer) {
if (user.mailNotification && mailsEnabled() && !isNewcomer && Roles.userIsInRole(user._id, ['admin', 'editor', 'university', 'lecturer', 'pro']) && !Roles.userIsInRole(user._id, ['blocked', 'firstLogin'])) { if (user.mailNotification && ServerSettings.isMailEnabled() && !isNewcomer && Roles.userIsInRole(user._id, ['admin', 'editor', 'university', 'lecturer', 'pro']) && !Roles.userIsInRole(user._id, ['blocked', 'firstLogin'])) {
try { try {
if (isReset) { if (isReset) {
if (Meteor.settings.debug.leitner) { if (Meteor.settings.debug.leitner) {
...@@ -153,7 +141,7 @@ Meteor.methods({ ...@@ -153,7 +141,7 @@ Meteor.methods({
}, },
prepareWebpush: function (cardset, user, isNewcomer = false) { prepareWebpush: function (cardset, user, isNewcomer = false) {
if (Meteor.isServer) { if (Meteor.isServer) {
if (WebPushSubscriptions.isPushEnabled() && (Bonus.isInBonus(cardset._id, user._id) || user.webNotification) && !isNewcomer) { if (ServerSettings.isPushEnabled() && (Bonus.isInBonus(cardset._id, user._id) || user.webNotification) && !isNewcomer) {
try { try {
let web = new WebNotifier(); let web = new WebNotifier();
if (Meteor.settings.debug.leitner) { if (Meteor.settings.debug.leitner) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment