Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[NEW] Manage Users in a Room(Add/Remove) #2351

Merged
merged 12 commits into from
Jul 8, 2019
Next Next commit
Check permission based on role of user
  • Loading branch information
Shailesh351 committed Jun 24, 2019
commit 129ecae981f3c2e99dde68e80668e35601d027f7
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ package chat.rocket.android.chatroom.presentation

import android.graphics.Bitmap
import android.net.Uri
import android.util.Log
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.analytics.AnalyticsManager
import chat.rocket.android.analytics.event.SubscriptionTypeEvent
@@ -23,17 +25,7 @@ import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.helper.MessageHelper
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.JobSchedulerInteractor
import chat.rocket.android.server.domain.MessagesRepository
import chat.rocket.android.server.domain.PermissionsInteractor
import chat.rocket.android.server.domain.PublicSettings
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.UsersRepository
import chat.rocket.android.server.domain.uploadMaxFileSize
import chat.rocket.android.server.domain.uploadMimeTypeFilter
import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.server.domain.*
Shailesh351 marked this conversation as resolved.
Show resolved Hide resolved
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.server.infrastructure.state
import chat.rocket.android.util.extension.getByteArray
@@ -179,6 +171,12 @@ class ChatRoomPresenter @Inject constructor(
done to either fix the load in speed of moderator roles or store the
information locally*/
if (getChatRole()) {

val canRemove = permissions.hasPermission(REMOVE_USER, chatRoles)

Log.d("PERM", chatRoles.toString())
Shailesh351 marked this conversation as resolved.
Show resolved Hide resolved
Log.d("PERM", canRemove.toString())

canModerate = isOwnerOrMod()
if (canModerate) {
//FIXME: add this in when moderator page is actually created
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package chat.rocket.android.server.domain

import android.util.Log
import chat.rocket.android.helper.UserHelper
import chat.rocket.core.model.ChatRoomRole
import javax.inject.Inject

// Creating rooms
private const val CREATE_PUBLIC_CHANNELS = "create-c"
private const val CREATE_DIRECT_MESSAGES = "create-d"
private const val CREATE_PRIVATE_CHANNELS = "create-p"

// Add/Remove user
const val REMOVE_USER = "remove-user"
const val ADD_USER_TO_JOINED_ROOM = "add-user-to-joined-room"
const val ADD_USER_TO_ANY_CHANNEL_ROOM = "add-user-to-any-c-room"
const val ADD_USER_TO_ANY_PRIVATE_ROOM = "add-user-to-any-p-room"

// Messages
private const val DELETE_MESSAGE = "delete-message"
private const val FORCE_DELETE_MESSAGE = "force-delete-message"
@@ -68,7 +76,6 @@ class PermissionsInteractor @Inject constructor(
} == true || userHelper.isAdmin()
}


fun isAdministrationEnabled(): Boolean {
currentServerUrl()?.let { serverUrl ->
val viewStatistics =
@@ -90,6 +97,29 @@ class PermissionsInteractor @Inject constructor(
return false
}

fun roles(permissionType: String): List<String>? {
val url = getCurrentServerInteractor.get()!!
var permissionRoles: List<String> = emptyList()

Log.d("PERM", permissionsRepository.get(url, permissionType).toString())
permissionsRepository.get(url, permissionType)?.let{
permission -> permissionRoles = permission.roles
}

return permissionRoles
}

fun hasPermission(permissionType: String, chatRoles: List<ChatRoomRole>): Boolean{
val permissionRoles = roles(permissionType)
val roles: List<String>? = chatRoles.firstOrNull { it.user.username == userHelper.username()}?.roles
Log.d("PERM", permissionRoles.toString())
return if (roles.isNullOrEmpty() || permissionRoles.isNullOrEmpty()){
false
} else {
roles.intersect(permissionRoles).isNotEmpty()
}
}

private fun currentServerUrl(): String? {
return getCurrentServerInteractor.get()
}