Exemple #1
0
func CountFollowingBrandByUserId(userId bson.ObjectId) (num int, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"userid": userId})
}
Exemple #2
0
func CountReviewByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"brandid": brandId})
}
Exemple #3
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 #4
0
func CountReviewByProductId(productId bson.ObjectId) (num int, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"productid": productId})
}
Exemple #5
0
func FindSomeByUserId(userId bson.ObjectId) (r []*Note, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": userId})
}
Exemple #6
0
func FindById(id bson.ObjectId) (review *Review, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
Exemple #7
0
func FindByUserId(userId bson.ObjectId) (r []*FollowBrand, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"userid": userId})
}
Exemple #8
0
func CountBrandFollowerByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"brandid": brandId})
}
Exemple #9
0
func FindByBrandId(brandId bson.ObjectId) (r []*FollowBrand, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"brandid": brandId})
}
Exemple #10
0
func FindByUserAndBrandId(userId, brandId bson.ObjectId) (followBrand *FollowBrand, err error) {
	if !userId.Valid() || !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"userid": userId, "brandid": brandId})
}
Exemple #11
0
func FindSomeByAuthorId(authorId bson.ObjectId) (r []*Post, err error) {
	if !authorId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": authorId})
}
Exemple #12
0
func FindById(id bson.ObjectId) (product *Product, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
Exemple #13
0
// Only called when doing update or delete.
// At inserting, user.OkayToDoAction is sufficient.
// This needs additional action: you can only update or delete a given comment only if it's yours (under a certain level).
func CanModifyComment(db *mgo.Database, inp map[string][]string, correction_level int, user_id bson.ObjectId, user_level int) error {
	rule := map[string]interface{}{
		"content_id": "must",
		"comment_id": "must",
		"type":       "must",
	}
	dat, err := extract.New(rule).Extract(inp)
	if err != nil {
		return err
	}
	// Even if he has the required level, and he is below correction_level, he can't modify other people's comment, only his owns.
	// So we query here the comment and check who is the owner of it.
	if user_level < correction_level {
		content_id_str := basic.StripId(dat["content_id"].(string))
		comment_id_str := basic.StripId(dat["comment_id"].(string))
		auth, err := findCommentAuthor(db, content_id_str, comment_id_str)
		if err != nil {
			return err
		}
		if auth.Hex() != user_id.Hex() {
			return fmt.Errorf("You are not the rightous owner of the comment.")
		}
	}
	return nil
}
Exemple #14
0
func (a *AbstractModel) UpdateByPk(id bson.ObjectId, update interface{}) error {
	if !id.Valid() {
		return errors.New("20314")
	}

	return a.Update(M{"_id": id}, update, true)
}
Exemple #15
0
func DeleteByUserAndBrandId(userId, brandId bson.ObjectId) (err error) {
	if !userId.Valid() || !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return DeleteFollowBrand(bson.M{"userid": userId, "brandid": brandId})
}
Exemple #16
0
// 添加共享d笔记
func (this *NoteService) AddSharedNote(note info.Note, myUserId bson.ObjectId) info.Note {
	// 判断我是否有权限添加
	if shareService.HasUpdateNotebookPerm(note.UserId.Hex(), myUserId.Hex(), note.NotebookId.Hex()) {
		note.CreatedUserId = myUserId // 是我给共享我的人创建的
		return this.AddNote(note)
	}
	return info.Note{}
}
Exemple #17
0
// 查找ObjectId数组中是否有指定值.
func ObjectIdInSlice(id bson.ObjectId, list []bson.ObjectId) bool {
	for _, b := range list {
		if b.Hex() == id.Hex() {
			return true
		}
	}
	return false
}
Exemple #18
0
// Get document from id
func (s *session) GetId(col string, id bson.ObjectId, doc interface{}) error {
	c := s.db.C(col)
	err := c.FindId(id).One(doc)
	if err != nil {
		log.Printf("**ERROR: Could not lookup document with id %v from collection %v: %v", id.Hex(), col, err)
	}
	return err
}
Exemple #19
0
func FindSomeByProductId(productId bson.ObjectId) (rs []*Review, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"productid": productId})
}
Exemple #20
0
func FindSomeByBrandId(brandId bson.ObjectId) (rs []*Review, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"brandid": brandId})
}
Exemple #21
0
func backupServer(serverId string, backupTime time.Time) (err error) {
	wip := <-wipGen.C
	defer close(wip)

	server := servers.Get(serverId)
	if server == nil {
		err = errors.New(fmt.Sprintf("no server for %s", serverId))
		return
	}

	var (
		url  string
		size int64
	)
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		url, size, err = server.BackupWorld(backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_backup",
				"serverId": serverId,
				"retries":  retries,
			})
		}
		return err
	})
	if err != nil {
		return
	}

	var snapshotId bson.ObjectId
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		snapshotId, err = StoreBackupInMongo(serverId, url, size, backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_db_store",
				"serverId": serverId,
				"retries":  retries,
			})

		}
		return err
	})

	pushPinkyEvent(map[string]interface{}{
		"ts":          time.Now(),
		"server_id":   serverId,
		"event":       "server_event",
		"type":        "backed_up",
		"snapshot_id": snapshotId.Hex(),
		"url":         url,
		"size":        size,
	})

	return
}
Exemple #22
0
func (ctx *DBCtx) AllContact(offset bson.ObjectId, limit int) []Contact {
	conts := []Contact{}
	if offset.Valid() {
		ctx.contColl.Find(bson.M{"_id": bson.M{"$gt": offset}}).Limit(limit).All(&conts)
	} else {
		ctx.contColl.Find(nil).Limit(limit).All(&conts)
	}
	return conts
}
Exemple #23
0
func (api *EventsApi) deleteImage(id bson.ObjectId) error {

	err := api.images.DeleteFile(api.images.GetBasePath() + string(os.PathSeparator) + id.Hex() + ".jpg")
	if err != nil {
		return err
	}

	api.imageCache.Remove(api.imageCache.FindKeys(id.Hex()))
	return nil
}
Exemple #24
0
//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (d *Daemon) Authenticate(id bson.ObjectId) error {
	c := db.C("daemons")
	err := c.FindId(id).One(&d.Entry)
	if err == nil {
		d.Id = id.Hex()
		d.OrgId = d.Entry.OrgId.Hex()
		return d.Authorise()
	}
	return err
}
Exemple #25
0
//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (u *User) Authenticate(id bson.ObjectId) error {
	c := db.C("users")
	err := c.FindId(id).One(&u.Entry)
	if err == nil {
		u.Id = id.Hex()
		u.OrgId = u.Entry.OrgId.Hex()
		return u.Authorise()
	}
	return err
}
func mapFromFeed(feed *domain.Feed) feedDao {
	var id bson.ObjectId
	if len(feed.ID) > 0 {
		id = bson.ObjectIdHex(feed.ID)
	} else {
		id = bson.NewObjectId()
		feed.ID = id.Hex()
	}
	return feedDao{id, feed.Uri, feed.LastSync}
}
Exemple #27
0
// 检测ObjectId数组中是否存在某一个id。
func ObjectIdIsIn(ids []bson.ObjectId, id bson.ObjectId) bool {
	result := false
	for i := 0; i < len(ids); i++ {
		if ids[i].Hex() == id.Hex() {
			result = true
			break
		}
	}

	return result
}
Exemple #28
0
func (c User) GetUpdate(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		action := "/User/" + id.Hex()
		user := c.ActiveUser
		if user.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			return c.Render(action, user)
		}
		return c.Forbidden("You are not allowed to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
Exemple #29
0
// Implements bson.Setter for mongo.Ref compatibility.
// Yes this bson dependency is dirty, but necessary
// for transition form mongo.Ref to model.Ref.
func (self *Ref) SetBSON(raw bson.Raw) error {
	var objectId *bson.ObjectId
	if raw.Unmarshal(&objectId) == nil {
		if objectId != nil {
			*self = Ref(objectId.Hex())
		} else {
			*self = ""
		}
		return nil
	}
	return raw.Unmarshal(self)
}
Exemple #30
0
func (table *mongoTable) CheckForId(id bson.ObjectId) error {

	count, err := table.CountById(id)
	if err != nil {
		return err
	}

	if count == 1 {
		return nil
	} else {
		return errors.New(table.collection.Name + " " + id.Hex() + " not found.")
	}
}