forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncables.go
63 lines (52 loc) · 1.61 KB
/
syncables.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
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"github.com/mattermost/mattermost-server/mlog"
)
// PopulateSyncablesSince adds users to teams and channels based on their group memberships and how those groups are
// configured to sync with teams and channels for group members on or after the given timestamp.
func (a *App) PopulateSyncablesSince(groupMembersCreatedAfter int64) error {
userTeamIDs, appErr := a.PendingAutoAddTeamMembers(groupMembersCreatedAfter)
if appErr != nil {
return appErr
}
for _, userTeam := range userTeamIDs {
_, err := a.AddTeamMember(userTeam.TeamID, userTeam.UserID)
if err != nil {
return err
}
a.Log.Info("added teammember",
mlog.String("user_id", userTeam.UserID),
mlog.String("team_id", userTeam.TeamID),
)
}
userChannelIDs, appErr := a.PendingAutoAddChannelMembers(groupMembersCreatedAfter)
if appErr != nil {
return appErr
}
for _, userChannel := range userChannelIDs {
channel, err := a.GetChannel(userChannel.ChannelID)
if err != nil {
return err
}
// First add user to team
_, err = a.AddTeamMember(channel.TeamId, userChannel.UserID)
if err != nil {
return err
}
a.Log.Info("added teammember",
mlog.String("user_id", userChannel.UserID),
mlog.String("team_id", channel.TeamId),
)
_, err = a.AddChannelMember(userChannel.UserID, channel, "", "", false)
if err != nil {
return err
}
a.Log.Info("added channelmember",
mlog.String("user_id", userChannel.UserID),
mlog.String("channel_id", userChannel.ChannelID),
)
}
return nil
}