Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Using a Box / Failure and how to set HTTP status code
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bg  
View profile  
 More options Oct 8 2012, 8:09 am
From: bg <brentgra...@gmail.com>
Date: Mon, 8 Oct 2012 05:09:30 -0700 (PDT)
Local: Mon, Oct 8 2012 8:09 am
Subject: Using a Box / Failure and how to set HTTP status code

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) => {
        UserConnectionHelper.addUserConnection(Session.currentUser.get.pk,
badgeNumber)
        "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")
....
....


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.