Skip to content

Commit

Permalink
Show a different message when account closed by class teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Nov 22, 2024
1 parent d73217b commit d66581f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions app/controllers/Appeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ final class Appeal(env: Env, reportC: => report.Report, userC: => User) extends
else notFound
}

def closedByTeacher = Auth { ctx ?=> _ ?=>
if ctx.isAppealUser || isGranted(_.Appeals) then
FoundPage(env.cms.renderKey("account-closed-by-teacher")):
views.site.page.lone
else notFound
}

private def renderAppealOrTree(
err: Option[Form[String]] = None
)(using Context)(using me: Me) = env.appeal.api.byId(me).flatMap {
Expand Down
15 changes: 10 additions & 5 deletions app/controllers/Auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ final class Auth(
).map(authenticateCookie(sessionId, remember))
.recoverWith(authRecovery)

private def authenticateAppealUser(u: UserModel, redirect: String => Result)(using
private def authenticateAppealUser(u: UserModel, redirect: String => Result, url: String)(using
ctx: Context
): Fu[Result] =
api.appeal
.saveAuthentication(u.id)
.flatMap: sessionId =>
authenticateCookie(sessionId, remember = false):
redirect(routes.Appeal.landing.url)
redirect(url)
.recoverWith(authRecovery)

private def authenticateCookie(sessionId: String, remember: Boolean)(
Expand Down Expand Up @@ -124,9 +124,14 @@ final class Auth(
case None => InternalServerError("Authentication error")
case Some(u) if u.enabled.no =>
negotiate(
env.mod.logApi.closedByMod(u).flatMap {
if _ then authenticateAppealUser(u, redirectTo)
else redirectTo(routes.Account.reopen.url)
env.mod.logApi.closedByTeacher(u).flatMap {
if _ then
authenticateAppealUser(u, redirectTo, routes.Appeal.closedByTeacher.url)
else
env.mod.logApi.closedByMod(u).flatMap {
if _ then authenticateAppealUser(u, redirectTo, routes.Appeal.landing.url)
else redirectTo(routes.Account.reopen.url)
}
},
Unauthorized(jsonError("This account is closed."))
)
Expand Down
1 change: 1 addition & 0 deletions conf/appeal.routes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GET /appeal controllers.appeal.Appeal.home
POST /appeal controllers.appeal.Appeal.post
GET /appeal/landing controllers.appeal.Appeal.landing
GET /appeal/closed-by-teacher controllers.appeal.Appeal.closedByTeacher
GET /appeal/queue controllers.appeal.Appeal.queue(filter: Option[String] ?= None)
GET /appeal/:username controllers.appeal.Appeal.show(username: UserStr)
POST /appeal/:username controllers.appeal.Appeal.reply(username: UserStr)
Expand Down
8 changes: 5 additions & 3 deletions modules/api/src/main/AccountClosure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ final class AccountClosure(

def close(u: User)(using me: Me): Funit = for
playbanned <- playbanApi.HasCurrentPlayban(u.id)
selfClose = me.is(u)
modClose = !selfClose && Granter(_.CloseAccount)
badApple = u.lameOrTroll || u.marks.alt || modClose
selfClose = me.is(u)
teacherClose = !selfClose && !Granter(_.CloseAccount) && Granter(_.Teacher)
modClose = !selfClose && Granter(_.CloseAccount)
badApple = u.lameOrTroll || u.marks.alt || modClose
_ <- userRepo.disable(u, keepEmail = badApple || playbanned)
_ <- relationApi.unfollowAll(u.id)
_ <- rankingApi.remove(u.id)
Expand All @@ -54,6 +55,7 @@ final class AccountClosure(
reports <- reportApi.processAndGetBySuspect(lila.report.Suspect(u))
_ <-
if selfClose then modLogApi.selfCloseAccount(u.id, reports)
else if teacherClose then modLogApi.teacherCloseAccount(u.id)
else modLogApi.closeAccount(u.id)
_ <- appealApi.onAccountClose(u)
_ <- ublogApi.onAccountClose(u)
Expand Down
1 change: 1 addition & 0 deletions modules/mod/src/main/Modlog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ object Modlog:
val disableTwoFactor = "disableTwoFactor"
val closeAccount = "closeAccount"
val selfCloseAccount = "selfCloseAccount"
val teacherCloseAccount = "teacherCloseAccount"
val reopenAccount = "reopenAccount"
val deletePost = "deletePost"
val openTopic = "openTopic"
Expand Down
6 changes: 6 additions & 0 deletions modules/mod/src/main/ModlogApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres
def closeAccount(user: UserId)(using me: Me) = add:
Modlog(me, user.some, Modlog.closeAccount)

def teacherCloseAccount(user: UserId)(using me: Me) = add:
Modlog(me, user.some, Modlog.teacherCloseAccount)

def selfCloseAccount(user: UserId, openReports: List[Report]) = add:
Modlog(
UserId.lichess.into(ModId),
Expand All @@ -96,6 +99,9 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres
def closedByMod(user: User): Fu[Boolean] =
fuccess(user.marks.alt) >>| coll.exists($doc("user" -> user.id, "action" -> Modlog.closeAccount))

def closedByTeacher(user: User): Fu[Boolean] =
fuccess(user.marks.alt) >>| coll.exists($doc("user" -> user.id, "action" -> Modlog.teacherCloseAccount))

def reopenAccount(user: UserId)(using Me) = add:
Modlog(user.some, Modlog.reopenAccount)

Expand Down

0 comments on commit d66581f

Please sign in to comment.