Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
2dad9429
Commit
2dad9429
authored
Feb 08, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add permission checks to edit and pin
parent
a0869f09
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
15 deletions
+30
-15
ServerPresenter.kt
...oid/authentication/server/presentation/ServerPresenter.kt
+2
-1
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+12
-9
GetPermissionsInteractor.kt
.../rocket/android/server/domain/GetPermissionsInteractor.kt
+7
-2
SettingsRepository.kt
...a/chat/rocket/android/server/domain/SettingsRepository.kt
+4
-2
strings.xml
app/src/main/res/values-pt-rBR/strings.xml
+2
-0
strings.xml
app/src/main/res/values/strings.xml
+3
-1
No files found.
app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt
View file @
2dad9429
...
...
@@ -23,7 +23,8 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
private
var
settingsFilter
=
arrayOf
(
SITE_URL
,
SITE_NAME
,
FAVICON_512
,
USE_REALNAME
,
ALLOW_ROOM_NAME_SPECIAL_CHARS
,
FAVORITE_ROOMS
,
ACCOUNT_LOGIN_FORM
,
ACCOUNT_GOOGLE
,
ACCOUNT_FACEBOOK
,
ACCOUNT_GITHUB
,
ACCOUNT_GITLAB
,
ACCOUNT_LINKEDIN
,
ACCOUNT_METEOR
,
ACCOUNT_TWITTER
,
ACCOUNT_WORDPRESS
,
LDAP_ENABLE
,
ACCOUNT_REGISTRATION
,
STORAGE_TYPE
,
HIDE_USER_JOIN
,
HIDE_USER_LEAVE
,
HIDE_TYPE_AU
,
HIDE_MUTE_UNMUTE
,
HIDE_TYPE_RU
,
ACCOUNT_CUSTOM_FIELDS
,
ALLOW_MESSAGE_DELETING
,
ALLOW_MESSAGE_EDITING
,
SHOW_DELETED_STATUS
,
SHOW_EDITED_STATUS
)
HIDE_MUTE_UNMUTE
,
HIDE_TYPE_RU
,
ACCOUNT_CUSTOM_FIELDS
,
ALLOW_MESSAGE_DELETING
,
ALLOW_MESSAGE_EDITING
,
ALLOW_MESSAGE_PINNING
,
SHOW_DELETED_STATUS
,
SHOW_EDITED_STATUS
)
fun
connect
(
server
:
String
)
{
if
(!
UrlHelper
.
isValidUrl
(
server
))
{
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
2dad9429
...
...
@@ -18,7 +18,6 @@ import chat.rocket.core.internal.rest.*
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.cancel
import
kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
...
...
@@ -28,7 +27,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private
val
strategy
:
CancelStrategy
,
getSettingsInteractor
:
GetSettingsInteractor
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
getPermissionsInteractor
:
GetPermissionsInteractor
,
private
val
permissions
:
GetPermissionsInteractor
,
private
val
messagesRepository
:
MessagesRepository
,
factory
:
RocketChatClientFactory
,
private
val
mapper
:
MessageViewModelMapper
)
{
...
...
@@ -149,17 +148,16 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
*/
fun
deleteMessage
(
roomId
:
String
,
id
:
String
)
{
launchUI
(
strategy
)
{
if
(!
getPermissionsInteractor
.
isMessageDeletingAllowed
())
{
if
(!
permissions
.
allowedMessageDeleting
())
{
return
@launchUI
}
//TODO: Default delete message always to true. Until we have the permissions system
//implemented, a user will only be able to delete his own messages.
try
{
//TODO: Should honor permission 'Message_ShowDeletedStatus'
client
.
deleteMessage
(
roomId
,
id
,
true
)
// if Message_ShowDeletedStatus == true an update to that message will be dispatched.
// Otherwise we signalize that we just want the message removed.
if
(!
getPermissionsInteractor
.
showDeletedStatus
())
{
if
(!
permissions
.
showDeletedStatus
())
{
view
.
dispatchDeleteMessage
(
id
)
}
}
catch
(
e
:
RocketChatException
)
{
...
...
@@ -225,8 +223,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
*/
fun
editMessage
(
roomId
:
String
,
messageId
:
String
,
text
:
String
)
{
launchUI
(
strategy
)
{
if
(!
getPermissionsInteractor
.
isMessageEditingAllowed
())
{
coroutineContext
.
cancel
()
if
(!
permissions
.
allowedMessageEditing
())
{
view
.
showMessage
(
R
.
string
.
permission_editing_not_allowed
)
return
@launchUI
}
...
...
@@ -236,7 +233,10 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
fun
pinMessage
(
messageId
:
String
)
{
launchUI
(
strategy
)
{
//TODO: Check permissions.
if
(!
permissions
.
allowedMessagePinning
())
{
view
.
showMessage
(
R
.
string
.
permission_pinning_not_allowed
)
return
@launchUI
}
try
{
client
.
pinMessage
(
messageId
)
}
catch
(
e
:
RocketChatException
)
{
...
...
@@ -247,7 +247,10 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
fun
unpinMessage
(
messageId
:
String
)
{
launchUI
(
strategy
)
{
//TODO: Check permissions.
if
(!
permissions
.
allowedMessagePinning
())
{
view
.
showMessage
(
R
.
string
.
permission_pinning_not_allowed
)
return
@launchUI
}
try
{
client
.
unpinMessage
(
messageId
)
}
catch
(
e
:
RocketChatException
)
{
...
...
app/src/main/java/chat/rocket/android/server/domain/GetPermissionsInteractor.kt
View file @
2dad9429
...
...
@@ -10,12 +10,17 @@ class GetPermissionsInteractor @Inject constructor(private val settingsRepositor
/**
* Check whether user is allowed to delete a message.
*/
fun
isMessageDeletingAllowed
()
=
publicSettings
()
?.
deleteMessageAllowed
()
?:
false
fun
allowedMessageDeleting
()
=
publicSettings
()
?.
allowedMessageDeleting
()
?:
false
/**
* Checks whether user is allowed to edit a message.
*/
fun
isMessageEditingAllowed
()
=
publicSettings
()
?.
deleteMessageAllowed
()
?:
false
fun
allowedMessageEditing
()
=
publicSettings
()
?.
allowedMessageEditing
()
?:
false
/**
* Checks whether user is allowed to pin a message to a channel.
*/
fun
allowedMessagePinning
()
=
publicSettings
()
?.
allowedMessagePinning
()
?:
false
/**
* Checks whether should show deleted message status.
...
...
app/src/main/java/chat/rocket/android/server/domain/SettingsRepository.kt
View file @
2dad9429
...
...
@@ -38,6 +38,7 @@ const val ALLOW_MESSAGE_DELETING = "Message_AllowDeleting"
const
val
ALLOW_MESSAGE_EDITING
=
"Message_AllowEditing"
const
val
SHOW_DELETED_STATUS
=
"Message_ShowDeletedStatus"
const
val
SHOW_EDITED_STATUS
=
"Message_ShowEditedStatus"
const
val
ALLOW_MESSAGE_PINNING
=
"Message_AllowPinning"
/*
* Extension functions for Public Settings.
*
...
...
@@ -56,10 +57,11 @@ fun Map<String, Value<Any>>.wordpressEnabled(): Boolean = this[ACCOUNT_WORDPRESS
fun
Map
<
String
,
Value
<
Any
>>.
useRealName
():
Boolean
=
this
[
USE_REALNAME
]
?.
value
==
true
// Message settings
fun
Map
<
String
,
Value
<
Any
>>.
deleteMessageAllowed
():
Boolean
=
this
[
ALLOW_MESSAGE_DELETING
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
editingMessageAllowed
():
Boolean
=
this
[
ALLOW_MESSAGE_EDITING
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
showDeletedStatus
():
Boolean
=
this
[
SHOW_DELETED_STATUS
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
showEditedStatus
():
Boolean
=
this
[
SHOW_EDITED_STATUS
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
allowedMessagePinning
():
Boolean
=
this
[
ALLOW_MESSAGE_PINNING
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
allowedMessageEditing
():
Boolean
=
this
[
ALLOW_MESSAGE_EDITING
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
allowedMessageDeleting
():
Boolean
=
this
[
ALLOW_MESSAGE_DELETING
]
?.
value
==
true
fun
Map
<
String
,
Value
<
Any
>>.
registrationEnabled
():
Boolean
{
val
value
=
this
[
ACCOUNT_REGISTRATION
]
...
...
app/src/main/res/values-pt-rBR/strings.xml
View file @
2dad9429
...
...
@@ -71,6 +71,8 @@
<!-- Permission messages -->
<string
name=
"permission_editing_not_allowed"
>
Edição não permitida
</string>
<string
name=
"permission_deleting_not_allowed"
>
Remoção não permitida
</string>
<string
name=
"permission_pinning_not_allowed"
>
Fixar não permitido
</string>
<!-- Pinned Messages -->
<string
name=
"title_pinned_messages"
>
Mensagens Pinadas
</string>
...
...
app/src/main/res/values/strings.xml
View file @
2dad9429
...
...
@@ -72,7 +72,9 @@
<string
name=
"action_title_editing"
>
Editing Message
</string>
<!-- Permission messages -->
<string
name=
"permission_editing_not_allowed"
>
Editing not allowed
</string>
<string
name=
"permission_editing_not_allowed"
>
Editing is not allowed
</string>
<string
name=
"permission_deleting_not_allowed"
>
Deleting is not allowed
</string>
<string
name=
"permission_pinning_not_allowed"
>
Pinning is not allowed
</string>
<!-- Pinned Messages -->
<string
name=
"title_pinned_messages"
>
Pinned Messages
</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment