コード例 #1
0
ファイル: AttachService.go プロジェクト: nosqldb/zhujian
// delete attach
func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) {
	attach := info.Attach{}
	db.Get(db.Attachs, attachId, &attach)

	if attach.AttachId != "" {
		// 判断是否有权限为笔记添加附件
		if !shareService.HasUpdateNotePerm(attach.NoteId.Hex(), userId) {
			return false, "No Perm"
		}

		if db.Delete(db.Attachs, bson.M{"_id": bson.ObjectIdHex(attachId)}) {
			this.updateNoteAttachNum(attach.NoteId, -1)
			attach.Path = strings.TrimLeft(attach.Path, "/")
			err := os.Remove(revel.BasePath + "/" + attach.Path)
			if err == nil {
				// userService.UpdateAttachSize(note.UserId.Hex(), -attach.Size)
				// 修改note Usn
				noteService.IncrNoteUsn(attach.NoteId.Hex(), userId)

				return true, "delete file success"
			}
			return false, "delete file error"
		}
		return false, "db error"
	}
	return false, "no such item"
}
コード例 #2
0
ファイル: BlogService.go プロジェクト: nosqldb/zhujian
// 点赞
// retun ok , isLike
func (this *BlogService) LikeBlog(noteId, userId string) (ok bool, isLike bool) {
	ok = false
	isLike = false
	if noteId == "" || userId == "" {
		return
	}
	// 判断是否点过赞, 如果点过那么取消点赞
	note := noteService.GetNoteById(noteId)
	if !note.IsBlog /*|| note.UserId.Hex() == userId */ {
		return
	}

	noteIdO := bson.ObjectIdHex(noteId)
	userIdO := bson.ObjectIdHex(userId)
	var n int
	if !db.Has(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO}) {
		n = 1
		// 添加之
		db.Insert(db.BlogLikes, info.BlogLike{LikeId: bson.NewObjectId(), NoteId: noteIdO, UserId: userIdO, CreatedTime: time.Now()})
		isLike = true
	} else {
		// 已点过, 那么删除之
		n = -1
		db.Delete(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO})
		isLike = false
	}
	ok = db.Update(db.Notes, bson.M{"_id": noteIdO}, bson.M{"$inc": bson.M{"LikeNum": n}})

	return
}
コード例 #3
0
ファイル: GroupService.go プロジェクト: nosqldb/zhujian
// 删除用户
func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool, msg string) {
	// groupId是否是ownUserId的?
	/*
		if !this.IsExistsGroupUser(ownUserId, groupId) {
			return false, "forbidden"
		}
	*/
	if !this.isMyGroup(ownUserId, groupId) {
		return false, "forbidden"
	}

	// 删除该用户分享到本组的笔记本, 笔记
	shareService.DeleteShareNotebookGroupWhenDeleteGroupUser(userId, groupId)
	shareService.DeleteShareNoteGroupWhenDeleteGroupUser(userId, groupId)

	return db.Delete(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}), ""
}
コード例 #4
0
ファイル: ShareService.go プロジェクト: nosqldb/zhujian
// 第三方测试没有userId
func (this *ShareService) AddShareNoteToUserId(noteId string, perm int, userId, toUserId string) (bool, string, string) {
	// 添加一条记录说明两者存在关系
	this.AddHasShareNote(userId, toUserId)

	// 先删除之
	db.Delete(db.ShareNotes, bson.M{"NoteId": bson.ObjectIdHex(noteId),
		"UserId":   bson.ObjectIdHex(userId),
		"ToUserId": bson.ObjectIdHex(toUserId),
	})

	shareNote := info.ShareNote{NoteId: bson.ObjectIdHex(noteId),
		UserId:      bson.ObjectIdHex(userId),
		ToUserId:    bson.ObjectIdHex(toUserId),
		Perm:        perm,
		CreatedTime: time.Now(),
	}
	return db.Insert(db.ShareNotes, shareNote), "", toUserId
}
コード例 #5
0
ファイル: BlogService.go プロジェクト: nosqldb/zhujian
// 作者(或管理员)可以删除所有评论
// 自己可以删除评论
func (this *BlogService) DeleteComment(noteId, commentId, userId string) bool {
	note := noteService.GetNoteById(noteId)
	if !note.IsBlog {
		return false
	}

	comment := info.BlogComment{}
	db.Get(db.BlogComments, commentId, &comment)

	if comment.CommentId == "" {
		return false
	}

	if userId == configService.GetAdminUserId() || note.UserId.Hex() == userId || comment.UserId.Hex() == userId {
		if db.Delete(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)}) {
			// 评论-1
			db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}})
			return true
		}
	}

	return false
}
コード例 #6
0
ファイル: ThemeService.go プロジェクト: nosqldb/zhujian
// 删除主题
func (this *ThemeService) DeleteTheme(userId, themeId string) (ok bool) {
	return db.Delete(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId), "UserId": bson.ObjectIdHex(userId), "IsActive": false})
}
コード例 #7
0
ファイル: TokenService.go プロジェクト: nosqldb/zhujian
// 删除token
func (this *TokenService) DeleteToken(userId string, tokenType int) bool {
	return db.Delete(db.Tokens, bson.M{"_id": bson.ObjectIdHex(userId), "Type": tokenType})
}
コード例 #8
0
ファイル: ShareService.go プロジェクト: nosqldb/zhujian
func (this *ShareService) DeleteShareNoteGroupWhenDeleteGroupUser(userId, groupId string) bool {
	return db.Delete(db.ShareNotes, bson.M{
		"UserId":    bson.ObjectIdHex(userId),
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}
コード例 #9
0
ファイル: ShareService.go プロジェクト: nosqldb/zhujian
func (this *ShareService) DeleteAllShareNoteGroup(groupId string) bool {
	return db.Delete(db.ShareNotes, bson.M{
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}
コード例 #10
0
ファイル: ShareService.go プロジェクト: nosqldb/zhujian
// 删除
func (this *ShareService) DeleteShareNotebookGroup(userId, notebookId, groupId string) bool {
	return db.Delete(db.ShareNotebooks, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
		"UserId":    bson.ObjectIdHex(userId),
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}