let teachers be students, convenient for testing

This commit is contained in:
Thibault Duplessis 2020-01-17 14:30:25 -06:00
parent 9e166551aa
commit 4ecb615816
2 changed files with 19 additions and 13 deletions

View file

@ -36,12 +36,14 @@ final class Clas(
}
def show(id: String) = Auth { implicit ctx => me =>
if (isGranted(_.Teacher))
isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap {
case true =>
WithClass(me, id) { _ => clas =>
env.clas.api.student.allOf(clas) map { students =>
views.html.clas.clas.showToTeacher(clas, students)
}
} else
}
case _ =>
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
_ ?? { clas =>
env.clas.api.student.activeOf(clas) flatMap { students =>
@ -52,6 +54,7 @@ final class Clas(
}
}
}
}
def edit(id: String) = Secure(_.Teacher) { implicit ctx => me =>
WithClass(me, id) { _ => clas =>

View file

@ -67,6 +67,9 @@ final class ClasApi(
update = $set("viewedAt" -> DateTime.now),
fetchNewObject = true
)
def isTeacherOf(user: User, clasId: Clas.Id): Fu[Boolean] =
coll.exists($id(clasId) ++ $doc("teachers" -> user.id))
}
object student {