1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1977 Object | Fix | Human objects deletion is restricted (#574)

This commit is contained in:
Konstantin Ivanov 2023-11-20 14:12:12 +01:00 committed by uburoiubu
parent ad36c15038
commit db9c245038
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
10 changed files with 13 additions and 51 deletions

View file

@ -936,28 +936,11 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
isArchived = command.isArchived,
isFavorite = command.isFavorite,
isLocked = command.isLocked,
isProfile = false,
fromName = getFrom(),
isTemplate = command.isTemplate
)
fr.showChildFragment()
}
is Command.OpenProfileMenu -> {
hideKeyboard()
findNavController().safeNavigate(
R.id.pageScreen,
R.id.objectMainMenuScreen,
bundleOf(
ObjectMenuBaseFragment.CTX_KEY to ctx,
ObjectMenuBaseFragment.IS_ARCHIVED_KEY to false,
ObjectMenuBaseFragment.IS_FAVORITE_KEY to command.isFavorite,
ObjectMenuBaseFragment.IS_LOCKED_KEY to command.isLocked,
ObjectMenuBaseFragment.IS_PROFILE_KEY to true,
ObjectMenuBaseFragment.FROM_NAME to getFrom(),
ObjectMenuBaseFragment.IS_TEMPLATE_KEY to false
)
)
}
is Command.OpenCoverGallery -> {
findNavController().safeNavigate(
R.id.pageScreen,

View file

@ -44,7 +44,6 @@ abstract class ObjectMenuBaseFragment :
BacklinkAction {
protected val ctx get() = arg<Id>(CTX_KEY)
private val isProfile get() = arg<Boolean>(IS_PROFILE_KEY)
private val isArchived get() = arg<Boolean>(IS_ARCHIVED_KEY)
private val isFavorite get() = arg<Boolean>(IS_FAVORITE_KEY)
private val isLocked get() = arg<Boolean>(IS_LOCKED_KEY)
@ -98,7 +97,6 @@ abstract class ObjectMenuBaseFragment :
ctx = ctx,
isArchived = isArchived,
isFavorite = isFavorite,
isProfile = isProfile,
isLocked = isLocked,
isTemplate = isTemplate ?: false
)
@ -290,7 +288,6 @@ abstract class ObjectMenuBaseFragment :
companion object {
const val CTX_KEY = "arg.doc-menu-bottom-sheet.ctx"
const val IS_ARCHIVED_KEY = "arg.doc-menu-bottom-sheet.is-archived"
const val IS_PROFILE_KEY = "arg.doc-menu-bottom-sheet.is-profile"
const val IS_FAVORITE_KEY = "arg.doc-menu-bottom-sheet.is-favorite"
const val IS_LOCKED_KEY = "arg.doc-menu-bottom-sheet.is-locked"
const val FROM_NAME = "arg.doc-menu-bottom-sheet.from-name"

View file

@ -40,7 +40,6 @@ class ObjectMenuFragment : ObjectMenuBaseFragment() {
fun new(
ctx: Id,
isArchived: Boolean,
isProfile: Boolean,
isFavorite: Boolean,
isLocked: Boolean,
fromName: String?,
@ -49,7 +48,6 @@ class ObjectMenuFragment : ObjectMenuBaseFragment() {
arguments = bundleOf(
CTX_KEY to ctx,
IS_ARCHIVED_KEY to isArchived,
IS_PROFILE_KEY to isProfile,
IS_FAVORITE_KEY to isFavorite,
IS_LOCKED_KEY to isLocked,
FROM_NAME to fromName,

View file

@ -880,7 +880,6 @@ open class ObjectSetFragment :
ObjectMenuBaseFragment.CTX_KEY to command.ctx,
ObjectMenuBaseFragment.IS_ARCHIVED_KEY to command.isArchived,
ObjectMenuBaseFragment.IS_FAVORITE_KEY to command.isFavorite,
ObjectMenuBaseFragment.IS_PROFILE_KEY to false,
ObjectMenuBaseFragment.IS_LOCKED_KEY to false,
ObjectMenuBaseFragment.FROM_NAME to title.text.toString()
)

View file

@ -1456,17 +1456,8 @@ class EditorViewModel(
controlPanelInteractor.onEvent(ControlPanelMachine.Event.OnDocumentMenuClicked)
val details = orchestrator.stores.details.current().details
val wrapper = ObjectWrapper.Basic(details[context]?.map.orEmpty())
val isProfile = getObjectTypeUniqueKeyFromDetails() == ObjectTypeIds.PROFILE
val isTemplate = isObjectTemplate()
when {
isProfile -> {
dispatch(
command = Command.OpenProfileMenu(
isFavorite = details[context]?.isFavorite ?: false,
isLocked = mode == EditorMode.Locked
)
)
}
isTemplate -> {
dispatch(
command = Command.OpenDocumentMenu(

View file

@ -62,11 +62,6 @@ sealed class Command {
val isTemplate: Boolean
) : Command()
data class OpenProfileMenu(
val isFavorite: Boolean,
val isLocked: Boolean
) : Command()
data class OpenCoverGallery(val ctx: String) : Command()
data class OpenObjectLayout(val ctx: String) : Command()

View file

@ -76,7 +76,6 @@ class ObjectMenuViewModel(
ctx: Id,
isArchived: Boolean,
isFavorite: Boolean,
isProfile: Boolean,
isTemplate: Boolean
): List<ObjectAction> = buildList {
@ -87,10 +86,11 @@ class ObjectMenuViewModel(
add(ObjectAction.ADD_TO_FAVOURITE)
}
}
if (!isProfile) {
if (isArchived) {
add(ObjectAction.RESTORE)
} else {
if (isArchived) {
add(ObjectAction.RESTORE)
} else {
if (objectRestrictions.none { it == ObjectRestriction.DELETE }) {
add(ObjectAction.DELETE)
}
}
@ -99,7 +99,7 @@ class ObjectMenuViewModel(
add(ObjectAction.SET_AS_DEFAULT)
}
if (!isProfile && !objectRestrictions.contains(ObjectRestriction.DUPLICATE) && !isTemplate) {
if (!objectRestrictions.contains(ObjectRestriction.DUPLICATE) && !isTemplate) {
add(ObjectAction.DUPLICATE)
}
@ -109,7 +109,7 @@ class ObjectMenuViewModel(
storage.details.current().details[objTypeId]?.let { objType ->
val objTypeWrapper = ObjectWrapper.Type(objType.map)
val isTemplateAllowed = objTypeWrapper.isTemplatesAllowed()
if (isTemplateAllowed && !isTemplate && !isProfile) {
if (isTemplateAllowed && !isTemplate) {
add(ObjectAction.USE_AS_TEMPLATE)
}
}

View file

@ -88,16 +88,14 @@ abstract class ObjectMenuViewModelBase(
ctx: Id,
isFavorite: Boolean,
isArchived: Boolean,
isProfile: Boolean,
isLocked: Boolean,
isTemplate: Boolean
) {
Timber.d("ObjectMenuViewModelBase, onStart, ctx:[$ctx], isFavorite:[$isFavorite], isArchived:[$isArchived], isProfile:[$isProfile], isLocked:[$isLocked]")
Timber.d("ObjectMenuViewModelBase, onStart, ctx:[$ctx], isFavorite:[$isFavorite], isArchived:[$isArchived], isLocked:[$isLocked]")
actions.value = buildActions(
ctx = ctx,
isArchived = isArchived,
isFavorite = isFavorite,
isProfile = isProfile,
isTemplate = isTemplate
)
jobs += viewModelScope.launch {
@ -111,7 +109,6 @@ abstract class ObjectMenuViewModelBase(
ctx: Id,
isArchived: Boolean,
isFavorite: Boolean,
isProfile: Boolean,
isTemplate: Boolean = false
): List<ObjectAction>

View file

@ -136,7 +136,6 @@ class ObjectSetMenuViewModel(
ctx: Id,
isArchived: Boolean,
isFavorite: Boolean,
isProfile: Boolean,
isTemplate: Boolean
): List<ObjectAction> = buildList {
if (isArchived) {

View file

@ -177,9 +177,12 @@ class EditorMenuTest : EditorPresentationTestSetup() {
vm.onDocumentMenuClicked()
observer.assertValue { value ->
value.peekContent() == Command.OpenProfileMenu(
value.peekContent() == Command.OpenDocumentMenu(
isFavorite = false,
isLocked = false
isLocked = false,
isArchived = false,
fromName = "",
isTemplate = false
)
}
}