Merge pull request #4001 from vector-im/feature/bca/spaces_fix_invite_private

Change default power to invite in private space + setting
This commit is contained in:
Valere 2021-09-15 19:16:50 +02:00 committed by GitHub
commit bb459a6e5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 131 additions and 32 deletions

1
changelog.d/3951.bugfix Normal file
View file

@ -0,0 +1 @@
"Non-Admin" user able to invite others to Private Space (by default)

View file

@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.powerlevels.Role
import org.matrix.android.sdk.api.session.space.CreateSpaceParams
import org.matrix.android.sdk.api.session.space.JoinSpaceResult
import org.matrix.android.sdk.api.session.space.Space
@ -77,7 +78,7 @@ internal class DefaultSpaceService @Inject constructor(
if (isPublic) {
this.roomAliasName = roomAliasLocalPart
this.powerLevelContentOverride = (powerLevelContentOverride ?: PowerLevelsContent()).copy(
invite = 0
invite = if (isPublic) Role.Default.value else Role.Moderator.value
)
this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT
this.historyVisibility = RoomHistoryVisibility.WORLD_READABLE

View file

@ -23,9 +23,12 @@ import org.matrix.android.sdk.api.session.events.model.EventType
/**
* Change on each permission has an effect on the power level event. Try to sort the effect by category.
*/
sealed class EditablePermission(@StringRes val labelResId: Int) {
sealed class EditablePermission(@StringRes val labelResId: Int, @StringRes val spaceLabelResId: Int = labelResId) {
// Updates `content.events.[eventType]`
open class EventTypeEditablePermission(val eventType: String, @StringRes labelResId: Int) : EditablePermission(labelResId)
open class EventTypeEditablePermission(val eventType: String,
@StringRes labelResId: Int,
@StringRes spaceLabelResId: Int = labelResId
) : EditablePermission(labelResId, spaceLabelResId)
class ModifyWidgets : EventTypeEditablePermission(
// Note: Element Web still use legacy value
@ -35,17 +38,20 @@ sealed class EditablePermission(@StringRes val labelResId: Int) {
class ChangeRoomAvatar : EventTypeEditablePermission(
EventType.STATE_ROOM_AVATAR,
R.string.room_permissions_change_room_avatar
R.string.room_permissions_change_room_avatar,
R.string.room_permissions_change_space_avatar
)
class ChangeMainAddressForTheRoom : EventTypeEditablePermission(
EventType.STATE_ROOM_CANONICAL_ALIAS,
R.string.room_permissions_change_main_address_for_the_room
R.string.room_permissions_change_main_address_for_the_room,
R.string.room_permissions_change_main_address_for_the_space
)
class EnableRoomEncryption : EventTypeEditablePermission(
EventType.STATE_ROOM_ENCRYPTION,
R.string.room_permissions_enable_room_encryption
R.string.room_permissions_enable_room_encryption,
R.string.room_permissions_enable_space_encryption
)
class ChangeHistoryVisibility : EventTypeEditablePermission(
@ -55,7 +61,8 @@ sealed class EditablePermission(@StringRes val labelResId: Int) {
class ChangeRoomName : EventTypeEditablePermission(
EventType.STATE_ROOM_NAME,
R.string.room_permissions_change_room_name
R.string.room_permissions_change_room_name,
R.string.room_permissions_change_space_name
)
class ChangePermissions : EventTypeEditablePermission(
@ -70,7 +77,8 @@ sealed class EditablePermission(@StringRes val labelResId: Int) {
class UpgradeTheRoom : EventTypeEditablePermission(
EventType.STATE_ROOM_TOMBSTONE,
R.string.room_permissions_upgrade_the_room
R.string.room_permissions_upgrade_the_room,
R.string.room_permissions_upgrade_the_space
)
class ChangeTopic : EventTypeEditablePermission(

View file

@ -26,6 +26,7 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.features.discovery.settingsInfoItem
import im.vector.app.features.form.formAdvancedToggleItem
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
import org.matrix.android.sdk.api.session.room.model.RoomType
import org.matrix.android.sdk.api.session.room.model.banOrDefault
import org.matrix.android.sdk.api.session.room.model.eventsDefaultOrDefault
import org.matrix.android.sdk.api.session.room.model.inviteOrDefault
@ -57,6 +58,13 @@ class RoomPermissionsController @Inject constructor(
EditablePermission.ChangeTopic()
)
private val usefulEditablePermissionsForSpace = listOf(
EditablePermission.ChangeRoomAvatar(),
EditablePermission.ChangeRoomName(),
EditablePermission.ChangeTopic(),
EditablePermission.InviteUsers()
)
private val advancedEditablePermissions = listOf(
EditablePermission.ChangeMainAddressForTheRoom(),
@ -79,6 +87,27 @@ class RoomPermissionsController @Inject constructor(
EditablePermission.UpgradeTheRoom()
)
private val advancedEditablePermissionsForSpace = listOf(
EditablePermission.ChangeMainAddressForTheRoom(),
EditablePermission.DefaultRole(),
EditablePermission.KickUsers(),
EditablePermission.BanUsers(),
EditablePermission.SendMessages(),
EditablePermission.RemoveMessagesSentByOthers(),
EditablePermission.NotifyEveryone(),
EditablePermission.ChangeSettings(),
// EditablePermission.ModifyWidgets(),
EditablePermission.ChangeHistoryVisibility(),
EditablePermission.ChangePermissions(),
EditablePermission.SendRoomServerAclEvents(),
// EditablePermission.EnableRoomEncryption(),
EditablePermission.UpgradeTheRoom()
)
init {
setData(null)
}
@ -103,13 +132,24 @@ class RoomPermissionsController @Inject constructor(
private fun buildPermissions(data: RoomPermissionsViewState, content: PowerLevelsContent) {
val host = this
val editable = data.actionPermissions.canChangePowerLevels
val isSpace = data.roomSummary.invoke()?.roomType == RoomType.SPACE
settingsInfoItem {
id("notice")
helperText(host.stringProvider.getString(if (editable) R.string.room_permissions_notice else R.string.room_permissions_notice_read_only))
helperText(host.stringProvider.getString(
if (editable) {
if (isSpace) R.string.space_permissions_notice else R.string.room_permissions_notice
} else {
if (isSpace) R.string.space_permissions_notice_read_only else R.string.room_permissions_notice_read_only
}))
}
// Useful permissions
usefulEditablePermissions.forEach { buildPermission(it, content, editable) }
if (isSpace) {
usefulEditablePermissionsForSpace.forEach { buildPermission(it, content, editable, true) }
} else {
usefulEditablePermissions.forEach { buildPermission(it, content, editable, false) }
}
// Toggle
formAdvancedToggleItem {
@ -121,15 +161,24 @@ class RoomPermissionsController @Inject constructor(
// Advanced permissions
if (data.showAdvancedPermissions) {
advancedEditablePermissions.forEach { buildPermission(it, content, editable) }
if (isSpace) {
advancedEditablePermissionsForSpace.forEach { buildPermission(it, content, editable, true) }
} else {
advancedEditablePermissions.forEach { buildPermission(it, content, editable, false) }
}
}
}
private fun buildPermission(editablePermission: EditablePermission, content: PowerLevelsContent, editable: Boolean) {
private fun buildPermission(editablePermission: EditablePermission,
content: PowerLevelsContent,
editable: Boolean,
isSpace: Boolean) {
val currentRole = getCurrentRole(editablePermission, content)
buildProfileAction(
id = editablePermission.labelResId.toString(),
title = stringProvider.getString(editablePermission.labelResId),
title = stringProvider.getString(
if (isSpace) editablePermission.spaceLabelResId else editablePermission.labelResId
),
subtitle = roleFormatter.format(currentRole),
divider = true,
editable = editable,

View file

@ -35,6 +35,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomPreset
import org.matrix.android.sdk.api.session.room.model.create.RestrictedRoomPreset
import org.matrix.android.sdk.api.session.room.powerlevels.Role
import org.matrix.android.sdk.api.session.space.CreateSpaceParams
import timber.log.Timber
import javax.inject.Inject
@ -73,7 +75,7 @@ class CreateSpaceViewModelTask @Inject constructor(
if (params.isPublic) {
this.roomAliasName = params.spaceAlias
this.powerLevelContentOverride = (powerLevelContentOverride ?: PowerLevelsContent()).copy(
invite = 0
invite = Role.Default.value
)
this.preset = CreateRoomPreset.PRESET_PUBLIC_CHAT
this.historyVisibility = RoomHistoryVisibility.WORLD_READABLE
@ -86,6 +88,9 @@ class CreateSpaceViewModelTask @Inject constructor(
ThreePid.Email(it)
}
)
this.powerLevelContentOverride = (powerLevelContentOverride ?: PowerLevelsContent()).copy(
invite = Role.Moderator.value
)
}
})
} catch (failure: Throwable) {

View file

@ -20,12 +20,12 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Parcelable
import com.google.android.material.appbar.MaterialToolbar
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.airbnb.mvrx.MvRx
import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState
import com.google.android.material.appbar.MaterialToolbar
import im.vector.app.R
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.extensions.addFragmentToBackstack
@ -40,6 +40,7 @@ import im.vector.app.features.roomdirectory.createroom.CreateRoomArgs
import im.vector.app.features.roomdirectory.createroom.CreateRoomFragment
import im.vector.app.features.roomprofile.RoomProfileArgs
import im.vector.app.features.roomprofile.alias.RoomAliasFragment
import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment
import kotlinx.parcelize.Parcelize
import javax.inject.Inject
@ -165,6 +166,14 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(),
)
}
}
SpaceManagedSharedViewEvents.NavigateToPermissionSettings -> {
args?.spaceId?.let { spaceId ->
addFragmentToBackstack(
R.id.simpleFragmentContainer, RoomPermissionsFragment::class.java,
RoomProfileArgs(spaceId)
)
}
}
}
}
}

View file

@ -57,6 +57,7 @@ class SpaceManageSharedViewModel @AssistedInject constructor(
SpaceManagedSharedAction.CreateRoom -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToCreateRoom)
SpaceManagedSharedAction.ManageRooms -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToManageRooms)
SpaceManagedSharedAction.OpenSpaceAliasesSettings -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToAliasSettings)
SpaceManagedSharedAction.OpenSpacePermissionSettings -> _viewEvents.post(SpaceManagedSharedViewEvents.NavigateToPermissionSettings)
}
}
}

View file

@ -25,4 +25,5 @@ sealed class SpaceManagedSharedAction : VectorViewModelAction {
object CreateRoom : SpaceManagedSharedAction()
object ManageRooms : SpaceManagedSharedAction()
object OpenSpaceAliasesSettings : SpaceManagedSharedAction()
object OpenSpacePermissionSettings : SpaceManagedSharedAction()
}

View file

@ -25,4 +25,5 @@ sealed class SpaceManagedSharedViewEvents : VectorViewEvents {
object NavigateToCreateRoom : SpaceManagedSharedViewEvents()
object NavigateToManageRooms : SpaceManagedSharedViewEvents()
object NavigateToAliasSettings : SpaceManagedSharedViewEvents()
object NavigateToPermissionSettings : SpaceManagedSharedViewEvents()
}

View file

@ -53,6 +53,7 @@ class SpaceSettingsController @Inject constructor(
fun onManageRooms()
fun setIsPublic(public: Boolean)
fun onRoomAliasesClicked()
fun onRoomPermissionsClicked()
}
var callback: Callback? = null
@ -134,7 +135,7 @@ class SpaceSettingsController @Inject constructor(
id = "manage_rooms",
title = stringProvider.getString(R.string.space_settings_manage_rooms),
// subtitle = data.getJoinRuleWording(stringProvider),
divider = vectorPreferences.developerMode() || isPublic,
divider = true,
editable = data.actionPermissions.canAddChildren,
action = {
if (data.actionPermissions.canAddChildren) callback?.onManageRooms()
@ -146,12 +147,21 @@ class SpaceSettingsController @Inject constructor(
id = "alias",
title = stringProvider.getString(R.string.space_settings_alias_title),
subtitle = stringProvider.getString(R.string.space_settings_alias_subtitle),
divider = vectorPreferences.developerMode(),
divider = true,
editable = true,
action = { callback?.onRoomAliasesClicked() }
)
}
buildProfileAction(
id = "permissions",
title = stringProvider.getString(R.string.space_settings_permissions_title),
subtitle = stringProvider.getString(R.string.space_settings_permissions_subtitle),
divider = vectorPreferences.developerMode(),
editable = true,
action = { callback?.onRoomPermissionsClicked() }
)
if (vectorPreferences.developerMode()) {
buildProfileAction(
id = "dev_tools",

View file

@ -237,6 +237,10 @@ class SpaceSettingsFragment @Inject constructor(
sharedViewModel.handle(SpaceManagedSharedAction.OpenSpaceAliasesSettings)
}
override fun onRoomPermissionsClicked() {
sharedViewModel.handle(SpaceManagedSharedAction.OpenSpacePermissionSettings)
}
override fun onImageReady(uri: Uri?) {
uri ?: return
viewModel.handle(

View file

@ -974,11 +974,15 @@
<!-- Room Permissions -->
<string name="room_settings_permissions_title">Room permissions</string>
<string name="space_settings_permissions_title">Space permissions</string>
<string name="room_settings_permissions_subtitle">View and update the roles required to change various parts of the room.</string>
<string name="space_settings_permissions_subtitle">View and update the roles required to change various parts of the space.</string>
<string name="room_permissions_title">"Permissions"</string>
<string name="room_permissions_notice">"Select the roles required to change various parts of the room"</string>
<string name="space_permissions_notice">"Select the roles required to change various parts of this space"</string>
<string name="room_permissions_notice_read_only">"You don't have permission to update the roles required to change various parts of the room"</string>
<string name="space_permissions_notice_read_only">"You don't have permission to update the roles required to change various parts of this space"</string>
<string name="room_permissions_default_role">Default role</string>
<string name="room_permissions_send_messages">Send messages</string>
@ -990,13 +994,18 @@
<string name="room_permissions_notify_everyone">Notify everyone</string>
<string name="room_permissions_modify_widgets">Modify widgets</string>
<string name="room_permissions_change_room_avatar">Change room avatar</string>
<string name="room_permissions_change_space_avatar">Change space avatar</string>
<string name="room_permissions_change_main_address_for_the_room">Change main address for the room</string>
<string name="room_permissions_change_main_address_for_the_space">Change main address for the space</string>
<string name="room_permissions_enable_room_encryption">Enable room encryption</string>
<string name="room_permissions_enable_space_encryption">Enable space encryption</string>
<string name="room_permissions_change_history_visibility">Change history visibility</string>
<string name="room_permissions_change_room_name">Change room name</string>
<string name="room_permissions_change_space_name">Change space name</string>
<string name="room_permissions_change_permissions">Change permissions</string>
<string name="room_permissions_send_m_room_server_acl_events">Send m.room.server_acl events</string>
<string name="room_permissions_upgrade_the_room">Upgrade the room</string>
<string name="room_permissions_upgrade_the_space">Upgrade the space</string>
<string name="room_permissions_change_topic">Change topic</string>
<!-- Room Details -->