Skip to content

Commit

Permalink
restrict user to open and download content if it's consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Aug 21, 2024
1 parent 5b4a0e2 commit 1b8a3c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ lint/reports/
/gradle/libs.versions_app.toml
app/google-services_1.json
app/google-services_2.json
/alfresco-auth/
/gradle/libs.versions-app.toml
/gradle/libs.versions-other.toml
/build-app.gradle
/build-other.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ class ContextualActionsBarFragment : Fragment(), MavericksView, EntryListener {
}

override fun invalidate() = withState(viewModel) {
it.entries.first().let { entry ->
(requireActivity() as AppCompatActivity).supportActionBar?.title = entry.name
}
val entry = it.entries.first()

(requireActivity() as AppCompatActivity).supportActionBar?.title = entry.name

view.removeAllViews()
addButtons(view, it.topActions)
addButtons(view, it.topActions, entry)
}

private fun addButtons(container: LinearLayout, actions: List<Action>) {
private fun addButtons(container: LinearLayout, actions: List<Action>, entry: Entry) {
container.addView(createSeparator())

for (action in actions) {
container.addView(createButton(action))
container.addView(createSeparator())
if (action !is ActionDownload || entry.canCreateUpdate) {
container.addView(createButton(action))
container.addView(createSeparator())
}
}

if (actions.isNotEmpty()) {
container.addView(createMoreButton())
container.addView(createSeparator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ContextualActionsViewModel(
listOf(if (entry.isFavorite) ActionRemoveFavorite(entry) else ActionAddFavorite(entry))

private fun externalActionsFor(entry: Entry) =
if (entry.isFile) {
if (entry.isFile && entry.canCreateUpdate) {
listOf(ActionOpenWith(entry), ActionDownload(entry))
} else {
listOf()
Expand Down
12 changes: 12 additions & 0 deletions data/src/main/kotlin/com/alfresco/content/data/Entry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ data class Entry(
@Transient
val canCreate: Boolean = false,
@Transient
val canCreateUpdate: Boolean = false,
@Transient
val isTrashed: Boolean = false,
@Transient
val otherId: String? = null,
Expand Down Expand Up @@ -193,6 +195,7 @@ data class Entry(
node.isFavorite ?: false,
canDelete(node.allowableOperations),
canCreate(node.allowableOperations),
canCreateUpdate = canCreateUpdate(node.allowableOperations),
).withOfflineStatus()
}

Expand All @@ -210,6 +213,7 @@ data class Entry(
result.isFavorite ?: false,
canDelete(result.allowableOperations),
canCreate(result.allowableOperations),
canCreateUpdate = canCreateUpdate(result.allowableOperations),
parentPaths = result.path?.elements?.map { it.id!! }?.toMutableList() ?: mutableListOf(),
).withOfflineStatus()
}
Expand All @@ -231,6 +235,7 @@ data class Entry(
result.isFavorite ?: false,
canDelete(result.allowableOperations),
canCreate(result.allowableOperations),
canCreateUpdate = canCreateUpdate(result.allowableOperations),
isExtension = isExtension,
parentPaths = result.path?.elements?.map { it.id!! }?.toMutableList() ?: mutableListOf(),
).withOfflineStatus()
Expand All @@ -250,6 +255,7 @@ data class Entry(
node.isFavorite ?: false,
canDelete(node.allowableOperations),
canCreate(node.allowableOperations),
canCreateUpdate = canCreateUpdate(node.allowableOperations),
otherId = node.properties?.get("cm:destination") as String?,
).withOfflineStatus()
}
Expand All @@ -271,6 +277,7 @@ data class Entry(
node.isFavorite ?: false,
canDelete(node.allowableOperations),
canCreate(node.allowableOperations),
canCreateUpdate = canCreateUpdate(node.allowableOperations),
otherId = node.properties?.get("cm:destination") as String?,
isExtension = isExtension,
).withOfflineStatus()
Expand All @@ -292,6 +299,7 @@ data class Entry(
file.allowableOperations == null,
true,
canDelete(favorite.allowableOperations),
canCreateUpdate = canCreateUpdate(favorite.allowableOperations),
).withOfflineStatus()
}
if (map.folder != null) {
Expand All @@ -309,6 +317,7 @@ data class Entry(
true,
canDelete(favorite.allowableOperations),
canCreate(favorite.allowableOperations),
canCreateUpdate = canCreateUpdate(favorite.allowableOperations),
).withOfflineStatus()
}
if (map.site != null) {
Expand Down Expand Up @@ -502,6 +511,9 @@ data class Entry(
private fun canCreate(operations: List<String>?) =
operations?.contains("create") ?: false

private fun canCreateUpdate(operations: List<String>?) =
listOf("create", "update").any { operations?.contains(it) == true }

private fun propertiesCompat(src: Map<String, Any?>?): MutableMap<String, String> {
val map = mutableMapOf<String, String>()

Expand Down

0 comments on commit 1b8a3c2

Please sign in to comment.