forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
150 lines (131 loc) · 4.91 KB
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"github.com/mattermost/mattermost-server/model"
)
func (a *App) GetGroup(id string) (*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().Get(id)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Group), nil
}
func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().GetByRemoteID(remoteID, groupSource)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Group), nil
}
func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().GetAllBySource(groupSource)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Group), nil
}
func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().Create(group)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Group), nil
}
func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().Update(group)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Group), nil
}
func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
result := <-a.Srv.Store.Group().Delete(groupID)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.Group), nil
}
func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) {
result := <-a.Srv.Store.Group().GetMemberUsers(groupID)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
}
func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError) {
result := <-a.Srv.Store.Group().GetMemberUsersPage(groupID, page, perPage)
if result.Err != nil {
return nil, 0, result.Err
}
members := result.Data.([]*model.User)
result = <-a.Srv.Store.Group().GetMemberCount(groupID)
if result.Err != nil {
return nil, 0, result.Err
}
count := int(result.Data.(int64))
return members, count, nil
}
func (a *App) CreateOrRestoreGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
result := <-a.Srv.Store.Group().CreateOrRestoreMember(groupID, userID)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupMember), nil
}
func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
result := <-a.Srv.Store.Group().DeleteMember(groupID, userID)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupMember), nil
}
func (a *App) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
result := <-a.Srv.Store.Group().CreateGroupSyncable(groupSyncable)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupSyncable), nil
}
func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
result := <-a.Srv.Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupSyncable), nil
}
func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
result := <-a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.GroupSyncable), nil
}
func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
result := <-a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupSyncable), nil
}
func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
result := <-a.Srv.Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.GroupSyncable), nil
}
func (a *App) PendingAutoAddTeamMembers(minGroupMembersCreateAt int64) ([]*model.UserTeamIDPair, *model.AppError) {
result := <-a.Srv.Store.Group().PendingAutoAddTeamMembers(minGroupMembersCreateAt)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.UserTeamIDPair), nil
}
func (a *App) PendingAutoAddChannelMembers(minGroupMembersCreateAt int64) ([]*model.UserChannelIDPair, *model.AppError) {
result := <-a.Srv.Store.Group().PendingAutoAddChannelMembers(minGroupMembersCreateAt)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.UserChannelIDPair), nil
}