Ejemplo n.º 1
0
func update(db *mgo.Database, ev ifaces.Event, rule map[string]interface{}, dat map[string][]string, user_id bson.ObjectId, fixvals map[string]interface{}) error {
	rule["id"] = "must"
	rule["type"] = "must"
	rule["draft_id"] = "must"
	upd_dat, extr_err := extract.New(rule).Extract(dat)
	if extr_err != nil {
		return extr_err
	}
	id := upd_dat["id"].(string)
	typ := upd_dat["type"].(string)
	basic.DateAndAuthor(rule, upd_dat, user_id, true)
	upd_dat["type"] = typ
	_, has_tags := upd_dat[Tag_fieldname_displayed]
	if has_tags {
		addTags(db, upd_dat, id, "update", typ)
	}
	basic.Slug(rule, upd_dat)
	mergeMaps(upd_dat, fixvals)
	err := basic.InudVersion(db, ev, upd_dat, Cname, "update", id)
	if err != nil {
		return err
	}
	_, has_fulltext := rule["fulltext"]
	id_bson := bson.ObjectIdHex(basic.StripId(id))
	if has_fulltext {
		saveFulltext(db, id_bson)
	}
	return nil
}
Ejemplo n.º 2
0
// Apart from rule, there are two mandatory field which must come from the UI: "content_id" and "comment_id"
func UpdateComment(db *mgo.Database, ev ifaces.Event, rule map[string]interface{}, inp map[string][]string, user_id bson.ObjectId) error {
	dat, err := extract.New(rule).Extract(inp)
	if err != nil {
		return err
	}
	basic.DateAndAuthor(rule, dat, user_id, true)
	ids, err := basic.ExtractIds(inp, []string{"content_id", "comment_id"})
	if err != nil {
		return err
	}
	comment_id := bson.ObjectIdHex(ids[1])
	q := bson.M{
		"_id": bson.ObjectIdHex(ids[0]),
		"comments.comment_id": comment_id,
	}
	upd := bson.M{
		"$set": bson.M{
			"comments.$": dat,
		},
	}
	err = db.C("contents").Update(q, upd)
	if err != nil {
		return err
	}
	return db.C("comments").Remove(m{"_id": comment_id})
}
Ejemplo n.º 3
0
func insert(db *mgo.Database, ev ifaces.Event, rule map[string]interface{}, dat map[string][]string, user_id bson.ObjectId, fixvals map[string]interface{}) (bson.ObjectId, error) {
	// Could check for id here, alert if we found one.
	rule["type"] = "must"
	rule["draft_id"] = "must" // Can be draft, or version.
	ins_dat, extr_err := extract.New(rule).Extract(dat)
	if extr_err != nil {
		return "", extr_err
	}
	typ := ins_dat["type"].(string)
	basic.DateAndAuthor(rule, ins_dat, user_id, false)
	_, has_tags := ins_dat[Tag_fieldname_displayed]
	if has_tags {
		addTags(db, ins_dat, "", "insert", typ)
	}
	basic.Slug(rule, ins_dat)
	mergeMaps(ins_dat, fixvals)
	err := basic.InudVersion(db, ev, ins_dat, "contents", "insert", "")
	if err != nil {
		return "", err
	}
	ret_id := ins_dat["_id"].(bson.ObjectId)
	_, has_fulltext := rule["fulltext"]
	if has_fulltext {
		saveFulltext(db, ret_id)
	}
	return ret_id, nil
}
Ejemplo n.º 4
0
// Apart from rule, there is one mandatory field which must come from the UI: "content_id"
// moderate_first should be read as "moderate first if it is a valid, spam protection passed comment"
// Spam protection happens outside of this anyway.
func InsertComment(db *mgo.Database, ev ifaces.Event, rule map[string]interface{}, inp map[string][]string, user_id bson.ObjectId, typ string, moderate_first bool) error {
	dat, err := extract.New(rule).Extract(inp)
	if err != nil {
		return err
	}
	dat["type"] = typ
	basic.DateAndAuthor(rule, dat, user_id, false)
	ids, err := basic.ExtractIds(inp, []string{"content_id"})
	if err != nil {
		return err
	}
	content_id := bson.ObjectIdHex(ids[0])
	comment_id := bson.NewObjectId()
	if moderate_first {
		err = insertModeration(db, dat, comment_id, content_id, typ)
	} else {
		err = insertToFinal(db, dat, comment_id, content_id)
	}
	// This will be made optional, a facebook style app does not need it, only a bloglike site.
	if err == nil {
		err = insertToVirtual(db, content_id, comment_id, user_id, typ, moderate_first)
	}
	return err
}