From 3761fc333b4ea3ec3af1e37f7aa26954c2533640 Mon Sep 17 00:00:00 2001 From: GuiLeme Date: Wed, 16 Aug 2023 11:18:51 -0300 Subject: [PATCH] [plugin-architecture-implementation] - fix for disable downloadable --- .../MakePresentationDownloadReqMsgHdlr.scala | 5 --- ...tionConversionCompletedSysPubMsgHdlr.scala | 5 ++- .../presentationpod/PresentationSender.scala | 41 ------------------- ...etPresentationDownloadablePubMsgHdlr.scala | 7 +++- .../common2/msgs/PresentationPodsMsgs.scala | 3 +- .../main/java/org/bigbluebutton/api/Util.java | 26 ++++-------- .../presentation/SupportedFileTypes.java | 4 -- .../imp/PresentationFileProcessor.java | 5 +-- .../server/handlers/presentationExport.js | 2 +- .../methods/setPresentationDownloadable.js | 4 +- .../presentation-uploader/component.jsx | 15 +++---- .../presentation-uploader/container.jsx | 4 +- .../component.jsx | 28 +++++++------ .../presentation-uploader/service.js | 6 +-- 14 files changed, 52 insertions(+), 103 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/MakePresentationDownloadReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/MakePresentationDownloadReqMsgHdlr.scala index bcf0c41479..f137641c44 100644 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/MakePresentationDownloadReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/MakePresentationDownloadReqMsgHdlr.scala @@ -168,11 +168,6 @@ trait MakePresentationDownloadReqMsgHdlr extends RightsManagementTrait { val originalFileExt = originalFilename.split("\\.").last val convertedFileExt = if (convertedFileName != "") convertedFileName.split("\\.").last else "" - val downloadableExtension: String = if (m.body.typeOfExport == "Converted") convertedFileExt - else originalFileExt - PresentationSender.broadcastSetPresentationDownloadableEvtMsg(bus, meetingId, "DEFAULT_PRESENTATION_POD", - "not-used", presId, true, originalFilename, downloadableExtension) - val convertedFileURI = if (convertedFileName != "") List("presentation", "download", meetingId, s"${presId}?presFilename=${presId}.${convertedFileExt}&filename=${convertedFileName}").mkString("", File.separator, "") else "" diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationConversionCompletedSysPubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationConversionCompletedSysPubMsgHdlr.scala index 1d164f496a..2aeeccfcb4 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationConversionCompletedSysPubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationConversionCompletedSysPubMsgHdlr.scala @@ -33,6 +33,8 @@ trait PresentationConversionCompletedSysPubMsgHdlr { msg.body.code, presVO, ) + + val originalDownloadableExtension = pres.name.split("\\.").last PresentationSender.broadcastSetPresentationDownloadableEvtMsg( bus, meetingId, @@ -40,7 +42,8 @@ trait PresentationConversionCompletedSysPubMsgHdlr { msg.header.userId, pres.id, pres.downloadable, - pres.name + pres.name, + originalDownloadableExtension ) val presWithConvertedName = PresentationInPod(pres.id, pres.name, pres.current, pres.pages, diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationSender.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationSender.scala index 33dd45fad5..5fec709db8 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationSender.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/PresentationSender.scala @@ -5,25 +5,6 @@ import org.bigbluebutton.common2.msgs._ import org.bigbluebutton.core.bus.MessageBus object PresentationSender { - def broadcastSetPresentationDownloadableEvtMsg( - bus: MessageBus, - meetingId: String, - podId: String, userId: String, - presentationId: String, - downloadable: Boolean, - presFilename: String, - ): Unit = { - broadcastSetPresentationDownloadableEvtMsgLogic( - bus, - meetingId, - podId, - userId, - presentationId, - downloadable, - presFilename, - "pdf", - ) - } def broadcastSetPresentationDownloadableEvtMsg( bus: MessageBus, meetingId: String, @@ -33,28 +14,6 @@ object PresentationSender { downloadable: Boolean, presFilename: String, downloadableExtension: String - ): Unit = { - broadcastSetPresentationDownloadableEvtMsgLogic( - bus, - meetingId, - podId, - userId, - presentationId, - downloadable, - presFilename, - downloadableExtension, - ) - } - - def broadcastSetPresentationDownloadableEvtMsgLogic( - bus: MessageBus, - meetingId: String, - podId: String, - userId: String, - presentationId: String, - downloadable: Boolean, - presFilename: String, - downloadableExtension: String, ): Unit = { val routing = Routing.addMsgToClientRouting( MessageTypes.BROADCAST_TO_MEETING, diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresentationDownloadablePubMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresentationDownloadablePubMsgHdlr.scala index c9d47a7fd4..9f1254f281 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresentationDownloadablePubMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/presentationpod/SetPresentationDownloadablePubMsgHdlr.scala @@ -31,8 +31,11 @@ trait SetPresentationDownloadablePubMsgHdlr extends RightsManagementTrait { pod <- PresentationPodsApp.getPresentationPod(state, podId) pres <- pod.getPresentation(presentationId) } yield { + val downloadableExtension = if (msg.body.typeOfExport == "Original") + pres.name.split("\\.").last else pres.filenameConverted.split("\\.").last + PresentationSender.broadcastSetPresentationDownloadableEvtMsg(bus, meetingId, pod.id, - msg.header.userId, presentationId, downloadable, pres.name) + msg.header.userId, presentationId, downloadable, pres.name, downloadableExtension) val pods = state.presentationPodManager.setPresentationDownloadableInPod(pod.id, presentationId, downloadable) state.update(pods) @@ -46,4 +49,4 @@ trait SetPresentationDownloadablePubMsgHdlr extends RightsManagementTrait { } } -} \ No newline at end of file +} diff --git a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PresentationPodsMsgs.scala b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PresentationPodsMsgs.scala index 7a9fdd48b4..58bba6352b 100755 --- a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PresentationPodsMsgs.scala +++ b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/PresentationPodsMsgs.scala @@ -33,7 +33,8 @@ case class RemovePresentationPubMsgBody(podId: String, presentationId: String) object SetPresentationDownloadablePubMsg { val NAME = "SetPresentationDownloadablePubMsg" } case class SetPresentationDownloadablePubMsg(header: BbbClientMsgHeader, body: SetPresentationDownloadablePubMsgBody) extends StandardMsg -case class SetPresentationDownloadablePubMsgBody(podId: String, presentationId: String, downloadable: Boolean) +case class SetPresentationDownloadablePubMsgBody(podId: String, presentationId: String, downloadable: Boolean, + typeOfExport: String) object ResizeAndMovePagePubMsg { val NAME = "ResizeAndMovePagePubMsg" } case class ResizeAndMovePagePubMsg(header: BbbClientMsgHeader, body: ResizeAndMovePagePubMsgBody) extends StandardMsg diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api/Util.java b/bbb-common-web/src/main/java/org/bigbluebutton/api/Util.java index 8f4d6c0660..c63746b264 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api/Util.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api/Util.java @@ -1,7 +1,6 @@ package org.bigbluebutton.api; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.util.UUID; import java.util.regex.Matcher; @@ -10,8 +9,6 @@ import java.util.regex.Pattern; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; -import org.bigbluebutton.presentation.SupportedFileTypes; - public final class Util { private static final Pattern MEETING_ID_PATTERN = Pattern.compile("^[a-z0-9-]+$"); @@ -116,21 +113,12 @@ public final class Util { return null; } - public static void deleteAllDownloadableMarksInPresentations(File presFileDir, String presId) { - String regexString = "\\.(" + String.join("|", - SupportedFileTypes.getSupportedFileTypes()) + ")\\.downloadable"; - File[] filesWithDownloadMark = presFileDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.matches(presId + regexString); - } - }); - - // Iterate through all of downloadable marks to delete them. Pattern is: - // ..downloadable - for (File downloadableMark: filesWithDownloadMark) { - if (downloadableMark != null && downloadableMark.exists()) { - downloadableMark.delete(); + public static void deleteAllDownloadableMarksInPresentations(File presFileDir) { + // Delete files with .downloadable at the end of its filename + File[] presFiles = presFileDir.listFiles(); + for (File presFile : presFiles) { + if (presFile.isFile() && presFile.getName().endsWith(".downloadable")) { + presFile.delete(); } } } @@ -143,7 +131,7 @@ public final class Util { ) throws IOException { File downloadMarker = Util.getPresFileDownloadMarker(presFileDir, presId, downloadableExtension); if (downloadable && downloadMarker != null && ! downloadMarker.exists()) { - Util.deleteAllDownloadableMarksInPresentations(presFileDir, presId); + Util.deleteAllDownloadableMarksInPresentations(presFileDir); downloadMarker.createNewFile(); } else if (!downloadable && downloadMarker != null && downloadMarker.exists()) { downloadMarker.delete(); diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/presentation/SupportedFileTypes.java b/bbb-common-web/src/main/java/org/bigbluebutton/presentation/SupportedFileTypes.java index 4af2008e20..b485347845 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/presentation/SupportedFileTypes.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/presentation/SupportedFileTypes.java @@ -63,10 +63,6 @@ public final class SupportedFileTypes { } }); - public static List getSupportedFileTypes() { - return SUPPORTED_FILE_LIST; - } - /* * Returns if the file with extension is supported. */ diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/PresentationFileProcessor.java b/bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/PresentationFileProcessor.java index 4da7c080dd..aaa9ba08a5 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/PresentationFileProcessor.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/PresentationFileProcessor.java @@ -66,9 +66,8 @@ public class PresentationFileProcessor { private void processMakePresentationDownloadableMsg(UploadedPresentation pres) { try { File presentationFileDir = pres.getUploadedFile().getParentFile(); - if (!pres.getFilenameConverted().equals("")){ - String fileExtensionConverted; - fileExtensionConverted = FilenameUtils.getExtension(pres.getFilenameConverted()); + if (!pres.getFilenameConverted().equals("")) { + String fileExtensionConverted = FilenameUtils.getExtension(pres.getFilenameConverted()); Util.makePresentationDownloadable(presentationFileDir, pres.getId(), pres.isDownloadable(), fileExtensionConverted); diff --git a/bigbluebutton-html5/imports/api/presentations/server/handlers/presentationExport.js b/bigbluebutton-html5/imports/api/presentations/server/handlers/presentationExport.js index dfea68c6e1..9ef88eb15a 100644 --- a/bigbluebutton-html5/imports/api/presentations/server/handlers/presentationExport.js +++ b/bigbluebutton-html5/imports/api/presentations/server/handlers/presentationExport.js @@ -22,7 +22,7 @@ export default async function handlePresentationExport({ body }, meetingId) { check(typeOfExport, String); if (typeOfExport === 'Original' || typeOfExport === 'Converted') { - if (typeOfExport.indexOf('Converted') !== -1) { + if (typeOfExport === 'Converted') { await setOriginalUriDownload( meetingId, presId, diff --git a/bigbluebutton-html5/imports/api/presentations/server/methods/setPresentationDownloadable.js b/bigbluebutton-html5/imports/api/presentations/server/methods/setPresentationDownloadable.js index 4ccf1e063a..67849f1b21 100644 --- a/bigbluebutton-html5/imports/api/presentations/server/methods/setPresentationDownloadable.js +++ b/bigbluebutton-html5/imports/api/presentations/server/methods/setPresentationDownloadable.js @@ -3,7 +3,7 @@ import { check } from 'meteor/check'; import { extractCredentials } from '/imports/api/common/server/helpers'; import Logger from '/imports/startup/server/logger'; -export default function setPresentationDownloadable(presentationId, downloadable) { +export default function setPresentationDownloadable(presentationId, downloadable, typeOfExport) { const REDIS_CONFIG = Meteor.settings.private.redis; const CHANNEL = REDIS_CONFIG.channels.toAkkaApps; const EVENT_NAME = 'SetPresentationDownloadablePubMsg'; @@ -15,11 +15,13 @@ export default function setPresentationDownloadable(presentationId, downloadable check(requesterUserId, String); check(downloadable, Match.Maybe(Boolean)); check(presentationId, String); + check(typeOfExport, Match.Maybe(String)); const payload = { presentationId, podId: 'DEFAULT_PRESENTATION_POD', downloadable, + typeOfExport, }; RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); diff --git a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/component.jsx b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/component.jsx index cea9393434..7423071625 100755 --- a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/component.jsx @@ -362,7 +362,7 @@ class PresentationUploader extends Component { this.deepMergeUpdateFileKey = this.deepMergeUpdateFileKey.bind(this); this.updateFileKey = this.updateFileKey.bind(this); this.getPresentationsToShow = this.getPresentationsToShow.bind(this); - this.handleToggleDownloadable = this.handleToggleDownloadable.bind(this); + this.handleDownloadableChange = this.handleDownloadableChange.bind(this); } componentDidUpdate(prevProps) { @@ -670,12 +670,10 @@ class PresentationUploader extends Component { return null; } - handleToggleDownloadable(item) { - const { dispatchTogglePresentationDownloadable } = this.props; + handleDownloadableChange(item, typeOfExport, downloadable) { + const { dispatchChangePresentationDownloadable } = this.props; - const oldDownloadableState = item.isDownloadable; - - dispatchTogglePresentationDownloadable(item, !oldDownloadableState); + dispatchChangePresentationDownloadable(item, downloadable, typeOfExport); } handleDismiss() { @@ -711,6 +709,7 @@ class PresentationUploader extends Component { const observer = (exportation, stopped) => { this.deepMergeUpdateFileKey(item.id, 'exportation', exportation); + console.log("Vou descobrir se manda duas vezes por aqui ----> ", item, type, exportation.status) if (exportation.status === EXPORT_STATUSES.EXPORTED && stopped) { if (type === 'Original' || type === 'Converted') { if (!item.isDownloadable) { @@ -759,6 +758,8 @@ class PresentationUploader extends Component { }); } }; + console.log("Vou descobrir se manda duas vezes por aqui ---(2)-> ", item, type) + exportPresentation(item.id, observer, type); } @@ -1089,7 +1090,7 @@ class PresentationUploader extends Component { isDownloadable={isDownloadable} allowDownloadOriginal={allowDownloadOriginal} allowDownloadWithAnnotations={allowDownloadWithAnnotations} - handleToggleDownloadable={this.handleToggleDownloadable} + handleDownloadableChange={this.handleDownloadableChange} item={item} closeModal={() => Session.set('showUploadPresentationView', false)} handleDownloadingOfPresentation={(type) => this diff --git a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/container.jsx b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/container.jsx index c870eae3d8..b2504ecc20 100644 --- a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/container.jsx +++ b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/container.jsx @@ -36,7 +36,7 @@ export default withTracker(() => { const { dispatchDisableDownloadable, dispatchEnableDownloadable, - dispatchTogglePresentationDownloadable, + dispatchChangePresentationDownloadable, exportPresentation, } = Service; const isOpen = isPresentationEnabled() && (Session.get('showUploadPresentationView') || false); @@ -56,7 +56,7 @@ export default withTracker(() => { renderPresentationItemStatus: PresUploaderToast.renderPresentationItemStatus, dispatchDisableDownloadable, dispatchEnableDownloadable, - dispatchTogglePresentationDownloadable, + dispatchChangePresentationDownloadable, exportPresentation, isOpen, selectedToBeNextCurrent: Session.get('selectedToBeNextCurrent') || null, diff --git a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/presentation-download-dropdown/component.jsx b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/presentation-download-dropdown/component.jsx index 81937ac6b1..2e18b16bbb 100644 --- a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/presentation-download-dropdown/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/presentation-download-dropdown/component.jsx @@ -38,7 +38,7 @@ const propTypes = { formatMessage: PropTypes.func.isRequired, }).isRequired, handleDownloadingOfPresentation: PropTypes.func.isRequired, - handleToggleDownloadable: PropTypes.func.isRequired, + handleDownloadableChange: PropTypes.func.isRequired, isDownloadable: PropTypes.bool.isRequired, item: PropTypes.shape({ id: PropTypes.string.isRequired, @@ -74,7 +74,7 @@ class PresentationDownloadDropdown extends PureComponent { const { intl, handleDownloadingOfPresentation, - handleToggleDownloadable, + handleDownloadableChange, isDownloadable, allowDownloadOriginal, allowDownloadWithAnnotations, @@ -87,14 +87,16 @@ class PresentationDownloadDropdown extends PureComponent { const { filenameConverted, filename, downloadableExtension } = item; const convertedFileExtension = filenameConverted?.split('.').slice(-1)[0]; const originalFileExtension = filename?.split('.').slice(-1)[0]; - const toggleDownloadOriginalPresentation = (enableDownload, isConverted) => { - handleToggleDownloadable(item); + const changeDownloadOriginalOrConvertedPresentation = (enableDownload, isConverted) => { + let typeOfExport; + if (isConverted) { + typeOfExport = 'Converted'; + } else { + typeOfExport = 'Original'; + } + handleDownloadableChange(item, typeOfExport, enableDownload); if (enableDownload) { - if (isConverted) { - handleDownloadingOfPresentation('Converted'); - } else { - handleDownloadingOfPresentation('Original'); - } + handleDownloadingOfPresentation(typeOfExport); } closeModal(); }; @@ -107,7 +109,7 @@ class PresentationDownloadDropdown extends PureComponent { dataTest: 'disableOriginalPresentationDownload', label: intl.formatMessage(intlMessages.disableOriginalPresentationDownload, { 0: originalFileExtension }), - onClick: () => toggleDownloadOriginalPresentation(false, false), + onClick: () => changeDownloadOriginalOrConvertedPresentation(false, false), }); } else { this.menuItems.push({ @@ -115,7 +117,7 @@ class PresentationDownloadDropdown extends PureComponent { dataTest: 'enableOriginalPresentationDownload', label: intl.formatMessage(intlMessages.enableOriginalPresentationDownload, { 0: originalFileExtension }), - onClick: () => toggleDownloadOriginalPresentation(true, false), + onClick: () => changeDownloadOriginalOrConvertedPresentation(true, false), }); } if ((!!filenameConverted && filenameConverted !== '') @@ -127,7 +129,7 @@ class PresentationDownloadDropdown extends PureComponent { dataTest: 'disableOriginalPresentationDownload', label: intl.formatMessage(intlMessages.disableOriginalPresentationDownload, { 0: convertedFileExtension }), - onClick: () => toggleDownloadOriginalPresentation(false, true), + onClick: () => changeDownloadOriginalOrConvertedPresentation(false, true), }); } else { this.menuItems.push({ @@ -135,7 +137,7 @@ class PresentationDownloadDropdown extends PureComponent { dataTest: 'enableOriginalPresentationDownload', label: intl.formatMessage(intlMessages.enableOriginalPresentationDownload, { 0: convertedFileExtension }), - onClick: () => toggleDownloadOriginalPresentation(true, true), + onClick: () => changeDownloadOriginalOrConvertedPresentation(true, true), }); } } diff --git a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/service.js b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/service.js index 00b5cd2599..0a4b5f1800 100644 --- a/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/service.js +++ b/bigbluebutton-html5/imports/ui/components/presentation/presentation-uploader/service.js @@ -79,8 +79,8 @@ const getPresentations = () => Presentations }; }); -const dispatchTogglePresentationDownloadable = (presentation, newState) => { - makeCall('setPresentationDownloadable', presentation.id, newState); +const dispatchChangePresentationDownloadable = (presentation, newState, typeOfExport) => { + makeCall('setPresentationDownloadable', presentation.id, newState, typeOfExport); }; const observePresentationConversion = ( @@ -487,7 +487,7 @@ export default { handleSavePresentation, getPresentations, persistPresentationChanges, - dispatchTogglePresentationDownloadable, + dispatchChangePresentationDownloadable, setPresentation, requestPresentationUploadToken, getExternalUploadData,