本文整理匯總了Golang中github.com/microcosm-cc/microcosm/models.Context.RespondWithOK方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithOK方法的具體用法?Golang Context.RespondWithOK怎麽用?Golang Context.RespondWithOK使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/microcosm-cc/microcosm/models.Context
的用法示例。
在下文中一共展示了Context.RespondWithOK方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Update
// Update handles PUT
func (ctl *IgnoredController) Update(c *models.Context) {
m := models.IgnoreType{}
err := c.Fill(&m)
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("The post data is invalid: %v", err.Error()),
http.StatusBadRequest,
)
return
}
if c.Auth.ProfileID < 1 {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
m.ProfileID = c.Auth.ProfileID
status, err := m.Update()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例2: Delete
// Delete handles DELETE
func (ctl *MenuController) Delete(c *models.Context, siteID int64) {
// Start :: Auth
site, status, err := models.GetSite(siteID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
// Use the user ID to check, since the current context is a different site (the root site)
// than the site the owner profile is associated with.
owner, status, err := models.GetProfileSummary(site.ID, site.OwnedByID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
if owner.UserID != c.Auth.UserID {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
// End :: Auth
status, err = models.DeleteMenu(siteID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例3: Update
// Update handles PUT
func (ctl *ProfileReadController) Update(c *models.Context) {
if c.Auth.ProfileID == 0 {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
rs := models.ReadScopeType{}
err := c.Fill(&rs)
if err != nil {
glog.Errorln(err.Error())
c.RespondWithErrorMessage(
fmt.Sprintf("The post data is invalid: %v", err.Error()),
http.StatusBadRequest,
)
return
}
itemTypeID, ok := h.ItemTypes[rs.ItemType]
if !ok {
c.RespondWithErrorMessage("Unknown item type", http.StatusBadRequest)
return
}
rs.ItemTypeID = itemTypeID
status, err := models.MarkScopeAsRead(c.Auth.ProfileID, rs)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例4: Delete
// Delete handles DELETE
func (ctl *UserController) Delete(c *models.Context) {
_, _, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
m, status, err := models.GetUser(itemID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
if !models.UserIsOnSite(m.ID, c.Site.ID) {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
status, err = m.Delete()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
audit.Delete(
c.Site.ID,
h.ItemTypes[h.ItemTypeUser],
itemID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
c.RespondWithOK()
}
示例5: Delete
// Delete handles DELETE
// Note: This only affects explicitly assigned roles and not roles implicitly
// included by criteria
func (ctl *RoleProfileController) Delete(c *models.Context) {
// Validate inputs
var microcosmID int64
if sid, exists := c.RouteVars["microcosm_id"]; exists {
id, err := strconv.ParseInt(sid, 10, 64)
if err != nil {
c.RespondWithErrorMessage("microcosm_id in URL is not a number", http.StatusBadRequest)
return
}
microcosmID = id
}
roleID, err := strconv.ParseInt(c.RouteVars["role_id"], 10, 64)
if err != nil {
c.RespondWithErrorMessage("role_id in URL is not a number", http.StatusBadRequest)
return
}
_, status, err := models.GetRole(c.Site.ID, microcosmID, roleID, c.Auth.ProfileID)
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
}
m := models.RoleProfileType{}
m.ID = profileID
// Authorisation
perms := models.GetPermission(
models.MakeAuthorisationContext(c, microcosmID, h.ItemTypes[h.ItemTypeMicrocosm], microcosmID),
)
if microcosmID > 0 {
// Related to a Microcosm
if !perms.IsModerator && !c.Auth.IsSiteOwner {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
} else {
// Default role for the site
if !c.Auth.IsSiteOwner {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
}
status, err = m.Delete(roleID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例6: Delete
// Delete handles DELETE
func (ctl *AuthController) Delete(c *models.Context) {
// Extract access token from request and delete its record
m, status, err := models.GetAccessToken(c.RouteVars["id"])
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("Error retrieving access token: %v", err.Error()),
status,
)
return
}
status, err = m.Delete()
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("Error deleting access token: %v", err.Error()),
status,
)
return
}
audit.Delete(
c.Site.ID,
h.ItemTypes[h.ItemTypeAuth],
m.UserID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
c.RespondWithOK()
}
示例7: Delete
// Delete handles DELETE
func (ctl *AttachmentController) Delete(c *models.Context) {
itemTypeID, itemID, perms, status, err := ParseItemInfo(c)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
if !perms.IsSiteOwner && !perms.IsModerator && perms.IsOwner {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
fileHash := c.RouteVars["fileHash"]
if fileHash == "" {
c.RespondWithErrorMessage(
fmt.Sprintf("The supplied file hash cannot be zero characters: %s", c.RouteVars["fileHash"]),
http.StatusBadRequest,
)
return
}
metadata, status, err := models.GetMetadata(fileHash)
if err != nil {
if status == http.StatusNotFound {
c.RespondWithErrorMessage(
fmt.Sprintf("File does not have a metadata record"),
http.StatusBadRequest,
)
return
}
c.RespondWithErrorMessage(
fmt.Sprintf("Could not retrieve metadata: %v", err.Error()),
http.StatusBadRequest,
)
return
}
status, err = models.DeleteAttachment(itemTypeID, itemID, fileHash)
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("Could not remove attachment: %v", err.Error()),
status,
)
return
}
// Update attach count on attachment_meta
metadata.AttachCount = metadata.AttachCount - 1
status, err = metadata.Update()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例8: Update
// Update handles PUT
func (ctl *WatcherController) Update(c *models.Context) {
m := models.WatcherType{}
err := c.Fill(&m)
if err != nil {
glog.Warning(err)
c.RespondWithErrorMessage(
fmt.Sprintf("The post data is invalid: %v", err.Error()),
http.StatusBadRequest,
)
return
}
itemType := strings.ToLower(m.ItemType)
if itemType != "" {
if _, exists := h.ItemTypes[itemType]; !exists {
glog.Warning(err)
c.RespondWithErrorMessage(
fmt.Sprintf("Watcher could not be saved: Item type not found"),
http.StatusBadRequest,
)
return
}
m.ItemTypeID = h.ItemTypes[itemType]
}
var status int
// watcher must exist to be updated
// Also the returned watcher ID belongs to the authed person by definition
// - no need to check later
m.ID, _, _, _, status, err = models.GetWatcherAndIgnoreStatus(
m.ItemTypeID,
m.ItemID,
c.Auth.ProfileID,
)
if err != nil {
glog.Error(err)
c.RespondWithErrorDetail(err, status)
return
}
// To update we only need id, SendEmail and SendSMS
status, err = m.Update()
if err != nil {
glog.Error(err)
c.RespondWithErrorMessage(
fmt.Sprintf("Could not update watcher: %v", err.Error()),
http.StatusBadRequest,
)
return
}
// Respond
c.RespondWithOK()
}
示例9: UpdateMany
// UpdateMany handles PUT for the collection
func (ctl *AttributesController) UpdateMany(c *models.Context) {
_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
ems := []models.AttributeType{}
err = c.Fill(&ems)
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("The post data is invalid: %v", err.Error()),
http.StatusBadRequest,
)
return
}
for _, v := range ems {
if strings.Trim(v.Key, " ") == "" {
c.RespondWithErrorMessage(
"key must be supplied with every attribute when updating multiple attributes",
http.StatusBadRequest,
)
return
}
}
perms := models.GetPermission(models.MakeAuthorisationContext(c, 0, itemTypeID, itemID))
if !perms.CanUpdate {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
status, err = models.UpdateManyAttributes(itemTypeID, itemID, ems)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
for _, m := range ems {
audit.Replace(
c.Site.ID,
h.ItemTypes[h.ItemTypeAttribute],
m.ID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
}
c.RespondWithOK()
}
示例10: Delete
// Delete handles DELETE
func (ctl *CommentController) Delete(c *models.Context) {
_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
// Start Authorisation
perms := models.GetPermission(
models.MakeAuthorisationContext(
c, 0, itemTypeID, itemID),
)
if !perms.CanDelete {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
// End Authorisation
// Partially instantiated type for Id passing
m, status, err := models.GetCommentSummary(c.Site.ID, itemID)
if err != nil {
if status == http.StatusNotFound {
c.RespondWithOK()
return
}
c.RespondWithErrorDetail(err, status)
return
}
// Delete resource
status, err = m.Delete(c.Site.ID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
audit.Delete(
c.Site.ID,
h.ItemTypes[h.ItemTypeComment],
m.ID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
c.RespondWithOK()
}
示例11: Delete
// 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()
}
示例12: Delete
// Delete handles DELETE
func (ctl *HuddleController) Delete(c *models.Context) {
_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
// Start Authorisation
perms := models.GetPermission(
models.MakeAuthorisationContext(
c, 0, itemTypeID, itemID),
)
if !perms.CanDelete {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
// End Authorisation
m, status, err := models.GetHuddle(c.Site.ID, c.Auth.ProfileID, itemID)
if err != nil {
if status == http.StatusNotFound {
c.RespondWithOK()
return
}
c.RespondWithErrorDetail(err, status)
return
}
status, err = m.Delete(c.Site.ID, c.Auth.ProfileID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
audit.Delete(
c.Site.ID,
h.ItemTypes[h.ItemTypeHuddle],
m.ID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
c.RespondWithOK()
}
示例13: Update
// Update handles PUT
func (ctl *MenuController) Update(c *models.Context, siteID int64) {
ems := []h.LinkType{}
// Start :: Auth
site, status, err := models.GetSite(siteID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
// Use the user ID to check, since the current context is a different site (the root site)
// than the site the owner profile is associated with.
owner, status, err := models.GetProfileSummary(site.ID, site.OwnedByID)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
if owner.UserID != c.Auth.UserID {
c.RespondWithErrorMessage(h.NoAuthMessage, http.StatusForbidden)
return
}
// End :: Auth
err = c.Fill(&ems)
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("The post data is invalid: %v", err.Error()),
http.StatusBadRequest,
)
return
}
status, err = models.UpdateMenu(siteID, ems)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
c.RespondWithOK()
}
示例14: Delete
// Delete handles DELETE
func (ctl *AttributeController) Delete(c *models.Context) {
_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
key := c.RouteVars["key"]
m := models.AttributeType{}
m.Key = key
attributeID, status, err := models.GetAttributeID(itemTypeID, itemID, m.Key)
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
m.ID = attributeID
status, err = m.Delete()
if err != nil {
c.RespondWithErrorDetail(err, status)
return
}
audit.Delete(
c.Site.ID,
h.ItemTypes[h.ItemTypeAttribute],
m.ID,
c.Auth.ProfileID,
time.Now(),
c.IP,
)
c.RespondWithOK()
}
示例15: Update
// Update handles PUT
func (ctl *MetricsController) Update(c *models.Context) {
// Hard coded to only work for founders.
if c.Auth.UserID != 1 && c.Auth.UserID != 2 {
c.RespondWithErrorMessage(
fmt.Sprintf("Only founders can manually update metrics: %d", c.Auth.UserID),
http.StatusForbidden,
)
return
}
err := models.UpdateMetrics()
if err != nil {
c.RespondWithErrorMessage(
fmt.Sprintf("Error updating metrics: %+v", err),
http.StatusInternalServerError,
)
return
}
c.RespondWithOK()
return
}