Skip to content

Commit

Permalink
temporarily remove hook that works properly, but causes unexpected si…
Browse files Browse the repository at this point in the history
…de effect in another functionality (#4703)
  • Loading branch information
bn-pass authored Jan 17, 2024
1 parent d86cb15 commit 5879343
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/services/lesson/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Configuration } = require('@hpi-schul-cloud/commons');

const { nanoid } = require('nanoid');
const { iff, isProvider } = require('feathers-hooks-common');
const { NotFound, BadRequest, Forbidden } = require('../../../errors');
const { NotFound, BadRequest } = require('../../../errors');
const { equal } = require('../../../helper/compare').ObjectId;
const {
injectUserId,
Expand Down Expand Up @@ -204,19 +204,6 @@ const restrictToUsersCoursesLessons = async (context) => {
return context;
};

const restrictToUsersDraftLessons = async (context) => {
const user = await context.app.service('users').get(context.params.account.userId, { query: { $populate: 'roles' } });
const userIsStudent = user.roles.filter((u) => u.name === 'student').length > 0;
const lesson = await context.app.service('lessons').get(context.id);
const isDraft = lesson.hidden;

if (isDraft && userIsStudent) {
throw new Forbidden(`You don't have permission.`);
}

return context;
};

const populateWhitelist = {
materialIds: [
'_id',
Expand Down Expand Up @@ -254,7 +241,7 @@ exports.before = () => {
get: [
hasPermission('TOPIC_VIEW'),
iff(isProvider('external'), getRestrictPopulatesHook(populateWhitelist)),
iff(isProvider('external'), restrictToUsersCoursesLessons, restrictToUsersDraftLessons),
iff(isProvider('external'), restrictToUsersCoursesLessons),
],
create: [
checkIfCourseGroupLesson.bind(this, 'COURSEGROUP_CREATE', 'TOPIC_CREATE', true),
Expand All @@ -267,7 +254,7 @@ exports.before = () => {
iff(isProvider('external'), preventPopulate),
permitGroupOperation,
ifNotLocal(checkCorrectCourseOrTeamId),
iff(isProvider('external'), restrictToUsersCoursesLessons, restrictToUsersDraftLessons),
iff(isProvider('external'), restrictToUsersCoursesLessons),
checkIfCourseGroupLesson.bind(this, 'COURSEGROUP_EDIT', 'TOPIC_EDIT', false),
],
patch: [
Expand Down

0 comments on commit 5879343

Please sign in to comment.