MCPcopy Create free account
hub / github.com/async-labs/async / checkPermission

Method checkPermission

api/server/models/Message.ts:493–527  ·  view source on GitHub ↗
({ userId, chatId, doc = null })

Source from the content-addressed store, hash-verified

491 }
492
493 private static async checkPermission({ userId, chatId, doc = null }) {
494 if (!userId || !chatId) {
495 throw new Error('Bad data. You have no permission.');
496 }
497
498 if (doc && doc.createdUserId !== userId) {
499 throw new Error('You do not have permission.');
500 }
501
502 const chat = await Chat.findById(chatId).setOptions({ lean: true });
503
504 const teamLeader = await User.findOne({
505 'teamsForTeamLeader.teamId': chat.teamId,
506 }).setOptions({
507 lean: true,
508 });
509
510 const team = teamLeader.teamsForTeamLeader.find((team) => {
511 return team.teamId === chat.teamId;
512 });
513
514 if (!chat && (teamLeader._id.toString() === userId || team.idsOfTeamMembers.includes(userId))) {
515 return { team };
516 }
517
518 if (
519 chat &&
520 (teamLeader._id.toString() === userId || team.idsOfTeamMembers.includes(userId)) &&
521 (chat.chatParticipantIds === userId || chat.chatParticipantIds.includes(userId))
522 ) {
523 return { team, chat };
524 }
525
526 throw new Error('Permission denied');
527 }
528}
529
530mongoSchema.loadClass(MessageClass);

Callers 8

getListMethod · 0.95
getListForThreadMethod · 0.95
addOrEditMethod · 0.95
editMethod · 0.95
deleteForClearHistoryMethod · 0.95
deleteMethod · 0.95
deleteFileMethod · 0.95
addFileMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected