Merge branch 'master' into MM-45118_my_top_dms
Этот коммит содержится в:
@@ -80,7 +80,7 @@ type AppIface interface {
|
||||
// Use GetLastAccessiblePostTime() to access the result.
|
||||
ComputeLastAccessiblePostTime() error
|
||||
// ConvertBotToUser converts a bot to user.
|
||||
ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError)
|
||||
ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError)
|
||||
// ConvertUserToBot converts a user to bot.
|
||||
ConvertUserToBot(user *model.User) (*model.Bot, *model.AppError)
|
||||
// CreateBot creates the given bot and corresponding user.
|
||||
@@ -94,10 +94,10 @@ type AppIface interface {
|
||||
CreateDefaultMemberships(c *request.Context, since int64, includeRemovedMembers bool) error
|
||||
// CreateGuest creates a guest and sets several fields of the returned User struct to
|
||||
// their zero values.
|
||||
CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError)
|
||||
CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError)
|
||||
// CreateUser creates a user and sets several fields of the returned User struct to
|
||||
// their zero values.
|
||||
CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError)
|
||||
CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError)
|
||||
// Creates and stores FileInfos for a post created before the FileInfos table existed.
|
||||
MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo
|
||||
// DefaultChannelNames returns the list of system-wide default channel names.
|
||||
@@ -381,10 +381,6 @@ type AppIface interface {
|
||||
// upload, returning a rejection error. In this case FileInfo would have
|
||||
// contained the last "good" FileInfo before the execution of that plugin.
|
||||
UploadFileX(c *request.Context, channelID, name string, input io.Reader, opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError)
|
||||
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
||||
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
||||
// The provided files should be closed by the caller so that they are not leaked.
|
||||
UploadFiles(c *request.Context, teamID string, channelID string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||
// UserIsInAdminRoleGroup returns true at least one of the user's groups are configured to set the members as
|
||||
// admins in the given syncable.
|
||||
UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError)
|
||||
@@ -500,10 +496,10 @@ type AppIface interface {
|
||||
CreateTermsOfService(text, userID string) (*model.TermsOfService, *model.AppError)
|
||||
CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError)
|
||||
CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError)
|
||||
CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithInviteId(c *request.Context, user *model.User, inviteId, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError)
|
||||
CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithInviteId(c request.CTX, user *model.User, inviteId, redirect string) (*model.User, *model.AppError)
|
||||
CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError)
|
||||
CreateWebhookPost(c request.CTX, userID string, channel *model.Channel, text, overrideUsername, overrideIconURL, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError)
|
||||
DBHealthCheckDelete() error
|
||||
DBHealthCheckWrite() error
|
||||
@@ -537,7 +533,7 @@ type AppIface interface {
|
||||
DeleteSharedChannelRemote(id string) (bool, error)
|
||||
DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId string) *model.AppError
|
||||
DeleteToken(token *model.Token) *model.AppError
|
||||
DisableAutoResponder(userID string, asAdmin bool) *model.AppError
|
||||
DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError
|
||||
DisableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
DoAppMigrations()
|
||||
DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError)
|
||||
@@ -875,7 +871,7 @@ type AppIface interface {
|
||||
IsUserSignUpAllowed() *model.AppError
|
||||
JoinChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError
|
||||
JoinDefaultChannels(c request.CTX, teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
||||
JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError)
|
||||
JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError)
|
||||
Ldap() einterfaces.LdapInterface
|
||||
LeaveChannel(c request.CTX, channelID string, userID string) *model.AppError
|
||||
LeaveTeam(c *request.Context, team *model.Team, user *model.User, requestorId string) *model.AppError
|
||||
@@ -913,7 +909,7 @@ type AppIface interface {
|
||||
PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError)
|
||||
PatchScheme(scheme *model.Scheme, patch *model.SchemePatch) (*model.Scheme, *model.AppError)
|
||||
PatchTeam(teamID string, patch *model.TeamPatch) (*model.Team, *model.AppError)
|
||||
PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError)
|
||||
PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError)
|
||||
PermanentDeleteAllUsers(c *request.Context) *model.AppError
|
||||
PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError
|
||||
PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppError
|
||||
@@ -947,7 +943,7 @@ type AppIface interface {
|
||||
RemoveAllDeactivatedMembersFromChannel(c request.CTX, channel *model.Channel) *model.AppError
|
||||
RemoveChannelsFromRetentionPolicy(policyID string, channelIDs []string) *model.AppError
|
||||
RemoveConfigListener(id string)
|
||||
RemoveCustomStatus(userID string) *model.AppError
|
||||
RemoveCustomStatus(c request.CTX, userID string) *model.AppError
|
||||
RemoveDirectory(path string) *model.AppError
|
||||
RemoveFile(path string) *model.AppError
|
||||
RemoveLdapPrivateCertificate() *model.AppError
|
||||
@@ -962,7 +958,7 @@ type AppIface interface {
|
||||
RemoveUserFromTeam(c *request.Context, teamID string, userID string, requestorId string) *model.AppError
|
||||
RemoveUsersFromChannelNotMemberOfTeam(c request.CTX, remover *model.User, channel *model.Channel, team *model.Team) *model.AppError
|
||||
RequestLicenseAndAckWarnMetric(c *request.Context, warnMetricId string, isBot bool) *model.AppError
|
||||
ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError
|
||||
ResetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string) *model.AppError
|
||||
ResetPermissionsSystem() *model.AppError
|
||||
ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, userIDs []string) (numAffected int, appErr *model.AppError)
|
||||
RestoreChannel(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
@@ -1037,16 +1033,16 @@ type AppIface interface {
|
||||
SetActiveChannel(c request.CTX, userID string, channelID string) *model.AppError
|
||||
SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap)
|
||||
SetChannels(ch *Channels)
|
||||
SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError
|
||||
SetDefaultProfileImage(user *model.User) *model.AppError
|
||||
SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError
|
||||
SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError
|
||||
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
||||
SetPluginKey(pluginID string, key string, value []byte) *model.AppError
|
||||
SetPluginKeyWithExpiry(pluginID string, key string, value []byte, expireInSeconds int64) *model.AppError
|
||||
SetPluginKeyWithOptions(pluginID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
|
||||
SetPostReminder(postID, userID string, targetTime int64) *model.AppError
|
||||
SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError
|
||||
SetProfileImageFromFile(userID string, file io.Reader) *model.AppError
|
||||
SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError
|
||||
SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError
|
||||
SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError
|
||||
SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError
|
||||
SetRemoteClusterLastPingAt(remoteClusterId string) *model.AppError
|
||||
SetSamlIdpCertificateFromMetadata(data []byte) *model.AppError
|
||||
SetSearchEngine(se *searchengine.Broker)
|
||||
@@ -1096,15 +1092,15 @@ type AppIface interface {
|
||||
UpdateHashedPasswordByUserId(userID, newHashedPassword string) *model.AppError
|
||||
UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
UpdateLastActivityAtIfNeeded(session model.Session)
|
||||
UpdateMfa(activate bool, userID, token string) *model.AppError
|
||||
UpdateMfa(c request.CTX, activate bool, userID, token string) *model.AppError
|
||||
UpdateMobileAppBadge(userID string)
|
||||
UpdateOAuthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError
|
||||
UpdateOutgoingWebhook(c request.CTX, oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
UpdatePassword(user *model.User, newPassword string) *model.AppError
|
||||
UpdatePasswordAsUser(userID, currentPassword, newPassword string) *model.AppError
|
||||
UpdatePasswordByUserIdSendEmail(userID, newPassword, method string) *model.AppError
|
||||
UpdatePasswordSendEmail(user *model.User, newPassword, method string) *model.AppError
|
||||
UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPassword string) *model.AppError
|
||||
UpdatePasswordByUserIdSendEmail(c request.CTX, userID, newPassword, method string) *model.AppError
|
||||
UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword, method string) *model.AppError
|
||||
UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) (*model.Post, *model.AppError)
|
||||
UpdatePreferences(userID string, preferences model.Preferences) *model.AppError
|
||||
UpdateRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster, *model.AppError)
|
||||
@@ -1125,20 +1121,19 @@ type AppIface interface {
|
||||
UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadReadForUserByPost(c request.CTX, currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadsReadForUser(userID, teamID string) *model.AppError
|
||||
UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError
|
||||
UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError)
|
||||
UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError)
|
||||
UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError)
|
||||
UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
UploadData(c *request.Context, us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError)
|
||||
UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError
|
||||
UploadMultipartFiles(c *request.Context, teamID string, channelID string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||
UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||
UpsertGroupMembers(groupID string, userIDs []string) ([]*model.GroupMember, *model.AppError)
|
||||
UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError)
|
||||
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
||||
VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError
|
||||
VerifyUserEmail(userID, email string) *model.AppError
|
||||
ViewChannel(c request.CTX, view *model.ChannelView, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||
|
||||
@@ -59,6 +59,10 @@ func (a *App) SessionHasPermissionToTeam(session model.Session, teamID string, p
|
||||
|
||||
// SessionHasPermissionToTeams returns true only if user has access to all teams.
|
||||
func (a *App) SessionHasPermissionToTeams(c request.CTX, session model.Session, teamIDs []string, permission *model.Permission) bool {
|
||||
if len(teamIDs) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, teamID := range teamIDs {
|
||||
if teamID == "" {
|
||||
return false
|
||||
@@ -126,6 +130,10 @@ func (a *App) SessionHasPermissionToChannel(c request.CTX, session model.Session
|
||||
|
||||
// SessionHasPermissionToChannels returns true only if user has access to all channels.
|
||||
func (a *App) SessionHasPermissionToChannels(c request.CTX, session model.Session, channelIDs []string, permission *model.Permission) bool {
|
||||
if len(channelIDs) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, channelID := range channelIDs {
|
||||
if channelID == "" {
|
||||
return false
|
||||
|
||||
@@ -98,7 +98,7 @@ func (a *App) SetAutoResponderStatus(user *model.User, oldNotifyProps model.Stri
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) DisableAutoResponder(userID string, asAdmin bool) *model.AppError {
|
||||
func (a *App) DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -111,7 +111,7 @@ func (a *App) DisableAutoResponder(userID string, asAdmin bool) *model.AppError
|
||||
patch.NotifyProps = user.NotifyProps
|
||||
patch.NotifyProps[model.AutoResponderActiveNotifyProp] = "false"
|
||||
|
||||
_, err := a.PatchUser(userID, patch, asAdmin)
|
||||
_, err := a.PatchUser(c, userID, patch, asAdmin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestSetAutoResponderStatus(t *testing.T) {
|
||||
patch.NotifyProps["auto_responder_active"] = "true"
|
||||
patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
userUpdated1, _ := th.App.PatchUser(user.Id, patch, true)
|
||||
userUpdated1, _ := th.App.PatchUser(th.Context, user.Id, patch, true)
|
||||
|
||||
// autoResponder is enabled, status should be OOO
|
||||
th.App.SetAutoResponderStatus(userUpdated1, user.NotifyProps)
|
||||
@@ -41,7 +41,7 @@ func TestSetAutoResponderStatus(t *testing.T) {
|
||||
patch2.NotifyProps["auto_responder_active"] = "false"
|
||||
patch2.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
userUpdated2, _ := th.App.PatchUser(user.Id, patch2, true)
|
||||
userUpdated2, _ := th.App.PatchUser(th.Context, user.Id, patch2, true)
|
||||
|
||||
// autoResponder is disabled, status should be ONLINE
|
||||
th.App.SetAutoResponderStatus(userUpdated2, userUpdated1.NotifyProps)
|
||||
@@ -66,15 +66,15 @@ func TestDisableAutoResponder(t *testing.T) {
|
||||
patch.NotifyProps["auto_responder_active"] = "true"
|
||||
patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
th.App.PatchUser(user.Id, patch, true)
|
||||
th.App.PatchUser(th.Context, user.Id, patch, true)
|
||||
|
||||
th.App.DisableAutoResponder(user.Id, true)
|
||||
th.App.DisableAutoResponder(th.Context, user.Id, true)
|
||||
|
||||
userUpdated1, err := th.App.GetUser(user.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, userUpdated1.NotifyProps["auto_responder_active"], "false")
|
||||
|
||||
th.App.DisableAutoResponder(user.Id, true)
|
||||
th.App.DisableAutoResponder(th.Context, user.Id, true)
|
||||
|
||||
userUpdated2, err := th.App.GetUser(user.Id)
|
||||
require.Nil(t, err)
|
||||
@@ -94,7 +94,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
|
||||
"auto_responder_message": "Hello, I'm unavailable today.",
|
||||
},
|
||||
}
|
||||
receiver, err := th.App.PatchUser(receiver.Id, patch, true)
|
||||
receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateDmChannel(receiver)
|
||||
@@ -124,7 +124,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
|
||||
"auto_responder_message": "Hello, I'm unavailable today.",
|
||||
},
|
||||
}
|
||||
receiver, err := th.App.PatchUser(receiver.Id, patch, true)
|
||||
receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateDmChannel(receiver)
|
||||
@@ -171,7 +171,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
|
||||
"auto_responder_message": "Hello, I'm unavailable today.",
|
||||
},
|
||||
}
|
||||
receiver, err := th.App.PatchUser(receiver.Id, patch, true)
|
||||
receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateDmChannel(receiver)
|
||||
@@ -211,7 +211,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
|
||||
"auto_responder_message": "Hello, I'm unavailable today.",
|
||||
},
|
||||
}
|
||||
receiver, err := th.App.PatchUser(receiver.Id, patch, true)
|
||||
receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
channel := th.CreateDmChannel(receiver)
|
||||
@@ -252,7 +252,7 @@ func TestSendAutoResponseSuccess(t *testing.T) {
|
||||
patch.NotifyProps["auto_responder_active"] = "true"
|
||||
patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
|
||||
userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
savedPost, _ := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -292,7 +292,7 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) {
|
||||
patch.NotifyProps["auto_responder_active"] = "true"
|
||||
patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
|
||||
userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
parentPost, _ := th.App.CreatePost(th.Context, &model.Post{
|
||||
@@ -341,7 +341,7 @@ func TestSendAutoResponseFailure(t *testing.T) {
|
||||
patch.NotifyProps["auto_responder_active"] = "false"
|
||||
patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today."
|
||||
|
||||
userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
|
||||
userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
savedPost, _ := th.App.CreatePost(th.Context, &model.Post{
|
||||
|
||||
@@ -606,7 +606,7 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
||||
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||
_, err := th.App.CreateUser(th.Context, &sysadmin1)
|
||||
require.Nil(t, err, "failed to create user")
|
||||
th.App.UpdateUserRoles(sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
|
||||
sysadmin2 := model.User{
|
||||
Email: "sys2@example.com",
|
||||
@@ -616,7 +616,7 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
||||
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||
_, err = th.App.CreateUser(th.Context, &sysadmin2)
|
||||
require.Nil(t, err, "failed to create user")
|
||||
th.App.UpdateUserRoles(sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
|
||||
// create user to be disabled
|
||||
user1, err := th.App.CreateUser(th.Context, &model.User{
|
||||
|
||||
@@ -1004,18 +1004,18 @@ func TestGetChannelMembersTimezones(t *testing.T) {
|
||||
user := th.BasicUser
|
||||
user.Timezone["useAutomaticTimezone"] = "false"
|
||||
user.Timezone["manualTimezone"] = "XOXO/BLABLA"
|
||||
th.App.UpdateUser(user, false)
|
||||
th.App.UpdateUser(th.Context, user, false)
|
||||
|
||||
user2 := th.BasicUser2
|
||||
user2.Timezone["automaticTimezone"] = "NoWhere/Island"
|
||||
th.App.UpdateUser(user2, false)
|
||||
th.App.UpdateUser(th.Context, user2, false)
|
||||
|
||||
user3 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := th.App.CreateUser(th.Context, &user3)
|
||||
th.App.AddUserToChannel(th.Context, ruser, th.BasicChannel, false)
|
||||
|
||||
ruser.Timezone["automaticTimezone"] = "NoWhere/Island"
|
||||
th.App.UpdateUser(ruser, false)
|
||||
th.App.UpdateUser(th.Context, ruser, false)
|
||||
|
||||
user4 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ = th.App.CreateUser(th.Context, &user4)
|
||||
|
||||
@@ -82,9 +82,9 @@ func (w *configWrapper) SaveConfig(newCfg *model.Config, sendConfigChangeCluster
|
||||
if w.srv.Metrics != nil {
|
||||
w.srv.Metrics.Register()
|
||||
}
|
||||
w.srv.platformService.RestartMetrics() // TODO: remove when this moved to the platform service
|
||||
w.srv.SetupMetricsServer()
|
||||
} else {
|
||||
w.srv.platformService.ShutdownMetrics() // TODO: remove when this moved to the platform service
|
||||
w.srv.StopMetricsServer()
|
||||
}
|
||||
|
||||
if w.srv.Cluster != nil {
|
||||
|
||||
71
app/file.go
71
app/file.go
@@ -12,7 +12,6 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -453,76 +452,6 @@ func GeneratePublicLinkHash(fileID, salt string) string {
|
||||
return base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
|
||||
}
|
||||
|
||||
func (a *App) UploadMultipartFiles(c *request.Context, teamID string, channelID string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||
files := make([]io.ReadCloser, len(fileHeaders))
|
||||
filenames := make([]string, len(fileHeaders))
|
||||
|
||||
for i, fileHeader := range fileHeaders {
|
||||
file, fileErr := fileHeader.Open()
|
||||
if fileErr != nil {
|
||||
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.read_request.app_error",
|
||||
map[string]any{"Filename": fileHeader.Filename}, fileErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Will be closed after UploadFiles returns
|
||||
defer file.Close()
|
||||
|
||||
files[i] = file
|
||||
filenames[i] = fileHeader.Filename
|
||||
}
|
||||
|
||||
return a.UploadFiles(c, teamID, channelID, userID, files, filenames, clientIds, now)
|
||||
}
|
||||
|
||||
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
||||
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
||||
// The provided files should be closed by the caller so that they are not leaked.
|
||||
func (a *App) UploadFiles(c *request.Context, teamID string, channelID string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||
if *a.Config().FileSettings.DriverName == "" {
|
||||
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if len(filenames) != len(files) || (len(clientIds) > 0 && len(clientIds) != len(files)) {
|
||||
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.incorrect_number_of_files.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resStruct := &model.FileUploadResponse{
|
||||
FileInfos: []*model.FileInfo{},
|
||||
ClientIds: []string{},
|
||||
}
|
||||
|
||||
previewPathList := []string{}
|
||||
thumbnailPathList := []string{}
|
||||
imageDataList := [][]byte{}
|
||||
|
||||
for i, file := range files {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
io.Copy(buf, file)
|
||||
data := buf.Bytes()
|
||||
|
||||
info, data, err := a.DoUploadFileExpectModification(c, now, teamID, channelID, userID, filenames[i], data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if info.PreviewPath != "" || info.ThumbnailPath != "" {
|
||||
previewPathList = append(previewPathList, info.PreviewPath)
|
||||
thumbnailPathList = append(thumbnailPathList, info.ThumbnailPath)
|
||||
imageDataList = append(imageDataList, data)
|
||||
}
|
||||
|
||||
resStruct.FileInfos = append(resStruct.FileInfos, info)
|
||||
|
||||
if len(clientIds) > 0 {
|
||||
resStruct.ClientIds = append(resStruct.ClientIds, clientIds[i])
|
||||
}
|
||||
}
|
||||
|
||||
a.HandleImages(previewPathList, thumbnailPathList, imageDataList)
|
||||
|
||||
return resStruct, nil
|
||||
}
|
||||
|
||||
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
||||
func (a *App) UploadFile(c *request.Context, data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError) {
|
||||
_, err := a.GetChannel(c, channelID)
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -130,21 +128,6 @@ func BenchmarkUploadFile(b *testing.B) {
|
||||
th.App.RemoveFile(info.Path)
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "image UploadFiles",
|
||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||
resp, err := th.App.UploadFiles(th.Context, teamID, channelID, userID,
|
||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewReader(data))},
|
||||
[]string{fmt.Sprintf("BenchmarkDoUploadFiles-%d%s", n, ext)},
|
||||
[]string{},
|
||||
time.Now())
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(resp.FileInfos[0].Id)
|
||||
th.App.RemoveFile(resp.FileInfos[0].Path)
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "image UploadFileX Content-Length",
|
||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||
|
||||
@@ -222,7 +222,7 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
th.SystemAdminUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy()
|
||||
|
||||
|
||||
@@ -527,12 +527,12 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode
|
||||
} else {
|
||||
var appErr *model.AppError
|
||||
if hasUserChanged {
|
||||
if savedUser, appErr = a.UpdateUser(user, false); appErr != nil {
|
||||
if savedUser, appErr = a.UpdateUser(c, user, false); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
}
|
||||
if hasUserRolesChanged {
|
||||
if savedUser, appErr = a.UpdateUserRoles(user.Id, roles, false); appErr != nil {
|
||||
if savedUser, appErr = a.UpdateUserRoles(c, user.Id, roles, false); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
}
|
||||
@@ -590,7 +590,7 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode
|
||||
if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
if err := a.SetProfileImageFromFile(savedUser.Id, file); err != nil {
|
||||
if err := a.SetProfileImageFromFile(c, savedUser.Id, file); err != nil {
|
||||
mlog.Warn("Unable to set the profile image from a file.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
||||
userVal := *user
|
||||
sessionVal := *session
|
||||
a.Srv().Go(func() {
|
||||
a.Ldap().UpdateProfilePictureIfNecessary(userVal, sessionVal)
|
||||
a.Ldap().UpdateProfilePictureIfNecessary(c, userVal, sessionVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -149,14 +149,14 @@ func TestSendNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
th.BasicUser.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||
th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false)
|
||||
th.BasicUser, appErr = th.App.UpdateUser(th.Context, th.BasicUser, false)
|
||||
require.Nil(t, appErr)
|
||||
t.Run("user wants notifications on all comments", func(t *testing.T) {
|
||||
testUserNotNotified(t, th.BasicUser)
|
||||
})
|
||||
|
||||
th.BasicUser.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyRoot
|
||||
th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false)
|
||||
th.BasicUser, appErr = th.App.UpdateUser(th.Context, th.BasicUser, false)
|
||||
require.Nil(t, appErr)
|
||||
t.Run("user wants notifications on root comment", func(t *testing.T) {
|
||||
testUserNotNotified(t, th.BasicUser)
|
||||
@@ -2723,13 +2723,13 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) {
|
||||
oldValue := th.BasicUser2.NotifyProps[model.CommentsNotifyProp]
|
||||
newNotifyProps := th.BasicUser2.NotifyProps
|
||||
newNotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||
u2, appErr := th.App.PatchUser(th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false)
|
||||
u2, appErr := th.App.PatchUser(th.Context, th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, model.CommentsNotifyAny, u2.NotifyProps[model.CommentsNotifyProp])
|
||||
defer func() {
|
||||
newNotifyProps := th.BasicUser2.NotifyProps
|
||||
newNotifyProps[model.CommentsNotifyProp] = oldValue
|
||||
_, nAppErr := th.App.PatchUser(th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false)
|
||||
_, nAppErr := th.App.PatchUser(th.Context, th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false)
|
||||
require.Nil(t, nAppErr)
|
||||
}()
|
||||
|
||||
|
||||
@@ -1791,7 +1791,7 @@ func (a *OpenTracingAppLayer) Config() *model.Config {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ConvertBotToUser")
|
||||
|
||||
@@ -1803,7 +1803,7 @@ func (a *OpenTracingAppLayer) ConvertBotToUser(bot *model.Bot, userPatch *model.
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.ConvertBotToUser(bot, userPatch, sysadmin)
|
||||
resultVar0, resultVar1 := a.app.ConvertBotToUser(c, bot, userPatch, sysadmin)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -2125,7 +2125,7 @@ func (a *OpenTracingAppLayer) CreateGroupWithUserIds(group *model.GroupWithUserI
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateGuest")
|
||||
|
||||
@@ -2565,7 +2565,7 @@ func (a *OpenTracingAppLayer) CreateUploadSession(c request.CTX, us *model.Uploa
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUser")
|
||||
|
||||
@@ -2609,7 +2609,7 @@ func (a *OpenTracingAppLayer) CreateUserAccessToken(token *model.UserAccessToken
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserAsAdmin")
|
||||
|
||||
@@ -2631,7 +2631,7 @@ func (a *OpenTracingAppLayer) CreateUserAsAdmin(c *request.Context, user *model.
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserFromSignup")
|
||||
|
||||
@@ -2653,7 +2653,7 @@ func (a *OpenTracingAppLayer) CreateUserFromSignup(c *request.Context, user *mod
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateUserWithInviteId(c *request.Context, user *model.User, inviteId string, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateUserWithInviteId(c request.CTX, user *model.User, inviteId string, redirect string) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserWithInviteId")
|
||||
|
||||
@@ -2675,7 +2675,7 @@ func (a *OpenTracingAppLayer) CreateUserWithInviteId(c *request.Context, user *m
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserWithToken")
|
||||
|
||||
@@ -3521,7 +3521,7 @@ func (a *OpenTracingAppLayer) DemoteUserToGuest(c request.CTX, user *model.User)
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DisableAutoResponder(userID string, asAdmin bool) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DisableAutoResponder")
|
||||
|
||||
@@ -3533,7 +3533,7 @@ func (a *OpenTracingAppLayer) DisableAutoResponder(userID string, asAdmin bool)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.DisableAutoResponder(userID, asAdmin)
|
||||
resultVar0 := a.app.DisableAutoResponder(c, userID, asAdmin)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -11709,7 +11709,7 @@ func (a *OpenTracingAppLayer) JoinDefaultChannels(c request.CTX, teamID string,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.JoinUserToTeam")
|
||||
|
||||
@@ -12657,7 +12657,7 @@ func (a *OpenTracingAppLayer) PatchTeam(teamID string, patch *model.TeamPatch) (
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PatchUser")
|
||||
|
||||
@@ -12669,7 +12669,7 @@ func (a *OpenTracingAppLayer) PatchUser(userID string, patch *model.UserPatch, a
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.PatchUser(userID, patch, asAdmin)
|
||||
resultVar0, resultVar1 := a.app.PatchUser(c, userID, patch, asAdmin)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -13444,7 +13444,7 @@ func (a *OpenTracingAppLayer) RemoveConfigListener(id string) {
|
||||
a.app.RemoveConfigListener(id)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RemoveCustomStatus(userID string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RemoveCustomStatus(c request.CTX, userID string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RemoveCustomStatus")
|
||||
|
||||
@@ -13456,7 +13456,7 @@ func (a *OpenTracingAppLayer) RemoveCustomStatus(userID string) *model.AppError
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RemoveCustomStatus(userID)
|
||||
resultVar0 := a.app.RemoveCustomStatus(c, userID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -13818,7 +13818,7 @@ func (a *OpenTracingAppLayer) RequestLicenseAndAckWarnMetric(c *request.Context,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) ResetPasswordFromToken(userSuppliedTokenString string, newPassword string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) ResetPasswordFromToken(c request.CTX, userSuppliedTokenString string, newPassword string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ResetPasswordFromToken")
|
||||
|
||||
@@ -13830,7 +13830,7 @@ func (a *OpenTracingAppLayer) ResetPasswordFromToken(userSuppliedTokenString str
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.ResetPasswordFromToken(userSuppliedTokenString, newPassword)
|
||||
resultVar0 := a.app.ResetPasswordFromToken(c, userSuppliedTokenString, newPassword)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -15497,7 +15497,7 @@ func (a *OpenTracingAppLayer) SetChannels(ch *app.Channels) {
|
||||
a.app.SetChannels(ch)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetCustomStatus")
|
||||
|
||||
@@ -15509,7 +15509,7 @@ func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomSta
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetCustomStatus(userID, cs)
|
||||
resultVar0 := a.app.SetCustomStatus(c, userID, cs)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -15519,7 +15519,7 @@ func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomSta
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetDefaultProfileImage")
|
||||
|
||||
@@ -15531,7 +15531,7 @@ func (a *OpenTracingAppLayer) SetDefaultProfileImage(user *model.User) *model.Ap
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetDefaultProfileImage(user)
|
||||
resultVar0 := a.app.SetDefaultProfileImage(c, user)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -15651,7 +15651,7 @@ func (a *OpenTracingAppLayer) SetPostReminder(postID string, userID string, targ
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImage")
|
||||
|
||||
@@ -15663,7 +15663,7 @@ func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipar
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetProfileImage(userID, imageData)
|
||||
resultVar0 := a.app.SetProfileImage(c, userID, imageData)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -15673,7 +15673,7 @@ func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipar
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Reader) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImageFromFile")
|
||||
|
||||
@@ -15685,7 +15685,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Rea
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetProfileImageFromFile(userID, file)
|
||||
resultVar0 := a.app.SetProfileImageFromFile(c, userID, file)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -15695,7 +15695,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Rea
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImageFromMultiPartFile")
|
||||
|
||||
@@ -15707,7 +15707,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(userID string, fi
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.SetProfileImageFromMultiPartFile(userID, file)
|
||||
resultVar0 := a.app.SetProfileImageFromMultiPartFile(c, userID, file)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -16910,7 +16910,7 @@ func (a *OpenTracingAppLayer) UpdateLastActivityAtIfNeeded(session model.Session
|
||||
a.app.UpdateLastActivityAtIfNeeded(session)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateMfa(activate bool, userID string, token string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdateMfa(c request.CTX, activate bool, userID string, token string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateMfa")
|
||||
|
||||
@@ -16922,7 +16922,7 @@ func (a *OpenTracingAppLayer) UpdateMfa(activate bool, userID string, token stri
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdateMfa(activate, userID, token)
|
||||
resultVar0 := a.app.UpdateMfa(c, activate, userID, token)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -17035,7 +17035,7 @@ func (a *OpenTracingAppLayer) UpdatePassword(user *model.User, newPassword strin
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPassword string, newPassword string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordAsUser(c request.CTX, userID string, currentPassword string, newPassword string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordAsUser")
|
||||
|
||||
@@ -17047,7 +17047,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPasswor
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdatePasswordAsUser(userID, currentPassword, newPassword)
|
||||
resultVar0 := a.app.UpdatePasswordAsUser(c, userID, currentPassword, newPassword)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -17057,7 +17057,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPasswor
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, newPassword string, method string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(c request.CTX, userID string, newPassword string, method string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordByUserIdSendEmail")
|
||||
|
||||
@@ -17069,7 +17069,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, new
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdatePasswordByUserIdSendEmail(userID, newPassword, method)
|
||||
resultVar0 := a.app.UpdatePasswordByUserIdSendEmail(c, userID, newPassword, method)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -17079,7 +17079,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, new
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(user *model.User, newPassword string, method string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword string, method string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordSendEmail")
|
||||
|
||||
@@ -17091,7 +17091,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(user *model.User, newPassw
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdatePasswordSendEmail(user, newPassword, method)
|
||||
resultVar0 := a.app.UpdatePasswordSendEmail(c, user, newPassword, method)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -17563,7 +17563,7 @@ func (a *OpenTracingAppLayer) UpdateThreadsReadForUser(userID string, teamID str
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUser")
|
||||
|
||||
@@ -17575,7 +17575,7 @@ func (a *OpenTracingAppLayer) UpdateUser(user *model.User, sendNotifications boo
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateUser(user, sendNotifications)
|
||||
resultVar0, resultVar1 := a.app.UpdateUser(c, user, sendNotifications)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17607,7 +17607,7 @@ func (a *OpenTracingAppLayer) UpdateUserActive(c *request.Context, userID string
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserAsUser")
|
||||
|
||||
@@ -17619,7 +17619,7 @@ func (a *OpenTracingAppLayer) UpdateUserAsUser(user *model.User, asAdmin bool) (
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateUserAsUser(user, asAdmin)
|
||||
resultVar0, resultVar1 := a.app.UpdateUserAsUser(c, user, asAdmin)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17651,7 +17651,7 @@ func (a *OpenTracingAppLayer) UpdateUserAuth(userID string, userAuth *model.User
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserRoles")
|
||||
|
||||
@@ -17663,7 +17663,7 @@ func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, se
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateUserRoles(userID, newRoles, sendWebSocketEvent)
|
||||
resultVar0, resultVar1 := a.app.UpdateUserRoles(c, userID, newRoles, sendWebSocketEvent)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17673,7 +17673,7 @@ func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, se
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserRolesWithUser")
|
||||
|
||||
@@ -17685,7 +17685,7 @@ func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(user *model.User, newRoles
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateUserRolesWithUser(user, newRoles, sendWebSocketEvent)
|
||||
resultVar0, resultVar1 := a.app.UpdateUserRolesWithUser(c, user, newRoles, sendWebSocketEvent)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17835,50 +17835,6 @@ func (a *OpenTracingAppLayer) UploadFileX(c *request.Context, channelID string,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UploadFiles(c *request.Context, teamID string, channelID string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UploadFiles")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UploadFiles(c, teamID, channelID, userID, files, filenames, clientIds, now)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UploadMultipartFiles(c *request.Context, teamID string, channelID string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UploadMultipartFiles")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UploadMultipartFiles(c, teamID, channelID, userID, fileHeaders, clientIds, now)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpsertGroupMember")
|
||||
@@ -17989,7 +17945,7 @@ func (a *OpenTracingAppLayer) UserIsInAdminRoleGroup(userID string, syncableID s
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.VerifyEmailFromToken")
|
||||
|
||||
@@ -18001,7 +17957,7 @@ func (a *OpenTracingAppLayer) VerifyEmailFromToken(userSuppliedTokenString strin
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.VerifyEmailFromToken(userSuppliedTokenString)
|
||||
resultVar0 := a.app.VerifyEmailFromToken(c, userSuppliedTokenString)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
|
||||
@@ -3,28 +3,14 @@
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/config"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
)
|
||||
|
||||
// ServiceConfig is used to initialize the PlatformService.
|
||||
// The mandatory fields will be checked during the initialization of the service.
|
||||
type ServiceConfig struct {
|
||||
// Mandatory fields
|
||||
ConfigStore *config.Store
|
||||
StartMetrics bool // TODO: find an elegant way to start/stop metrics server by default
|
||||
// Optional fields
|
||||
Metrics einterfaces.MetricsInterface
|
||||
Cluster einterfaces.ClusterInterface
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) validate() error {
|
||||
// Mandatory fields need to be checked here
|
||||
if c.ConfigStore == nil {
|
||||
return errors.New("ConfigStore is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"runtime"
|
||||
"sync"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const TimeToWaitForConnectionsToCloseOnServerShutdown = time.Second
|
||||
|
||||
type platformMetrics struct {
|
||||
server *http.Server
|
||||
router *mux.Router
|
||||
lock sync.Mutex
|
||||
|
||||
metricsImpl einterfaces.MetricsInterface
|
||||
|
||||
cfgFn func() *model.Config
|
||||
}
|
||||
|
||||
func newPlatformMetrics(metricsImpl einterfaces.MetricsInterface, cfgFn func() *model.Config) *platformMetrics {
|
||||
if !*cfgFn().MetricsSettings.Enable {
|
||||
return nil
|
||||
}
|
||||
|
||||
pm := &platformMetrics{
|
||||
cfgFn: cfgFn,
|
||||
}
|
||||
|
||||
pm.stopMetricsServer()
|
||||
|
||||
if err := pm.initMetricsRouter(); err != nil {
|
||||
mlog.Error("Error initiating metrics router.", mlog.Err(err))
|
||||
}
|
||||
|
||||
if metricsImpl != nil {
|
||||
metricsImpl.Register()
|
||||
}
|
||||
|
||||
pm.startMetricsServer()
|
||||
|
||||
return pm
|
||||
}
|
||||
|
||||
func (pm *platformMetrics) stopMetricsServer() {
|
||||
pm.lock.Lock()
|
||||
defer pm.lock.Unlock()
|
||||
|
||||
if pm.server != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), TimeToWaitForConnectionsToCloseOnServerShutdown)
|
||||
defer cancel()
|
||||
|
||||
pm.server.Shutdown(ctx)
|
||||
mlog.Info("Metrics and profiling server is stopping")
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *platformMetrics) startMetricsServer() {
|
||||
var notify chan struct{}
|
||||
pm.lock.Lock()
|
||||
defer func() {
|
||||
if notify != nil {
|
||||
<-notify
|
||||
}
|
||||
pm.lock.Unlock()
|
||||
}()
|
||||
|
||||
l, err := net.Listen("tcp", *pm.cfgFn().MetricsSettings.ListenAddress)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
notify = make(chan struct{})
|
||||
pm.server = &http.Server{
|
||||
Handler: handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(pm.router),
|
||||
ReadTimeout: time.Duration(*pm.cfgFn().ServiceSettings.ReadTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(*pm.cfgFn().ServiceSettings.WriteTimeout) * time.Second,
|
||||
}
|
||||
|
||||
go func() {
|
||||
close(notify)
|
||||
if err := pm.server.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||
mlog.Critical(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
mlog.Info("Metrics and profiling server is started", mlog.String("address", l.Addr().String()))
|
||||
}
|
||||
|
||||
func (pm *platformMetrics) initMetricsRouter() error {
|
||||
pm.router = mux.NewRouter()
|
||||
runtime.SetBlockProfileRate(*pm.cfgFn().MetricsSettings.BlockProfileRate)
|
||||
|
||||
metricsPage := `
|
||||
<html>
|
||||
<body>{{if .}}
|
||||
<div><a href="/metrics">Metrics</a></div>{{end}}
|
||||
<div><a href="/debug/pprof/">Profiling Root</a></div>
|
||||
<div><a href="/debug/pprof/cmdline">Profiling Command Line</a></div>
|
||||
<div><a href="/debug/pprof/symbol">Profiling Symbols</a></div>
|
||||
<div><a href="/debug/pprof/goroutine">Profiling Goroutines</a></div>
|
||||
<div><a href="/debug/pprof/heap">Profiling Heap</a></div>
|
||||
<div><a href="/debug/pprof/threadcreate">Profiling Threads</a></div>
|
||||
<div><a href="/debug/pprof/block">Profiling Blocking</a></div>
|
||||
<div><a href="/debug/pprof/trace">Profiling Execution Trace</a></div>
|
||||
<div><a href="/debug/pprof/profile">Profiling CPU</a></div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
metricsPageTmpl, err := template.New("page").Parse(metricsPage)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create template")
|
||||
}
|
||||
|
||||
rootHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
metricsPageTmpl.Execute(w, pm.metricsImpl != nil)
|
||||
}
|
||||
|
||||
pm.router.HandleFunc("/", rootHandler)
|
||||
pm.router.StrictSlash(true)
|
||||
|
||||
pm.router.Handle("/debug", http.RedirectHandler("/", http.StatusMovedPermanently))
|
||||
pm.router.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
pm.router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
pm.router.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||
pm.router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||
pm.router.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||
|
||||
// Manually add support for paths linked to by index page at /debug/pprof/
|
||||
pm.router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
|
||||
pm.router.Handle("/debug/pprof/heap", pprof.Handler("heap"))
|
||||
pm.router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
|
||||
pm.router.Handle("/debug/pprof/block", pprof.Handler("block"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) HandleMetrics(route string, h http.Handler) {
|
||||
if ps.metrics.router != nil {
|
||||
ps.metrics.router.Handle(route, h)
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RestartMetrics() {
|
||||
ps.metrics = newPlatformMetrics(ps.serviceConfig.Metrics, ps.serviceConfig.ConfigStore.Get)
|
||||
}
|
||||
@@ -3,42 +3,17 @@
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/config"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
)
|
||||
|
||||
// PlatformService is the service for the platform related tasks. It is
|
||||
// responsible for non-entity related functionalities that are required
|
||||
// by a product such as database access, configuration access, licensing etc.
|
||||
type PlatformService struct {
|
||||
serviceConfig ServiceConfig
|
||||
configStore *config.Store
|
||||
|
||||
metrics *platformMetrics
|
||||
|
||||
cluster einterfaces.ClusterInterface
|
||||
}
|
||||
|
||||
// New creates a new PlatformService.
|
||||
func New(sc ServiceConfig) (*PlatformService, error) {
|
||||
if err := sc.validate(); err != nil {
|
||||
func New(c ServiceConfig) (*PlatformService, error) {
|
||||
if err := c.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ps := &PlatformService{
|
||||
serviceConfig: sc,
|
||||
configStore: sc.ConfigStore,
|
||||
cluster: sc.Cluster,
|
||||
}
|
||||
|
||||
ps.metrics = newPlatformMetrics(sc.Metrics, ps.configStore.Get)
|
||||
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) ShutdownMetrics() {
|
||||
if ps.metrics != nil {
|
||||
ps.metrics.stopMetricsServer()
|
||||
}
|
||||
return &PlatformService{}, nil
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ func (api *PluginAPI) RevokeUserAccessToken(tokenID string) *model.AppError {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
|
||||
return api.app.UpdateUser(user, true)
|
||||
return api.app.UpdateUser(api.ctx, user, true)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateUserActive(userID string, active bool) *model.AppError {
|
||||
@@ -359,11 +359,11 @@ func (api *PluginAPI) SetUserStatusTimedDND(userID string, endTime int64) (*mode
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError {
|
||||
return api.app.SetCustomStatus(userID, customStatus)
|
||||
return api.app.SetCustomStatus(api.ctx, userID, customStatus)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) RemoveUserCustomStatus(userID string) *model.AppError {
|
||||
return api.app.RemoveCustomStatus(userID)
|
||||
return api.app.RemoveCustomStatus(api.ctx, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetUserCustomStatus(userID string) (*model.CustomStatus, *model.AppError) {
|
||||
@@ -738,7 +738,7 @@ func (api *PluginAPI) SetProfileImage(userID string, data []byte) *model.AppErro
|
||||
return err
|
||||
}
|
||||
|
||||
return api.app.SetProfileImageFromFile(userID, bytes.NewReader(data))
|
||||
return api.app.SetProfileImageFromFile(api.ctx, userID, bytes.NewReader(data))
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError) {
|
||||
|
||||
@@ -547,7 +547,7 @@ func TestPluginAPIUserCustomStatus(t *testing.T) {
|
||||
custom.Text = ""
|
||||
err = api.UpdateUserCustomStatus(user1.Id, custom)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err.Error(), "SetCustomStatus: Failed to update the custom status. Please add either emoji or custom text status or both., ")
|
||||
assert.Equal(t, err.Error(), "SetCustomStatus: Failed to update the custom status. Please add either emoji or custom text status or both.")
|
||||
|
||||
// Remove custom status
|
||||
err = api.RemoveUserCustomStatus(user1.Id)
|
||||
@@ -889,7 +889,7 @@ func TestPluginAPIInstallPlugin(t *testing.T) {
|
||||
|
||||
_, appErr := api.InstallPlugin(bytes.NewReader(tarData), true)
|
||||
assert.NotNil(t, appErr, "should not allow upload if upload disabled")
|
||||
assert.Equal(t, appErr.Error(), "installPlugin: Plugins and/or plugin uploads have been disabled., ")
|
||||
assert.Equal(t, appErr.Error(), "installPlugin: Plugins and/or plugin uploads have been disabled.")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
|
||||
@@ -462,15 +462,12 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
||||
}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
_, err := th.App.UploadFiles(th.Context,
|
||||
"noteam",
|
||||
_, err := th.App.UploadFile(th.Context,
|
||||
[]byte("inputfile"),
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewBufferString("inputfile"))},
|
||||
[]string{"testhook.txt"},
|
||||
[]string{},
|
||||
time.Now(),
|
||||
"testhook.txt",
|
||||
)
|
||||
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Equal(t, "File rejected by plugin. rejected", err.Message)
|
||||
}
|
||||
@@ -515,15 +512,12 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
||||
}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
_, err := th.App.UploadFiles(th.Context,
|
||||
"noteam",
|
||||
_, err := th.App.UploadFile(th.Context,
|
||||
[]byte("inputfile"),
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewBufferString("inputfile"))},
|
||||
[]string{"testhook.txt"},
|
||||
[]string{},
|
||||
time.Now(),
|
||||
"testhook.txt",
|
||||
)
|
||||
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Equal(t, "File rejected by plugin. rejected", err.Message)
|
||||
}
|
||||
@@ -562,20 +556,16 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
||||
}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
response, err := th.App.UploadFiles(th.Context,
|
||||
"noteam",
|
||||
response, err := th.App.UploadFile(th.Context,
|
||||
[]byte("inputfile"),
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewBufferString("inputfile"))},
|
||||
[]string{"testhook.txt"},
|
||||
[]string{},
|
||||
time.Now(),
|
||||
"testhook.txt",
|
||||
)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, response)
|
||||
assert.Equal(t, 1, len(response.FileInfos))
|
||||
|
||||
fileID := response.FileInfos[0].Id
|
||||
fileID := response.Id
|
||||
fileInfo, err := th.App.GetFileInfo(fileID)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, fileInfo)
|
||||
@@ -638,19 +628,14 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
||||
}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
response, err := th.App.UploadFiles(th.Context,
|
||||
"noteam",
|
||||
response, err := th.App.UploadFile(th.Context,
|
||||
[]byte("inputfile"),
|
||||
th.BasicChannel.Id,
|
||||
th.BasicUser.Id,
|
||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewBufferString("inputfile"))},
|
||||
[]string{"testhook.txt"},
|
||||
[]string{},
|
||||
time.Now(),
|
||||
"testhook.txt",
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, response)
|
||||
assert.Equal(t, 1, len(response.FileInfos))
|
||||
fileID := response.FileInfos[0].Id
|
||||
fileID := response.Id
|
||||
|
||||
fileInfo, err := th.App.GetFileInfo(fileID)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -453,7 +453,7 @@ func TestGetPluginStatusesDisabled(t *testing.T) {
|
||||
|
||||
_, err := th.App.GetPluginStatuses()
|
||||
require.NotNil(t, err)
|
||||
require.EqualError(t, err, "GetPluginStatuses: Plugins have been disabled. Please check your logs for details., ")
|
||||
require.EqualError(t, err, "GetPluginStatuses: Plugins have been disabled. Please check your logs for details.")
|
||||
}
|
||||
|
||||
func TestGetPluginStatuses(t *testing.T) {
|
||||
|
||||
145
app/server.go
145
app/server.go
@@ -9,8 +9,10 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"hash/maphash"
|
||||
"html/template"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -25,6 +27,7 @@ import (
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/cors"
|
||||
@@ -32,7 +35,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/email"
|
||||
"github.com/mattermost/mattermost-server/v6/app/featureflag"
|
||||
"github.com/mattermost/mattermost-server/v6/app/platform"
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/app/teams"
|
||||
"github.com/mattermost/mattermost-server/v6/app/users"
|
||||
@@ -129,6 +131,10 @@ type Server struct {
|
||||
|
||||
localModeServer *http.Server
|
||||
|
||||
metricsServer *http.Server
|
||||
metricsRouter *mux.Router
|
||||
metricsLock sync.Mutex
|
||||
|
||||
didFinishListen chan struct{}
|
||||
|
||||
goroutineCount int32
|
||||
@@ -171,7 +177,6 @@ type Server struct {
|
||||
configStore *configWrapper
|
||||
filestore filestore.FileBackend
|
||||
|
||||
platformService *platform.PlatformService
|
||||
telemetryService *telemetry.TelemetryService
|
||||
userService *users.UserService
|
||||
teamService *teams.TeamService
|
||||
@@ -251,17 +256,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.configStore = &configWrapper{srv: s, Store: configStore}
|
||||
}
|
||||
|
||||
ps, sErr := platform.New(platform.ServiceConfig{
|
||||
ConfigStore: s.configStore.Store,
|
||||
StartMetrics: s.startMetrics,
|
||||
Metrics: s.Metrics,
|
||||
Cluster: s.Cluster,
|
||||
})
|
||||
if sErr != nil {
|
||||
return nil, errors.Wrap(sErr, "failed to initialize platform")
|
||||
}
|
||||
s.platformService = ps
|
||||
|
||||
// Step 2: Logging
|
||||
if err := s.initLogging(); err != nil {
|
||||
mlog.Error("Could not initiate logging", mlog.Err(err))
|
||||
@@ -625,6 +619,10 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = true })
|
||||
}
|
||||
|
||||
if s.startMetrics {
|
||||
s.SetupMetricsServer()
|
||||
}
|
||||
|
||||
s.AddLicenseListener(func(oldLicense, newLicense *model.License) {
|
||||
if (oldLicense == nil && newLicense == nil) || !s.startMetrics {
|
||||
return
|
||||
@@ -634,7 +632,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return
|
||||
}
|
||||
|
||||
s.platformService.RestartMetrics() // TODO: remove when this moved to the platform service
|
||||
s.SetupMetricsServer()
|
||||
})
|
||||
|
||||
s.SearchEngine.UpdateConfig(s.Config())
|
||||
@@ -703,6 +701,24 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) SetupMetricsServer() {
|
||||
if !*s.Config().MetricsSettings.Enable {
|
||||
return
|
||||
}
|
||||
|
||||
s.StopMetricsServer()
|
||||
|
||||
if err := s.InitMetricsRouter(); err != nil {
|
||||
mlog.Error("Error initiating metrics router.", mlog.Err(err))
|
||||
}
|
||||
|
||||
if s.Metrics != nil {
|
||||
s.Metrics.Register()
|
||||
}
|
||||
|
||||
s.startMetricsServer()
|
||||
}
|
||||
|
||||
func maxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
@@ -1030,7 +1046,7 @@ func (s *Server) Shutdown() {
|
||||
s.Cluster.StopInterNodeCommunication()
|
||||
}
|
||||
|
||||
s.platformService.ShutdownMetrics()
|
||||
s.StopMetricsServer()
|
||||
|
||||
// This must be done after the cluster is stopped.
|
||||
if s.Jobs != nil {
|
||||
@@ -1614,9 +1630,104 @@ func doConfigCleanup(s *Server) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove this method when we switch to using platform service.
|
||||
func (s *Server) StopMetricsServer() {
|
||||
s.metricsLock.Lock()
|
||||
defer s.metricsLock.Unlock()
|
||||
|
||||
if s.metricsServer != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), TimeToWaitForConnectionsToCloseOnServerShutdown)
|
||||
defer cancel()
|
||||
|
||||
s.metricsServer.Shutdown(ctx)
|
||||
s.Log.Info("Metrics and profiling server is stopping")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) HandleMetrics(route string, h http.Handler) {
|
||||
s.platformService.HandleMetrics(route, h)
|
||||
if s.metricsRouter != nil {
|
||||
s.metricsRouter.Handle(route, h)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) InitMetricsRouter() error {
|
||||
s.metricsRouter = mux.NewRouter()
|
||||
runtime.SetBlockProfileRate(*s.Config().MetricsSettings.BlockProfileRate)
|
||||
|
||||
metricsPage := `
|
||||
<html>
|
||||
<body>{{if .}}
|
||||
<div><a href="/metrics">Metrics</a></div>{{end}}
|
||||
<div><a href="/debug/pprof/">Profiling Root</a></div>
|
||||
<div><a href="/debug/pprof/cmdline">Profiling Command Line</a></div>
|
||||
<div><a href="/debug/pprof/symbol">Profiling Symbols</a></div>
|
||||
<div><a href="/debug/pprof/goroutine">Profiling Goroutines</a></div>
|
||||
<div><a href="/debug/pprof/heap">Profiling Heap</a></div>
|
||||
<div><a href="/debug/pprof/threadcreate">Profiling Threads</a></div>
|
||||
<div><a href="/debug/pprof/block">Profiling Blocking</a></div>
|
||||
<div><a href="/debug/pprof/trace">Profiling Execution Trace</a></div>
|
||||
<div><a href="/debug/pprof/profile">Profiling CPU</a></div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
metricsPageTmpl, err := template.New("page").Parse(metricsPage)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create template")
|
||||
}
|
||||
|
||||
rootHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
metricsPageTmpl.Execute(w, s.Metrics != nil)
|
||||
}
|
||||
|
||||
s.metricsRouter.HandleFunc("/", rootHandler)
|
||||
s.metricsRouter.StrictSlash(true)
|
||||
|
||||
s.metricsRouter.Handle("/debug", http.RedirectHandler("/", http.StatusMovedPermanently))
|
||||
s.metricsRouter.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
s.metricsRouter.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
s.metricsRouter.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||
s.metricsRouter.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||
s.metricsRouter.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||
|
||||
// Manually add support for paths linked to by index page at /debug/pprof/
|
||||
s.metricsRouter.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
|
||||
s.metricsRouter.Handle("/debug/pprof/heap", pprof.Handler("heap"))
|
||||
s.metricsRouter.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
|
||||
s.metricsRouter.Handle("/debug/pprof/block", pprof.Handler("block"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) startMetricsServer() {
|
||||
var notify chan struct{}
|
||||
s.metricsLock.Lock()
|
||||
defer func() {
|
||||
if notify != nil {
|
||||
<-notify
|
||||
}
|
||||
s.metricsLock.Unlock()
|
||||
}()
|
||||
|
||||
l, err := net.Listen("tcp", *s.Config().MetricsSettings.ListenAddress)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
notify = make(chan struct{})
|
||||
s.metricsServer = &http.Server{
|
||||
Handler: handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(s.metricsRouter),
|
||||
ReadTimeout: time.Duration(*s.Config().ServiceSettings.ReadTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(*s.Config().ServiceSettings.WriteTimeout) * time.Second,
|
||||
}
|
||||
|
||||
go func() {
|
||||
close(notify)
|
||||
if err := s.metricsServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||
mlog.Critical(err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
s.Log.Info("Metrics and profiling server is started", mlog.String("address", l.Addr().String()))
|
||||
}
|
||||
|
||||
func (s *Server) sendLicenseUpForRenewalEmail(users map[string]*model.User, license *model.License) *model.AppError {
|
||||
|
||||
@@ -48,7 +48,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *mod
|
||||
|
||||
message = strings.TrimSpace(message)
|
||||
if message == CmdCustomStatusClear {
|
||||
if err := a.RemoveCustomStatus(args.UserId); err != nil {
|
||||
if err := a.RemoveCustomStatus(c, args.UserId); err != nil {
|
||||
mlog.Debug(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_custom_status.clear.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *mod
|
||||
|
||||
customStatus := GetCustomStatus(message)
|
||||
customStatus.PreSave()
|
||||
if err := a.SetCustomStatus(args.UserId, customStatus); err != nil {
|
||||
if err := a.SetCustomStatus(c, args.UserId, customStatus); err != nil {
|
||||
mlog.Debug(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_custom_status.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func (th *TestHelper) initBasic() *TestHelper {
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
th.SystemAdminUser = th.createUser()
|
||||
th.App.UpdateUserRoles(th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy()
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
@@ -405,7 +406,7 @@ func (a *App) UpdateDNDStatusOfUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError {
|
||||
func (a *App) SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError {
|
||||
if cs == nil || (cs.Emoji == "" && cs.Text == "") {
|
||||
return model.NewAppError("SetCustomStatus", "api.custom_status.set_custom_statuses.update.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -416,26 +417,26 @@ func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppE
|
||||
}
|
||||
|
||||
user.SetCustomStatus(cs)
|
||||
_, updateErr := a.UpdateUser(user, true)
|
||||
_, updateErr := a.UpdateUser(c, user, true)
|
||||
if updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
|
||||
if err := a.addRecentCustomStatus(userID, cs); err != nil {
|
||||
a.Log().Error("Can't add recent custom status for", mlog.String("userID", userID), mlog.Err(err))
|
||||
c.Logger().Error("Can't add recent custom status for", mlog.String("userID", userID), mlog.Err(err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) RemoveCustomStatus(userID string) *model.AppError {
|
||||
func (a *App) RemoveCustomStatus(c request.CTX, userID string) *model.AppError {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user.ClearCustomStatus()
|
||||
_, updateErr := a.UpdateUser(user, true)
|
||||
_, updateErr := a.UpdateUser(c, user, true)
|
||||
if updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
|
||||
@@ -53,14 +53,14 @@ func TestCustomStatus(t *testing.T) {
|
||||
Text: "honk!",
|
||||
}
|
||||
|
||||
err := th.App.SetCustomStatus(user.Id, cs)
|
||||
err := th.App.SetCustomStatus(th.Context, user.Id, cs)
|
||||
require.Nil(t, err, "failed to set custom status %v", err)
|
||||
|
||||
csSaved, err := th.App.GetCustomStatus(user.Id)
|
||||
require.Nil(t, err, "failed to get custom status after save %v", err)
|
||||
require.Equal(t, cs, csSaved)
|
||||
|
||||
err = th.App.RemoveCustomStatus(user.Id)
|
||||
err = th.App.RemoveCustomStatus(th.Context, user.Id)
|
||||
require.Nil(t, err, "failed to to clear custom status %v", err)
|
||||
|
||||
var csClear *model.CustomStatus
|
||||
@@ -117,9 +117,9 @@ func TestCustomStatusErrors(t *testing.T) {
|
||||
var appErr *model.AppError
|
||||
switch tc.customStatus {
|
||||
case "set":
|
||||
appErr = th.App.SetCustomStatus(fakeUserID, cs)
|
||||
appErr = th.App.SetCustomStatus(th.Context, fakeUserID, cs)
|
||||
case "remove":
|
||||
appErr = th.App.RemoveCustomStatus(fakeUserID)
|
||||
appErr = th.App.RemoveCustomStatus(th.Context, fakeUserID)
|
||||
}
|
||||
|
||||
require.NotNil(t, appErr)
|
||||
|
||||
@@ -337,7 +337,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
t.Run("Team with restricted domains skips over members that do not match the allowed domains", func(t *testing.T) {
|
||||
restrictedUser := th.CreateUser()
|
||||
restrictedUser.Email = "restricted@mattermost.org"
|
||||
_, err = th.App.UpdateUser(restrictedUser, false)
|
||||
_, err = th.App.UpdateUser(th.Context, restrictedUser, false)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.UpsertGroupMember(scienceGroup.Id, restrictedUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -763,7 +763,7 @@ func (a *App) AddUserToTeamByInviteId(c *request.Context, inviteId string, userI
|
||||
return team, teamMember, nil
|
||||
}
|
||||
|
||||
func (a *App) JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) {
|
||||
func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) {
|
||||
teamMember, alreadyAdded, err := a.ch.srv.teamService.JoinUserToTeam(team, user)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
|
||||
148
app/user.go
148
app/user.go
@@ -43,7 +43,7 @@ const (
|
||||
ImageProfilePixelDimension = 128
|
||||
)
|
||||
|
||||
func (a *App) CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError) {
|
||||
if err := a.IsUserSignUpAllowed(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -104,19 +104,19 @@ func (a *App) CreateUserWithToken(c *request.Context, user *model.User, token *m
|
||||
for _, channel := range channels {
|
||||
_, err := a.AddChannelMember(c, ruser.Id, channel, ChannelMemberOpts{})
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to add channel member", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to add channel member", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.DeleteToken(token); err != nil {
|
||||
mlog.Warn("Error while deleting token", mlog.Err(err))
|
||||
c.Logger().Warn("Error while deleting token", mlog.Err(err))
|
||||
}
|
||||
|
||||
return ruser, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateUserWithInviteId(c *request.Context, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateUserWithInviteId(c request.CTX, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) {
|
||||
if err := a.IsUserSignUpAllowed(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -154,26 +154,26 @@ func (a *App) CreateUserWithInviteId(c *request.Context, user *model.User, invit
|
||||
a.AddDirectChannels(c, team.Id, ruser)
|
||||
|
||||
if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil {
|
||||
mlog.Warn("Failed to send welcome email on create user with inviteId", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to send welcome email on create user with inviteId", mlog.Err(err))
|
||||
}
|
||||
|
||||
return ruser, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
ruser, err := a.CreateUser(c, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil {
|
||||
mlog.Warn("Failed to send welcome email to the new user, created by system admin", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to send welcome email to the new user, created by system admin", mlog.Err(err))
|
||||
}
|
||||
|
||||
return ruser, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) {
|
||||
if err := a.IsUserSignUpAllowed(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func (a *App) CreateUserFromSignup(c *request.Context, user *model.User, redirec
|
||||
}
|
||||
|
||||
if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil {
|
||||
mlog.Warn("Failed to send welcome email on create user from signup", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to send welcome email on create user from signup", mlog.Err(err))
|
||||
}
|
||||
|
||||
return ruser, nil
|
||||
@@ -211,17 +211,17 @@ func (a *App) IsFirstUserAccount() bool {
|
||||
|
||||
// CreateUser creates a user and sets several fields of the returned User struct to
|
||||
// their zero values.
|
||||
func (a *App) CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError) {
|
||||
return a.createUserOrGuest(c, user, false)
|
||||
}
|
||||
|
||||
// CreateGuest creates a guest and sets several fields of the returned User struct to
|
||||
// their zero values.
|
||||
func (a *App) CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError) {
|
||||
func (a *App) CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError) {
|
||||
return a.createUserOrGuest(c, user, true)
|
||||
}
|
||||
|
||||
func (a *App) createUserOrGuest(c *request.Context, user *model.User, guest bool) (*model.User, *model.AppError) {
|
||||
func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*model.User, *model.AppError) {
|
||||
if err := a.isUniqueToGroupNames(user.Username); err != nil {
|
||||
err.Where = "createUserOrGuest"
|
||||
return nil, err
|
||||
@@ -285,7 +285,7 @@ func (a *App) createUserOrGuest(c *request.Context, user *model.User, guest bool
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Preference().Save(preferences); err != nil {
|
||||
mlog.Warn("Encountered error saving user preferences", mlog.Err(err))
|
||||
c.Logger().Warn("Encountered error saving user preferences", mlog.Err(err))
|
||||
}
|
||||
|
||||
go a.UpdateViewedProductNoticesForNewUser(ruser.Id)
|
||||
@@ -347,7 +347,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re
|
||||
if provider.IsSameUser(userByEmail, user) {
|
||||
if _, err := a.Srv().Store.User().UpdateAuthData(userByEmail.Id, user.AuthService, user.AuthData, "", false); err != nil {
|
||||
// if the user is not updated, write a warning to the log, but don't prevent user login
|
||||
mlog.Warn("Error attempting to update user AuthData", mlog.Err(err))
|
||||
c.Logger().Warn("Error attempting to update user AuthData", mlog.Err(err))
|
||||
}
|
||||
return userByEmail, nil
|
||||
}
|
||||
@@ -369,7 +369,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re
|
||||
|
||||
err = a.AddDirectChannels(c, teamID, user)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to add direct channels", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to add direct channels", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,7 +759,7 @@ func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError)
|
||||
return a.ch.srv.GetDefaultProfileImage(user)
|
||||
}
|
||||
|
||||
func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
func (a *App) SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError {
|
||||
img, appErr := a.GetDefaultProfileImage(user)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -771,14 +771,14 @@ func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.User().ResetLastPictureUpdate(user.Id); err != nil {
|
||||
mlog.Warn("Failed to reset last picture update", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to reset last picture update", mlog.Err(err))
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
|
||||
updatedUser, appErr := a.GetUser(user.Id)
|
||||
if appErr != nil {
|
||||
mlog.Warn("Error in getting users profile forcing logout", mlog.String("user_id", user.Id), mlog.Err(appErr))
|
||||
c.Logger().Warn("Error in getting users profile forcing logout", mlog.String("user_id", user.Id), mlog.Err(appErr))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -792,21 +792,21 @@ func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError {
|
||||
func (a *App) SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError {
|
||||
file, err := imageData.Open()
|
||||
if err != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
defer file.Close()
|
||||
return a.SetProfileImageFromMultiPartFile(userID, file)
|
||||
return a.SetProfileImageFromMultiPartFile(c, userID, file)
|
||||
}
|
||||
|
||||
func (a *App) SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError {
|
||||
func (a *App) SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError {
|
||||
if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return a.SetProfileImageFromFile(userID, file)
|
||||
return a.SetProfileImageFromFile(c, userID, file)
|
||||
}
|
||||
|
||||
func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) {
|
||||
@@ -831,7 +831,7 @@ func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppError {
|
||||
func (a *App) SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError {
|
||||
buf, err := a.AdjustImage(file)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -847,7 +847,7 @@ func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppE
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.User().UpdateLastPictureUpdate(userID); err != nil {
|
||||
mlog.Warn("Error with updating last picture update", mlog.Err(err))
|
||||
c.Logger().Warn("Error with updating last picture update", mlog.Err(err))
|
||||
}
|
||||
a.invalidateUserCacheAndPublish(userID)
|
||||
a.onUserProfileChange(userID)
|
||||
@@ -855,7 +855,7 @@ func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppE
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdatePasswordAsUser(userID, currentPassword, newPassword string) *model.AppError {
|
||||
func (a *App) UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPassword string) *model.AppError {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -880,7 +880,7 @@ func (a *App) UpdatePasswordAsUser(userID, currentPassword, newPassword string)
|
||||
|
||||
T := i18n.GetUserTranslations(user.Locale)
|
||||
|
||||
return a.UpdatePasswordSendEmail(user, newPassword, T("api.user.update_password.menu"))
|
||||
return a.UpdatePasswordSendEmail(c, user, newPassword, T("api.user.update_password.menu"))
|
||||
}
|
||||
|
||||
func (a *App) userDeactivated(c *request.Context, userID string) *model.AppError {
|
||||
@@ -999,8 +999,8 @@ func (a *App) SanitizeProfile(user *model.User, asAdmin bool) {
|
||||
user.SanitizeProfile(options)
|
||||
}
|
||||
|
||||
func (a *App) UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError) {
|
||||
updatedUser, err := a.UpdateUser(user, true)
|
||||
func (a *App) UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError) {
|
||||
updatedUser, err := a.UpdateUser(c, user, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ func (a *App) CheckProviderAttributes(user *model.User, patch *model.UserPatch)
|
||||
return conflictField
|
||||
}
|
||||
|
||||
func (a *App) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) {
|
||||
func (a *App) PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1047,7 +1047,7 @@ func (a *App) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*m
|
||||
|
||||
user.Patch(patch)
|
||||
|
||||
updatedUser, err := a.UpdateUser(user, true)
|
||||
updatedUser, err := a.UpdateUser(c, user, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1112,7 +1112,7 @@ func (a *App) isUniqueToGroupNames(val string) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
prev, err := a.ch.srv.userService.GetUser(user.Id)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -1192,13 +1192,13 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
if *a.Config().EmailSettings.RequireEmailVerification {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.SendEmailVerification(userUpdate.New, newEmail, ""); err != nil {
|
||||
mlog.Error("Failed to send email verification", mlog.Err(err))
|
||||
c.Logger().Error("Failed to send email verification", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
} else {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendEmailChangeEmail(userUpdate.Old.Email, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Failed to send email change email", mlog.Err(err))
|
||||
c.Logger().Error("Failed to send email change email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
if userUpdate.New.Username != userUpdate.Old.Username {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendChangeUsernameEmail(userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Failed to send change username email", mlog.Err(err))
|
||||
c.Logger().Error("Failed to send change username email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1251,7 +1251,7 @@ func (a *App) updateUserNotifyProps(userID string, props map[string]string) *mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateMfa(activate bool, userID, token string) *model.AppError {
|
||||
func (a *App) UpdateMfa(c request.CTX, activate bool, userID, token string) *model.AppError {
|
||||
if activate {
|
||||
if err := a.ActivateMfa(userID, token); err != nil {
|
||||
return err
|
||||
@@ -1265,25 +1265,25 @@ func (a *App) UpdateMfa(activate bool, userID, token string) *model.AppError {
|
||||
a.Srv().Go(func() {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get user", mlog.Err(err))
|
||||
c.Logger().Error("Failed to get user", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
if err := a.Srv().EmailService.SendMfaChangeEmail(user.Email, activate, user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Failed to send mfa change email", mlog.Err(err))
|
||||
c.Logger().Error("Failed to send mfa change email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdatePasswordByUserIdSendEmail(userID, newPassword, method string) *model.AppError {
|
||||
func (a *App) UpdatePasswordByUserIdSendEmail(c request.CTX, userID, newPassword, method string) *model.AppError {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return a.UpdatePasswordSendEmail(user, newPassword, method)
|
||||
return a.UpdatePasswordSendEmail(c, user, newPassword, method)
|
||||
}
|
||||
|
||||
func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppError {
|
||||
@@ -1302,14 +1302,14 @@ func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppErr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdatePasswordSendEmail(user *model.User, newPassword, method string) *model.AppError {
|
||||
func (a *App) UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword, method string) *model.AppError {
|
||||
if err := a.UpdatePassword(user, newPassword); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendPasswordChangeEmail(user.Email, method, user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Failed to send password change email", mlog.Err(err))
|
||||
c.Logger().Error("Failed to send password change email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1335,11 +1335,11 @@ func (a *App) UpdateHashedPassword(user *model.User, newHashedPassword string) *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError {
|
||||
return a.resetPasswordFromToken(userSuppliedTokenString, newPassword, model.GetMillis())
|
||||
func (a *App) ResetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string) *model.AppError {
|
||||
return a.resetPasswordFromToken(c, userSuppliedTokenString, newPassword, model.GetMillis())
|
||||
}
|
||||
|
||||
func (a *App) resetPasswordFromToken(userSuppliedTokenString, newPassword string, nowMilli int64) *model.AppError {
|
||||
func (a *App) resetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string, nowMilli int64) *model.AppError {
|
||||
token, err := a.GetPasswordRecoveryToken(userSuppliedTokenString)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1373,12 +1373,12 @@ func (a *App) resetPasswordFromToken(userSuppliedTokenString, newPassword string
|
||||
|
||||
T := i18n.GetUserTranslations(user.Locale)
|
||||
|
||||
if err := a.UpdatePasswordSendEmail(user, newPassword, T("api.user.reset_password.method")); err != nil {
|
||||
if err := a.UpdatePasswordSendEmail(c, user, newPassword, T("api.user.reset_password.method")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.DeleteToken(token); err != nil {
|
||||
mlog.Warn("Failed to delete token", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to delete token", mlog.Err(err))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1474,17 +1474,17 @@ func (a *App) DeleteToken(token *model.Token) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
func (a *App) UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.UpdateUserRolesWithUser(user, newRoles, sendWebSocketEvent)
|
||||
return a.UpdateUserRolesWithUser(c, user, newRoles, sendWebSocketEvent)
|
||||
}
|
||||
|
||||
func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
func (a *App) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) {
|
||||
|
||||
if err := a.CheckRolesExist(strings.Fields(newRoles)); err != nil {
|
||||
return nil, err
|
||||
@@ -1522,7 +1522,7 @@ func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWeb
|
||||
|
||||
if result := <-schan; result.NErr != nil {
|
||||
// soft error since the user roles were still updated
|
||||
mlog.Warn("Failed during updating user roles", mlog.Err(result.NErr))
|
||||
c.Logger().Warn("Failed during updating user roles", mlog.Err(result.NErr))
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
@@ -1539,9 +1539,9 @@ func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWeb
|
||||
}
|
||||
|
||||
func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.AppError {
|
||||
mlog.Warn("Attempting to permanently delete account", mlog.String("user_id", user.Id), mlog.String("user_email", user.Email))
|
||||
c.Logger().Warn("Attempting to permanently delete account", mlog.String("user_id", user.Id), mlog.String("user_email", user.Email))
|
||||
if user.IsInRole(model.SystemAdminRoleId) {
|
||||
mlog.Warn("You are deleting a user that is a system administrator. You may need to set another account as the system administrator using the command line tools.", mlog.String("user_email", user.Email))
|
||||
c.Logger().Warn("You are deleting a user that is a system administrator. You may need to set another account as the system administrator using the command line tools.", mlog.String("user_email", user.Email))
|
||||
}
|
||||
|
||||
if _, err := a.UpdateActive(c, user, false); err != nil {
|
||||
@@ -1600,13 +1600,13 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A
|
||||
|
||||
infos, err := a.Srv().Store.FileInfo().GetForUser(user.Id)
|
||||
if err != nil {
|
||||
mlog.Warn("Error getting file list for user from FileInfoStore", mlog.Err(err))
|
||||
c.Logger().Warn("Error getting file list for user from FileInfoStore", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, info := range infos {
|
||||
res, err := a.FileExists(info.Path)
|
||||
if err != nil {
|
||||
mlog.Warn(
|
||||
c.Logger().Warn(
|
||||
"Error checking existence of file",
|
||||
mlog.String("path", info.Path),
|
||||
mlog.Err(err),
|
||||
@@ -1615,14 +1615,14 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A
|
||||
}
|
||||
|
||||
if !res {
|
||||
mlog.Warn("File not found", mlog.String("path", info.Path))
|
||||
c.Logger().Warn("File not found", mlog.String("path", info.Path))
|
||||
continue
|
||||
}
|
||||
|
||||
err = a.RemoveFile(info.Path)
|
||||
|
||||
if err != nil {
|
||||
mlog.Warn(
|
||||
c.Logger().Warn(
|
||||
"Unable to remove file",
|
||||
mlog.String("path", info.Path),
|
||||
mlog.Err(err),
|
||||
@@ -1646,7 +1646,7 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A
|
||||
return model.NewAppError("PermanentDeleteUser", "app.team.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
mlog.Warn("Permanently deleted account", mlog.String("user_email", user.Email), mlog.String("user_id", user.Id))
|
||||
c.Logger().Warn("Permanently deleted account", mlog.String("user_email", user.Email), mlog.String("user_id", user.Id))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1693,7 +1693,7 @@ func (a *App) SendEmailVerification(user *model.User, newEmail, redirect string)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError {
|
||||
func (a *App) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError {
|
||||
token, err := a.GetVerifyEmailToken(userSuppliedTokenString)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1731,7 +1731,7 @@ func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppErr
|
||||
}
|
||||
|
||||
if err := a.DeleteToken(token); err != nil {
|
||||
mlog.Warn("Failed to delete token", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to delete token", mlog.Err(err))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -2163,23 +2163,23 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
for _, team := range userTeams {
|
||||
// Soft error if there is an issue joining the default channels
|
||||
if err := a.JoinDefaultChannels(c, team.Id, user, false, requestorId); err != nil {
|
||||
mlog.Warn("Failed to join default channels", mlog.String("user_id", user.Id), mlog.String("team_id", team.Id), mlog.String("requestor_id", requestorId), mlog.Err(err))
|
||||
c.Logger().Warn("Failed to join default channels", mlog.String("user_id", user.Id), mlog.String("team_id", team.Id), mlog.String("requestor_id", requestorId), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
promotedUser, err := a.GetUser(user.Id)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get user on promote guest to user", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to get user on promote guest to user", mlog.Err(err))
|
||||
} else {
|
||||
a.sendUpdatedUserEvent(*promotedUser)
|
||||
if uErr := a.ch.srv.userService.UpdateSessionsIsGuest(promotedUser.Id, promotedUser.IsGuest()); uErr != nil {
|
||||
mlog.Warn("Unable to update user sessions", mlog.String("user_id", promotedUser.Id), mlog.Err(uErr))
|
||||
c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", promotedUser.Id), mlog.Err(uErr))
|
||||
}
|
||||
}
|
||||
|
||||
teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get team members for user on promote guest to user", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to get team members for user on promote guest to user", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, member := range teamMembers {
|
||||
@@ -2187,7 +2187,7 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
|
||||
channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get channel members for user on promote guest to user", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to get channel members for user on promote guest to user", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, member := range channelMembers {
|
||||
@@ -2196,7 +2196,7 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil)
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
c.Logger().Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
@@ -2218,12 +2218,12 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
|
||||
a.sendUpdatedUserEvent(*demotedUser)
|
||||
if uErr := a.ch.srv.userService.UpdateSessionsIsGuest(demotedUser.Id, demotedUser.IsGuest()); uErr != nil {
|
||||
mlog.Warn("Unable to update user sessions", mlog.String("user_id", demotedUser.Id), mlog.Err(uErr))
|
||||
c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", demotedUser.Id), mlog.Err(uErr))
|
||||
}
|
||||
|
||||
teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get team members for users on demote user to guest", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to get team members for users on demote user to guest", mlog.Err(err))
|
||||
}
|
||||
|
||||
for _, member := range teamMembers {
|
||||
@@ -2231,7 +2231,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
|
||||
channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get channel members for users on demote user to guest", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to get channel members for users on demote user to guest", mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -2241,7 +2241,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil)
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
c.Logger().Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
@@ -2295,8 +2295,8 @@ func (a *App) GetKnownUsers(userID string) ([]string, *model.AppError) {
|
||||
}
|
||||
|
||||
// ConvertBotToUser converts a bot to user.
|
||||
func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) {
|
||||
user, nErr := a.Srv().Store.User().Get(context.Background(), bot.UserId)
|
||||
func (a *App) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) {
|
||||
user, nErr := a.Srv().Store.User().Get(c.Context(), bot.UserId)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -2308,7 +2308,7 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad
|
||||
}
|
||||
|
||||
if sysadmin && !user.IsInRole(model.SystemAdminRoleId) {
|
||||
_, appErr := a.UpdateUserRoles(
|
||||
_, appErr := a.UpdateUserRoles(c,
|
||||
user.Id,
|
||||
fmt.Sprintf("%s %s", user.Roles, model.SystemAdminRoleId),
|
||||
false)
|
||||
@@ -2319,7 +2319,7 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad
|
||||
|
||||
user.Patch(userPatch)
|
||||
|
||||
user, err := a.UpdateUser(user, false)
|
||||
user, err := a.UpdateUser(c, user, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2518,7 +2518,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea
|
||||
|
||||
payload, jsonErr := json.Marshal(userThread)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
c.Logger().Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message.Add("thread", string(payload))
|
||||
message.Add("previous_unread_replies", int64(0))
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestSetDefaultProfileImage(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
err := th.App.SetDefaultProfileImage(&model.User{
|
||||
err := th.App.SetDefaultProfileImage(th.Context, &model.User{
|
||||
Id: model.NewId(),
|
||||
Username: "notvaliduser",
|
||||
})
|
||||
@@ -97,7 +97,7 @@ func TestSetDefaultProfileImage(t *testing.T) {
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
err = th.App.SetDefaultProfileImage(user)
|
||||
err = th.App.SetDefaultProfileImage(th.Context, user)
|
||||
require.Nil(t, err)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
@@ -140,11 +140,11 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
|
||||
*cfg.TeamSettings.RestrictCreationToDomains = "foo.com"
|
||||
})
|
||||
|
||||
_, err := th.App.UpdateUser(user, false)
|
||||
_, err := th.App.UpdateUser(th.Context, user, false)
|
||||
assert.Nil(t, err)
|
||||
|
||||
user.Email = "asdf@ghjk.l"
|
||||
_, err = th.App.UpdateUser(user, false)
|
||||
_, err = th.App.UpdateUser(th.Context, user, false)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
t.Run("Restricted Domains must be ignored for guest users", func(t *testing.T) {
|
||||
@@ -156,7 +156,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
|
||||
})
|
||||
|
||||
guest.Email = "asdf@bar.com"
|
||||
updatedGuest, err := th.App.UpdateUser(guest, false)
|
||||
updatedGuest, err := th.App.UpdateUser(th.Context, guest, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, guest.Email, updatedGuest.Email)
|
||||
})
|
||||
@@ -170,11 +170,11 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
|
||||
})
|
||||
|
||||
guest.Email = "asdf@bar.com"
|
||||
_, err := th.App.UpdateUser(guest, false)
|
||||
_, err := th.App.UpdateUser(th.Context, guest, false)
|
||||
require.NotNil(t, err)
|
||||
|
||||
guest.Email = "asdf@foo.com"
|
||||
updatedGuest, err := th.App.UpdateUser(guest, false)
|
||||
updatedGuest, err := th.App.UpdateUser(th.Context, guest, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, guest.Email, updatedGuest.Email)
|
||||
})
|
||||
@@ -189,7 +189,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
|
||||
t.Run("fails if the username matches a group name", func(t *testing.T) {
|
||||
user.Username = *group.Name
|
||||
u, err := th.App.UpdateUser(user, false)
|
||||
u, err := th.App.UpdateUser(th.Context, user, false)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "app.user.group_name_conflict", err.Id)
|
||||
require.Nil(t, u)
|
||||
@@ -215,7 +215,7 @@ func TestUpdateUserMissingFields(t *testing.T) {
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
_, err := th.App.UpdateUser(tc.input, false)
|
||||
_, err := th.App.UpdateUser(th.Context, tc.input, false)
|
||||
|
||||
if name == "no missing fields" {
|
||||
assert.Nil(t, err)
|
||||
@@ -517,7 +517,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
newEmail := th.MakeEmail()
|
||||
|
||||
user.Email = newEmail
|
||||
user2, appErr := th.App.UpdateUser(user, false)
|
||||
user2, appErr := th.App.UpdateUser(th.Context, user, false)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, currentEmail, user2.Email)
|
||||
assert.True(t, user2.EmailVerified)
|
||||
@@ -525,7 +525,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
token, err := th.App.Srv().EmailService.CreateVerifyEmailToken(user2.Id, newEmail)
|
||||
assert.NoError(t, err)
|
||||
|
||||
appErr = th.App.VerifyEmailFromToken(token.Token)
|
||||
appErr = th.App.VerifyEmailFromToken(th.Context, token.Token)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user2, appErr = th.App.GetUser(user2.Id)
|
||||
@@ -544,7 +544,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
|
||||
newBotEmail := th.MakeEmail()
|
||||
botuser.Email = newBotEmail
|
||||
botuser2, appErr := th.App.UpdateUser(&botuser, false)
|
||||
botuser2, appErr := th.App.UpdateUser(th.Context, &botuser, false)
|
||||
assert.Nil(t, appErr)
|
||||
assert.Equal(t, botuser2.Email, newBotEmail)
|
||||
|
||||
@@ -559,7 +559,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
newEmail := user2.Email
|
||||
|
||||
user.Email = newEmail
|
||||
user3, err := th.App.UpdateUser(user, false)
|
||||
user3, err := th.App.UpdateUser(th.Context, user, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, err.Id, "app.user.save.email_exists.app_error")
|
||||
assert.Nil(t, user3)
|
||||
@@ -573,7 +573,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
newEmail := th.MakeEmail()
|
||||
|
||||
user.Email = newEmail
|
||||
user2, err := th.App.UpdateUser(user, false)
|
||||
user2, err := th.App.UpdateUser(th.Context, user, false)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, newEmail, user2.Email)
|
||||
|
||||
@@ -588,7 +588,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
|
||||
newBotEmail := th.MakeEmail()
|
||||
botuser.Email = newBotEmail
|
||||
botuser2, err := th.App.UpdateUser(&botuser, false)
|
||||
botuser2, err := th.App.UpdateUser(th.Context, &botuser, false)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, botuser2.Email, newBotEmail)
|
||||
})
|
||||
@@ -602,7 +602,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
newEmail := user2.Email
|
||||
|
||||
user.Email = newEmail
|
||||
user3, err := th.App.UpdateUser(user, false)
|
||||
user3, err := th.App.UpdateUser(th.Context, user, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, err.Id, "app.user.save.email_exists.app_error")
|
||||
assert.Nil(t, user3)
|
||||
@@ -616,7 +616,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
// we update the email a first time and update. The first
|
||||
// token is sent with the email
|
||||
user.Email = th.MakeEmail()
|
||||
_, appErr := th.App.UpdateUser(user, true)
|
||||
_, appErr := th.App.UpdateUser(th.Context, user, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
tokens := []*model.Token{}
|
||||
@@ -632,7 +632,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
// time and another token gets sent. The first one should not
|
||||
// work anymore and the second should work properly
|
||||
user.Email = th.MakeEmail()
|
||||
_, appErr = th.App.UpdateUser(user, true)
|
||||
_, appErr = th.App.UpdateUser(th.Context, user, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -649,9 +649,9 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
_, err := th.App.Srv().Store.Token().GetByToken(firstToken.Token)
|
||||
require.Error(t, err)
|
||||
|
||||
require.NotNil(t, th.App.VerifyEmailFromToken(firstToken.Token))
|
||||
require.Nil(t, th.App.VerifyEmailFromToken(secondToken.Token))
|
||||
require.NotNil(t, th.App.VerifyEmailFromToken(firstToken.Token))
|
||||
require.NotNil(t, th.App.VerifyEmailFromToken(th.Context, firstToken.Token))
|
||||
require.Nil(t, th.App.VerifyEmailFromToken(th.Context, secondToken.Token))
|
||||
require.NotNil(t, th.App.VerifyEmailFromToken(th.Context, firstToken.Token))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1096,7 +1096,7 @@ func TestPasswordRecovery(t *testing.T) {
|
||||
assert.Equal(t, th.BasicUser.Id, tokenData.UserId)
|
||||
assert.Equal(t, th.BasicUser.Email, tokenData.Email)
|
||||
|
||||
err = th.App.ResetPasswordFromToken(token.Token, "abcdefgh")
|
||||
err = th.App.ResetPasswordFromToken(th.Context, token.Token, "abcdefgh")
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
@@ -1109,10 +1109,10 @@ func TestPasswordRecovery(t *testing.T) {
|
||||
})
|
||||
|
||||
th.BasicUser.Email = th.MakeEmail()
|
||||
_, err = th.App.UpdateUser(th.BasicUser, false)
|
||||
_, err = th.App.UpdateUser(th.Context, th.BasicUser, false)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = th.App.ResetPasswordFromToken(token.Token, "abcdefgh")
|
||||
err = th.App.ResetPasswordFromToken(th.Context, token.Token, "abcdefgh")
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
@@ -1120,7 +1120,7 @@ func TestPasswordRecovery(t *testing.T) {
|
||||
token, err := th.App.CreatePasswordRecoveryToken(th.BasicUser.Id, th.BasicUser.Email)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = th.App.resetPasswordFromToken(token.Token, "abcdefgh", model.GetMillis())
|
||||
err = th.App.resetPasswordFromToken(th.Context, token.Token, "abcdefgh", model.GetMillis())
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
@@ -1128,7 +1128,7 @@ func TestPasswordRecovery(t *testing.T) {
|
||||
token, err := th.App.CreatePasswordRecoveryToken(th.BasicUser.Id, th.BasicUser.Email)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = th.App.resetPasswordFromToken(token.Token, "abcdefgh", model.GetMillisForTime(time.Now().Add(25*time.Hour)))
|
||||
err = th.App.resetPasswordFromToken(th.Context, token.Token, "abcdefgh", model.GetMillisForTime(time.Now().Add(25*time.Hour)))
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
@@ -1604,12 +1604,12 @@ func TestUpdateUserRolesWithUser(t *testing.T) {
|
||||
assert.Equal(t, user.Roles, model.SystemUserRoleId)
|
||||
|
||||
// Upgrade to sysadmin.
|
||||
user, err := th.App.UpdateUserRolesWithUser(user, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
user, err := th.App.UpdateUserRolesWithUser(th.Context, user, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, user.Roles, model.SystemUserRoleId+" "+model.SystemAdminRoleId)
|
||||
|
||||
// Test bad role.
|
||||
_, err = th.App.UpdateUserRolesWithUser(user, "does not exist", false)
|
||||
_, err = th.App.UpdateUserRolesWithUser(th.Context, user, "does not exist", false)
|
||||
require.NotNil(t, err)
|
||||
}
|
||||
|
||||
@@ -1636,7 +1636,7 @@ func TestPatchUser(t *testing.T) {
|
||||
defer th.App.PermanentDeleteUser(th.Context, testUser)
|
||||
|
||||
t.Run("Patch with a username already exists", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
_, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{
|
||||
Username: model.NewString(th.BasicUser.Username),
|
||||
}, true)
|
||||
|
||||
@@ -1645,7 +1645,7 @@ func TestPatchUser(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Patch with a email already exists", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
_, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{
|
||||
Email: model.NewString(th.BasicUser.Email),
|
||||
}, true)
|
||||
|
||||
@@ -1654,7 +1654,7 @@ func TestPatchUser(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Patch username with a new username", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
_, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{
|
||||
Username: model.NewString(model.NewId()),
|
||||
}, true)
|
||||
|
||||
|
||||
@@ -20,23 +20,23 @@ func TestRestrictedViewMembers(t *testing.T) {
|
||||
user1 := th.CreateUser()
|
||||
user1.Nickname = "test user1"
|
||||
user1.Username = "test-user-1"
|
||||
th.App.UpdateUser(user1, false)
|
||||
th.App.UpdateUser(th.Context, user1, false)
|
||||
user2 := th.CreateUser()
|
||||
user2.Username = "test-user-2"
|
||||
user2.Nickname = "test user2"
|
||||
th.App.UpdateUser(user2, false)
|
||||
th.App.UpdateUser(th.Context, user2, false)
|
||||
user3 := th.CreateUser()
|
||||
user3.Username = "test-user-3"
|
||||
user3.Nickname = "test user3"
|
||||
th.App.UpdateUser(user3, false)
|
||||
th.App.UpdateUser(th.Context, user3, false)
|
||||
user4 := th.CreateUser()
|
||||
user4.Username = "test-user-4"
|
||||
user4.Nickname = "test user4"
|
||||
th.App.UpdateUser(user4, false)
|
||||
th.App.UpdateUser(th.Context, user4, false)
|
||||
user5 := th.CreateUser()
|
||||
user5.Username = "test-user-5"
|
||||
user5.Nickname = "test user5"
|
||||
th.App.UpdateUser(user5, false)
|
||||
th.App.UpdateUser(th.Context, user5, false)
|
||||
|
||||
// user1 is member of all the channels and teams because is the creator
|
||||
th.BasicUser = user1
|
||||
|
||||
Ссылка в новой задаче
Block a user