-
Notifications
You must be signed in to change notification settings - Fork 46
feat: Restrict access to upload for Viewers profile (WPB-25257) #4849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
938f1d5
247ed5b
63ba58a
63d0739
34d3829
17d356e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,40 +25,46 @@ import androidx.compose.runtime.setValue | |
| import androidx.lifecycle.SavedStateHandle | ||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.ramcosta.composedestinations.generated.app.navArgs | ||
| import com.wire.android.datastore.GlobalDataStore | ||
| import com.wire.android.mapper.ContactMapper | ||
| import com.wire.android.ui.home.conversations.ConversationNavArgs | ||
| import com.wire.android.ui.home.conversations.InvalidLinkDialogState | ||
| import com.wire.android.ui.home.conversations.MessageComposerViewState | ||
| import com.wire.android.ui.home.conversations.VisitLinkDialogState | ||
| import com.wire.android.ui.home.conversations.model.UIMessage | ||
| import com.ramcosta.composedestinations.generated.app.navArgs | ||
| import com.wire.android.util.EMPTY | ||
| import com.wire.android.util.FileManager | ||
| import com.wire.android.util.dispatchers.DispatcherProvider | ||
| import com.wire.kalium.logic.configuration.FileSharingStatus | ||
| import com.wire.kalium.logic.data.asset.KaliumFileSystem | ||
| import com.wire.kalium.logic.data.conversation.Conversation.TypingIndicatorMode | ||
| import com.wire.kalium.logic.data.conversation.ConversationDetails | ||
| import com.wire.kalium.logic.data.conversation.InteractionAvailability | ||
| import com.wire.kalium.logic.data.id.QualifiedID | ||
| import com.wire.kalium.logic.data.message.SelfDeletionTimer | ||
| import com.wire.kalium.logic.data.user.OtherUser | ||
| import com.wire.kalium.logic.data.user.SelfUser | ||
| import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase | ||
| import com.wire.kalium.logic.feature.conversation.IsInteractionAvailableResult | ||
| import com.wire.kalium.logic.feature.conversation.MarkConversationAsReadLocallyUseCase | ||
| import com.wire.kalium.logic.feature.conversation.MembersToMentionUseCase | ||
| import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase | ||
| import com.wire.kalium.logic.feature.conversation.ObserveConversationInteractionAvailabilityUseCase | ||
| import com.wire.kalium.logic.feature.conversation.MarkConversationAsReadLocallyUseCase | ||
| import com.wire.kalium.logic.feature.conversation.SendTypingEventUseCase | ||
| import com.wire.kalium.logic.feature.conversation.UpdateConversationReadDateUseCase | ||
| import com.wire.kalium.logic.feature.message.ephemeral.EnqueueMessageSelfDeletionUseCase | ||
| import com.wire.kalium.logic.feature.selfDeletingMessages.PersistNewSelfDeletionTimerUseCase | ||
| import com.wire.kalium.logic.feature.session.CurrentSessionFlowUseCase | ||
| import com.wire.kalium.logic.feature.session.CurrentSessionResult | ||
| import com.wire.kalium.logic.feature.user.IsFileSharingEnabledUseCase | ||
| import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.NonCancellable | ||
| import kotlinx.coroutines.flow.collectLatest | ||
| import kotlinx.coroutines.flow.combine | ||
| import kotlinx.coroutines.flow.distinctUntilChanged | ||
| import kotlinx.coroutines.flow.filterIsInstance | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.flatMapLatest | ||
| import kotlinx.coroutines.flow.flowOf | ||
|
|
@@ -74,6 +80,8 @@ class MessageComposerViewModel @Inject constructor( | |
| val savedStateHandle: SavedStateHandle, | ||
| private val dispatchers: DispatcherProvider, | ||
| private val isFileSharingEnabled: IsFileSharingEnabledUseCase, | ||
| private val observeConversationDetails: ObserveConversationDetailsUseCase, | ||
| private val observeSelfUser: ObserveSelfUserUseCase, | ||
| private val observeConversationInteractionAvailability: ObserveConversationInteractionAvailabilityUseCase, | ||
| private val updateConversationReadDate: UpdateConversationReadDateUseCase, | ||
| private val markConversationAsReadLocally: MarkConversationAsReadLocallyUseCase, | ||
|
|
@@ -116,6 +124,7 @@ class MessageComposerViewModel @Inject constructor( | |
| initTempWritableImageUri() | ||
| observeIsTypingAvailable() | ||
| setFileSharingStatus() | ||
| observeAttachmentOptionsAvailability() | ||
| getEnterToSendState() | ||
| observeCallState() | ||
| } | ||
|
|
@@ -199,6 +208,38 @@ class MessageComposerViewModel @Inject constructor( | |
| } | ||
| } | ||
|
|
||
| private fun observeAttachmentOptionsAvailability() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we disable attachment options, should we also disable sharing files into this conversation from other apps?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be better to to add a real restriction on the logic level to make sure we do not depend on the enabled/disabled button states. |
||
| viewModelScope.launch { | ||
|
|
||
| combine( | ||
| observeSelfUser().distinctUntilChanged(), | ||
| observeConversationDetails(conversationId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observing all conversations details just for reading two fields (wireCell and teamId) is probably an overkill. |
||
| .filterIsInstance<ObserveConversationDetailsUseCase.Result.Success>() | ||
| .map { it.conversationDetails } | ||
| .distinctUntilChanged(), | ||
| ) { selfUser, conversationDetails -> | ||
| canUseAttachmentOptions( | ||
| selfUser = selfUser, | ||
| conversationDetails = conversationDetails, | ||
| ) | ||
| }.collectLatest { areAttachmentOptionsEnabled -> | ||
| messageComposerViewState.value = messageComposerViewState.value.copy( | ||
| areAttachmentOptionsEnabled = areAttachmentOptionsEnabled | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun canUseAttachmentOptions( | ||
| selfUser: SelfUser, | ||
| conversationDetails: ConversationDetails, | ||
| ): Boolean { | ||
| val isCellsConversation = (conversationDetails as? ConversationDetails.Group)?.wireCell != null | ||
| val isConversationOwnedBySelfTeam = conversationDetails.conversation.teamId == selfUser.teamId | ||
|
|
||
| return !(isCellsConversation && !isConversationOwnedBySelfTeam) | ||
| } | ||
|
|
||
| fun updateConversationReadDate(utcISO: String) { | ||
| val instant = Instant.parse(utcISO) | ||
| lastReadInstant = instant | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,8 +388,13 @@ fun EnabledMessageComposer( | |
| additionalOptionStateHolder.toRichTextEditing() | ||
| }, | ||
| onCloseRichEditingButtonClicked = additionalOptionStateHolder::toAttachmentAndAdditionalOptionsMenu, | ||
| onDrawingModeClicked = openDrawingCanvas, | ||
| isFileSharingEnabled = messageComposerViewState.value.isFileSharingEnabled | ||
| onDrawingModeClicked = { | ||
| if (messageComposerViewState.value.areAttachmentOptionsEnabled) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for an extra condition here since the button will be disabled when areAttachmentOptionsEnabled == false |
||
| openDrawingCanvas() | ||
| } | ||
| }, | ||
| isFileSharingEnabled = messageComposerViewState.value.isFileSharingEnabled, | ||
| areAttachmentOptionsEnabled = messageComposerViewState.value.areAttachmentOptionsEnabled, | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -453,6 +458,7 @@ fun EnabledMessageComposer( | |
| AdditionalOptionSubMenu( | ||
| optionsVisible = inputStateHolder.optionsVisible, | ||
| isFileSharingEnabled = messageComposerViewState.value.isFileSharingEnabled, | ||
| areAttachmentOptionsEnabled = messageComposerViewState.value.areAttachmentOptionsEnabled, | ||
| additionalOptionsState = additionalOptionStateHolder.additionalOptionsSubMenuState, | ||
| onRecordAudioMessageClicked = { | ||
| if (!messageComposerViewState.value.isCallOngoing) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not aware of this "Viewers profile" feature but it seems like this does not allow uploading to user from other team. This is a clear business logic and must be placed into kalium use case.