From 4d44f09c847329a59828142234650f3c91131de7 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Thu, 2 Nov 2017 13:16:44 -0700 Subject: [PATCH 1/2] - add permissions check on a few messages --- .../CreateNewPresentationPodPubMsgHdlr.scala | 63 +++++++----- .../GetAllPresentationPodsReqMsgHdlr.scala | 43 ++++---- .../GetPresentationInfoReqMsgHdlr.scala | 59 ++++++----- .../RemovePresentationPodPubMsgHdlr.scala | 98 ++++++++++--------- .../RemovePresentationPubMsgHdlr.scala | 56 ++++++----- .../SetCurrentPagePubMsgHdlr.scala | 71 ++++++++------ .../SetCurrentPresentationPubMsgHdlr.scala | 50 ++++++---- .../SetPresenterInPodReqMsgHdlr.scala | 69 +++++++------ 8 files changed, 289 insertions(+), 220 deletions(-) mode change 100644 => 100755 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetAllPresentationPodsReqMsgHdlr.scala mode change 100644 => 100755 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetPresentationInfoReqMsgHdlr.scala mode change 100644 => 100755 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPagePubMsgHdlr.scala mode change 100644 => 100755 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/CreateNewPresentationPodPubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/CreateNewPresentationPodPubMsgHdlr.scala index 5ea9d62a2f..1b3b3f73ef 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/CreateNewPresentationPodPubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/CreateNewPresentationPodPubMsgHdlr.scala @@ -1,50 +1,59 @@ package org.bigbluebutton.core.apps.presentationpod +import org.bigbluebutton.SystemConfiguration import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.PresentationPod import org.bigbluebutton.core.running.LiveMeeting -trait CreateNewPresentationPodPubMsgHdlr { +trait CreateNewPresentationPodPubMsgHdlr extends SystemConfiguration { this: PresentationPodHdlrs => def handle(msg: CreateNewPresentationPodPubMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): MeetingState2x = { - def buildCreateNewPresentationPodEvtMsg(meetingId: String, ownerId: String, podId: String): BbbCommonEnvCoreMsg = { - val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, ownerId) - val envelope = BbbCoreEnvelope(CreateNewPresentationPodEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(CreateNewPresentationPodEvtMsg.NAME, meetingId, ownerId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to eject user from meeting." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def buildCreateNewPresentationPodEvtMsg(meetingId: String, ownerId: String, podId: String): BbbCommonEnvCoreMsg = { + val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, ownerId) + val envelope = BbbCoreEnvelope(CreateNewPresentationPodEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(CreateNewPresentationPodEvtMsg.NAME, meetingId, ownerId) - val body = CreateNewPresentationPodEvtMsgBody(ownerId, podId) - val event = CreateNewPresentationPodEvtMsg(header, body) + val body = CreateNewPresentationPodEvtMsgBody(ownerId, podId) + val event = CreateNewPresentationPodEvtMsg(header, body) - BbbCommonEnvCoreMsg(envelope, event) - } + BbbCommonEnvCoreMsg(envelope, event) + } - val ownerId = msg.body.ownerId + val ownerId = msg.body.ownerId - val resultPod: PresentationPod = PresentationPodsApp.getPresentationPod(state, "DEFAULT_PRESENTATION_POD") match { - case None => PresentationPodsApp.createDefaultPresentationPod(ownerId) - case Some(pod) => { - if (pod.ownerId == "") { - PresentationPodsApp.changeOwnershipOfDefaultPod(state, ownerId).get - } else { - PresentationPodsApp.createPresentationPod(ownerId) + val resultPod: PresentationPod = PresentationPodsApp.getPresentationPod(state, "DEFAULT_PRESENTATION_POD") match { + case None => PresentationPodsApp.createDefaultPresentationPod(ownerId) + case Some(pod) => { + if (pod.ownerId == "") { + PresentationPodsApp.changeOwnershipOfDefaultPod(state, ownerId).get + } else { + PresentationPodsApp.createPresentationPod(ownerId) + } } } + + val respMsg = buildCreateNewPresentationPodEvtMsg( + liveMeeting.props.meetingProp.intId, + ownerId, resultPod.id + ) + bus.outGW.send(respMsg) + + val pods = state.presentationPodManager.addPod(resultPod) + + state.update(pods) } - val respMsg = buildCreateNewPresentationPodEvtMsg( - liveMeeting.props.meetingProp.intId, - ownerId, resultPod.id - ) - bus.outGW.send(respMsg) - - val pods = state.presentationPodManager.addPod(resultPod) - - state.update(pods) - } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetAllPresentationPodsReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetAllPresentationPodsReqMsgHdlr.scala old mode 100644 new mode 100755 index 4425988499..ab3eddeb07 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetAllPresentationPodsReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetAllPresentationPodsReqMsgHdlr.scala @@ -2,6 +2,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.domain.{ PresentationPodVO, PresentationVO } import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.PresentationPod @@ -13,26 +14,34 @@ trait GetAllPresentationPodsReqMsgHdlr { def handle(msg: GetAllPresentationPodsReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): MeetingState2x = { - def buildGetAllPresentationPodsRespMsg(pods: Vector[PresentationPodVO], requesterId: String): BbbCommonEnvCoreMsg = { - val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, liveMeeting.props.meetingProp.intId, requesterId) - val envelope = BbbCoreEnvelope(GetAllPresentationPodsRespMsg.NAME, routing) - val header = BbbClientMsgHeader(GetAllPresentationPodsRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.GUEST_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to get all presentation pods from meeting." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def buildGetAllPresentationPodsRespMsg(pods: Vector[PresentationPodVO], requesterId: String): BbbCommonEnvCoreMsg = { + val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, liveMeeting.props.meetingProp.intId, requesterId) + val envelope = BbbCoreEnvelope(GetAllPresentationPodsRespMsg.NAME, routing) + val header = BbbClientMsgHeader(GetAllPresentationPodsRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) - val body = GetAllPresentationPodsRespMsgBody(pods) - val event = GetAllPresentationPodsRespMsg(header, body) + val body = GetAllPresentationPodsRespMsgBody(pods) + val event = GetAllPresentationPodsRespMsg(header, body) - BbbCommonEnvCoreMsg(envelope, event) + BbbCommonEnvCoreMsg(envelope, event) + } + + val requesterId = msg.body.requesterId + + val pods = PresentationPodsApp.getAllPresentationPodsInMeeting(state) + + val podsVO = pods.map(pod => PresentationPodsApp.translatePresentationPodToVO(pod)) + val event = buildGetAllPresentationPodsRespMsg(podsVO, requesterId) + + bus.outGW.send(event) + + state } - val requesterId = msg.body.requesterId - - val pods = PresentationPodsApp.getAllPresentationPodsInMeeting(state) - - val podsVO = pods.map(pod => PresentationPodsApp.translatePresentationPodToVO(pod)) - val event = buildGetAllPresentationPodsRespMsg(podsVO, requesterId) - - bus.outGW.send(event) - - state } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetPresentationInfoReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetPresentationInfoReqMsgHdlr.scala old mode 100644 new mode 100755 index 98da14b504..bcecbfa096 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetPresentationInfoReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/GetPresentationInfoReqMsgHdlr.scala @@ -2,6 +2,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.domain.PresentationVO import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -12,34 +13,42 @@ trait GetPresentationInfoReqMsgHdlr { def handle(msg: GetPresentationInfoReqMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): MeetingState2x = { - def buildGetPresentationInfoRespMsg(presentations: Vector[PresentationVO], podId: String, - requesterId: String): BbbCommonEnvCoreMsg = { - val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, liveMeeting.props.meetingProp.intId, requesterId) - val envelope = BbbCoreEnvelope(GetPresentationInfoRespMsg.NAME, routing) - val header = BbbClientMsgHeader(GetPresentationInfoRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.GUEST_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission get presentation info from meeting." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def buildGetPresentationInfoRespMsg(presentations: Vector[PresentationVO], podId: String, + requesterId: String): BbbCommonEnvCoreMsg = { + val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, liveMeeting.props.meetingProp.intId, requesterId) + val envelope = BbbCoreEnvelope(GetPresentationInfoRespMsg.NAME, routing) + val header = BbbClientMsgHeader(GetPresentationInfoRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) - val body = GetPresentationInfoRespMsgBody(podId, presentations) - val event = GetPresentationInfoRespMsg(header, body) + val body = GetPresentationInfoRespMsgBody(podId, presentations) + val event = GetPresentationInfoRespMsg(header, body) - BbbCommonEnvCoreMsg(envelope, event) + BbbCommonEnvCoreMsg(envelope, event) + } + + val requesterId = msg.body.userId + val podId = msg.body.podId + + for { + pod <- PresentationPodsApp.getPresentationPod(state, podId) + } yield { + val presInPod = pod.presentations + + val presVOs = presInPod.values.map { p => + PresentationVO(p.id, p.name, p.current, p.pages.values.toVector, p.downloadable) + }.toVector + val event = buildGetPresentationInfoRespMsg(presVOs, podId, requesterId) + + bus.outGW.send(event) + + } + state } - val requesterId = msg.body.userId - val podId = msg.body.podId - - for { - pod <- PresentationPodsApp.getPresentationPod(state, podId) - } yield { - val presInPod = pod.presentations - - val presVOs = presInPod.values.map { p => - PresentationVO(p.id, p.name, p.current, p.pages.values.toVector, p.downloadable) - }.toVector - val event = buildGetPresentationInfoRespMsg(presVOs, podId, requesterId) - - bus.outGW.send(event) - - } - state } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPodPubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPodPubMsgHdlr.scala index 6f503c3410..32b898301b 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPodPubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPodPubMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -11,54 +12,61 @@ trait RemovePresentationPodPubMsgHdlr { def handle(msg: RemovePresentationPodPubMsg, state: MeetingState2x, liveMeeting: LiveMeeting, bus: MessageBus): MeetingState2x = { - def buildRemovePresentationPodEvtMsg(meetingId: String, ownerId: String, podId: String): BbbCommonEnvCoreMsg = { - val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, ownerId) - val envelope = BbbCoreEnvelope(RemovePresentationPodEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(RemovePresentationPodEvtMsg.NAME, meetingId, ownerId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.PRESENTER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to remove presentation pod from meeting." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def buildRemovePresentationPodEvtMsg(meetingId: String, ownerId: String, podId: String): BbbCommonEnvCoreMsg = { + val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, ownerId) + val envelope = BbbCoreEnvelope(RemovePresentationPodEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(RemovePresentationPodEvtMsg.NAME, meetingId, ownerId) - val body = RemovePresentationPodEvtMsgBody(ownerId, podId) - val event = RemovePresentationPodEvtMsg(header, body) + val body = RemovePresentationPodEvtMsgBody(ownerId, podId) + val event = RemovePresentationPodEvtMsg(header, body) - BbbCommonEnvCoreMsg(envelope, event) + BbbCommonEnvCoreMsg(envelope, event) + } + + val requesterId = msg.body.requesterId // TODO -- use it + + val newState = for { + pod <- PresentationPodsApp.getPresentationPod(state, msg.body.podId) + } yield { + + val ownerId = pod.ownerId + + val event = buildRemovePresentationPodEvtMsg( + liveMeeting.props.meetingProp.intId, + ownerId, pod.id + ) + + bus.outGW.send(event) + + val pods = state.presentationPodManager.removePod(pod.id) + state.update(pods) + } + + newState match { + case Some(ns) => ns + case None => state + } + + // TODO check if requesterId == ownerId + // TODO check about notifying only the list of authorized? + + // val respMsg = buildRemovePresentationPodEvtMsg( + // liveMeeting.props.meetingProp.intId, + // ownerId, pod.id + // ) + // bus.outGW.send(respMsg) + // + // log.warning("RemovePresentationPodPubMsgHdlr new podId=" + pod.id) + // + // val pods = state.presentationPodManager.removePod(pod) + // state.update(pods) } - val requesterId = msg.body.requesterId // TODO -- use it - - val newState = for { - pod <- PresentationPodsApp.getPresentationPod(state, msg.body.podId) - } yield { - - val ownerId = pod.ownerId - - val event = buildRemovePresentationPodEvtMsg( - liveMeeting.props.meetingProp.intId, - ownerId, pod.id - ) - - bus.outGW.send(event) - - val pods = state.presentationPodManager.removePod(pod.id) - state.update(pods) - } - - newState match { - case Some(ns) => ns - case None => state - } - - // TODO check if requesterId == ownerId - // TODO check about notifying only the list of authorized? - - // val respMsg = buildRemovePresentationPodEvtMsg( - // liveMeeting.props.meetingProp.intId, - // ownerId, pod.id - // ) - // bus.outGW.send(respMsg) - // - // log.warning("RemovePresentationPodPubMsgHdlr new podId=" + pod.id) - // - // val pods = state.presentationPodManager.removePod(pod) - // state.update(pods) - } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPubMsgHdlr.scala index edce9107ac..7894a2a0f4 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/RemovePresentationPubMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -13,35 +14,42 @@ trait RemovePresentationPubMsgHdlr { liveMeeting: LiveMeeting, bus: MessageBus ): MeetingState2x = { - def broadcastRemovePresentationEvtMsg(podId: String, userId: String, presentationId: String): Unit = { - val routing = Routing.addMsgToClientRouting( - MessageTypes.BROADCAST_TO_MEETING, - liveMeeting.props.meetingProp.intId, userId - ) - val envelope = BbbCoreEnvelope(RemovePresentationEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(RemovePresentationEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.PRESENTER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to remove presentation from meeting." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def broadcastRemovePresentationEvtMsg(podId: String, userId: String, presentationId: String): Unit = { + val routing = Routing.addMsgToClientRouting( + MessageTypes.BROADCAST_TO_MEETING, + liveMeeting.props.meetingProp.intId, userId + ) + val envelope = BbbCoreEnvelope(RemovePresentationEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(RemovePresentationEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) - val body = RemovePresentationEvtMsgBody(podId, presentationId) - val event = RemovePresentationEvtMsg(header, body) - val msgEvent = BbbCommonEnvCoreMsg(envelope, event) - bus.outGW.send(msgEvent) - } + val body = RemovePresentationEvtMsgBody(podId, presentationId) + val event = RemovePresentationEvtMsg(header, body) + val msgEvent = BbbCommonEnvCoreMsg(envelope, event) + bus.outGW.send(msgEvent) + } - val podId = msg.body.podId - val presentationId = msg.body.presentationId + val podId = msg.body.podId + val presentationId = msg.body.presentationId - val newState = for { - pod <- PresentationPodsApp.getPresentationPod(state, podId) - } yield { - broadcastRemovePresentationEvtMsg(pod.id, msg.header.userId, presentationId) + val newState = for { + pod <- PresentationPodsApp.getPresentationPod(state, podId) + } yield { + broadcastRemovePresentationEvtMsg(pod.id, msg.header.userId, presentationId) - val pods = state.presentationPodManager.removePresentationInPod(pod.id, presentationId) - state.update(pods) - } + val pods = state.presentationPodManager.removePresentationInPod(pod.id, presentationId) + state.update(pods) + } - newState match { - case Some(ns) => ns - case None => state + newState match { + case Some(ns) => ns + case None => state + } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPagePubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPagePubMsgHdlr.scala old mode 100644 new mode 100755 index b7bb49a520..fb26b89b7b --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPagePubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPagePubMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -15,44 +16,52 @@ trait SetCurrentPagePubMsgHdlr { liveMeeting: LiveMeeting, bus: MessageBus ): MeetingState2x = { - def broadcastSetCurrentPageEvtMsg(podId: String, presentationId: String, pageId: String, userId: String): Unit = { - val routing = Routing.addMsgToClientRouting( - MessageTypes.BROADCAST_TO_MEETING, - liveMeeting.props.meetingProp.intId, userId - ) - val envelope = BbbCoreEnvelope(SetCurrentPageEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(SetCurrentPageEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.GUEST_LEVEL, PermissionCheck.PRESENTER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to set presentation page." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def broadcastSetCurrentPageEvtMsg(podId: String, presentationId: String, pageId: String, userId: String): Unit = { + val routing = Routing.addMsgToClientRouting( + MessageTypes.BROADCAST_TO_MEETING, + liveMeeting.props.meetingProp.intId, userId + ) + val envelope = BbbCoreEnvelope(SetCurrentPageEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(SetCurrentPageEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) - val body = SetCurrentPageEvtMsgBody(podId, presentationId, pageId) - val event = SetCurrentPageEvtMsg(header, body) - val msgEvent = BbbCommonEnvCoreMsg(envelope, event) - bus.outGW.send(msgEvent) - } + val body = SetCurrentPageEvtMsgBody(podId, presentationId, pageId) + val event = SetCurrentPageEvtMsg(header, body) + val msgEvent = BbbCommonEnvCoreMsg(envelope, event) + bus.outGW.send(msgEvent) + } - val podId = msg.body.podId - val userId = msg.header.userId - val presentationId = msg.body.presentationId - val pageId = msg.body.pageId + val podId = msg.body.podId + val userId = msg.header.userId + val presentationId = msg.body.presentationId + val pageId = msg.body.pageId - val newState = for { - pod <- PresentationPodsApp.getPresentationPod(state, podId) - presentationToModify <- pod.getPresentation(presentationId) - updatedPod <- pod.setCurrentPage(presentationId, pageId) - } yield { + val newState = for { + pod <- PresentationPodsApp.getPresentationPod(state, podId) + presentationToModify <- pod.getPresentation(presentationId) + updatedPod <- pod.setCurrentPage(presentationId, pageId) + } yield { - if (Users2x.userIsInPresenterGroup(liveMeeting.users2x, userId) || userId.equals(pod.ownerId)) { - broadcastSetCurrentPageEvtMsg(pod.id, presentationId, pageId, userId) + if (Users2x.userIsInPresenterGroup(liveMeeting.users2x, userId) || userId.equals(pod.ownerId)) { + broadcastSetCurrentPageEvtMsg(pod.id, presentationId, pageId, userId) - val pods = state.presentationPodManager.addPod(updatedPod) - state.update(pods) - } else { - state + val pods = state.presentationPodManager.addPod(updatedPod) + state.update(pods) + } else { + state + } + } + + newState match { + case Some(ns) => ns + case None => state } } - newState match { - case Some(ns) => ns - case None => state - } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPresentationPubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPresentationPubMsgHdlr.scala index 39d2ff9e53..5a166aaf1f 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPresentationPubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetCurrentPresentationPubMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -13,32 +14,39 @@ trait SetCurrentPresentationPubMsgHdlr { liveMeeting: LiveMeeting, bus: MessageBus ): MeetingState2x = { - def broadcastSetCurrentPresentationEvent(podId: String, userId: String, presentationId: String): Unit = { - val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, liveMeeting.props.meetingProp.intId, userId) - val envelope = BbbCoreEnvelope(SetCurrentPresentationEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(SetCurrentPresentationEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.GUEST_LEVEL, PermissionCheck.PRESENTER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to set presentation page." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def broadcastSetCurrentPresentationEvent(podId: String, userId: String, presentationId: String): Unit = { + val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, liveMeeting.props.meetingProp.intId, userId) + val envelope = BbbCoreEnvelope(SetCurrentPresentationEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(SetCurrentPresentationEvtMsg.NAME, liveMeeting.props.meetingProp.intId, userId) - val body = SetCurrentPresentationEvtMsgBody(podId, presentationId) - val event = SetCurrentPresentationEvtMsg(header, body) - val msgEvent = BbbCommonEnvCoreMsg(envelope, event) - bus.outGW.send(msgEvent) - } + val body = SetCurrentPresentationEvtMsgBody(podId, presentationId) + val event = SetCurrentPresentationEvtMsg(header, body) + val msgEvent = BbbCommonEnvCoreMsg(envelope, event) + bus.outGW.send(msgEvent) + } - val podId = msg.body.podId - val presId = msg.body.presentationId + val podId = msg.body.podId + val presId = msg.body.presentationId - val newState = for { - updatedPod <- PresentationPodsApp.setCurrentPresentationInPod(state, podId, presId) - } yield { - broadcastSetCurrentPresentationEvent(podId, msg.header.userId, presId) + val newState = for { + updatedPod <- PresentationPodsApp.setCurrentPresentationInPod(state, podId, presId) + } yield { + broadcastSetCurrentPresentationEvent(podId, msg.header.userId, presId) - val pods = state.presentationPodManager.addPod(updatedPod) - state.update(pods) - } + val pods = state.presentationPodManager.addPod(updatedPod) + state.update(pods) + } - newState match { - case Some(ns) => ns - case None => state + newState match { + case Some(ns) => ns + case None => state + } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala old mode 100644 new mode 100755 index 4828a0fbba..9d4b54930d --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.presentationpod import org.bigbluebutton.common2.msgs._ +import org.bigbluebutton.core.apps.PermissionCheck import org.bigbluebutton.core.bus.MessageBus import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.running.LiveMeeting @@ -14,44 +15,52 @@ trait SetPresenterInPodReqMsgHdlr { liveMeeting: LiveMeeting, bus: MessageBus ): MeetingState2x = { - def broadcastSetPresenterInPodRespMsg(podId: String, prevPresenterId: String, nextPresenterId: String, requesterId: String): Unit = { - val routing = Routing.addMsgToClientRouting( - MessageTypes.BROADCAST_TO_MEETING, - liveMeeting.props.meetingProp.intId, requesterId - ) - val envelope = BbbCoreEnvelope(SetPresenterInPodRespMsg.NAME, routing) - val header = BbbClientMsgHeader(SetPresenterInPodRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) + if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { + val meetingId = liveMeeting.props.meetingProp.intId + val reason = "No permission to set presentation page." + PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) + state + } else { + def broadcastSetPresenterInPodRespMsg(podId: String, prevPresenterId: String, nextPresenterId: String, requesterId: String): Unit = { + val routing = Routing.addMsgToClientRouting( + MessageTypes.BROADCAST_TO_MEETING, + liveMeeting.props.meetingProp.intId, requesterId + ) + val envelope = BbbCoreEnvelope(SetPresenterInPodRespMsg.NAME, routing) + val header = BbbClientMsgHeader(SetPresenterInPodRespMsg.NAME, liveMeeting.props.meetingProp.intId, requesterId) - val body = SetPresenterInPodRespMsgBody(podId, prevPresenterId, nextPresenterId) - val event = SetPresenterInPodRespMsg(header, body) - val msgEvent = BbbCommonEnvCoreMsg(envelope, event) - bus.outGW.send(msgEvent) - } + val body = SetPresenterInPodRespMsgBody(podId, prevPresenterId, nextPresenterId) + val event = SetPresenterInPodRespMsg(header, body) + val msgEvent = BbbCommonEnvCoreMsg(envelope, event) + bus.outGW.send(msgEvent) + } - val podId: String = msg.body.podId - val requesterId: String = msg.header.userId - val nextPresenterId: String = msg.body.nextPresenterId - val prevPresenterId: String = msg.body.prevPresenterId + val podId: String = msg.body.podId + val requesterId: String = msg.header.userId + val nextPresenterId: String = msg.body.nextPresenterId + val prevPresenterId: String = msg.body.prevPresenterId - val newState = for { - pod <- PresentationPodsApp.getPresentationPod(state, podId) - } yield { + val newState = for { + pod <- PresentationPodsApp.getPresentationPod(state, podId) + } yield { - if (Users2x.userIsInPresenterGroup(liveMeeting.users2x, requesterId) || requesterId.equals(pod.ownerId)) { - val updatedPod = pod.setCurrentPresenter(nextPresenterId) + if (Users2x.userIsInPresenterGroup(liveMeeting.users2x, requesterId) || requesterId.equals(pod.ownerId)) { + val updatedPod = pod.setCurrentPresenter(nextPresenterId) - broadcastSetPresenterInPodRespMsg(pod.id, prevPresenterId, nextPresenterId, requesterId) + broadcastSetPresenterInPodRespMsg(pod.id, prevPresenterId, nextPresenterId, requesterId) - val pods = state.presentationPodManager.addPod(updatedPod) - state.update(pods) - } else { - state + val pods = state.presentationPodManager.addPod(updatedPod) + state.update(pods) + } else { + state + } + } + + newState match { + case Some(ns) => ns + case None => state } } - newState match { - case Some(ns) => ns - case None => state - } } } From 1c5c387456fb7878248175eb72db7403ebddfbd3 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Thu, 2 Nov 2017 14:08:38 -0700 Subject: [PATCH 2/2] - add all moderators to presenter group --- .../SetPresenterInPodReqMsgHdlr.scala | 2 +- .../AddUserToPresenterGroupCmdMsgHdlr.scala | 14 +--------- .../core/apps/users/UsersApp.scala | 26 +++++++++++++++++++ .../core/running/HandlerHelpers.scala | 6 +++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala index 9d4b54930d..0e3b63ee45 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresenterInPodReqMsgHdlr.scala @@ -17,7 +17,7 @@ trait SetPresenterInPodReqMsgHdlr { if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { val meetingId = liveMeeting.props.meetingProp.intId - val reason = "No permission to set presentation page." + val reason = "No permission to set presenter in presentation." PermissionCheck.ejectUserForFailedPermission(meetingId, msg.header.userId, reason, bus.outGW) state } else { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/AddUserToPresenterGroupCmdMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/AddUserToPresenterGroupCmdMsgHdlr.scala index 8d664ebc52..c73a32f7f2 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/AddUserToPresenterGroupCmdMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/AddUserToPresenterGroupCmdMsgHdlr.scala @@ -13,17 +13,6 @@ trait AddUserToPresenterGroupCmdMsgHdlr { def handleAddUserToPresenterGroupCmdMsg(msg: AddUserToPresenterGroupCmdMsg) { - def broadcastAddUserToPresenterGroup(meetingId: String, userId: String, requesterId: String): Unit = { - val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, userId) - val envelope = BbbCoreEnvelope(UserAddedToPresenterGroupEvtMsg.NAME, routing) - val header = BbbClientMsgHeader(UserAddedToPresenterGroupEvtMsg.NAME, meetingId, userId) - val body = UserAddedToPresenterGroupEvtMsgBody(userId, requesterId) - val event = UserAddedToPresenterGroupEvtMsg(header, body) - val msgEvent = BbbCommonEnvCoreMsg(envelope, event) - - outGW.send(msgEvent) - } - if (applyPermissionCheck && !PermissionCheck.isAllowed(PermissionCheck.MOD_LEVEL, PermissionCheck.VIEWER_LEVEL, liveMeeting.users2x, msg.header.userId)) { val meetingId = liveMeeting.props.meetingProp.intId val reason = "No permission to add user to presenter group." @@ -36,8 +25,7 @@ trait AddUserToPresenterGroupCmdMsgHdlr { requester <- Users2x.findWithIntId(liveMeeting.users2x, requesterId) } yield { if (requester.role == Roles.MODERATOR_ROLE) { - Users2x.addUserToPresenterGroup(liveMeeting.users2x, userId) - broadcastAddUserToPresenterGroup(liveMeeting.props.meetingProp.intId, userId, requesterId) + UsersApp.addUserToPresenterGroup(liveMeeting, outGW, userId, requesterId) } } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala index a0f414b3ed..99bf9aebf8 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala @@ -2,9 +2,35 @@ package org.bigbluebutton.core.apps.users import akka.actor.ActorContext import akka.event.Logging +import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.InternalEventBus +import org.bigbluebutton.core.models.{ Roles, Users2x } import org.bigbluebutton.core.running.{ LiveMeeting, OutMsgRouter } +object UsersApp { + def broadcastAddUserToPresenterGroup(meetingId: String, userId: String, requesterId: String, + outGW: OutMsgRouter): Unit = { + val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, userId) + val envelope = BbbCoreEnvelope(UserAddedToPresenterGroupEvtMsg.NAME, routing) + val header = BbbClientMsgHeader(UserAddedToPresenterGroupEvtMsg.NAME, meetingId, userId) + val body = UserAddedToPresenterGroupEvtMsgBody(userId, requesterId) + val event = UserAddedToPresenterGroupEvtMsg(header, body) + val msgEvent = BbbCommonEnvCoreMsg(envelope, event) + + outGW.send(msgEvent) + } + + def addUserToPresenterGroup(liveMeeting: LiveMeeting, outGW: OutMsgRouter, + userId: String, requesterId: String): Unit = { + Users2x.addUserToPresenterGroup(liveMeeting.users2x, userId) + UsersApp.broadcastAddUserToPresenterGroup( + liveMeeting.props.meetingProp.intId, + userId, requesterId, outGW + ) + } + +} + class UsersApp( val liveMeeting: LiveMeeting, val outGW: OutMsgRouter, diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala index 328f529965..3a5bf81977 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/running/HandlerHelpers.scala @@ -3,6 +3,7 @@ package org.bigbluebutton.core.running import org.bigbluebutton.SystemConfiguration import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.api.{ BreakoutRoomEndedInternalMsg, DestroyMeetingInternalMsg, EndBreakoutRoomInternalMsg } +import org.bigbluebutton.core.apps.users.UsersApp import org.bigbluebutton.core.bus.{ BigBlueButtonEvent, InternalEventBus } import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models._ @@ -54,6 +55,11 @@ trait HandlerHelpers extends SystemConfiguration { if (!Users2x.hasPresenter(liveMeeting.users2x)) { automaticallyAssignPresenter(outGW, liveMeeting) } + + if (newUser.role == Roles.MODERATOR_ROLE) { + UsersApp.addUserToPresenterGroup(liveMeeting, outGW, newUser.intId, newUser.intId) + } + state.update(state.expiryTracker.setUserHasJoined()) case None => state