From 3951cf6c2f082e0befc7da8de958f25556874d52 Mon Sep 17 00:00:00 2001 From: Guilherme Leme Date: Mon, 14 Oct 2024 09:03:37 -0300 Subject: [PATCH 1/3] [new-server-side-architecture] - sonar cloud feedback implementation - removed a possible bug --- .../core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala index edbdd0ee02..3ea288353b 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala @@ -54,8 +54,8 @@ trait PluginDataChannelReplaceEntryMsgHdlr extends HandlerHelpers { ) } case None => println(s"Data channel '${msg.body.channelName}' not found in plugin '${msg.body.pluginName}'.") - case None => println(s"Plugin '${msg.body.pluginName}' not found.") } + case None => println(s"Plugin '${msg.body.pluginName}' not found.") } } } From 1c3c11afde08882b364d1be837e8a238ba329c29 Mon Sep 17 00:00:00 2001 From: Guilherme Leme Date: Mon, 14 Oct 2024 10:42:34 -0300 Subject: [PATCH 2/3] [new-server-side-architecture] - sonar cloud feedback implementation - removed a possible bug --- .../PluginDataChannelDeleteEntryMsgHdlr.scala | 24 +++----------- .../PluginDataChannelPushEntryMsgHdlr.scala | 15 ++------- ...PluginDataChannelReplaceEntryMsgHdlr.scala | 23 ++----------- .../PluginDataChannelResetMsgHdlr.scala | 12 ++----- .../core/apps/plugin/PluginHdlrHelpers.scala | 27 +++++++++++++++ .../common2/msgs/PluginMsgs.scala | 14 ++++++-- .../api/ParamsProcessorUtil.java | 33 ++++++++++--------- 7 files changed, 67 insertions(+), 81 deletions(-) create mode 100644 akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala index c321c6dbf5..9abc3592c0 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelDeleteEntryMsg +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{ checkPermission, defaultCreatorCheck } import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.{ PluginModel, Roles, Users2x } @@ -20,26 +21,9 @@ trait PluginDataChannelDeleteEntryMsgHdlr extends HandlerHelpers { case Some(p) => p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { case Some(dc) => - val hasPermission = for { - replaceOrDeletePermission <- dc.replaceOrDeletePermission - } yield { - replaceOrDeletePermission.toLowerCase match { - case "all" => true - case "moderator" => user.role == Roles.MODERATOR_ROLE - case "presenter" => user.presenter - case "creator" => { - val creatorUserId = PluginDataChannelEntryDAO.getEntryCreator( - meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName, - msg.body.entryId - ) - creatorUserId == msg.header.userId - } - case _ => false - } - } + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( + meetingId, msg.body, msg.header.userId + )) if (!hasPermission.contains(true)) { println(s"No permission to delete in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") } else { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala index 5ac622881d..e3037a8ca9 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala @@ -1,9 +1,10 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelPushEntryMsg +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.checkPermission import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.{ PluginModel, Roles, Users2x } +import org.bigbluebutton.core.models.{ PluginModel, Roles, UserState, Users2x } import org.bigbluebutton.core.running.{ HandlerHelpers, LiveMeeting } trait PluginDataChannelPushEntryMsgHdlr extends HandlerHelpers { @@ -20,17 +21,7 @@ trait PluginDataChannelPushEntryMsgHdlr extends HandlerHelpers { case Some(p) => p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { case Some(dc) => - val hasPermission = for { - pushPermission <- dc.pushPermission - } yield { - pushPermission.toLowerCase match { - case "all" => true - case "moderator" => user.role == Roles.MODERATOR_ROLE - case "presenter" => user.presenter - case _ => false - } - } - + val hasPermission = checkPermission(user, dc.pushPermission) if (!hasPermission.contains(true)) { println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") } else { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala index 3ea288353b..1683d807f3 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala @@ -1,6 +1,7 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelReplaceEntryMsg +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{checkPermission, defaultCreatorCheck} import org.bigbluebutton.core.db.{JsonUtils, PluginDataChannelEntryDAO} import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.{PluginModel, Roles, Users2x} @@ -20,26 +21,8 @@ trait PluginDataChannelReplaceEntryMsgHdlr extends HandlerHelpers { case Some(p) => p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { case Some(dc) => - val hasPermission = for { - replaceOrDeletePermission <- dc.replaceOrDeletePermission - } yield { - replaceOrDeletePermission.toLowerCase match { - case "all" => true - case "moderator" => user.role == Roles.MODERATOR_ROLE - case "presenter" => user.presenter - case "creator" => { - val creatorUserId = PluginDataChannelEntryDAO.getEntryCreator( - meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName, - msg.body.entryId - ) - creatorUserId == msg.header.userId - } - case _ => false - } - } + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( + meetingId, msg.body, msg.header.userId)) if (!hasPermission.contains(true)) { println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala index 27e6a23d88..1f5030cf9a 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala @@ -2,6 +2,7 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.ClientSettings import org.bigbluebutton.common2.msgs.PluginDataChannelResetMsg +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.checkPermission import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x import org.bigbluebutton.core.models.{ PluginModel, Roles, Users2x } @@ -21,16 +22,7 @@ trait PluginDataChannelResetMsgHdlr extends HandlerHelpers { case Some(p) => p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { case Some(dc) => - val hasPermission = for { - replaceOrDeletePermission <- dc.replaceOrDeletePermission - } yield { - replaceOrDeletePermission.toLowerCase match { - case "all" => true - case "moderator" => user.role == Roles.MODERATOR_ROLE - case "presenter" => user.presenter - case _ => false - } - } + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission) if (!hasPermission.contains(true)) { println(s"No permission to delete (reset) in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala new file mode 100644 index 0000000000..469d9fae6a --- /dev/null +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala @@ -0,0 +1,27 @@ +package org.bigbluebutton.core.apps.plugin + +import org.bigbluebutton.common2.msgs.PluginDataChannelReplaceOrDeleteBaseBody +import org.bigbluebutton.core.db.PluginDataChannelEntryDAO +import org.bigbluebutton.core.models.{ Roles, UserState } + +object PluginHdlrHelpers { + def checkPermission(user: UserState, permissionType: List[String], creatorCheck: => Boolean = false): List[Boolean] = { + permissionType.map(_.toLowerCase).map { + case "all" => true + case "moderator" => user.role == Roles.MODERATOR_ROLE + case "presenter" => user.presenter + case "creator" => creatorCheck + case _ => false + } + } + def defaultCreatorCheck[T <: PluginDataChannelReplaceOrDeleteBaseBody](meetingId: String, msgBody: T, userId: String): Boolean = { + val creatorUserId = PluginDataChannelEntryDAO.getEntryCreator( + meetingId, + msgBody.pluginName, + msgBody.channelName, + msgBody.subChannelName, + msgBody.entryId + ) + creatorUserId == userId + } +} diff --git a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PluginMsgs.scala b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PluginMsgs.scala index 7fe61c9d8b..53c67031c4 100755 --- a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PluginMsgs.scala +++ b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PluginMsgs.scala @@ -7,6 +7,14 @@ import org.bigbluebutton.common2.domain.PluginLearningAnalyticsDashboardGenericD /** * Sent from graphql-actions to bbb-akka */ + +trait PluginDataChannelReplaceOrDeleteBaseBody{ + val pluginName: String + val channelName: String + val subChannelName: String + val entryId: String +} + object PluginDataChannelPushEntryMsg { val NAME = "PluginDataChannelPushEntryMsg" } case class PluginDataChannelPushEntryMsg(header: BbbClientMsgHeader, body: PluginDataChannelPushEntryMsgBody) extends StandardMsg case class PluginDataChannelPushEntryMsgBody( @@ -20,13 +28,13 @@ case class PluginDataChannelPushEntryMsgBody( object PluginDataChannelReplaceEntryMsg { val NAME = "PluginDataChannelReplaceEntryMsg" } case class PluginDataChannelReplaceEntryMsg(header: BbbClientMsgHeader, body: PluginDataChannelReplaceEntryMsgBody) extends StandardMsg -case class PluginDataChannelReplaceEntryMsgBody( +case class PluginDataChannelReplaceEntryMsgBody ( pluginName: String, channelName: String, subChannelName: String, payloadJson: Map[String, Any], entryId: String, - ) + ) extends PluginDataChannelReplaceOrDeleteBaseBody object PluginDataChannelDeleteEntryMsg { val NAME = "PluginDataChannelDeleteEntryMsg" } case class PluginDataChannelDeleteEntryMsg(header: BbbClientMsgHeader, body: PluginDataChannelDeleteEntryMsgBody) extends StandardMsg @@ -35,7 +43,7 @@ case class PluginDataChannelDeleteEntryMsgBody( subChannelName: String, channelName: String, entryId: String - ) + ) extends PluginDataChannelReplaceOrDeleteBaseBody object PluginDataChannelResetMsg { val NAME = "PluginDataChannelResetMsg" } diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java b/bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java index aa663b8358..a2d4263d8e 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java @@ -27,10 +27,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; +import com.google.gson.*; import org.bigbluebutton.api.domain.*; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -434,23 +431,27 @@ public class ParamsProcessorUtil { ArrayList pluginsManifests = new ArrayList(); String pluginsManifestParams = params.get(ApiParams.PLUGINS_MANIFESTS); if (!StringUtils.isEmpty(pluginsManifestParams)) { - JsonElement pluginsManifestsJsonElement = new Gson().fromJson(pluginsManifestParams, JsonElement.class); + try { + JsonElement pluginsManifestsJsonElement = new Gson().fromJson(pluginsManifestParams, JsonElement.class); - if(pluginsManifestsJsonElement != null && pluginsManifestsJsonElement.isJsonArray()) { - JsonArray pluginsManifestsJson = pluginsManifestsJsonElement.getAsJsonArray(); - for (JsonElement pluginsManifestJson : pluginsManifestsJson) { - if(pluginsManifestJson.isJsonObject()) { - JsonObject pluginsManifestJsonObj = pluginsManifestJson.getAsJsonObject(); - if(pluginsManifestJsonObj.has("url")) { - String url = pluginsManifestJsonObj.get("url").getAsString(); - PluginsManifest newPlugin = new PluginsManifest(url); - if(pluginsManifestJsonObj.has("checksum")) { - newPlugin.setChecksum(pluginsManifestJsonObj.get("checksum").getAsString()); + if(pluginsManifestsJsonElement != null && pluginsManifestsJsonElement.isJsonArray()) { + JsonArray pluginsManifestsJson = pluginsManifestsJsonElement.getAsJsonArray(); + for (JsonElement pluginsManifestJson : pluginsManifestsJson) { + if(pluginsManifestJson.isJsonObject()) { + JsonObject pluginsManifestJsonObj = pluginsManifestJson.getAsJsonObject(); + if(pluginsManifestJsonObj.has("url")) { + String url = pluginsManifestJsonObj.get("url").getAsString(); + PluginsManifest newPlugin = new PluginsManifest(url); + if(pluginsManifestJsonObj.has("checksum")) { + newPlugin.setChecksum(pluginsManifestJsonObj.get("checksum").getAsString()); + } + pluginsManifests.add(newPlugin); } - pluginsManifests.add(newPlugin); } } } + } catch (JsonSyntaxException err) { + log.error("Error in pluginsManifests URL parameter's json structure."); } } From 96926391ecc35e910053243001801518168bed28 Mon Sep 17 00:00:00 2001 From: Guilherme Leme Date: Mon, 14 Oct 2024 11:43:48 -0300 Subject: [PATCH 3/3] [new-server-side-architecture] - Remove code duplication --- .../PluginDataChannelDeleteEntryMsgHdlr.scala | 47 ++++++------------ .../PluginDataChannelPushEntryMsgHdlr.scala | 49 +++++++------------ ...PluginDataChannelReplaceEntryMsgHdlr.scala | 46 ++++++----------- .../PluginDataChannelResetMsgHdlr.scala | 42 +++++----------- .../core/apps/plugin/PluginHdlrHelpers.scala | 25 +++++++++- 5 files changed, 86 insertions(+), 123 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala index 9abc3592c0..10803dd51e 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelDeleteEntryMsgHdlr.scala @@ -1,44 +1,29 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelDeleteEntryMsg -import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{ checkPermission, defaultCreatorCheck } +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{ checkPermission, dataChannelCheckingLogic, defaultCreatorCheck } import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.{ PluginModel, Roles, Users2x } import org.bigbluebutton.core.running.{ HandlerHelpers, LiveMeeting } trait PluginDataChannelDeleteEntryMsgHdlr extends HandlerHelpers { def handle(msg: PluginDataChannelDeleteEntryMsg, state: MeetingState2x, liveMeeting: LiveMeeting): Unit = { - val pluginsDisabled: Boolean = liveMeeting.props.meetingProp.disabledFeatures.contains("plugins") - val meetingId = liveMeeting.props.meetingProp.intId - - for { - _ <- if (!pluginsDisabled) Some(()) else None - user <- Users2x.findWithIntId(liveMeeting.users2x, msg.header.userId) - } yield { - PluginModel.getPluginByName(liveMeeting.plugins, msg.body.pluginName) match { - case Some(p) => - p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { - case Some(dc) => - val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( - meetingId, msg.body, msg.header.userId - )) - if (!hasPermission.contains(true)) { - println(s"No permission to delete in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") - } else { - PluginDataChannelEntryDAO.delete( - meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName, - msg.body.entryId - ) - } - case None => println(s"Data channel '${msg.body.channelName}' not found in plugin '${msg.body.pluginName}'.") - } - case None => println(s"Plugin '${msg.body.pluginName}' not found.") + dataChannelCheckingLogic(liveMeeting, msg.header.userId, msg.body.pluginName, msg.body.channelName, (user, dc, meetingId) => { + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( + meetingId, msg.body, msg.header.userId + )) + if (!hasPermission.contains(true)) { + println(s"No permission to delete in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") + } else { + PluginDataChannelEntryDAO.delete( + meetingId, + msg.body.pluginName, + msg.body.channelName, + msg.body.subChannelName, + msg.body.entryId + ) } - } + }) } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala index e3037a8ca9..e83b867412 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelPushEntryMsgHdlr.scala @@ -1,45 +1,30 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelPushEntryMsg -import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.checkPermission +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{ checkPermission, dataChannelCheckingLogic, defaultCreatorCheck } import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.{ PluginModel, Roles, UserState, Users2x } import org.bigbluebutton.core.running.{ HandlerHelpers, LiveMeeting } trait PluginDataChannelPushEntryMsgHdlr extends HandlerHelpers { def handle(msg: PluginDataChannelPushEntryMsg, state: MeetingState2x, liveMeeting: LiveMeeting): Unit = { - val pluginsDisabled: Boolean = liveMeeting.props.meetingProp.disabledFeatures.contains("plugins") - val meetingId = liveMeeting.props.meetingProp.intId - - for { - _ <- if (!pluginsDisabled) Some(()) else None - user <- Users2x.findWithIntId(liveMeeting.users2x, msg.header.userId) - } yield { - PluginModel.getPluginByName(liveMeeting.plugins, msg.body.pluginName) match { - case Some(p) => - p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { - case Some(dc) => - val hasPermission = checkPermission(user, dc.pushPermission) - if (!hasPermission.contains(true)) { - println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") - } else { - PluginDataChannelEntryDAO.insert( - meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName, - msg.header.userId, - msg.body.payloadJson, - msg.body.toRoles, - msg.body.toUserIds - ) - } - case None => println(s"Data channel '${msg.body.channelName}' not found in plugin '${msg.body.pluginName}'.") - } - case None => println(s"Plugin '${msg.body.pluginName}' not found.") + dataChannelCheckingLogic(liveMeeting, msg.header.userId, msg.body.pluginName, msg.body.channelName, (user, dc, meetingId) => { + val hasPermission = checkPermission(user, dc.pushPermission) + if (!hasPermission.contains(true)) { + println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") + } else { + PluginDataChannelEntryDAO.insert( + meetingId, + msg.body.pluginName, + msg.body.channelName, + msg.body.subChannelName, + msg.header.userId, + msg.body.payloadJson, + msg.body.toRoles, + msg.body.toUserIds + ) } - } + }) } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala index 1683d807f3..b216353f55 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelReplaceEntryMsgHdlr.scala @@ -1,45 +1,31 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelReplaceEntryMsg -import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{checkPermission, defaultCreatorCheck} +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{checkPermission, dataChannelCheckingLogic, defaultCreatorCheck} import org.bigbluebutton.core.db.{JsonUtils, PluginDataChannelEntryDAO} import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.{PluginModel, Roles, Users2x} import org.bigbluebutton.core.running.{HandlerHelpers, LiveMeeting} trait PluginDataChannelReplaceEntryMsgHdlr extends HandlerHelpers { def handle(msg: PluginDataChannelReplaceEntryMsg, state: MeetingState2x, liveMeeting: LiveMeeting): Unit = { - val pluginsDisabled: Boolean = liveMeeting.props.meetingProp.disabledFeatures.contains("plugins") - val meetingId = liveMeeting.props.meetingProp.intId - for { - _ <- if (!pluginsDisabled) Some(()) else None - user <- Users2x.findWithIntId(liveMeeting.users2x, msg.header.userId) - } yield { - PluginModel.getPluginByName(liveMeeting.plugins, msg.body.pluginName) match { - case Some(p) => - p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { - case Some(dc) => - val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( - meetingId, msg.body, msg.header.userId)) + dataChannelCheckingLogic(liveMeeting, msg.header.userId, msg.body.pluginName, msg.body.channelName, (user, dc, meetingId) => { + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission, defaultCreatorCheck( + meetingId, msg.body, msg.header.userId)) - if (!hasPermission.contains(true)) { - println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") - } else { - PluginDataChannelEntryDAO.replace( - msg.header.meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName, - msg.body.entryId, - JsonUtils.mapToJson(msg.body.payloadJson), - ) - } - case None => println(s"Data channel '${msg.body.channelName}' not found in plugin '${msg.body.pluginName}'.") - } - case None => println(s"Plugin '${msg.body.pluginName}' not found.") + if (!hasPermission.contains(true)) { + println(s"No permission to write in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") + } else { + PluginDataChannelEntryDAO.replace( + msg.header.meetingId, + msg.body.pluginName, + msg.body.channelName, + msg.body.subChannelName, + msg.body.entryId, + JsonUtils.mapToJson(msg.body.payloadJson), + ) } - } + }) } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala index 1f5030cf9a..61dcfec982 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginDataChannelResetMsgHdlr.scala @@ -1,43 +1,27 @@ package org.bigbluebutton.core.apps.plugin -import org.bigbluebutton.ClientSettings import org.bigbluebutton.common2.msgs.PluginDataChannelResetMsg -import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.checkPermission +import org.bigbluebutton.core.apps.plugin.PluginHdlrHelpers.{ checkPermission, dataChannelCheckingLogic } import org.bigbluebutton.core.db.PluginDataChannelEntryDAO import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.{ PluginModel, Roles, Users2x } import org.bigbluebutton.core.running.{ HandlerHelpers, LiveMeeting } trait PluginDataChannelResetMsgHdlr extends HandlerHelpers { def handle(msg: PluginDataChannelResetMsg, state: MeetingState2x, liveMeeting: LiveMeeting): Unit = { - val pluginsDisabled: Boolean = liveMeeting.props.meetingProp.disabledFeatures.contains("plugins") - val meetingId = liveMeeting.props.meetingProp.intId + dataChannelCheckingLogic(liveMeeting, msg.header.userId, msg.body.pluginName, msg.body.channelName, (user, dc, meetingId) => { + val hasPermission = checkPermission(user, dc.replaceOrDeletePermission) - for { - _ <- if (!pluginsDisabled) Some(()) else None - user <- Users2x.findWithIntId(liveMeeting.users2x, msg.header.userId) - } yield { - PluginModel.getPluginByName(liveMeeting.plugins, msg.body.pluginName) match { - case Some(p) => - p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == msg.body.channelName) match { - case Some(dc) => - val hasPermission = checkPermission(user, dc.replaceOrDeletePermission) - - if (!hasPermission.contains(true)) { - println(s"No permission to delete (reset) in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") - } else { - PluginDataChannelEntryDAO.reset( - meetingId, - msg.body.pluginName, - msg.body.channelName, - msg.body.subChannelName - ) - } - case None => println(s"Data channel '${msg.body.channelName}' not found in plugin '${msg.body.pluginName}'.") - } - case None => println(s"Plugin '${msg.body.pluginName}' not found.") + if (!hasPermission.contains(true)) { + println(s"No permission to delete (reset) in plugin: '${msg.body.pluginName}', data channel: '${msg.body.channelName}'.") + } else { + PluginDataChannelEntryDAO.reset( + meetingId, + msg.body.pluginName, + msg.body.channelName, + msg.body.subChannelName + ) } - } + }) } } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala index 469d9fae6a..68bed194e1 100644 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/plugin/PluginHdlrHelpers.scala @@ -2,7 +2,8 @@ package org.bigbluebutton.core.apps.plugin import org.bigbluebutton.common2.msgs.PluginDataChannelReplaceOrDeleteBaseBody import org.bigbluebutton.core.db.PluginDataChannelEntryDAO -import org.bigbluebutton.core.models.{ Roles, UserState } +import org.bigbluebutton.core.models.{ DataChannel, PluginModel, Roles, UserState, Users2x } +import org.bigbluebutton.core.running.LiveMeeting object PluginHdlrHelpers { def checkPermission(user: UserState, permissionType: List[String], creatorCheck: => Boolean = false): List[Boolean] = { @@ -24,4 +25,26 @@ object PluginHdlrHelpers { ) creatorUserId == userId } + + def dataChannelCheckingLogic(liveMeeting: LiveMeeting, userId: String, + pluginName: String, channelName: String, + caseSomeDataChannelAndPlugin: (UserState, DataChannel, String) => Unit): Option[Unit] = { + val pluginsDisabled: Boolean = liveMeeting.props.meetingProp.disabledFeatures.contains("plugins") + val meetingId = liveMeeting.props.meetingProp.intId + + for { + _ <- if (!pluginsDisabled) Some(()) else None + user <- Users2x.findWithIntId(liveMeeting.users2x, userId) + } yield { + PluginModel.getPluginByName(liveMeeting.plugins, pluginName) match { + case Some(p) => + p.manifest.content.dataChannels.getOrElse(List()).find(dc => dc.name == channelName) match { + case Some(dc) => + caseSomeDataChannelAndPlugin(user, dc, meetingId) + case None => println(s"Data channel '${channelName}' not found in plugin '${pluginName}'.") + } + case None => println(s"Plugin '${pluginName}' not found.") + } + } + } }