本文整理汇总了Golang中github.com/leanote/leanote/app/db.Has函数的典型用法代码示例。如果您正苦于以下问题:Golang Has函数的具体用法?Golang Has怎么用?Golang Has使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Has函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: HasUpdatePerm
// updatedUserId是否有修改userId noteId的权限?
func (this *ShareService) HasUpdatePerm(userId, updatedUserId, noteId string) bool {
// 1. noteId是否被共享了?
// 得到该note share的信息
/*
UserId bson.ObjectId `bson:"UserId"`
ToUserId bson.ObjectId `bson:"ToUserId"`
NoteId bson.ObjectId `bson:"NoteId"`
Perm int `bson:"Perm"` // 权限, 0只读, 1可修改
*/
if !db.Has(db.ShareNotes,
bson.M{"UserId": bson.ObjectIdHex(userId), "ToUserId": bson.ObjectIdHex(updatedUserId), "NoteId": bson.ObjectIdHex(noteId), "Perm": 1}) {
// noteId的notebookId是否被共享了?
notebookId := noteService.GetNotebookId(noteId)
if notebookId.Hex() == "" {
return false
}
// 判断notebook是否被共享
if !db.Has(db.ShareNotebooks,
bson.M{"UserId": bson.ObjectIdHex(userId), "ToUserId": bson.ObjectIdHex(updatedUserId), "NotebookId": notebookId, "Perm": 1}) {
return false
} else {
return true
}
} else {
return true
}
}
开发者ID:bigxing,项目名称:leanote,代码行数:29,代码来源:ShareService.go
示例2: IsMyFile
// 是否是我的文件
func (this *FileService) IsMyFile(userId, fileId string) bool {
// 如果有问题会panic
if !bson.IsObjectIdHex(fileId) || !bson.IsObjectIdHex(userId) {
return false
}
return db.Has(db.Files, bson.M{"UserId": bson.ObjectIdHex(userId), "_id": bson.ObjectIdHex(fileId)})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:8,代码来源:FileService.go
示例3: IsExistsGroupUser
// 判断组中是否包含指定用户
func (this *GroupService) IsExistsGroupUser(userId, groupId string) (ok bool) {
// 如果我拥有这个组, 那也行
if this.isMyGroup(userId, groupId) {
return true
}
return db.Has(db.GroupUsers, bson.M{"UserId": bson.ObjectIdHex(userId), "GroupId": bson.ObjectIdHex(groupId)})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:8,代码来源:GroupService.go
示例4: LikeBlog
// 点赞
// 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
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:32,代码来源:BlogService.go
示例5: getUniqueUrlTitle
func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int) string {
urlTitle2 := urlTitle
// 判断urlTitle是不是过长, 过长则截断, 300
// 不然生成index有问题
// it will not index a single field with more than 1024 bytes.
// If you're indexing a field that is 2.5MB, it's not really indexing it, it's being skipped.
if len(urlTitle2) > 320 {
urlTitle2 = urlTitle2[:300] // 为什么要少些, 因为怕无限循环, 因为把padding截了
}
if padding > 1 {
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
}
userIdO := bson.ObjectIdHex(userId)
var collection *mgo.Collection
if types == "note" {
collection = db.Notes
} else if types == "notebook" {
collection = db.Notebooks
} else if types == "single" {
collection = db.BlogSingles
}
for db.Has(collection, bson.M{"UserId": userIdO, "UrlTitle": urlTitle2}) { // 用户下唯一
padding++
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
}
return urlTitle2
}
开发者ID:nevernet,项目名称:leanote,代码行数:31,代码来源:init.go
示例6: HasUpdateNotebookPerm
// updatedUserId是否有修改userId notebookId的权限?
func (this *ShareService) HasUpdateNotebookPerm(userId, updatedUserId, notebookId string) bool {
// 判断notebook是否被共享
if !db.Has(db.ShareNotebooks,
bson.M{"UserId": bson.ObjectIdHex(userId), "ToUserId": bson.ObjectIdHex(updatedUserId), "NotebookId": bson.ObjectIdHex(notebookId), "Perm": 1}) {
return false
} else {
return true
}
}
开发者ID:bigxing,项目名称:leanote,代码行数:10,代码来源:ShareService.go
示例7: IsILikeIt
func (this *BlogService) IsILikeIt(noteId, userId string) bool {
if userId == "" {
return false
}
if db.Has(db.BlogLikes, bson.M{"NoteId": bson.ObjectIdHex(noteId), "UserId": bson.ObjectIdHex(userId)}) {
return true
}
return false
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:9,代码来源:BlogService.go
示例8: HasSharedNotebook
// noteId的notebook是否共享了给我
func (this *ShareService) HasSharedNotebook(noteId, myUserId, sharedUserId string) bool {
notebookId := noteService.GetNotebookId(noteId)
if notebookId != "" {
return db.Has(db.ShareNotebooks, bson.M{"NotebookId": notebookId,
"UserId": bson.ObjectIdHex(sharedUserId),
"ToUserId": bson.ObjectIdHex(myUserId),
})
}
return false
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:11,代码来源:ShareService.go
示例9: ActiveTheme
// 使用主题
func (this *ThemeService) ActiveTheme(userId, themeId string) (ok bool) {
if db.Has(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId), "UserId": bson.ObjectIdHex(userId)}) {
// 之前的设为false
db.UpdateByQField(db.Themes, bson.M{"UserId": bson.ObjectIdHex(userId), "IsActive": true}, "IsActive", false)
// 现在的设为true
db.UpdateByQField(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId)}, "IsActive", true)
// UserBlog ThemeId
db.UpdateByQField(db.UserBlogs, bson.M{"_id": bson.ObjectIdHex(userId)}, "ThemeId", bson.ObjectIdHex(themeId))
return true
}
return false
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:14,代码来源:ThemeService.go
示例10: HasReadPerm
// updatedUserId是否有查看userId noteId的权限?
// userId是所有者
func (this *ShareService) HasReadPerm(userId, updatedUserId, noteId string) bool {
q := this.getOrQ(updatedUserId) // (toUserId == "xxx" || ToGroupId in (1, 2,3))
q["UserId"] = bson.ObjectIdHex(userId)
q["NoteId"] = bson.ObjectIdHex(noteId)
if !db.Has(db.ShareNotes, q) {
// noteId的notebookId是否被共享了?
notebookId := noteService.GetNotebookId(noteId)
if notebookId.Hex() == "" {
return false
}
delete(q, "NoteId")
q["NotebookId"] = notebookId
// 判断notebook是否被共享
if !db.Has(db.ShareNotebooks, q) {
return false
} else {
return true
}
} else {
return true
}
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:26,代码来源:ShareService.go
示例11: UpdateUsername
// 更新username
func (this *UserService) UpdateUsername(userId, username string) (bool, string) {
if userId == "" || username == "" || username == "admin" { // admin用户是内置的, 不能设置
return false, "usernameIsExisted"
}
usernameRaw := username // 原先的, 可能是同一个, 但有大小写
username = strings.ToLower(username)
// 先判断是否存在
userIdO := bson.ObjectIdHex(userId)
if db.Has(db.Users, bson.M{"Username": username, "_id": bson.M{"$ne": userIdO}}) {
return false, "usernameIsExisted"
}
ok := db.UpdateByQMap(db.Users, bson.M{"_id": userIdO}, bson.M{"Username": username, "UsernameRaw": usernameRaw})
return ok, ""
}
开发者ID:rainkong,项目名称:leanote,代码行数:17,代码来源:UserService.go
示例12: AddUser
// 为group添加用户
// 用户是否已存在?
func (this *GroupService) AddUser(ownUserId, groupId, userId string) (ok bool, msg string) {
// groupId是否是ownUserId的?
if !this.isMyGroup(ownUserId, groupId) {
return false, "forbidden"
}
// 是否已存在
if db.Has(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}) {
return false, "hasUsers"
}
return db.Insert(db.GroupUsers, info.GroupUser{
GroupUserId: bson.NewObjectId(),
GroupId: bson.ObjectIdHex(groupId),
UserId: bson.ObjectIdHex(userId),
CreatedTime: time.Now(),
}), ""
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:20,代码来源:GroupService.go
示例13: getUniqueUrlTitle
func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int) string {
urlTitle2 := urlTitle
if padding > 1 {
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
}
userIdO := bson.ObjectIdHex(userId)
var collection *mgo.Collection
if types == "note" {
collection = db.Notes
} else if types == "notebook" {
collection = db.Notebooks
} else if types == "single" {
collection = db.BlogSingles
}
for db.Has(collection, bson.M{"UserId": userIdO, "UrlTitle": urlTitle2}) { // 用户下唯一
padding++
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
}
return urlTitle2
}
开发者ID:intZz,项目名称:leanote,代码行数:22,代码来源:init.go
示例14: IsMyNotebook
// 判断是否是我的notebook
func (this *NotebookService) IsMyNotebook(notebookId, userId string) bool {
return db.Has(db.Notebooks, bson.M{"_id": bson.ObjectIdHex(notebookId), "UserId": bson.ObjectIdHex(userId)})
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:4,代码来源:NotebookService.go
示例15: HasSharedNote
// userId是否被共享了noteId
func (this *ShareService) HasSharedNote(noteId, myUserId string) bool {
return db.Has(db.ShareNotes, bson.M{"ToUserId": bson.ObjectIdHex(myUserId), "NoteId": bson.ObjectIdHex(noteId)})
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:4,代码来源:ShareService.go
示例16: isMyGroup
func (this *GroupService) isMyGroup(ownUserId, groupId string) (ok bool) {
return db.Has(db.Groups, bson.M{"_id": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(ownUserId)})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:3,代码来源:GroupService.go
示例17: GetFile
// 获取文件路径
// 要判断是否具有权限
// userId是否具有fileId的访问权限
func (this *FileService) GetFile(userId, fileId string) string {
if fileId == "" {
return ""
}
file := info.File{}
db.Get(db.Files, fileId, &file)
path := file.Path
if path == "" {
return ""
}
// 1. 判断权限
// 是否是我的文件
if userId != "" && file.UserId.Hex() == userId {
return path
}
// 得到使用过该fileId的所有笔记NoteId
// 这些笔记是否有public的, 若有则ok
// 这些笔记(笔记本)是否有共享给我的, 若有则ok
noteIds := noteImageService.GetNoteIds(fileId)
if noteIds != nil && len(noteIds) > 0 {
// 这些笔记是否有public的
if db.Has(db.Notes, bson.M{"_id": bson.M{"$in": noteIds}, "IsBlog": true}) {
return path
}
// 2014/12/28 修复, 如果是分享给用户组, 那就不行, 这里可以实现
for _, noteId := range noteIds {
note := noteService.GetNoteById(noteId.Hex())
if shareService.HasReadPerm(note.UserId.Hex(), userId, noteId.Hex()) {
return path
}
}
/*
// 若有共享给我的笔记?
// 对该笔记可读?
if db.Has(db.ShareNotes, bson.M{"ToUserId": bson.ObjectIdHex(userId), "NoteId": bson.M{"$in": noteIds}}) {
return path
}
// 笔记本是否共享给我?
// 通过笔记得到笔记本
notes := []info.Note{}
db.ListByQWithFields(db.Notes, bson.M{"_id": bson.M{"$in": noteIds}}, []string{"NotebookId"}, ¬es)
if notes != nil && len(notes) > 0 {
notebookIds := make([]bson.ObjectId, len(notes))
for i := 0; i < len(notes); i++ {
notebookIds[i] = notes[i].NotebookId
}
if db.Has(db.ShareNotebooks, bson.M{"ToUserId": bson.ObjectIdHex(userId), "NotebookId": bson.M{"$in": notebookIds}}) {
return path
}
}
*/
}
// 可能是刚复制到owner上, 但内容又没有保存, 所以没有note->imageId的映射, 此时看是否有fromFileId
if file.FromFileId != "" {
fromFile := info.File{}
db.Get2(db.Files, file.FromFileId, &fromFile)
if fromFile.UserId.Hex() == userId {
return fromFile.Path
}
}
return ""
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:75,代码来源:FileService.go
示例18: IsMyFile
// 是否是我的文件
func (this *FileService) IsMyFile(userId, fileId string) bool {
return db.Has(db.Files, bson.M{"UserId": bson.ObjectIdHex(userId), "_id": bson.ObjectIdHex(fileId)})
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:4,代码来源:FileService.go
注:本文中的github.com/leanote/leanote/app/db.Has函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论