#96 实现组内的任何一个人都可以分享内容到这个组中.
存在不足:共享内容以分享者进行归类组织. 更好的内容组织方式:共享给组的以组归类组织,共享给个人的以分享者个人组织
This commit is contained in:
@ -61,6 +61,32 @@ func (this *GroupService) GetGroups(userId string) ([]info.Group) {
|
||||
db.ListByQ(db.Groups, bson.M{"UserId": bson.ObjectIdHex(userId)}, &groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
|
||||
// 获取包含此用户的组对象数组
|
||||
func (this *GroupService) GetGroupsContainOf(userId string) []info.Group {
|
||||
groupIds := this.GetGroupIdsContainOf(userId)
|
||||
groups := []info.Group{}
|
||||
db.ListByQ(db.Groups, bson.M{"_id": bson.M{"$in": groupIds}}, &groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
// 获取包含此用户的组Id数组
|
||||
func (this *GroupService) GetGroupIdsContainOf(userId string) []bson.ObjectId {
|
||||
groupUsers := []info.GroupUser{}
|
||||
db.ListByQWithFields(db.GroupUsers, bson.M{"UserId": bson.ObjectIdHex(userId)}, []string{"GroupId"}, &groupUsers)
|
||||
if len(groupUsers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
groupIds := make([]bson.ObjectId, len(groupUsers))
|
||||
for i, each := range groupUsers {
|
||||
groupIds[i] = each.GroupId
|
||||
}
|
||||
|
||||
return groupIds
|
||||
}
|
||||
|
||||
// 得到分组, shareService用
|
||||
func (this *GroupService) GetGroup(userId, groupId string) (info.Group) {
|
||||
// 得到分组s
|
||||
@ -131,3 +157,8 @@ func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool
|
||||
}
|
||||
return db.Delete(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}), ""
|
||||
}
|
||||
|
||||
// 判断组中是否包含指定用户
|
||||
func (this *GroupService) IsExistsGroupUser(userId, groupId string) (ok bool) {
|
||||
return db.Has(db.GroupUsers, bson.M{"UserId": bson.ObjectIdHex(userId), "GroupId": bson.ObjectIdHex(groupId)})
|
||||
}
|
@ -666,8 +666,7 @@ func (this *ShareService) HasReadNotePerm(noteId, userId string) bool {
|
||||
|
||||
// 得到笔记分享给的groups
|
||||
func (this *ShareService) GetNoteShareGroups(noteId, userId string) []info.ShareNote {
|
||||
// 得到分组s
|
||||
groups := groupService.GetGroups(userId)
|
||||
groups := groupService.GetGroupsContainOf(userId)
|
||||
|
||||
// 得到有分享的分组
|
||||
shares := []info.ShareNote{}
|
||||
@ -694,9 +693,7 @@ func (this *ShareService) GetNoteShareGroups(noteId, userId string) []info.Share
|
||||
|
||||
// 共享笔记给分组
|
||||
func (this *ShareService) AddShareNoteGroup(userId, noteId, groupId string, perm int) (bool) {
|
||||
// 得到group, 是否是我的group
|
||||
group := groupService.GetGroup(userId, groupId)
|
||||
if group.GroupId == "" {
|
||||
if !groupService.IsExistsGroupUser(userId, groupId) {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -724,8 +721,7 @@ func (this *ShareService) DeleteShareNoteGroup(userId, noteId, groupId string) b
|
||||
|
||||
// 得到笔记本分享给的groups
|
||||
func (this *ShareService) GetNotebookShareGroups(notebookId, userId string) []info.ShareNotebook {
|
||||
// 得到分组s
|
||||
groups := groupService.GetGroups(userId)
|
||||
groups := groupService.GetGroupsContainOf(userId)
|
||||
|
||||
// 得到有分享的分组
|
||||
shares := []info.ShareNotebook{}
|
||||
@ -752,9 +748,7 @@ func (this *ShareService) GetNotebookShareGroups(notebookId, userId string) []in
|
||||
}
|
||||
// 共享笔记给分组
|
||||
func (this *ShareService) AddShareNotebookGroup(userId, notebookId, groupId string, perm int) (bool) {
|
||||
// 得到group, 是否是我的group
|
||||
group := groupService.GetGroup(userId, groupId)
|
||||
if group.GroupId == "" {
|
||||
if !groupService.IsExistsGroupUser(userId, groupId) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user