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 {Meteor} from "meteor/meteor";
import {Workload} from "./learned";
import {ServerSettings} from "./settings";
export let Bonus = class Bonus {
static isInBonus (cardset_id, user_id = undefined) {
......@@ -33,14 +34,14 @@ export let Bonus = class Bonus {
static getNotificationStatus (user, isCSVExport = false) {
let notifications = "";
if (user.mailNotification) {
if (ServerSettings.isMailEnabled() && user.mailNotification) {
if (isCSVExport) {
notifications += TAPi18n.__('leitnerProgress.notification.mail', {}, "de");
} else {
notifications += "<i class='fa fa-envelope'> " + TAPi18n.__('leitnerProgress.notification.mail') + "</i>";
}
}
if (user.webNotification) {
if (ServerSettings.isPushEnabled() && user.webNotification) {
if (notifications !== "") {
notifications += " & ";
}
......
import {Meteor} from "meteor/meteor";
import {AdminSettings} from "./adminSettings";
export const Categories = new TAPi18n.Collection("settings");
......@@ -7,3 +8,13 @@ if (Meteor.isServer) {
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 {Mongo} from "meteor/mongo";
import webPush from 'web-push';
import {AdminSettings} from "./adminSettings";
import {ServerSettings} from "./settings";
export const WebPushSubscriptions = new Mongo.Collection("webPushSubscriptions");
......@@ -13,7 +13,7 @@ export let WebPushNotifications = class WebPushNotifications {
* Meteor-method addWebPushSubscription.
*/
static subscribeForPushNotification () {
if (this.isPushEnabled()) {
if (ServerSettings.isPushEnabled()) {
try {
if (navigator.serviceWorker !== undefined) {
navigator.serviceWorker.getRegistration()
......@@ -48,10 +48,6 @@ export let WebPushNotifications = class WebPushNotifications {
}
}
}
static isPushEnabled () {
return AdminSettings.findOne({name: "pushSettings"}).enabled;
}
};
Meteor.methods({
......
......@@ -29,6 +29,7 @@ import {MainNavigation} from "../../api/mainNavigation";
import {BarfyStarsConfig} from "../../api/barfyStars.js";
import {Utilities} from "../../api/utilities";
import {TranscriptBonus} from "../../api/transcriptBonus";
import {ServerSettings} from "../../api/settings";
Meteor.subscribe("collegesCourses");
......@@ -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 () {
return Route.isPublic();
});
......
import {Meteor} from "meteor/meteor";
import {AdminSettings} from "../../../api/adminSettings.js";
import "./settings.html";
import {ServerSettings} from "../../../api/settings";
Template.admin_settings.events({
'click #enableWordcloudPomodoro': function () {
......@@ -73,10 +74,10 @@ Template.admin_settings.helpers({
return AdminSettings.findOne({name: "wordcloudPomodoroSettings"}).enabled;
},
isMailEnabled: function () {
return AdminSettings.findOne({name: "mailSettings"}).enabled;
return ServerSettings.isMailEnabled();
},
isPushEnabled: function () {
return AdminSettings.findOne({name: "pushSettings"}).enabled;
return ServerSettings.isPushEnabled();
},
getNotificationTargetText: function () {
let user = Meteor.users.findOne({_id: AdminSettings.findOne({name: "testNotifications"}).target});
......
......@@ -33,8 +33,10 @@
<th>{{_ "panel-body.givenname"}}</th>
<th>{{_ "panel-body.email"}}
</th>
<th>{{_ "confirmLearn-form.notification"}}
</th>
{{#if isNotificationEnabled}}
<th>{{_ "confirmLearn-form.notification"}}
</th>
{{/if}}
<th>{{_ "leitnerProgress.box" number=1}} [{{this.learningInterval.[0]}}]
</th>
<th>{{_ "leitnerProgress.box" number=2}} [{{this.learningInterval.[1]}}]
......@@ -54,7 +56,9 @@
<td>{{this.birthname}}</td>
<td>{{this.givenname}}</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.box2}}</td>
<td>{{this.box3}}</td>
......
......@@ -20,7 +20,9 @@
<th>{{_ "panel-body.birthname"}}</th>
<th>{{_ "panel-body.givenname"}}</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=2}}</th>
<th>{{_ "leitnerProgress.box" number=3}}</th>
......@@ -38,9 +40,11 @@
<td>
{{this.email}}
</td>
<td>
{{{getNotificationStatus this}}}
</td>
{{#if isNotificationEnabled}}
<td>
{{{getNotificationStatus this}}}
</td>
{{/if}}
<td>
{{this.box1}}
</td>
......
......@@ -74,30 +74,40 @@
<span id="errorGivenName" class="help-block name"></span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">{{_ "confirmLearn-form.notification"}}</label>
<form>
<fieldset>
<div class="col-md-9 form-group notifications-form-group">
<div class="col-sm-6" style="{{#if isSocialLogin}}display: none;{{/if}}">
<label class="checkbox-inline" for="mailNotificationCheckbox">
<input type="checkbox" name="notification"
id="mailNotificationCheckbox"
{{getMailNotifications}}>
{{_ "confirmLearn-form.mailNotificationCheckbox"}}
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline" for="webNotificationCheckbox">
<input type="checkbox" name="notification" id="webNotificationCheckbox"
{{getWebNotifications}}>
{{_ "confirmLearn-form.webNotificationCheckbox"}}
</label>
{{#if isNotificationEnabled}}
<div class="form-group">
<label class="col-md-4 control-label">{{_ "confirmLearn-form.notification"}}</label>
<form>
<fieldset>
<div class="col-md-9 form-group notifications-form-group">
{{#if isMailEnabled}}
<div class="col-sm-6"
style="{{#if isSocialLogin}}display: none;{{/if}}">
<label class="checkbox-inline" for="mailNotificationCheckbox">
<input type="checkbox" name="notification"
id="mailNotificationCheckbox"
{{getMailNotifications}}>
{{_ "confirmLearn-form.mailNotificationCheckbox"}}
</label>
</div>
{{/if}}
{{#if isPushEnabled}}
<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>
</fieldset>
</form>
</div>
</fieldset>
</form>
</div>
{{else}}
<br>
{{/if}}
<button id="profileCancel" type="button"
class="btn btn-default btn-raised profileSave"
data-id="disabled">{{_
......
......@@ -6,6 +6,7 @@ import {Session} from "meteor/session";
import {ColorThemes} from "../../../api/theme";
import {BertAlertVisuals} from "../../../api/bertAlertVisuals";
import "./settings.html";
import {ServerSettings} from "../../../api/settings";
/*
* ############################################################################
......@@ -229,8 +230,14 @@ Template.profileSettings.events({
// Name validation
let user_id = Meteor.userId();
if (validEmail && validBirthName && validGivenName) {
let mailNotification = document.getElementById('mailNotificationCheckbox').checked;
let webNotification = document.getElementById('webNotificationCheckbox').checked;
let mailNotification = Meteor.user().mailNotification;
if (ServerSettings.isMailEnabled()) {
mailNotification = document.getElementById('mailNotificationCheckbox').checked;
}
let webNotification = Meteor.user().webNotification;
if (ServerSettings.isPushEnabled()) {
webNotification = document.getElementById('webNotificationCheckbox').checked;
}
$('#inputEmailValidation').val('');
$('#inputEmailValidationForm').addClass("hidden");
Session.set("profileSettingsSave", true);
......
......@@ -4,20 +4,8 @@ import {Cardsets} from "../imports/api/cardsets";
import {MailNotifier} from "./sendmail.js";
import {WebNotifier} from "./sendwebpush.js";
import {Bonus} from "../imports/api/bonus";
import {AdminSettings} from "../imports/api/adminSettings.js";
import {LeitnerUtilities} from "../imports/api/leitner";
import {WebPushSubscriptions} from "../imports/api/webPushSubscriptions";
/** 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;
}
}
import {ServerSettings} from "../imports/api/settings";
/** 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
......@@ -132,7 +120,7 @@ Meteor.methods({
},
prepareMail: function (cardset, user, isReset = false, isNewcomer = false) {
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 {
if (isReset) {
if (Meteor.settings.debug.leitner) {
......@@ -153,7 +141,7 @@ Meteor.methods({
},
prepareWebpush: function (cardset, user, isNewcomer = false) {
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 {
let web = new WebNotifier();
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