Exemple #1
0
func (c Blog) GetRead(id bson.ObjectId) revel.Result {
	if id.Hex() != "" {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		return c.Render(article)
	}
	return c.NotFound("Invalid article Id.")
}
Exemple #2
0
func (c Blog) Update(article *models.Article) revel.Result {
	if c.ActiveUser != nil {
		check := models.GetArticleByObjectId(c.MongoSession, article.Id)
		if check.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			article.Tags = strings.Split(c.Params.Values["article.Tags"][0], ",")
			article.Validate(c.Validation)
			if c.Validation.HasErrors() {
				c.Validation.Keep()
				c.FlashParams()
				c.Flash.Error("Please correct the errors below.")
				return c.Redirect("/blog/%s/edit", article.Id.Hex())
			}

			// @todo properly implement this
			article.Author_id = check.Author_id
			article.Published = check.Published
			article.Posted = check.Posted

			article.Save(c.MongoSession)
			return c.Redirect("/blog/%s", article.Id.Hex())
		}
		return c.Forbidden("You do not have permission to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
Exemple #3
0
func (c Blog) Delete(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		if article.CanBeDeletedBy(c.MongoSession, c.ActiveUser) {
			article.Delete(c.MongoSession)
		}
	}
	return c.RenderText("")
}
Exemple #4
0
func (c Blog) GetDelete(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		if article.CanBeDeletedBy(c.MongoSession, c.ActiveUser) {
			return c.Render(article)
		}
		return c.Forbidden("You do not have permission to delete this resource.")
	}
	return c.Forbidden("Only site users may delete content.")
}
Exemple #5
0
func (c Blog) GetUpdate(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		if article.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			action := "/Blog/Update"
			actionButton := "Update"
			return c.Render(action, article, actionButton)
		}
		return c.Forbidden("You do not have permission to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
Exemple #6
0
func (c Blog) Links(id bson.ObjectId) revel.Result {
	links := false
	canUpdate := false
	canDelete := false
	article := &models.Article{}
	if c.ActiveUser != nil {
		article = models.GetArticleByObjectId(c.MongoSession, id)
		if article.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			canUpdate = true
			links = true
		}
		if article.CanBeDeletedBy(c.MongoSession, c.ActiveUser) {
			canDelete = true
			links = true
		}
	}
	return c.Render(article, links, canUpdate, canDelete)
}