Skip to content
Browse files

Implemented getting information about a link. Fixes #22.

  • Loading branch information...
1 parent 6274ee2 commit 2bc36f6f0108ef7851848b050a4bd2ee8bba5f0a @paddyforan paddyforan committed Nov 25, 2012
Showing with 48 additions and 0 deletions.
  1. +48 −0 links.go
View
48 links.go
@@ -179,6 +179,54 @@ func sendLinks(w http.ResponseWriter, r *twocloud.RequestBundle) {
}
func getLink(w http.ResponseWriter, r *twocloud.RequestBundle) {
+ username := r.Request.URL.Query().Get(":username")
+ user := r.AuthUser
+ if strings.ToLower(username) != strings.ToLower(r.AuthUser.Username) {
+ if !r.AuthUser.IsAdmin {
+ Respond(w, r, http.StatusUnauthorized, "You don't have access to that user's links.", []interface{}{})
+ return
+ }
+ id, err := r.GetUserID(username)
+ if err != nil {
+ r.Log.Error(err.Error())
+ Respond(w, r, http.StatusInternalServerError, "Internal server error", []interface{}{})
+ return
+ }
+ user, err = r.GetUser(id)
+ if err != nil {
+ r.Log.Error(err.Error())
+ Respond(w, r, http.StatusInternalServerError, "Internal server error", []interface{}{})
+ return
+ }
+ }
+ deviceID, err := ruid.RUIDFromString(r.Request.URL.Query().Get(":device"))
+ if err != nil {
+ r.Log.Error(err.Error())
+ Respond(w, r, http.StatusBadRequest, "Invalid device ID", []interface{}{})
+ return
+ }
+ device, err := r.GetDevice(deviceID)
+ if err != nil {
+ r.Log.Error(err.Error())
+ Respond(w, r, http.StatusInternalServerError, "Internal server error", []interface{}{})
+ return
+ }
+ if device.UserID != user.ID {
+ Respond(w, r, http.StatusBadRequest, "That device ID does not belong to that user.", []interface{}{})
+ return
+ }
+ linkID, err := ruid.RUIDFromString(r.Request.URL.Query().Get(":link"))
+ if err != nil {
+ Respond(w, r, http.StatusBadRequest, "Invalid link ID", []interface{}{})
+ return
+ }
+ link, err := r.GetLink(linkID)
+ if err != nil {
+ Respond(w, r, http.StatusInternalServerError, "Internal server error", []interface{}{})
+ return
+ }
+ Respond(w, r, http.StatusOK, "Successfully retrieved link information", []interface{}{link})
+ return
}
func updateLink(w http.ResponseWriter, r *twocloud.RequestBundle) {

0 comments on commit 2bc36f6

Please sign in to comment.
Something went wrong with that request. Please try again.