Skip to content

Commit

Permalink
check if locked to subjects properly
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Feb 8, 2024
1 parent 94eabff commit 22cedfc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions node/src/gql/mutation/me/mentor-subjects-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
GraphQLInputObjectType,
GraphQLList,
} from 'graphql';
import { Mentor as MentorModel } from '../../../models';
import {
Mentor as MentorModel,
MentorConfig as MentorConfigModel,
} from '../../../models';
import { Subject } from '../../../models/Subject';
import { User } from '../../../models/User';
import { canEditMentor } from '../../../utils/check-permissions';
Expand Down Expand Up @@ -55,8 +58,13 @@ export const updateMentorSubjects = {
if (!(await canEditMentor(mentor, context.user))) {
throw new Error('you do not have permission to edit this mentor');
}
if (mentor.mentorConfig && mentor.lockedToConfig) {
throw new Error('Mentor is locked, please unlock them before editing');
const mentorConfig = mentor.mentorConfig
? await MentorConfigModel.findById(mentor.mentorConfig)
: null;
if (mentorConfig && mentorConfig.lockedToSubjects) {
throw new Error(
'Mentor subjects are locked, please unlock them before editing'
);
}
const updated = await MentorModel.findByIdAndUpdate(
mentor._id,
Expand Down
1 change: 1 addition & 0 deletions node/test/fixtures/mongodb/data-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
subjects: [
'5ffdf41a1ee2c62320b49eb3', //STEM
],
lockedToSubjects: true,
publiclyVisible: true,
mentorType: 'CHAT',
orgPermissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('updateMentorSubjects', () => {
});
expect(response.body).to.have.deep.nested.property(
'errors[0].message',
'Mentor is locked, please unlock them before editing'
'Mentor subjects are locked, please unlock them before editing'
);
});

Expand Down

0 comments on commit 22cedfc

Please sign in to comment.