分享给项目组无法输出已设置项目组 #143
This commit is contained in:
@ -62,29 +62,30 @@ func (this *GroupService) GetGroups(userId string) ([]info.Group) {
|
|||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取包含此用户的组对象数组
|
// 获取包含此用户的组对象数组
|
||||||
|
// 获取该用户所属组, 和我的组
|
||||||
func (this *GroupService) GetGroupsContainOf(userId string) []info.Group {
|
func (this *GroupService) GetGroupsContainOf(userId string) []info.Group {
|
||||||
groupIds := this.GetGroupIdsContainOf(userId)
|
// 我的组
|
||||||
|
myGroups := this.GetGroups(userId)
|
||||||
|
myGroupMap := map[bson.ObjectId]bool{}
|
||||||
|
|
||||||
|
for _, group := range myGroups {
|
||||||
|
myGroupMap[group.GroupId] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所属组
|
||||||
|
groupIds := this.GetBelongToGroupIds(userId)
|
||||||
|
|
||||||
groups := []info.Group{}
|
groups := []info.Group{}
|
||||||
db.ListByQ(db.Groups, bson.M{"_id": bson.M{"$in": groupIds}}, &groups)
|
db.ListByQ(db.Groups, bson.M{"_id": bson.M{"$in": groupIds}}, &groups)
|
||||||
return groups
|
|
||||||
}
|
for _, group := range groups {
|
||||||
|
if !myGroupMap[group.GroupId] {
|
||||||
// 获取包含此用户的组Id数组
|
myGroups = append(myGroups, group)
|
||||||
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))
|
return myGroups
|
||||||
for i, each := range groupUsers {
|
|
||||||
groupIds[i] = each.GroupId
|
|
||||||
}
|
|
||||||
|
|
||||||
return groupIds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 得到分组, shareService用
|
// 得到分组, shareService用
|
||||||
@ -160,5 +161,9 @@ func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool
|
|||||||
|
|
||||||
// 判断组中是否包含指定用户
|
// 判断组中是否包含指定用户
|
||||||
func (this *GroupService) IsExistsGroupUser(userId, groupId string) (ok bool) {
|
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)})
|
return db.Has(db.GroupUsers, bson.M{"UserId": bson.ObjectIdHex(userId), "GroupId": bson.ObjectIdHex(groupId)})
|
||||||
}
|
}
|
Reference in New Issue
Block a user