-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix admin actions visibility for non admin mods #1412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.jerboa.feat | ||
|
||
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityModeratorView | ||
import android.content.Context | ||
import com.jerboa.MainActivity | ||
import com.jerboa.db.entity.Account | ||
import com.jerboa.findActivity | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityId | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonId | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView | ||
import java.time.Instant | ||
|
@@ -12,29 +16,25 @@ import java.time.temporal.ChronoUnit | |
fun canMod( | ||
creatorId: PersonId, | ||
admins: List<PersonView>?, | ||
moderators: List<CommunityModeratorView>?, | ||
myId: PersonId?, | ||
moderators: List<PersonId>?, | ||
myId: PersonId, | ||
onSelf: Boolean = false, | ||
): Boolean { | ||
return if (myId !== null) { | ||
// You can do moderator actions only on the mods added after you. | ||
val adminIds = admins?.map { a -> a.person.id }.orEmpty() | ||
val modIds = moderators?.map { m -> m.moderator.id }.orEmpty() | ||
|
||
val adminsThenMods = adminIds.toMutableList() | ||
adminsThenMods.addAll(modIds) | ||
|
||
val myIndex = adminsThenMods.indexOf(myId) | ||
if (myIndex == -1) { | ||
false | ||
} else { | ||
// onSelf +1 on mod actions not for yourself, IE ban, remove, etc | ||
val subList = adminsThenMods.subList(0, myIndex.plus(if (onSelf) 0 else 1)) | ||
|
||
!subList.contains(creatorId) | ||
} | ||
} else { | ||
// You can do moderator actions only on the mods added after you. | ||
val adminIds = admins?.map { a -> a.person.id }.orEmpty() | ||
val modIds = moderators.orEmpty() | ||
|
||
val adminsThenMods = adminIds.toMutableList() | ||
adminsThenMods.addAll(modIds) | ||
|
||
val myIndex = adminsThenMods.indexOf(myId) | ||
return if (myIndex == -1) { | ||
false | ||
} else { | ||
// onSelf +1 on mod actions not for yourself, IE ban, remove, etc | ||
val subList = adminsThenMods.subList(0, myIndex.plus(if (onSelf) 0 else 1)) | ||
|
||
!subList.contains(creatorId) | ||
} | ||
} | ||
|
||
|
@@ -45,15 +45,30 @@ fun futureDaysToUnixTime(days: Long?): Long? { | |
} | ||
|
||
fun amMod( | ||
moderators: List<CommunityModeratorView>?, | ||
myId: PersonId?, | ||
moderators: List<PersonId>?, | ||
myId: PersonId, | ||
): Boolean { | ||
return moderators?.map { it.moderator.id }?.contains(myId) ?: false | ||
return moderators?.contains(myId) ?: false | ||
} | ||
|
||
fun amAdmin( | ||
admins: List<PersonView>?, | ||
myId: PersonId?, | ||
): Boolean { | ||
return admins?.map { it.person.id }?.contains(myId) ?: false | ||
/** | ||
* In screens with posts from different communities we don't have access to moderators of those communities | ||
* So that means that non admin mods can't moderate those posts from that screen | ||
* | ||
* So this is QoL were we simulate the mods of the community | ||
* It is not completely accurate as it doesn't take into account the hierarchy of mods | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This really shows that the Once I eventually get some time to work on that, we'd be able to remove the mod list from almost every response, and stuff like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I forgot, how does the Currently we don't do that correctly either. canMod should probably return which actions can be done? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just looked through the lemmy-ui code, and its only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only distinguish? Can top admin not pin his own comment? Or lock/feature his own posts? |
||
fun simulateModerators( | ||
ctx: Context, | ||
account: Account, | ||
forCommunity: CommunityId, | ||
): List<PersonId> { | ||
if (account.isMod) { | ||
val siteVM = (ctx.findActivity() as MainActivity).siteViewModel | ||
val canModerate = siteVM.moderatedCommunities().orEmpty().contains(forCommunity) | ||
if (canModerate) { | ||
return listOf(account.id) | ||
} | ||
} | ||
return emptyList() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the moderator hierarchy not apply to admins? i.e. Any admin can moderate any admin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does apply to other admins. Check L28 and L35, it adds admins, then mods for the ordered hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about the code, but rather does Lemmy also have the hierarchy for admin. (so yes I assume)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep admins also have a hierarchy.