Skip to content

Commit

Permalink
Added middleware to confirm isTeacher.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Oct 5, 2023
1 parent e6c6434 commit 352fce6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions controllers/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const editTopicHandler = (req, res, next) => {
const schoolId = res.locals.currentSchool;
const { filesStorage } = await filesStoragesHelper
.filesStorageInit(schoolId, lesson._id, 'lessons', false, req);
const isTeacher = req.isTeacher;

if (lesson.title) lesson.title = decode(lesson.title);
if (lesson.contents) lesson.contents = decode(lesson.contents);
Expand All @@ -63,6 +64,7 @@ const editTopicHandler = (req, res, next) => {
lesson,
courseId: req.params.courseId,
topicId: req.params.topicId,
isTeacher,
schoolId,
teamId: req.params.teamId,
courseGroupId: req.query.courseGroup,
Expand Down
16 changes: 16 additions & 0 deletions middleware/checkIfUserIsTeacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express');

const router = express.Router();

const checkIfUserIsTeacher = (req, res, next) => {
if (req.user && req.user.role === 'teacher') {
req.isTeacher = true;
} else {
req.isTeacher = false;
}
next();
};

router.use('topic/edit-topic', checkIfUserIsTeacher);

module.exports = checkIfUserIsTeacher;
15 changes: 12 additions & 3 deletions views/topic/edit-topic.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@
<div class="form-group">
<label>{{$t "topic._topic.label.content" }}</label>

<!-- React Magic -->
<div id="content-blocks" data-value="{{lesson.contents}}" data-parent-id="{{lesson._id}}" data-school-id="{{schoolId}}" data-parent-type="lessons" data-etherpadbaseurl="{{etherpadBaseUrl}}"
data-nexboardenabled="{{#ifEnv "FEATURE_NEXBOARD_ENABLED" "true"}}{{#unless userIsTeacher}}true{{/unless}}{{/ifEnv}}"></div>
{{!-- <div id="content-blocks" data-value="{{lesson.contents}}" data-parent-id="{{lesson._id}}" data-school-id="{{schoolId}}" data-parent-type="lessons" data-etherpadbaseurl="{{etherpadBaseUrl}}"
data-nexboardenabled="{{#ifEnv "FEATURE_NEXBOARD_ENABLED" "true"}}{{#unless userIsTeacher}}true{{/unless}}{{/ifEnv}}"></div> --}}
{{#unless userIsTeacher}}
<div id="content-blocks"
data-value="{{lesson.contents}}"
data-parent-id="{{lesson._id}}"
data-school-id="{{schoolId}}"
data-parent-type="lessons"
data-etherpadbaseurl="{{etherpadBaseUrl}}"
data-nexboardenabled="{{#ifEnv "FEATURE_NEXBOARD_ENABLED" "true"}}true{{/ifEnv}}">
</div>
{{/unless}}
</div>
{{#ifneq 0 (arrayLength @root.lessonFilesStorageData.files)}}
<label>{{$t "topic._topic.label.embeddedFiles" }}</label>
Expand Down

0 comments on commit 352fce6

Please sign in to comment.