Merge pull request #104 from Refactoring/master

实现组内人员可分享内容至这个组
This commit is contained in:
life committed 2015-04-02 09:43:12 +08:00
commit b59eba4ca4
249 files changed
+35 -10644

No files matched your search

+31
View File
@@ -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)})
}
+4 -10
View File
@@ -674,8 +674,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{}
@@ -702,9 +701,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
}
@@ -732,8 +729,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{}
@@ -760,9 +756,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
}