Commit 966b5586 authored by Curtis Adam's avatar Curtis Adam

Add server setting to disable university management

parent 08d778fd
......@@ -637,8 +637,9 @@
"interval": "Lernintervalle einstellen",
"notifications": "Benachrichtigungen",
"settings": "Einstellungen",
"manageS": "Hochschule verwalten",
"manage": "Hochschule und Studiengang verwalten",
"manageUniversityLong": "Hochschule und Studiengang verwalten",
"manageUniversity": "Hochschule verwalten",
"manageCourse": "Studiengang verwalten",
"see_all": "Alle ansehen",
"name": "Name",
"kind": "Art",
......
......@@ -637,13 +637,14 @@
"interval": "Learning period",
"notifications": "Notifications",
"settings": "Settings",
"manage": "Manage college and course",
"see_all": "See all",
"name": "Name",
"kind": "Kind",
"front": "Front",
"back": "Back",
"manageS": "College manager",
"manageUniversityLong": "Manage college and course",
"manageUniversity": "College manager",
"manageCourse": "Course manager",
"admin": "Admin",
"pro": "Pro",
"university": "Edu",
......
......@@ -17,70 +17,147 @@ if (Meteor.isServer) {
'editor',
'lecturer'
])) {
return Cards.find();
if (Meteor.settings.public.university.singleUniversity) {
return Cards.find({college: Meteor.settings.public.university.default});
} else {
return Cards.find();
}
} else if (Roles.userIsInRole(this.userId, 'pro')) {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
$or: [
{owner: this.userId},
{visible: true}
]
}).map(function (cardset) {
return cardset._id;
})
}
});
if (Meteor.settings.public.university.singleUniversity) {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
$or: [
{owner: this.userId},
{visible: true},
{college: Meteor.settings.public.university.default}
]
}).map(function (cardset) {
return cardset._id;
})
}
});
} else {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
$or: [
{owner: this.userId},
{visible: true}
]
}).map(function (cardset) {
return cardset._id;
})
}
});
}
} else if (Roles.userIsInRole(this.userId, 'university')) {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
visible: true,
kind: {$in: ['free', 'edu']}
}).map(function (cardset) {
return cardset._id;
})
}
});
if (Meteor.settings.public.university.singleUniversity) {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
visible: true,
college: Meteor.settings.public.university.default,
kind: {$in: ['free', 'edu']}
}).map(function (cardset) {
return cardset._id;
})
}
});
} else {
return Cards.find({
cardset_id: {
$in: Cardsets.find({
visible: true,
kind: {$in: ['free', 'edu']}
}).map(function (cardset) {
return cardset._id;
})
}
});
}
} else {
return Cards.find({
$or: [
//is owner
{
cardset_id: {
$in: Cardsets.find({owner: this.userId}).map(function (cardset) {
return cardset._id;
})
}
},
//is visible and is free
{
cardset_id: {
$in: Cardsets.find({
visible: true,
kind: 'free'
}).map(function (cardset) {
return cardset._id;
})
if (Meteor.settings.public.university.singleUniversity) {
return Cards.find({
$or: [
//is owner
{
cardset_id: {
$in: Cardsets.find({owner: this.userId, college: Meteor.settings.public.university.default}).map(function (cardset) {
return cardset._id;
})
}
},
//is visible and is free
{
cardset_id: {
$in: Cardsets.find({
visible: true,
kind: 'free',
college: Meteor.settings.public.university.default
}).map(function (cardset) {
return cardset._id;
})
}
},
//is visible and has bought
{
cardset_id: {
$in: Paid.find({
user_id: this.userId,
college: Meteor.settings.public.university.default,
cardset_id: {
$in: Cardsets.find({visible: true}).map(function (cardset) {
return cardset._id;
})
}
}).map(function (paid) {
return paid.cardset_id;
})
}
}
},
//is visible and has bought
{
cardset_id: {
$in: Paid.find({
user_id: this.userId,
cardset_id: {
$in: Cardsets.find({visible: true}).map(function (cardset) {
return cardset._id;
})
}
}).map(function (paid) {
return paid.cardset_id;
})
]
});
} else {
return Cards.find({
$or: [
//is owner
{
cardset_id: {
$in: Cardsets.find({owner: this.userId}).map(function (cardset) {
return cardset._id;
})
}
},
//is visible and is free
{
cardset_id: {
$in: Cardsets.find({
visible: true,
kind: 'free'
}).map(function (cardset) {
return cardset._id;
})
}
},
//is visible and has bought
{
cardset_id: {
$in: Paid.find({
user_id: this.userId,
cardset_id: {
$in: Cardsets.find({visible: true}).map(function (cardset) {
return cardset._id;
})
}
}).map(function (paid) {
return paid.cardset_id;
})
}
}
}
]
});
]
});
}
}
}
});
......
......@@ -16,22 +16,47 @@ if (Meteor.isServer) {
'admin',
'editor'
])) {
return Cardsets.find();
if (Meteor.settings.public.university.singleUniversity) {
return Cardsets.find({"college": Meteor.settings.public.university.default});
} else {
return Cardsets.find();
}
} else if (Roles.userIsInRole(this.userId, 'lecturer')) {
return Cardsets.find({
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
if (Meteor.settings.public.university.singleUniversity) {
return Cardsets.find({
"college": Meteor.settings.public.university.default,
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
} else {
return Cardsets.find({
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
}
} else if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
return Cardsets.find({
$or: [
{visible: true},
{owner: this.userId}
]
});
if (Meteor.settings.public.university.singleUniversity) {
return Cardsets.find({
"college": Meteor.settings.public.university.default,
$or: [
{visible: true},
{owner: this.userId}
]
});
} else {
return Cardsets.find({
$or: [
{visible: true},
{owner: this.userId}
]
});
}
}
});
Meteor.publish("tags", function () {
......@@ -182,6 +207,9 @@ Meteor.methods({
* @param {String} course - Assigned university course
*/
addCardset: function (name, description, visible, ratings, kind, module, moduleShort, moduleNum, skillLevel, college, course) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
check(name, String);
check(description, String);
check(visible, Boolean);
......@@ -389,6 +417,9 @@ Meteor.methods({
* @param {String} course - Assigned university course
*/
updateCardset: function (id, name, description, module, moduleShort, moduleNum, skillLevel, college, course) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
check(id, String);
check(name, String);
check(description, String);
......
......@@ -7,13 +7,20 @@ export const CollegesCourses = new Mongo.Collection("collegesCourses");
if (Meteor.isServer) {
Meteor.publish("collegesCourses", function () {
if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
return CollegesCourses.find();
if (Meteor.settings.public.university.singleUniversity) {
return CollegesCourses.find({"college": Meteor.settings.public.university.default});
} else {
return CollegesCourses.find();
}
}
});
}
Meteor.methods({
"updateCollegesCoursess": function (college, course) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
check(college, String);
check(course, String);
......@@ -27,6 +34,9 @@ Meteor.methods({
});
},
"deleteCollegesCourses": function (college, course) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
check(college, String);
check(course, String);
......@@ -40,6 +50,9 @@ Meteor.methods({
});
},
"editCollegesCourses": function (college, course, newCollege, newCourse) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
check(college, String);
check(course, String);
check(newCollege, String);
......
......@@ -8,11 +8,21 @@ export const Learned = new Mongo.Collection("learned");
if (Meteor.isServer) {
Meteor.publish("learned", function () {
if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
var cardsetsIds = Cardsets.find({
owner: this.userId
}).map(function (cardset) {
return cardset._id;
});
var cardsetsIds;
if (Meteor.settings.public.university.singleUniversity) {
cardsetsIds = Cardsets.find({
owner: this.userId,
college: Meteor.settings.public.university.default
}).map(function (cardset) {
return cardset._id;
});
} else {
cardsetsIds = Cardsets.find({
owner: this.userId
}).map(function (cardset) {
return cardset._id;
});
}
var learned = Learned.find({
$or: [
......@@ -25,8 +35,11 @@ if (Meteor.isServer) {
});
Meteor.publish("allLearned", function () {
if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
var learned = Learned.find({});
return learned;
if (Meteor.settings.public.university.singleUniversity) {
return Learned.find({college: Meteor.settings.public.university.default});
} else {
return Learned.find({});
}
}
}
);
......
......@@ -40,6 +40,11 @@ Template.registerHelper("isLecturerOrPro", function () {
}
});
// Check if multiple universities are enabled
Template.registerHelper("singleUniversity", function () {
return Meteor.settings.public.university.singleUniversity;
});
// Returns the number of cards in a carddeck
Template.registerHelper("countCards", function (cardset_id) {
return Cardsets.findOne({_id: cardset_id}).quantity;
......
This diff is collapsed.
......@@ -140,34 +140,36 @@
</div>
</div>
</div><!-- / skills Dropdown -->
<!-- start college Dropdown -->
<div class="form-group setdetails categories row">
<label id="editCardsetCollegeLabelAdmin" class="col-md-3 control-label"
for="editCardsetCollegeAdmin">{{_
"modal-dialog.college"}}</label>
<div class="dropup">
<div class="btn-group col-xs-12 col-sm-12 col-md-9" role="group">
<button type="button" id="editCardsetCollegeAdmin"
class="btn btn-raised editCardsetCollegeDropdownAdmin longButton"
data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false" value="{{this.college}}">{{this.college}}</button>
<button class="btn btn-raised dropdown-toggle editCardsetCollegeDropdownAdmin"
type="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
<span class="caret"></span>
<span class="sr-only"></span>
</button>
<ul class="dropdown-menu longButton">
{{#each getColleges}}
<li class="collegeAdmin" value="{{this.college}}"
data="{{this.college}}"><a
href="#">{{this.college}}</a></li>
{{/each}}
</ul>
<span id="helpEditCardsetCollegeAdmin" class="help-block collegeAdmin"></span>
{{#unless singleUniversity}}
<!-- start college Dropdown -->
<div class="form-group setdetails categories row">
<label id="editCardsetCollegeLabelAdmin" class="col-md-3 control-label"
for="editCardsetCollegeAdmin">{{_
"modal-dialog.college"}}</label>
<div class="dropup">
<div class="btn-group col-xs-12 col-sm-12 col-md-9" role="group">
<button type="button" id="editCardsetCollegeAdmin"
class="btn btn-raised editCardsetCollegeDropdownAdmin longButton"
data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false" value="{{this.college}}">{{this.college}}</button>
<button class="btn btn-raised dropdown-toggle editCardsetCollegeDropdownAdmin"
type="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
<span class="caret"></span>
<span class="sr-only"></span>
</button>
<ul class="dropdown-menu longButton">
{{#each getColleges}}
<li class="collegeAdmin" value="{{this.college}}"
data="{{this.college}}"><a
href="#">{{this.college}}</a></li>
{{/each}}
</ul>
<span id="helpEditCardsetCollegeAdmin" class="help-block collegeAdmin"></span>
</div>
</div>
</div>
</div><!-- / college Dropdown -->
</div><!-- / college Dropdown -->
{{/unless}}
<!-- start course Dropdown -->
<div class="form-group setdetails categories row">
<label id="editCardsetCourseLabelAdmin" class="col-md-3 control-label"
......
......@@ -135,11 +135,13 @@ Template.admin_cardset.events({
$('#helpEditCardsetModuleNumAdmin').html(TAPi18n.__('modal-dialog.moduleNum_required'));
$('#helpEditCardsetModuleNumAdmin').css('color', '#b94a48');
}
if ($('#editCardsetCollegeAdmin').val() === "") {
$('#editCardsetCollegeLabelAdmin').css('color', '#b94a48');
$('.editCardsetCollegeDropdownAdmin').css('border-color', '#b94a48');
$('#helpEditCardsetCollegeAdmin').html(TAPi18n.__('modal-dialog.college_required'));
$('#helpEditCardsetCollegeAdmin').css('color', '#b94a48');
if (!Meteor.settings.public.university.singleUniversity) {
if ($('#editCardsetCollegeAdmin').val() === "") {
$('#editCardsetCollegeLabelAdmin').css('color', '#b94a48');
$('.editCardsetCollegeDropdownAdmin').css('border-color', '#b94a48');
$('#helpEditCardsetCollegeAdmin').html(TAPi18n.__('modal-dialog.college_required'));
$('#helpEditCardsetCollegeAdmin').css('color', '#b94a48');
}
}
if ($('#editCardsetCourseAdmin').val() === "") {
$('#editCardsetCourseLabelAdmin').css('color', '#b94a48');
......@@ -158,63 +160,128 @@ Template.admin_cardset.events({
$('#helpCC-modules-admin').html(TAPi18n.__('admin.cardset.wrongCombination'));
$('#helpCC-modules-admin').css('color', '#b94a48');
}
if ($('#editCardsetNameAdmin').val() !== "" &&
$('#editCardsetDescriptionAdmin').val() !== "" &&
$('#editCardsetModuleAdmin').val() !== "" &&
$('#editCardsetModuleShortAdmin').val() !== "" &&
$('#editCardsetModuleNumAdmin').val() !== "" &&
$('#editCardsetSkillLevel').val() !== "" &&
$('#editCardsetCollegeAdmin').val() !== "" &&
$('#editCardsetCourseAdmin').val() !== "" &&
($("#kindoption0Admin").hasClass('active') ||
($("#kindoption1Admin").hasClass('active') ||
$("#kindoption2Admin").hasClass('active') ||
$("#kindoption3Admin").hasClass('active')) &&
this.quantity >= 5)) {
var name = tmpl.find('#editCardsetNameAdmin').value;
var description = tmpl.find('#editCardsetDescriptionAdmin').value;
var module = tmpl.find('#editCardsetModuleAdmin').value;
var moduleShort = tmpl.find('#editCardsetModuleShortAdmin').value;
var moduleNum = tmpl.find('#editCardsetModuleNumAdmin').value;
var skillLevel = $('#editCardsetSkillLevel').val();
var college = $('#editCardsetCollegeAdmin').text();
var course = $('#editCardsetCourseAdmin').text();
var kind = tmpl.find('#publishKindAdmin > .active > input').value;
var price = 0;
var visible = true;
var license = [];
if (("#cc-modules-admin").length) {
if ($("#cc-option0-admin").hasClass('active')) {
license.push("by");
}
if ($("#cc-option1-admin").hasClass('active')) {
license.push("nc");
let name;
let description;
let module;
let moduleShort;
let moduleNum;
let skillLevel;
let college;
let course;
let kind;
let price;
let visible;
let license;
if (Meteor.settings.public.university.singleUniversity) {
if ($('#editCardsetNameAdmin').val() !== "" &&
$('#editCardsetDescriptionAdmin').val() !== "" &&
$('#editCardsetModuleAdmin').val() !== "" &&
$('#editCardsetModuleShortAdmin').val() !== "" &&
$('#editCardsetModuleNumAdmin').val() !== "" &&
$('#editCardsetSkillLevel').val() !== "" &&
$('#editCardsetCollegeAdmin').val() !== "" &&
$('#editCardsetCourseAdmin').val() !== "" &&
($("#kindoption0Admin").hasClass('active') ||
($("#kindoption1Admin").hasClass('active') ||
$("#kindoption2Admin").hasClass('active') ||
$("#kindoption3Admin").hasClass('active')) &&
this.quantity >= 5)) {
name = tmpl.find('#editCardsetNameAdmin').value;
description = tmpl.find('#editCardsetDescriptionAdmin').value;
module = tmpl.find('#editCardsetModuleAdmin').value;
moduleShort = tmpl.find('#editCardsetModuleShortAdmin').value;
moduleNum = tmpl.find('#editCardsetModuleNumAdmin').value;
skillLevel = $('#editCardsetSkillLevel').val();
college = Meteor.settings.public.university.default;
course = $('#editCardsetCourseAdmin').text();
kind = tmpl.find('#publishKindAdmin > .active > input').value;
price = 0;
visible = true;
license = [];
if (("#cc-modules-admin").length) {
if ($("#cc-option0-admin").hasClass('active')) {
license.push("by");
}
if ($("#cc-option1-admin").hasClass('active')) {
license.push("nc");
}
if ($("#cc-option2-admin").hasClass('active')) {
license.push("nd");
}
if ($("#cc-option3-admin").hasClass('active')) {
license.push("sa");
}
}
if ($("#cc-option2-admin").hasClass('active')) {
license.push("nd");
Meteor.call('updateLicense', this._id, license);
if (kind === 'edu' || kind === 'pro') {
if (tmpl.find('#publishPriceAdmin') !== null) {
price = tmpl.find('#publishPriceAdmin').value;
} else {
price = this.price;
}
}
if ($("#cc-option3-admin").hasClass('active')) {
license.push("sa");
if (kind === 'personal') {
visible = false;
}
Meteor.call("publishCardset", this._id, kind, price, visible);
Meteor.call("updateCardset", this._id, name, description, module, moduleShort, moduleNum, Number(skillLevel), college, course);
window.history.go(-1);
}
Meteor.call('updateLicense', this._id, license);
if (kind === 'edu' || kind === 'pro') {
if (tmpl.find('#publishPriceAdmin') !== null) {
price = tmpl.find('#publishPriceAdmin').value;
} else {
price = this.price;
} else {
if ($('#editCardsetNameAdmin').val() !== "" &&
$('#editCardsetDescriptionAdmin').val() !== "" &&
$('#editCardsetModuleAdmin').val() !== "" &&
$('#editCardsetModuleShortAdmin').val() !== "" &&
$('#editCardsetModuleNumAdmin').val() !== "" &&
$('#editCardsetSkillLevel').val() !== "" &&
$('#editCardsetCollegeAdmin').val() !== "" &&
$('#editCardsetCourseAdmin').val() !== "" &&
($("#kindoption0Admin").hasClass('active') ||
($("#kindoption1Admin").hasClass('active') ||
$("#kindoption2Admin").hasClass('active') ||
$("#kindoption3Admin").hasClass('active')) &&
this.quantity >= 5)) {
name = tmpl.find('#editCardsetNameAdmin').value;
description = tmpl.find('#editCardsetDescriptionAdmin').value;
module = tmpl.find('#editCardsetModuleAdmin').value;
moduleShort = tmpl.find('#editCardsetModuleShortAdmin').value;
moduleNum = tmpl.find('#editCardsetModuleNumAdmin').value;
skillLevel = $('#editCardsetSkillLevel').val();
college = $('#editCardsetCollegeAdmin').text();
course = $('#editCardsetCourseAdmin').text();
kind = tmpl.find('#publishKindAdmin > .active > input').value;
price = 0;
visible = true;
license = [];
if (("#cc-modules-admin").length) {
if ($("#cc-option0-admin").hasClass('active')) {
license.push("by");
}
if ($("#cc-option1-admin").hasClass('active')) {
license.push("nc");
}
if ($("#cc-option2-admin").hasClass('active')) {
license.push("nd");
}
if ($("#cc-option3-admin").hasClass('active')) {
license.push("sa");
}
}
Meteor.call('updateLicense', this._id, license);
if (kind === 'edu' || kind === 'pro') {
if (tmpl.find('#publishPriceAdmin') !== null) {
price = tmpl.find('#publishPriceAdmin').value;
} else {
price = this.price;
}
}
if (kind === 'personal') {
visible = false;
}
Meteor.call("publishCardset", this._id, kind, price, visible);
Meteor.call("updateCardset", this._id, name, description, module, moduleShort, moduleNum, Number(skillLevel), college, course);
window.history.go(-1);
}
if (kind === 'personal') {
visible = false;
}
Meteor.call("publishCardset", this._id, kind, price, visible);
Meteor.call("updateCardset", this._id, name, description, module, moduleShort, moduleNum, Number(skillLevel), college, course);
window.history.go(-1);
}
},
'click #cardsetCancelAdmin': function () {
......
<template name="admin_university">
<div class="content-header">
<h1>{{_ "admin.manage"}}</h1>
<h1>{{#unless singleUniversity}}{{_ "admin.manageUniversityLong"}}{{else}}{{_ "admin.manageCourse"}}{{/unless}}</h1>
</div>
<div class="well well-sm">
<table class="table table-bordered table-hover table-striped" id="collegeTable">
<thead class="set-list">
<tr>
<th><span>{{_ "admin.confirm-form.settings.college"}}</span>