limit heavy class features to reaonably sized classes
parent
f577e39ba8
commit
0a5875221f
|
@ -127,8 +127,10 @@ final class Clas(
|
|||
|
||||
def notifyStudents(id: String) = Secure(_.Teacher) { implicit ctx => me =>
|
||||
WithClass(me, id) { clas =>
|
||||
env.clas.api.student.activeWithUsers(clas) map { students =>
|
||||
Ok(html.clas.clas.notify(clas, students, env.clas.forms.clas.notifyText))
|
||||
env.clas.api.student.activeWithUsers(clas) flatMap { students =>
|
||||
Reasonable(clas, students, "notify") {
|
||||
Ok(html.clas.clas.notify(clas, students, env.clas.forms.clas.notifyText)).fuccess
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,11 +146,13 @@ final class Clas(
|
|||
},
|
||||
text =>
|
||||
env.clas.api.student.activeWithUsers(clas) flatMap { students =>
|
||||
val url = routes.Clas.show(clas.id.value).url
|
||||
val full = if (text contains url) text else s"$text\n\n${env.net.baseUrl}$url"
|
||||
env.msg.api.multiPost(me, students.map(_.user.id), full)
|
||||
} inject
|
||||
Redirect(routes.Clas.show(clas.id.value)).flashSuccess
|
||||
Reasonable(clas, students, "notify") {
|
||||
val url = routes.Clas.show(clas.id.value).url
|
||||
val full = if (text contains url) text else s"$text\n\n${env.net.baseUrl}$url"
|
||||
env.msg.api.multiPost(me, students.map(_.user.id), full) inject
|
||||
Redirect(routes.Clas.show(clas.id.value)).flashSuccess
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -165,8 +169,10 @@ final class Clas(
|
|||
lila.rating.PerfType(key) ?? { perfType =>
|
||||
WithClass(me, id) { clas =>
|
||||
env.clas.api.student.activeWithUsers(clas) flatMap { students =>
|
||||
env.clas.progressApi(perfType, days, students) map { progress =>
|
||||
views.html.clas.teacherDashboard.progress(clas, students, progress)
|
||||
Reasonable(clas, students, "progress") {
|
||||
env.clas.progressApi(perfType, days, students) map { progress =>
|
||||
views.html.clas.teacherDashboard.progress(clas, students, progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,6 +412,12 @@ final class Clas(
|
|||
Redirect("https://forms.gle/b19pDZZuotncxtbRA")
|
||||
}
|
||||
|
||||
private def Reasonable(clas: lila.clas.Clas, students: List[lila.clas.Student.WithUser], active: String)(
|
||||
f: => Fu[Result]
|
||||
)(implicit ctx: Context): Fu[Result] =
|
||||
if (students.size <= lila.clas.Clas.maxStudents) f
|
||||
else Unauthorized(views.html.clas.teacherDashboard.unreasonable(clas, students, active)).fuccess
|
||||
|
||||
private def WithClass(me: lila.user.User, clasId: String)(
|
||||
f: lila.clas.Clas => Fu[Result]
|
||||
): Fu[Result] =
|
||||
|
|
|
@ -6,7 +6,7 @@ import lila.app.templating.Environment._
|
|||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.clas.{ Clas, Student }
|
||||
|
||||
private object bits {
|
||||
object bits {
|
||||
|
||||
def layout(
|
||||
title: String,
|
||||
|
|
|
@ -80,6 +80,22 @@ object teacherDashboard {
|
|||
studentList(c, archived)
|
||||
}
|
||||
|
||||
def unreasonable(c: Clas, students: List[Student.WithUser], active: String)(implicit ctx: Context) =
|
||||
layout(c, students, active)(
|
||||
div(cls := "box__pad students__empty")(
|
||||
p(
|
||||
"This feature is only available for classes of ",
|
||||
lila.clas.Clas.maxStudents,
|
||||
" or fewer students."
|
||||
),
|
||||
p(
|
||||
"This class has ",
|
||||
students.size,
|
||||
" students. You could maybe create more classes to split the students."
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def progress(
|
||||
c: Clas,
|
||||
students: List[Student.WithUser],
|
||||
|
|
Loading…
Reference in New Issue