示例#1
0
文件: fulltext.go 项目: Laller/chill
func (c *C) RegenerateFulltext(a iface.Filter) error {
	cb := func(doc map[string]interface{}, g iface.Grabbed) error {
		upd := c.updateFromDoc(doc)
		return g.Update(upd)
	}
	return a.Iterate(cb)
}
示例#2
0
文件: file.go 项目: Laller/chill
func (c *C) New(a iface.Filter) ([]map[string]interface{}, error) {
	scheme, err := c.getScheme(a.Subject(), "Insert")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, nil)
}
示例#3
0
文件: basics.go 项目: Laller/chill
func (b *Basics) UpdateAll(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$set": data,
	}
	_, err := a.UpdateAll(upd)
	return err
}
示例#4
0
文件: jsonedit.go 项目: Laller/chill
func (c *C) Insert(a iface.Filter, data map[string]interface{}) error {
	m, err := c.decrypt(data)
	if err != nil {
		return err
	}
	m["created"] = time.Now().UnixNano() // Should include user too maybe.
	return a.Insert(m)
}
示例#5
0
文件: jsonedit.go 项目: Laller/chill
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
	m, err := c.decrypt(data)
	if err != nil {
		return err
	}
	m["modified"] = time.Now().UnixNano()
	return a.Update(m)
}
示例#6
0
文件: file.go 项目: Laller/chill
func (c *C) DeleteFile(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$pull": map[string]interface{}{
			data["key"].(string): data["file"],
		},
	}
	return a.Update(upd)
}
示例#7
0
文件: fulltext.go 项目: Laller/chill
func (c *C) SaveFulltext(a iface.Filter) error {
	doc, err := a.FindOne()
	if err != nil {
		return err
	}
	upd := c.updateFromDoc(doc)
	return a.Update(upd)
}
示例#8
0
// Finds a user by id.
func FindUser(a iface.Filter, id bson.ObjectId) (map[string]interface{}, error) {
	q := m{"_id": id}
	v, err := a.AddQuery(q).FindOne()
	if err != nil {
		return nil, err
	}
	delete(v, "password")
	return v, nil
}
示例#9
0
// Finds he user by name password equality.
func namePass(a iface.Filter, name, encoded_pass string) (map[string]interface{}, error) {
	q := bson.M{
		"name":     name,
		"password": encoded_pass,
	}
	doc, err := a.AddQuery(q).FindOne()
	if err != nil {
		return nil, err
	}
	return convert.Clean(doc).(map[string]interface{}), nil
}
示例#10
0
文件: file.go 项目: Laller/chill
func (c *C) Edit(a iface.Filter) ([]map[string]interface{}, error) {
	doc, err := a.FindOne()
	if err != nil {
		return nil, err
	}
	scheme, err := c.getScheme(a.Subject(), "Update")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, doc)
}
示例#11
0
// Returns true if the username is still available.
func NameAvailable(a iface.Filter, name string) (bool, error) {
	q := bson.M{"slug": slugify.S(name)}
	users, err := a.AddQuery(q).Find()
	if err != nil {
		return false, err
	}
	if len(users) > 0 {
		return false, nil
	}
	return true, nil
}
示例#12
0
func RegisterUser(a iface.Filter, user map[string]interface{}) (bson.ObjectId, error) {
	user["password"] = hashPass(user["password"].(string))
	if _, has := user["level"]; !has {
		user["level"] = 100
	}
	user_id := bson.NewObjectId()
	user["_id"] = user_id
	err := a.Insert(user)
	if err != nil {
		return "", fmt.Errorf("Name is not unique.")
	}
	return user_id, nil
}
示例#13
0
文件: file.go 项目: Laller/chill
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
	files_map, has := data["_files"].(map[string]interface{})
	upd := map[string]interface{}{
		"$set": data,
	}
	if has {
		ids, err := a.Ids()
		if err != nil {
			return err
		}
		err = c.moveFiles(a.Subject(), ids[0].Hex(), files_map)
		if err != nil {
			return err
		}
		delete(data, "_files")
		upd["$addToSet"] = eachIfNeeded(fileheadersToFilenames(files_map))
	}
	err := a.Update(upd)
	if err != nil {
		return err
	}
	if c.Ev != nil {
		c.Ev.Fire("Updated", a)
		c.Ev.Fire(a.Subject()+"Updated", a)
	}
	return nil
}
示例#14
0
文件: jsonedit.go 项目: Laller/chill
func (c *C) Edit(a iface.Filter) (string, error) {
	doc, err := a.FindOne()
	if err != nil {
		return "", err
	}
	for _, v := range ignore {
		delete(doc, v)
	}
	marsh, err := json.MarshalIndent(doc, "", "\t")
	if err != nil {
		return "", err
	}
	return string(marsh), nil
}
示例#15
0
文件: basics.go 项目: Laller/chill
func (b *Basics) Update(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$set": data,
	}
	err := a.Update(upd)
	if err != nil {
		return err
	}
	if b.Ev != nil {
		b.Ev.Fire("Updated", a)
		b.Ev.Fire(a.Subject()+"Updated", a)
	}
	return nil
}
示例#16
0
文件: users.go 项目: Laller/chill
func hasAdmin(f iface.Filter) error {
	q := map[string]interface{}{
		"level": 300,
	}
	f.AddQuery(q)
	c, err := f.Count()
	if err != nil {
		return err
	}
	if c > 0 {
		return fmt.Errorf("Site already has an admin.")
	}
	return nil
}
示例#17
0
文件: filter.go 项目: Laller/chill
func (f *Filter) Reduce(a ...iface.Filter) (iface.Filter, error) {
	l := len(a)
	if l == 0 {
		return &Filter{}, fmt.Errorf("Nothing to reduce.")
	}
	var prev iface.Filter
	prev = f
	for _, v := range a {
		ids, err := prev.Ids()
		if err != nil {
			return &Filter{}, err
		}
		v.AddParents("_"+prev.Subject(), ids)
		prev = v
	}
	return prev, nil
}
示例#18
0
文件: file.go 项目: Laller/chill
func (c *C) Insert(a iface.Filter, data map[string]interface{}) (bson.ObjectId, error) {
	files_map, has_files := data["_files"].(map[string]interface{})
	if has_files {
		delete(data, "_files")
		merge(data, fileheadersToFilenames(files_map))
	}
	id, err := c.Basics.Insert(a, data)
	if err != nil {
		return id, err
	}
	if has_files {
		err := c.moveFiles(a.Subject(), id.Hex(), files_map)
		if err != nil {
			return "", err
		}
	}
	return id, nil
}
示例#19
0
文件: basics.go 项目: Laller/chill
func (b *Basics) Get(a iface.Filter) ([]interface{}, *QueryInfo, error) {
	list, err := a.Find()
	if err != nil {
		return nil, nil, err
	}
	count, err := a.Count()
	if err != nil {
		return nil, nil, err
	}
	return list, &QueryInfo{
		count, a.Modifiers().Skip(),
		a.Modifiers().Limit(),
		a.Modifiers().Sort(),
	}, nil
}
示例#20
0
文件: basics.go 项目: Laller/chill
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (bson.ObjectId, error) {
	id := bson.NewObjectId()
	data["_id"] = id
	err := a.Insert(data)
	if err != nil {
		return "", err
	}
	if b.Ev != nil {
		q := map[string]interface{}{
			"_id": id,
		}
		filt := a.Clone().AddQuery(q)
		b.Ev.Fire("Inserted", filt)
		b.Ev.Fire(a.Subject()+"Inserted", filt)
	}
	return id, nil
}
示例#21
0
文件: basics.go 项目: Laller/chill
func (b *Basics) RemoveAll(a iface.Filter) error {
	_, err := a.RemoveAll()
	return err
}
示例#22
0
文件: file.go 项目: Laller/chill
func (c *C) DeleteAllFiles(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$unset": data["key"].(string), // We don't care about the files themselves.
	}
	return a.Update(upd)
}
示例#23
0
文件: basics.go 项目: Laller/chill
func (b *Basics) GetSingle(a iface.Filter) (map[string]interface{}, error) {
	return a.FindOne()
}
示例#24
0
文件: basics.go 项目: Laller/chill
func (b *Basics) Remove(a iface.Filter) error {
	return a.Remove()
}