Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
// only that channel's members are created. If channelID is nil all channel memberships are created.
|
||||
// If includeRemovedMembers is true, then channel members who left or were removed from the channel will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) createDefaultChannelMemberships(since int64, channelID *string, includeRemovedMembers bool) error {
|
||||
func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, channelID *string, includeRemovedMembers bool) error {
|
||||
channelMembers, appErr := a.ChannelMembersToAdd(since, channelID, includeRemovedMembers)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -36,7 +37,7 @@ func (a *App) createDefaultChannelMemberships(since int64, channelID *string, in
|
||||
|
||||
// First add user to team
|
||||
if tmem == nil {
|
||||
_, err = a.AddTeamMember(channel.TeamId, userChannel.UserID)
|
||||
_, err = a.AddTeamMember(c, channel.TeamId, userChannel.UserID)
|
||||
if err != nil {
|
||||
if err.Id == "api.team.join_user_to_team.allowed_domains.app_error" {
|
||||
a.Log().Info("User not added to channel - the domain associated with the user is not in the list of allowed team domains",
|
||||
@@ -54,7 +55,7 @@ func (a *App) createDefaultChannelMemberships(since int64, channelID *string, in
|
||||
)
|
||||
}
|
||||
|
||||
_, err = a.AddChannelMember(userChannel.UserID, channel, ChannelMemberOpts{
|
||||
_, err = a.AddChannelMember(c, userChannel.UserID, channel, ChannelMemberOpts{
|
||||
SkipTeamMemberIntegrityCheck: true,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -82,14 +83,14 @@ func (a *App) createDefaultChannelMemberships(since int64, channelID *string, in
|
||||
// only that team's members are created. If teamID is nil all team memberships are created.
|
||||
// If includeRemovedMembers is true, then team members who left or were removed from the team will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) createDefaultTeamMemberships(since int64, teamID *string, includeRemovedMembers bool) error {
|
||||
func (a *App) createDefaultTeamMemberships(c *request.Context, since int64, teamID *string, includeRemovedMembers bool) error {
|
||||
teamMembers, appErr := a.TeamMembersToAdd(since, teamID, includeRemovedMembers)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
for _, userTeam := range teamMembers {
|
||||
_, err := a.AddTeamMember(userTeam.TeamID, userTeam.UserID)
|
||||
_, err := a.AddTeamMember(c, userTeam.TeamID, userTeam.UserID)
|
||||
if err != nil {
|
||||
if err.Id == "api.team.join_user_to_team.allowed_domains.app_error" {
|
||||
a.Log().Info("User not added to team - the domain associated with the user is not in the list of allowed team domains",
|
||||
@@ -114,13 +115,13 @@ func (a *App) createDefaultTeamMemberships(since int64, teamID *string, includeR
|
||||
// are configured to sync with teams and channels for group members on or after the given timestamp.
|
||||
// If includeRemovedMembers is true, then members who left or were removed from a team/channel will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) CreateDefaultMemberships(since int64, includeRemovedMembers bool) error {
|
||||
err := a.createDefaultTeamMemberships(since, nil, includeRemovedMembers)
|
||||
func (a *App) CreateDefaultMemberships(c *request.Context, since int64, includeRemovedMembers bool) error {
|
||||
err := a.createDefaultTeamMemberships(c, since, nil, includeRemovedMembers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.createDefaultChannelMemberships(since, nil, includeRemovedMembers)
|
||||
err = a.createDefaultChannelMemberships(c, since, nil, includeRemovedMembers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -130,13 +131,13 @@ func (a *App) CreateDefaultMemberships(since int64, includeRemovedMembers bool)
|
||||
|
||||
// DeleteGroupConstrainedMemberships deletes team and channel memberships of users who aren't members of the allowed
|
||||
// groups of all group-constrained teams and channels.
|
||||
func (a *App) DeleteGroupConstrainedMemberships() error {
|
||||
err := a.deleteGroupConstrainedChannelMemberships(nil)
|
||||
func (a *App) DeleteGroupConstrainedMemberships(c *request.Context) error {
|
||||
err := a.deleteGroupConstrainedChannelMemberships(c, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.deleteGroupConstrainedTeamMemberships(nil)
|
||||
err = a.deleteGroupConstrainedTeamMemberships(c, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -147,14 +148,14 @@ func (a *App) DeleteGroupConstrainedMemberships() error {
|
||||
// deleteGroupConstrainedTeamMemberships deletes team memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained team. If a teamID is given then the procedure is scoped to the given team,
|
||||
// if teamID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedTeamMemberships(teamID *string) error {
|
||||
func (a *App) deleteGroupConstrainedTeamMemberships(c *request.Context, teamID *string) error {
|
||||
teamMembers, appErr := a.TeamMembersToRemove(teamID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
for _, userTeam := range teamMembers {
|
||||
err := a.RemoveUserFromTeam(userTeam.TeamId, userTeam.UserId, "")
|
||||
err := a.RemoveUserFromTeam(c, userTeam.TeamId, userTeam.UserId, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -171,7 +172,7 @@ func (a *App) deleteGroupConstrainedTeamMemberships(teamID *string) error {
|
||||
// deleteGroupConstrainedChannelMemberships deletes channel memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained channel. If a channelID is given then the procedure is scoped to the given team,
|
||||
// if channelID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedChannelMemberships(channelID *string) error {
|
||||
func (a *App) deleteGroupConstrainedChannelMemberships(c *request.Context, channelID *string) error {
|
||||
channelMembers, appErr := a.ChannelMembersToRemove(channelID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -183,7 +184,7 @@ func (a *App) deleteGroupConstrainedChannelMemberships(channelID *string) error
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.RemoveUserFromChannel(userChannel.UserId, "", channel)
|
||||
err = a.RemoveUserFromChannel(c, userChannel.UserId, "", channel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,7 +233,7 @@ func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSynca
|
||||
|
||||
// SyncRolesAndMembership updates the SchemeAdmin status and membership of all of the members of the given
|
||||
// syncable.
|
||||
func (a *App) SyncRolesAndMembership(syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
|
||||
func (a *App) SyncRolesAndMembership(c *request.Context, syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
|
||||
a.SyncSyncableRoles(syncableID, syncableType)
|
||||
|
||||
lastJob, _ := a.Srv().Store.Job().GetNewestJobByStatusAndType(model.JOB_STATUS_SUCCESS, model.JOB_TYPE_LDAP_SYNC)
|
||||
@@ -243,12 +244,12 @@ func (a *App) SyncRolesAndMembership(syncableID string, syncableType model.Group
|
||||
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
a.createDefaultTeamMemberships(since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedTeamMemberships(&syncableID)
|
||||
a.createDefaultTeamMemberships(c, since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedTeamMemberships(c, &syncableID)
|
||||
a.ClearTeamMembersCache(syncableID)
|
||||
case model.GroupSyncableTypeChannel:
|
||||
a.createDefaultChannelMemberships(since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedChannelMemberships(&syncableID)
|
||||
a.createDefaultChannelMemberships(c, since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedChannelMemberships(c, &syncableID)
|
||||
a.ClearChannelMembersCache(syncableID)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user