// Delete handles DELETE func (ctl *HuddleParticipantController) Delete(c *models.Context) { huddleID, err := strconv.ParseInt(c.RouteVars["huddle_id"], 10, 64) if err != nil { c.RespondWithErrorMessage("huddle_id in URL is not a number", http.StatusBadRequest) return } _, status, err := models.GetHuddle(c.Site.ID, c.Auth.ProfileID, huddleID) if err != nil { c.RespondWithErrorDetail(err, status) return } profileID, err := strconv.ParseInt(c.RouteVars["profile_id"], 10, 64) if err != nil { c.RespondWithErrorMessage("profile_id in URL is not a number", http.StatusBadRequest) return } // Start Authorisation perms := models.GetPermission( models.MakeAuthorisationContext( c, 0, h.ItemTypes[h.ItemTypeHuddle], huddleID), ) if !perms.CanDelete { c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden) return } // End Authorisation if profileID != c.Auth.ProfileID { c.RespondWithErrorMessage("Only the participant in question can remove a participant from a huddle", http.StatusBadRequest) return } m := models.HuddleParticipantType{} m.ID = profileID status, err = m.Delete(huddleID) if err != nil { c.RespondWithErrorDetail(err, status) return } c.RespondWithOK() }
// Update handles PUT func (ctl *HuddleParticipantController) Update(c *models.Context) { huddleID, err := strconv.ParseInt(c.RouteVars["huddle_id"], 10, 64) if err != nil { c.RespondWithErrorMessage("huddle_id in URL is not a number", http.StatusBadRequest) return } r, status, err := models.GetHuddle(c.Site.ID, c.Auth.ProfileID, huddleID) if err != nil { c.RespondWithErrorDetail(err, status) return } profileID, err := strconv.ParseInt(c.RouteVars["profile_id"], 10, 64) if err != nil { c.RespondWithErrorMessage("profile_id in URL is not a number", http.StatusBadRequest) return } // Start Authorisation perms := models.GetPermission( models.MakeAuthorisationContext( c, 0, h.ItemTypes[h.ItemTypeHuddle], huddleID), ) if !perms.CanUpdate { c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden) return } if r.IsConfidential == false { c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden) return } // End Authorisation m := models.HuddleParticipantType{} m.ID = profileID status, err = m.Update(c.Site.ID, huddleID) if err != nil { c.RespondWithErrorDetail(err, status) return } c.RespondWithSeeOther(m.GetLink(r.GetLink())) }