From 8b3d32584ce9c0a0169e0f3cc93a63cec2238829 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 11 May 2022 16:12:19 +0200 Subject: [PATCH] restrict to share content without permissions Signed-off-by: Marcel Hibbe --- .../talk/controllers/ChatController.kt | 10 ++++++- .../ConversationsListController.java | 27 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 2d4b2fbc1..caa519d79 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -346,7 +346,9 @@ class ChatController(args: Bundle) : setTitle() hasChatPermission = - AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission(conversationUser) + AttendeePermissionsUtil(currentConversation!!.permissions).hasChatPermission( + conversationUser + ) try { setupMentionAutocomplete() @@ -1458,6 +1460,12 @@ class ChatController(args: Bundle) : private fun uploadFiles(files: MutableList, isVoiceMessage: Boolean) { var metaData = "" + + if (!hasChatPermission) { + Log.e(TAG, "uploading file(s) is forbidden because of missing attendee permissions") + return + } + if (isVoiceMessage) { metaData = VOICE_MESSAGE_META_DATA } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java index 8779a67c5..4d0f893a5 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java @@ -86,6 +86,7 @@ import com.nextcloud.talk.models.json.statuses.StatusesOverall; import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment; import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog; import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.AttendeePermissionsUtil; import com.nextcloud.talk.utils.ClosedInterfaceImpl; import com.nextcloud.talk.utils.ConductorRemapping; import com.nextcloud.talk.utils.DisplayUtils; @@ -359,7 +360,6 @@ public class ConversationsListController extends BaseController implements Searc showShareToScreen = !showShareToScreen && hasActivityActionSendIntent(); - if (showShareToScreen) { hideSearchBar(); getActionBar().setTitle(R.string.send_to_three_dots); @@ -867,13 +867,25 @@ public class ConversationsListController extends BaseController implements Searc public boolean onItemClick(View view, int position) { try { selectedConversation = ((ConversationItem) Objects.requireNonNull(adapter.getItem(position))).getModel(); + if (selectedConversation != null && getActivity() != null) { + boolean hasChatPermission = + new AttendeePermissionsUtil(selectedConversation.permissions).hasChatPermission(currentUser); + if (showShareToScreen) { - handleSharedData(); - showShareToScreen = false; + if (hasChatPermission && !isReadOnlyConversation(selectedConversation)) { + handleSharedData(); + showShareToScreen = false; + } else { + Toast.makeText(context, R.string.send_to_forbidden, Toast.LENGTH_LONG).show(); + } } else if (forwardMessage) { - openConversation(bundle.getString(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_TEXT())); - forwardMessage = false; + if (hasChatPermission && !isReadOnlyConversation(selectedConversation)) { + openConversation(bundle.getString(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_TEXT())); + forwardMessage = false; + } else { + Toast.makeText(context, R.string.send_to_forbidden, Toast.LENGTH_LONG).show(); + } } else { openConversation(); } @@ -885,6 +897,11 @@ public class ConversationsListController extends BaseController implements Searc return true; } + private Boolean isReadOnlyConversation(Conversation conversation) { + return conversation.conversationReadOnlyState == + Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY; + } + private void handleSharedData() { collectDataFromIntent(); if (!textToPaste.isEmpty()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba1df70e9..b94aa7bd1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -392,6 +392,8 @@ Send to … Sharing files from storage is not possible without permissions Open in Files app + You are not allowed to share content to this chat + Add to conversation