refactor study Role.canWrite
This commit is contained in:
parent
6e628a1aa9
commit
7c5bb2b18c
|
@ -192,9 +192,9 @@ final class StudyApi(
|
|||
(study isOwner byUserId) ?? {
|
||||
val role = StudyMember.Role.byId.getOrElse(roleStr, StudyMember.Role.Read)
|
||||
study.members.get(userId) ifTrue study.isPublic foreach { member =>
|
||||
if (member.role == StudyMember.Role.Read && role == StudyMember.Role.Write)
|
||||
if (!member.role.canWrite && role.canWrite)
|
||||
bus.publish(lila.hub.actorApi.study.StudyMemberGotWriteAccess(userId, studyId.value), 'study)
|
||||
else if (member.role == StudyMember.Role.Write && role == StudyMember.Role.Read)
|
||||
else if (member.role.canWrite && !role.canWrite)
|
||||
bus.publish(lila.hub.actorApi.study.StudyMemberLostWriteAccess(userId, studyId.value), 'study)
|
||||
}
|
||||
studyRepo.setRole(study, userId, role) >>-
|
||||
|
|
|
@ -9,7 +9,7 @@ case class StudyMember(
|
|||
role: StudyMember.Role,
|
||||
addedAt: DateTime) {
|
||||
|
||||
def canContribute = role == StudyMember.Role.Write
|
||||
def canContribute = role.canWrite
|
||||
}
|
||||
|
||||
object StudyMember {
|
||||
|
@ -18,10 +18,10 @@ object StudyMember {
|
|||
|
||||
def make(user: User) = StudyMember(id = user.id, role = Role.Read, addedAt = DateTime.now)
|
||||
|
||||
sealed abstract class Role(val id: String)
|
||||
sealed abstract class Role(val id: String, val canWrite: Boolean)
|
||||
object Role {
|
||||
case object Read extends Role("r")
|
||||
case object Write extends Role("w")
|
||||
case object Read extends Role("r", false)
|
||||
case object Write extends Role("w", true)
|
||||
val byId = List(Read, Write).map { x => x.id -> x }.toMap
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue