Skip to content

Commit

Permalink
Merge pull request #816 from Infomaniak/update-drive-user-with-deprec…
Browse files Browse the repository at this point in the history
…ated-type

remove deprecated type in DriveUJser and UserFileAccess and add role …
  • Loading branch information
JorisBodin authored Jun 23, 2022
2 parents eac9bdb + 007ee7f commit 42a65c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
25 changes: 17 additions & 8 deletions app/src/main/java/com/infomaniak/drive/data/models/DriveUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,36 @@ package com.infomaniak.drive.data.models
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.infomaniak.lib.core.models.user.User
import com.infomaniak.lib.core.utils.Utils.enumValueOfOrNull
import com.infomaniak.lib.core.utils.firstOrEmpty
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import kotlinx.android.parcel.Parcelize

@Parcelize
open class DriveUser(
@PrimaryKey override var id: Int = -1,
@PrimaryKey final override var id: Int = -1,
@SerializedName("avatar_url")
var avatarUrl: String? = "",
@SerializedName("display_name")
var displayName: String = "",
var avatar: String = "",
var email: String = "",
var type: String = "",

@SerializedName("role")
private var _role: String = "",
/** Never used */
override var right: String = "",
) : RealmObject(), Parcelable, Shareable {

val role get() = enumValueOfOrNull<Role>(_role)

inline val isExternalUser get() = role == Role.EXTERNAL

constructor(user: User) : this() {
id = user.id
displayName = user.displayName ?: ""
}

fun isExternalUser(): Boolean = type == Type.SHARED.value

fun getUserAvatar() = avatar.ifBlank { avatarUrl.toString() }

fun getInitials(): String {
Expand All @@ -57,8 +60,14 @@ open class DriveUser(
}
}

enum class Type(val value: String) {
MAIN("main"),
SHARED("shared")
enum class Role {
@SerializedName("admin")
ADMIN,

@SerializedName("user")
USER,

@SerializedName("external")
EXTERNAL
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/infomaniak/drive/data/models/Share.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ data class Share(
var status: UserFileAccessStatus,
var email: String = "",
var user: DriveUser? = null,
var type: String = ""
var role: DriveUser.Role,
) : Parcelable, Shareable {

fun isExternalUser(): Boolean = type == DriveUser.Type.SHARED.value
inline val isExternalUser get() = role == DriveUser.Role.EXTERNAL

enum class UserFileAccessStatus {
/** User has access to the Drive */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class FileShareDetailsFragment : Fragment() {
private fun openSelectPermissionDialog(shareable: Shareable) {

val permissionsGroup = when {
shareable is Invitation || (shareable is DriveUser && shareable.isExternalUser()) -> PermissionsGroup.EXTERNAL_USERS_RIGHTS
shareable is Invitation || (shareable is DriveUser && shareable.isExternalUser) -> PermissionsGroup.EXTERNAL_USERS_RIGHTS
else -> PermissionsGroup.USERS_RIGHTS
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SharedItemsAdapter(
rightsValue.setText(userFileAccess.getFilePermission().translation)

externalUserLabel.apply {
if (userFileAccess.isExternalUser()) {
if (userFileAccess.isExternalUser) {
text = context.getString(
if (userFileAccess.status == UserFileAccess.UserFileAccessStatus.PENDING) R.string.shareUserNotAccepted
else R.string.shareUserExternal
Expand Down

0 comments on commit 42a65c3

Please sign in to comment.