Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
Implemented getting a subscription by its ID. Fixes #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paddy Foran committed Nov 29, 2012
1 parent 4dd2fde commit 16e7f3b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions subscriptions.go
Expand Up @@ -78,6 +78,26 @@ func getUserSubscription(w http.ResponseWriter, r *twocloud.RequestBundle) {
}

func getSubscription(w http.ResponseWriter, r *twocloud.RequestBundle) {
requestedSubscription := r.Request.URL.Query().Get(":subscription")
subscriptionID, err := ruid.RUIDFromString(requestedSubscription)
if err != nil {
Respond(w, r, http.StatusBadRequest, "Invalid subscription ID", []interface{}{})
return
}
subscription := *r.AuthUser.Subscription
if r.AuthUser.Subscription.ID != subscriptionID {
if !r.AuthUser.IsAdmin {
Respond(w, r, http.StatusUnauthorized, "You don't have access to that subscription.", []interface{}{})
return
}
subscription, err = r.GetSubscription(subscriptionID)
if err != nil {
Respond(w, r, http.StatusInternalServerError, "Internal server error", []interface{}{})
return
}
}
Respond(w, r, http.StatusOK, "Successfully retrieved subscription information", []interface{}{subscription})
return
}

func startSubscription(w http.ResponseWriter, r *twocloud.RequestBundle) {
Expand Down

0 comments on commit 16e7f3b

Please sign in to comment.