Hi all,
Three questions ->
1) Is this an appropriate way to use Box?
2) My nested matches in userAllowed, are feeling alot like a bunch of if statements, so any more concise way to express all those checks?
3) How do I set the HTTP status of the response? I can see some examples around status but haven't been able to find exactly how I would respond with a specifc code (like a 401) for a specific condition.
val return_string = resourceAction.userAllowed("addConnection") match {
case Full(true) => {
"this will return the JSON of the new connection to be rendered in the browser"
}
case Failure(msg, exception, failure) => msg
}
Full(JsonResponse(JString(return_string)))
}
userAllowed
//This is just checking that a bunch of criteria are met, and needs to return a specific message for the one that isn't
def userAllowed(action: String): Box[Boolean] = {
action match {
case "addConnection" => {
Session.defaultEvent match {
case Some(event) => event.name.get match {
case "XYZ" => Session.currentUser match { //must be a XYZ event
case Some(user) => { ////user must be logged in
user.type.get match {
case "PQR" => Full(true) //must be logged in
case _ => Failure("addConnection not allowed for users of type " + user.avatar.get)
}
case None => Failure("addConnection only allowed for logged in users")
....
....