mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2911 All Content | User permissions (#1645)
This commit is contained in:
parent
90e51668b3
commit
b55a15334a
6 changed files with 50 additions and 17 deletions
|
@ -126,7 +126,8 @@ sealed class UiContentItem {
|
|||
val layout: ObjectType.Layout? = null,
|
||||
val icon: ObjectIcon = ObjectIcon.None,
|
||||
val lastModifiedDate: Long = 0L,
|
||||
val createdDate: Long = 0L
|
||||
val createdDate: Long = 0L,
|
||||
val isPossibleToDelete: Boolean = false
|
||||
) : UiContentItem()
|
||||
|
||||
data class Type(
|
||||
|
@ -199,15 +200,17 @@ fun Key?.mapRelationKeyToSort(): AllContentSort {
|
|||
fun List<ObjectWrapper.Basic>.toUiContentItems(
|
||||
space: SpaceId,
|
||||
urlBuilder: UrlBuilder,
|
||||
objectTypes: List<ObjectWrapper.Type>
|
||||
objectTypes: List<ObjectWrapper.Type>,
|
||||
isOwnerOrEditor: Boolean
|
||||
): List<UiContentItem.Item> {
|
||||
return map { it.toAllContentItem(space, urlBuilder, objectTypes) }
|
||||
return map { it.toAllContentItem(space, urlBuilder, objectTypes, isOwnerOrEditor) }
|
||||
}
|
||||
|
||||
fun ObjectWrapper.Basic.toAllContentItem(
|
||||
space: SpaceId,
|
||||
urlBuilder: UrlBuilder,
|
||||
objectTypes: List<ObjectWrapper.Type>
|
||||
objectTypes: List<ObjectWrapper.Type>,
|
||||
isOwnerOrEditor: Boolean
|
||||
): UiContentItem.Item {
|
||||
val obj = this
|
||||
val typeUrl = obj.getProperType()
|
||||
|
@ -233,18 +236,21 @@ fun ObjectWrapper.Basic.toAllContentItem(
|
|||
builder = urlBuilder
|
||||
),
|
||||
lastModifiedDate = DateParser.parse(obj.getValue(Relations.LAST_MODIFIED_DATE)) ?: 0L,
|
||||
createdDate = DateParser.parse(obj.getValue(Relations.CREATED_DATE)) ?: 0L
|
||||
createdDate = DateParser.parse(obj.getValue(Relations.CREATED_DATE)) ?: 0L,
|
||||
isPossibleToDelete = isOwnerOrEditor
|
||||
)
|
||||
}
|
||||
|
||||
fun List<ObjectWrapper.Basic>.toUiContentTypes(
|
||||
urlBuilder: UrlBuilder
|
||||
urlBuilder: UrlBuilder,
|
||||
isOwnerOrEditor: Boolean
|
||||
): List<UiContentItem.Type> {
|
||||
return map { it.toAllContentType(urlBuilder) }
|
||||
return map { it.toAllContentType(urlBuilder, isOwnerOrEditor) }
|
||||
}
|
||||
|
||||
fun ObjectWrapper.Basic.toAllContentType(
|
||||
urlBuilder: UrlBuilder,
|
||||
isOwnerOrEditor: Boolean
|
||||
): UiContentItem.Type {
|
||||
val obj = this
|
||||
val layout = layout ?: ObjectType.Layout.BASIC
|
||||
|
@ -258,16 +264,18 @@ fun ObjectWrapper.Basic.toAllContentType(
|
|||
),
|
||||
sourceObject = obj.map[SOURCE_OBJECT]?.toString(),
|
||||
uniqueKey = obj.uniqueKey,
|
||||
readOnly = obj.restrictions.contains(ObjectRestriction.DELETE),
|
||||
readOnly = obj.restrictions.contains(ObjectRestriction.DELETE) || !isOwnerOrEditor,
|
||||
editable = !obj.restrictions.contains(ObjectRestriction.DETAILS)
|
||||
)
|
||||
}
|
||||
|
||||
fun List<ObjectWrapper.Basic>.toUiContentRelations(): List<UiContentItem.Relation> {
|
||||
return map { it.toAllContentRelation() }
|
||||
fun List<ObjectWrapper.Basic>.toUiContentRelations(isOwnerOrEditor: Boolean): List<UiContentItem.Relation> {
|
||||
return map { it.toAllContentRelation(isOwnerOrEditor) }
|
||||
}
|
||||
|
||||
fun ObjectWrapper.Basic.toAllContentRelation(): UiContentItem.Relation {
|
||||
fun ObjectWrapper.Basic.toAllContentRelation(
|
||||
isOwnerOrEditor: Boolean
|
||||
): UiContentItem.Relation {
|
||||
val relation = ObjectWrapper.Relation(map)
|
||||
val obj = this
|
||||
return UiContentItem.Relation(
|
||||
|
@ -275,7 +283,7 @@ fun ObjectWrapper.Basic.toAllContentRelation(): UiContentItem.Relation {
|
|||
name = obj.name.orEmpty(),
|
||||
format = relation.format,
|
||||
sourceObject = map[SOURCE_OBJECT]?.toString(),
|
||||
readOnly = obj.restrictions.contains(ObjectRestriction.DELETE),
|
||||
readOnly = obj.restrictions.contains(ObjectRestriction.DELETE) || !isOwnerOrEditor,
|
||||
editable = !obj.restrictions.contains(ObjectRestriction.DETAILS)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.anytypeio.anytype.domain.base.fold
|
|||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.LocaleProvider
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
|
||||
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
|
||||
|
@ -75,6 +76,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onCompletion
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
@ -100,7 +102,8 @@ class AllContentViewModel(
|
|||
private val createObject: CreateObject,
|
||||
private val setObjectListIsArchived: SetObjectListIsArchived,
|
||||
private val setObjectDetails: SetObjectDetails,
|
||||
private val removeObjectsFromWorkspace: RemoveObjectsFromWorkspace
|
||||
private val removeObjectsFromWorkspace: RemoveObjectsFromWorkspace,
|
||||
private val userPermissionProvider: UserPermissionProvider
|
||||
) : ViewModel(), AnalyticSpaceHelperDelegate by analyticSpaceHelperDelegate {
|
||||
|
||||
private val searchResultIds = MutableStateFlow<List<Id>>(emptyList())
|
||||
|
@ -135,11 +138,24 @@ class AllContentViewModel(
|
|||
|
||||
private var shouldScrollToTopItems = false
|
||||
|
||||
private val permission = MutableStateFlow(userPermissionProvider.get(vmParams.spaceId))
|
||||
|
||||
init {
|
||||
Timber.d("AllContentViewModel init, spaceId:[${vmParams.spaceId.id}]")
|
||||
setupInitialStateParams()
|
||||
setupSearchStateFlow()
|
||||
setupMenuFlow()
|
||||
proceedWithObservingPermissions()
|
||||
}
|
||||
|
||||
private fun proceedWithObservingPermissions() {
|
||||
viewModelScope.launch {
|
||||
userPermissionProvider
|
||||
.observe(space = vmParams.spaceId)
|
||||
.collect {
|
||||
permission.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupInitialStateParams() {
|
||||
|
@ -263,13 +279,16 @@ class AllContentViewModel(
|
|||
return when (activeTab) {
|
||||
AllContentTab.TYPES -> {
|
||||
val items = objectWrappers.toUiContentTypes(
|
||||
urlBuilder = urlBuilder
|
||||
urlBuilder = urlBuilder,
|
||||
isOwnerOrEditor = permission.value?.isOwnerOrEditor() == true
|
||||
)
|
||||
items
|
||||
}
|
||||
|
||||
AllContentTab.RELATIONS -> {
|
||||
val items = objectWrappers.toUiContentRelations()
|
||||
val items = objectWrappers.toUiContentRelations(
|
||||
isOwnerOrEditor = permission.value?.isOwnerOrEditor() == true
|
||||
)
|
||||
items
|
||||
}
|
||||
|
||||
|
@ -277,7 +296,8 @@ class AllContentViewModel(
|
|||
val items = objectWrappers.toUiContentItems(
|
||||
space = vmParams.spaceId,
|
||||
urlBuilder = urlBuilder,
|
||||
objectTypes = storeOfObjectTypes.getAll()
|
||||
objectTypes = storeOfObjectTypes.getAll(),
|
||||
isOwnerOrEditor = permission.value?.isOwnerOrEditor() == true
|
||||
)
|
||||
val result = when (activeSort) {
|
||||
is AllContentSort.ByDateCreated -> {
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.anytypeio.anytype.domain.all_content.UpdateAllContentState
|
|||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.LocaleProvider
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
|
||||
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
|
||||
|
@ -33,6 +34,7 @@ class AllContentViewModelFactory @Inject constructor(
|
|||
private val setObjectListIsArchived: SetObjectListIsArchived,
|
||||
private val setObjectDetails: SetObjectDetails,
|
||||
private val removeObjectsFromWorkspace: RemoveObjectsFromWorkspace,
|
||||
private val userPermissionProvider: UserPermissionProvider
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T =
|
||||
|
@ -51,5 +53,6 @@ class AllContentViewModelFactory @Inject constructor(
|
|||
setObjectListIsArchived = setObjectListIsArchived,
|
||||
setObjectDetails = setObjectDetails,
|
||||
removeObjectsFromWorkspace = removeObjectsFromWorkspace,
|
||||
userPermissionProvider = userPermissionProvider
|
||||
) as T
|
||||
}
|
|
@ -793,6 +793,7 @@ fun SwipeToDismissListItems(
|
|||
SwipeToDismissBox(
|
||||
modifier = modifier,
|
||||
state = dismissState,
|
||||
enableDismissFromEndToStart = item.isPossibleToDelete,
|
||||
enableDismissFromStartToEnd = false,
|
||||
backgroundContent = {
|
||||
DismissBackground(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue