Migrate store methods to use request.Context instead of context.Context (#24836)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0d5a8b8841
Коммит
13c05a571f
@@ -39,7 +39,7 @@ import (
|
||||
// AppIface is extracted from App struct and contains all it's exported methods. It's provided to allow partial interface passing and app layers creation.
|
||||
type AppIface interface {
|
||||
// @openTracingParams args
|
||||
ExecuteCommand(c request.CTX, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
|
||||
ExecuteCommand(c *request.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
|
||||
// @openTracingParams teamID
|
||||
// previous ListCommands now ListAutocompleteCommands
|
||||
ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError)
|
||||
@@ -129,7 +129,7 @@ type AppIface interface {
|
||||
DeletePublicKey(name string) *model.AppError
|
||||
// DemoteUserToGuest Convert user's roles and all his membership's roles from
|
||||
// regular user roles to guest roles.
|
||||
DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
DemoteUserToGuest(c *request.Context, user *model.User) *model.AppError
|
||||
// DisablePlugin will set the config for an installed plugin to disabled, triggering deactivation if active.
|
||||
// Notifies cluster peers through config change.
|
||||
DisablePlugin(id string) *model.AppError
|
||||
@@ -365,7 +365,7 @@ type AppIface interface {
|
||||
// This to be used for places we check the users password when they are already logged in
|
||||
DoubleCheckPassword(user *model.User, password string) *model.AppError
|
||||
// UpdateBotActive marks a bot as active or inactive, along with its corresponding user.
|
||||
UpdateBotActive(c request.CTX, botUserId string, active bool) (*model.Bot, *model.AppError)
|
||||
UpdateBotActive(c *request.Context, botUserId string, active bool) (*model.Bot, *model.AppError)
|
||||
// UpdateBotOwner changes a bot's owner to the given value.
|
||||
UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.AppError)
|
||||
// UpdateChannel updates a given channel by its Id. It also publishes the CHANNEL_UPDATED event.
|
||||
@@ -424,7 +424,7 @@ type AppIface interface {
|
||||
AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError)
|
||||
AdjustInProductLimits(limits *model.ProductLimits, subscription *model.Subscription) *model.AppError
|
||||
AdjustTeamsFromProductLimits(teamLimits *model.TeamsLimits) *model.AppError
|
||||
AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
AllowOAuthAppAccessToUser(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
AppendFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||
AsymmetricSigningKey() *ecdsa.PrivateKey
|
||||
AttachCloudSessionCookie(c *request.Context, w http.ResponseWriter, r *http.Request)
|
||||
@@ -500,7 +500,7 @@ type AppIface interface {
|
||||
CreateRetentionPolicy(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, *model.AppError)
|
||||
CreateRole(role *model.Role) (*model.Role, *model.AppError)
|
||||
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
CreateSession(session *model.Session) (*model.Session, *model.AppError)
|
||||
CreateSession(c *request.Context, session *model.Session) (*model.Session, *model.AppError)
|
||||
CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
CreateTeam(c request.CTX, team *model.Team) (*model.Team, *model.AppError)
|
||||
CreateTeamWithUser(c *request.Context, team *model.Team, userID string) (*model.Team, *model.AppError)
|
||||
@@ -517,7 +517,7 @@ type AppIface interface {
|
||||
DataRetention() einterfaces.DataRetentionInterface
|
||||
DeactivateGuests(c *request.Context) *model.AppError
|
||||
DeactivateMfa(userID string) *model.AppError
|
||||
DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError
|
||||
DeauthorizeOAuthAppForUser(c *request.Context, userID, appID string) *model.AppError
|
||||
DeleteAcknowledgementForPost(c *request.Context, postID, userID string) *model.AppError
|
||||
DeleteAllExpiredPluginKeys() *model.AppError
|
||||
DeleteAllKeysForPlugin(pluginID string) *model.AppError
|
||||
@@ -547,7 +547,7 @@ type AppIface interface {
|
||||
DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId string) *model.AppError
|
||||
DeleteToken(token *model.Token) *model.AppError
|
||||
DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError
|
||||
DisableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
DisableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError
|
||||
DoAppMigrations()
|
||||
DoCheckForAdminNotifications(trial bool) *model.AppError
|
||||
DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError)
|
||||
@@ -561,7 +561,7 @@ type AppIface interface {
|
||||
DoUploadFile(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
|
||||
DoUploadFileExpectModification(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
|
||||
DownloadFromURL(downloadURL string) ([]byte, error)
|
||||
EnableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
EnableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError
|
||||
EnvironmentConfig(filter func(reflect.StructField) bool) map[string]any
|
||||
ExportFileBackend() filestore.FileBackend
|
||||
ExportFileExists(path string) (bool, *model.AppError)
|
||||
@@ -575,7 +575,7 @@ type AppIface interface {
|
||||
FileSize(path string) (int64, *model.AppError)
|
||||
FillInChannelProps(c request.CTX, channel *model.Channel) *model.AppError
|
||||
FillInChannelsProps(c request.CTX, channelList model.ChannelList) *model.AppError
|
||||
FilterUsersByVisible(viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError)
|
||||
FilterUsersByVisible(c request.CTX, viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError)
|
||||
FindTeamByName(name string) bool
|
||||
FinishSendAdminNotifyPost(trial bool, now int64, pluginBasedData map[string][]*model.NotifyAdminData)
|
||||
GenerateAndSaveDesktopToken(createAt int64, user *model.User) (*string, *model.AppError)
|
||||
@@ -696,13 +696,13 @@ type AppIface interface {
|
||||
GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string
|
||||
GetNotificationNameFormat(user *model.User) string
|
||||
GetNumberOfChannelsOnTeam(c request.CTX, teamID string) (int, *model.AppError)
|
||||
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
||||
GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
||||
GetOAuthAccessTokenForCodeFlow(c *request.Context, clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
||||
GetOAuthAccessTokenForImplicitFlow(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
||||
GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError)
|
||||
GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthImplicitRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthImplicitRedirect(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthLoginEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID, action, redirectTo, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthSignupEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID string, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthStateToken(token string) (*model.Token, *model.AppError)
|
||||
@@ -768,8 +768,8 @@ type AppIface interface {
|
||||
GetSchemes(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
|
||||
GetSchemesPage(scope string, page int, perPage int) ([]*model.Scheme, *model.AppError)
|
||||
GetSession(token string) (*model.Session, *model.AppError)
|
||||
GetSessionById(sessionID string) (*model.Session, *model.AppError)
|
||||
GetSessions(userID string) ([]*model.Session, *model.AppError)
|
||||
GetSessionById(c *request.Context, sessionID string) (*model.Session, *model.AppError)
|
||||
GetSessions(c *request.Context, userID string) ([]*model.Session, *model.AppError)
|
||||
GetSharedChannel(channelID string) (*model.SharedChannel, error)
|
||||
GetSharedChannelRemote(id string) (*model.SharedChannelRemote, error)
|
||||
GetSharedChannelRemoteByIds(channelID string, remoteID string) (*model.SharedChannelRemote, error)
|
||||
@@ -791,10 +791,10 @@ type AppIface interface {
|
||||
GetTeamByName(name string) (*model.Team, *model.AppError)
|
||||
GetTeamIcon(team *model.Team) ([]byte, *model.AppError)
|
||||
GetTeamIdFromQuery(query url.Values) (string, *model.AppError)
|
||||
GetTeamMember(teamID, userID string) (*model.TeamMember, *model.AppError)
|
||||
GetTeamMember(c request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError)
|
||||
GetTeamMembers(teamID string, offset int, limit int, teamMembersGetOptions *model.TeamMembersGetOptions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersByIds(teamID string, userIDs []string, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUser(userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUser(c request.CTX, userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUserWithPagination(userID string, page, perPage int) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamPoliciesForUser(userID string, offset, limit int) (*model.RetentionPolicyForTeamList, *model.AppError)
|
||||
GetTeamStats(teamID string, restrictions *model.ViewUsersRestrictions) (*model.TeamStats, *model.AppError)
|
||||
@@ -853,7 +853,7 @@ type AppIface interface {
|
||||
GetUsersWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||
GetUsersWithoutTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetVerifyEmailToken(token string) (*model.Token, *model.AppError)
|
||||
GetViewUsersRestrictions(userID string) (*model.ViewUsersRestrictions, *model.AppError)
|
||||
GetViewUsersRestrictions(c request.CTX, userID string) (*model.ViewUsersRestrictions, *model.AppError)
|
||||
GetWarnMetricsBot() (*model.Bot, *model.AppError)
|
||||
GetWarnMetricsStatus() (map[string]*model.WarnMetricStatus, *model.AppError)
|
||||
HTTPService() httpservice.HTTPService
|
||||
@@ -866,9 +866,9 @@ type AppIface interface {
|
||||
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
||||
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
||||
HasPermissionToChannel(c request.CTX, askingUserId string, channelID string, permission *model.Permission) bool
|
||||
HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool
|
||||
HasPermissionToChannelByPost(c request.CTX, askingUserId string, postID string, permission *model.Permission) bool
|
||||
HasPermissionToReadChannel(c request.CTX, userID string, channel *model.Channel) bool
|
||||
HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool
|
||||
HasPermissionToTeam(c request.CTX, askingUserId string, teamID string, permission *model.Permission) bool
|
||||
HasPermissionToUser(askingUserId string, userID string) bool
|
||||
HasSharedChannel(channelID string) (bool, error)
|
||||
HooksManager() *product.HooksManager
|
||||
@@ -992,15 +992,15 @@ type AppIface interface {
|
||||
RestoreChannel(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||
RestoreGroup(groupID string) (*model.Group, *model.AppError)
|
||||
RestoreTeam(teamID string) *model.AppError
|
||||
RestrictUsersGetByPermissions(userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError)
|
||||
RestrictUsersSearchByPermissions(userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError)
|
||||
RestrictUsersGetByPermissions(c request.CTX, userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError)
|
||||
RestrictUsersSearchByPermissions(c request.CTX, userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError)
|
||||
ReturnSessionToPool(session *model.Session)
|
||||
RevokeAccessToken(token string) *model.AppError
|
||||
RevokeAllSessions(userID string) *model.AppError
|
||||
RevokeSession(session *model.Session) *model.AppError
|
||||
RevokeSessionById(sessionID string) *model.AppError
|
||||
RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError
|
||||
RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
RevokeAccessToken(c *request.Context, token string) *model.AppError
|
||||
RevokeAllSessions(c *request.Context, userID string) *model.AppError
|
||||
RevokeSession(c *request.Context, session *model.Session) *model.AppError
|
||||
RevokeSessionById(c *request.Context, sessionID string) *model.AppError
|
||||
RevokeSessionsForDeviceId(c *request.Context, userID string, deviceID string, currentSessionId string) *model.AppError
|
||||
RevokeUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError
|
||||
RolesGrantPermission(roleNames []string, permissionId string) bool
|
||||
Saml() einterfaces.SamlInterface
|
||||
SanitizePostListMetadataForUser(c request.CTX, postList *model.PostList, userID string) (*model.PostList, *model.AppError)
|
||||
@@ -1097,7 +1097,7 @@ type AppIface interface {
|
||||
SwitchEmailToLdap(c *request.Context, email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError)
|
||||
SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError)
|
||||
SwitchLdapToEmail(c *request.Context, ldapPassword, code, email, newPassword string) (string, *model.AppError)
|
||||
SwitchOAuthToEmail(email, password, requesterId string) (string, *model.AppError)
|
||||
SwitchOAuthToEmail(c *request.Context, email, password, requesterId string) (string, *model.AppError)
|
||||
TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError)
|
||||
TelemetryId() string
|
||||
TestElasticsearch(cfg *model.Config) *model.AppError
|
||||
@@ -1111,7 +1111,7 @@ type AppIface interface {
|
||||
TotalWebsocketConnections() int
|
||||
TriggerWebhook(c request.CTX, payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
||||
UnregisterPluginCommand(pluginID, teamID, trigger string)
|
||||
UpdateActive(c request.CTX, user *model.User, active bool) (*model.User, *model.AppError)
|
||||
UpdateActive(c *request.Context, user *model.User, active bool) (*model.User, *model.AppError)
|
||||
UpdateChannelMemberNotifyProps(c request.CTX, data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberRoles(c request.CTX, channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberSchemeRoles(c request.CTX, channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
||||
@@ -1146,8 +1146,8 @@ type AppIface interface {
|
||||
UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, categoryOrder []string) *model.AppError
|
||||
UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateTeamMemberRoles(teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamMemberSchemeRoles(teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamMemberRoles(c request.CTX, teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamMemberSchemeRoles(c request.CTX, teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamPrivacy(teamID string, teamType string, allowOpenInvite bool) *model.AppError
|
||||
UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateThreadFollowForUser(userID, teamID, threadID string, state bool) *model.AppError
|
||||
@@ -1156,7 +1156,7 @@ type AppIface interface {
|
||||
UpdateThreadReadForUserByPost(c request.CTX, currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadsReadForUser(userID, teamID string) *model.AppError
|
||||
UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
UpdateUserActive(c request.CTX, userID string, active bool) *model.AppError
|
||||
UpdateUserActive(c *request.Context, userID string, active bool) *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(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
@@ -1169,7 +1169,7 @@ type AppIface interface {
|
||||
UpsertGroupMembers(groupID string, userIDs []string) ([]*model.GroupMember, *model.AppError)
|
||||
UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
UserAlreadyNotifiedOnRequiredFeature(user string, feature model.MattermostFeature) bool
|
||||
UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError)
|
||||
UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError)
|
||||
UserIsFirstAdmin(user *model.User) bool
|
||||
ValidateDesktopToken(token string, expiryTime int64) (*model.User, *model.AppError)
|
||||
VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError
|
||||
|
||||
@@ -281,11 +281,11 @@ func (a *App) HasPermissionTo(askingUserId string, permission *model.Permission)
|
||||
return a.RolesGrantPermission(roles, permission.Id)
|
||||
}
|
||||
|
||||
func (a *App) HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToTeam(c request.CTX, askingUserId string, teamID string, permission *model.Permission) bool {
|
||||
if teamID == "" || askingUserId == "" {
|
||||
return false
|
||||
}
|
||||
teamMember, _ := a.GetTeamMember(teamID, askingUserId)
|
||||
teamMember, _ := a.GetTeamMember(c, teamID, askingUserId)
|
||||
if teamMember != nil && teamMember.DeleteAt == 0 {
|
||||
if a.RolesGrantPermission(teamMember.GetRoles(), permission.Id) {
|
||||
return true
|
||||
@@ -310,13 +310,13 @@ func (a *App) HasPermissionToChannel(c request.CTX, askingUserId string, channel
|
||||
var channel *model.Channel
|
||||
channel, err = a.GetChannel(c, channelID)
|
||||
if err == nil {
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
return a.HasPermissionToTeam(c, askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
}
|
||||
|
||||
func (a *App) HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToChannelByPost(c request.CTX, askingUserId string, postID string, permission *model.Permission) bool {
|
||||
if channelMember, err := a.Srv().Store().Channel().GetMemberForPost(postID, askingUserId); err == nil {
|
||||
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||
return true
|
||||
@@ -324,7 +324,7 @@ func (a *App) HasPermissionToChannelByPost(askingUserId string, postID string, p
|
||||
}
|
||||
|
||||
if channel, err := a.Srv().Store().Channel().GetForPost(postID); err == nil {
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
return a.HasPermissionToTeam(c, askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
@@ -406,5 +406,5 @@ func (a *App) HasPermissionToReadChannel(c request.CTX, userID string, channel *
|
||||
if !*a.Config().TeamSettings.ExperimentalViewArchivedChannels && channel.DeleteAt != 0 {
|
||||
return false
|
||||
}
|
||||
return a.HasPermissionToChannel(c, userID, channel.Id, model.PermissionReadChannelContent) || (channel.Type == model.ChannelTypeOpen && a.HasPermissionToTeam(userID, channel.TeamId, model.PermissionReadPublicChannel))
|
||||
return a.HasPermissionToChannel(c, userID, channel.Id, model.PermissionReadChannelContent) || (channel.Type == model.ChannelTypeOpen && a.HasPermissionToTeam(c, userID, channel.TeamId, model.PermissionReadPublicChannel))
|
||||
}
|
||||
|
||||
@@ -57,17 +57,17 @@ func TestHasPermissionToTeam(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.BasicUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.Context, th.BasicUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
th.RemoveUserFromTeam(th.BasicUser, th.BasicTeam)
|
||||
assert.False(t, th.App.HasPermissionToTeam(th.BasicUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.False(t, th.App.HasPermissionToTeam(th.Context, th.BasicUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.Context, th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam)
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.Context, th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
th.RemovePermissionFromRole(model.PermissionListTeamChannels.Id, model.TeamUserRoleId)
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.Context, th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
th.RemoveUserFromTeam(th.SystemAdminUser, th.BasicTeam)
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
assert.True(t, th.App.HasPermissionToTeam(th.Context, th.SystemAdminUser.Id, th.BasicTeam.Id, model.PermissionListTeamChannels))
|
||||
}
|
||||
|
||||
func TestSessionHasPermissionToChannel(t *testing.T) {
|
||||
@@ -332,7 +332,7 @@ func TestSessionHasPermissionToManageUserOrBot(t *testing.T) {
|
||||
func TestHasPermissionToCategory(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
session, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
require.Nil(t, err)
|
||||
|
||||
categories, err := th.App.GetSidebarCategoriesForTeamForUser(th.Context, th.BasicUser.Id, th.BasicTeam.Id)
|
||||
@@ -418,7 +418,7 @@ func TestSessionHasPermissionToGroup(t *testing.T) {
|
||||
th.RemovePermissionFromRole(permission.Id, groupRole.Name)
|
||||
}
|
||||
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}, Roles: systemRole.Name})
|
||||
session, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}, Roles: systemRole.Name})
|
||||
require.Nil(t, err)
|
||||
|
||||
result := th.App.SessionHasPermissionToGroup(*session, group.Id, permission)
|
||||
|
||||
@@ -388,7 +388,7 @@ func (a *App) GetBots(options *model.BotGetOptions) (model.BotList, *model.AppEr
|
||||
}
|
||||
|
||||
// UpdateBotActive marks a bot as active or inactive, along with its corresponding user.
|
||||
func (a *App) UpdateBotActive(c request.CTX, botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
func (a *App) UpdateBotActive(c *request.Context, botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
user, nErr := a.Srv().Store().User().Get(context.Background(), botUserId)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -495,7 +495,7 @@ func (a *App) UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.A
|
||||
}
|
||||
|
||||
// disableUserBots disables all bots owned by the given user.
|
||||
func (a *App) disableUserBots(c request.CTX, userID string) *model.AppError {
|
||||
func (a *App) disableUserBots(c *request.Context, userID string) *model.AppError {
|
||||
perPage := 20
|
||||
for {
|
||||
options := &model.BotGetOptions{
|
||||
|
||||
@@ -1586,7 +1586,7 @@ func (a *App) addUserToChannel(c request.CTX, user *model.User, channel *model.C
|
||||
// AddUserToChannel adds a user to a given channel.
|
||||
func (a *App) AddUserToChannel(c request.CTX, user *model.User, channel *model.Channel, skipTeamMemberIntegrityCheck bool) (*model.ChannelMember, *model.AppError) {
|
||||
if !skipTeamMemberIntegrityCheck {
|
||||
teamMember, nErr := a.Srv().Store().Team().GetMember(context.Background(), channel.TeamId, user.Id)
|
||||
teamMember, nErr := a.Srv().Store().Team().GetMember(c, channel.TeamId, user.Id)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -2534,7 +2534,7 @@ func (a *App) removeUserFromChannel(c request.CTX, userIDToRemove string, remove
|
||||
return err
|
||||
}
|
||||
if len(currentMembers) == 0 {
|
||||
teamMember, err := a.GetTeamMember(channel.TeamId, userIDToRemove)
|
||||
teamMember, err := a.GetTeamMember(c, channel.TeamId, userIDToRemove)
|
||||
if err != nil {
|
||||
return model.NewAppError("removeUserFromChannel", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
func (a *App) createInitialSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, nErr := a.Srv().Store().Channel().CreateInitialSidebarCategories(userID, opts)
|
||||
func (a *App) createInitialSidebarCategories(c request.CTX, userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, nErr := a.Srv().Store().Channel().CreateInitialSidebarCategories(c, userID, opts)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func (a *App) GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID s
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategoriesForTeamForUser(userID, teamID)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, &store.SidebarCategorySearchOpts{
|
||||
categories, appErr = a.createInitialSidebarCategories(c, userID, &store.SidebarCategorySearchOpts{
|
||||
TeamID: teamID,
|
||||
ExcludeTeam: false,
|
||||
})
|
||||
@@ -55,7 +55,7 @@ func (a *App) GetSidebarCategories(c request.CTX, userID string, opts *store.Sid
|
||||
categories, err := a.Srv().Store().Channel().GetSidebarCategories(userID, opts)
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
categories, appErr = a.createInitialSidebarCategories(userID, opts)
|
||||
categories, appErr = a.createInitialSidebarCategories(c, userID, opts)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -709,7 +709,7 @@ func TestLeaveLastChannel(t *testing.T) {
|
||||
t.Run("Guest leaves not last channel", func(t *testing.T) {
|
||||
err = th.App.LeaveChannel(th.Context, townSquare.Id, guest.Id)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
_, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err, "It should maintain the team membership")
|
||||
})
|
||||
|
||||
@@ -718,7 +718,7 @@ func TestLeaveLastChannel(t *testing.T) {
|
||||
assert.Nil(t, err, "It should allow to remove a guest user from the default channel")
|
||||
_, err = th.App.GetChannelMember(th.Context, th.BasicChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
_, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
_, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err, "It should remove the team membership")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ var atMentionRegexp = regexp.MustCompile(`\B@[[:alnum:]][[:alnum:]\.\-_:]*`)
|
||||
type CommandProvider interface {
|
||||
GetTrigger() string
|
||||
GetCommand(a *App, T i18n.TranslateFunc) *model.Command
|
||||
DoCommand(a *App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse
|
||||
DoCommand(a *App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse
|
||||
}
|
||||
|
||||
var commandProviders = make(map[string]CommandProvider)
|
||||
@@ -179,7 +179,7 @@ func (a *App) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Com
|
||||
}
|
||||
|
||||
// @openTracingParams args
|
||||
func (a *App) ExecuteCommand(c request.CTX, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
func (a *App) ExecuteCommand(c *request.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
trigger := ""
|
||||
message := ""
|
||||
index := strings.IndexFunc(args.Command, unicode.IsSpace)
|
||||
@@ -279,7 +279,7 @@ func (a *App) MentionsToTeamMembers(c request.CTX, message, teamID string) model
|
||||
continue
|
||||
}
|
||||
|
||||
_, err := a.GetTeamMember(teamID, userFromTrimmed.Id)
|
||||
_, err := a.GetTeamMember(c, teamID, userFromTrimmed.Id)
|
||||
if err != nil {
|
||||
// The user is not in the team, so we should ignore it
|
||||
return
|
||||
@@ -292,7 +292,7 @@ func (a *App) MentionsToTeamMembers(c request.CTX, message, teamID string) model
|
||||
return
|
||||
}
|
||||
|
||||
_, err := a.GetTeamMember(teamID, user.Id)
|
||||
_, err := a.GetTeamMember(c, teamID, user.Id)
|
||||
if err != nil {
|
||||
// The user is not in the team, so we should ignore it
|
||||
return
|
||||
@@ -355,7 +355,7 @@ func (a *App) MentionsToPublicChannels(c request.CTX, message, teamID string) mo
|
||||
|
||||
// tryExecuteBuiltInCommand attempts to run a built in command based on the given arguments. If no such command can be
|
||||
// found, returns nil for all arguments.
|
||||
func (a *App) tryExecuteBuiltInCommand(c request.CTX, args *model.CommandArgs, trigger string, message string) (*model.Command, *model.CommandResponse) {
|
||||
func (a *App) tryExecuteBuiltInCommand(c *request.Context, args *model.CommandArgs, trigger string, message string) (*model.Command, *model.CommandResponse) {
|
||||
provider := GetCommandProvider(trigger)
|
||||
if provider == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -658,7 +658,7 @@ func (p *testCommandProvider) GetCommand(a *App, T i18n.TranslateFunc) *model.Co
|
||||
}
|
||||
}
|
||||
|
||||
func (p *testCommandProvider) DoCommand(a *App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (p *testCommandProvider) DoCommand(a *App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return &model.CommandResponse{
|
||||
Text: "I do nothing!",
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestNotifySessionsExpired(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, d := range data {
|
||||
_, err := th.App.CreateSession(&model.Session{
|
||||
_, err := th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser.Id,
|
||||
DeviceId: d.deviceID,
|
||||
ExpiresAt: d.expiresAt,
|
||||
|
||||
@@ -804,7 +804,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]imports.U
|
||||
isAdminByTeamId = map[string]bool{}
|
||||
)
|
||||
|
||||
existingMemberships, nErr := a.Srv().Store().Team().GetTeamsForUser(context.Background(), user.Id, "", true)
|
||||
existingMemberships, nErr := a.Srv().Store().Team().GetTeamsForUser(c, user.Id, "", true)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("importUserTeams", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
@@ -916,12 +916,12 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]imports.U
|
||||
|
||||
for _, member := range append(newMembers, oldMembers...) {
|
||||
if member.ExplicitRoles != rolesByTeamId[member.TeamId] {
|
||||
if _, err = a.UpdateTeamMemberRoles(member.TeamId, user.Id, rolesByTeamId[member.TeamId]); err != nil {
|
||||
if _, err = a.UpdateTeamMemberRoles(c, member.TeamId, user.Id, rolesByTeamId[member.TeamId]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
a.UpdateTeamMemberSchemeRoles(member.TeamId, user.Id, isGuestByTeamId[member.TeamId], isUserByTeamId[member.TeamId], isAdminByTeamId[member.TeamId])
|
||||
a.UpdateTeamMemberSchemeRoles(c, member.TeamId, user.Id, isGuestByTeamId[member.TeamId], isUserByTeamId[member.TeamId], isAdminByTeamId[member.TeamId])
|
||||
}
|
||||
|
||||
for _, team := range allTeams {
|
||||
|
||||
@@ -1077,7 +1077,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
user, appErr = th.App.GetUserByUsername(username)
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
teamMember, appErr := th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, appErr := th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get team member from database.")
|
||||
require.Equal(t, "team_user", teamMember.Roles)
|
||||
|
||||
@@ -1136,7 +1136,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
// Check both member properties.
|
||||
teamMember, appErr = th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, appErr = th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get team member from database.")
|
||||
require.Equal(t, "team_user team_admin", teamMember.Roles)
|
||||
|
||||
@@ -1452,7 +1452,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
user, appErr = th.App.GetUserByUsername(*userData.Username)
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
teamMember, appErr = th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, appErr = th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the team member")
|
||||
|
||||
assert.True(t, teamMember.SchemeAdmin)
|
||||
@@ -1494,7 +1494,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
user, appErr = th.App.GetUserByUsername(*deletedUserData.Username)
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
teamMember, appErr = th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, appErr = th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the team member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
@@ -1536,7 +1536,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
user, appErr = th.App.GetUserByUsername(*deletedGuestData.Username)
|
||||
require.Nil(t, appErr, "Failed to get user from database.")
|
||||
|
||||
teamMember, appErr = th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, appErr = th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr, "Failed to get the team member")
|
||||
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
@@ -1737,7 +1737,7 @@ func TestImportUserTeams(t *testing.T) {
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
teamMembers, nErr := th.App.Srv().Store().Team().GetTeamsForUser(context.Background(), user.Id, "", true)
|
||||
teamMembers, nErr := th.App.Srv().Store().Team().GetTeamsForUser(th.Context, user.Id, "", true)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, teamMembers, tc.expectedUserTeams)
|
||||
if tc.expectedUserTeams == 1 {
|
||||
@@ -1880,7 +1880,7 @@ func TestImportUserChannels(t *testing.T) {
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
_, _, err := th.App.ch.srv.teamService.JoinUserToTeam(th.BasicTeam, user)
|
||||
_, _, err := th.App.ch.srv.teamService.JoinUserToTeam(th.Context, th.BasicTeam, user)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Two times import must end with the same results
|
||||
|
||||
@@ -102,7 +102,7 @@ func (a *App) SwitchEmailToLdap(c *request.Context, email, password, code, ldapL
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
if err := a.RevokeAllSessions(c, user.Id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func (a *App) SwitchLdapToEmail(c *request.Context, ldapPassword, code, email, n
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
if err := a.RevokeAllSessions(c, user.Id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
||||
a.ch.srv.platform.SetSessionExpireInHours(session, *a.Config().ServiceSettings.SessionLengthMobileInHours)
|
||||
|
||||
// A special case where we logout of all other sessions with the same Id
|
||||
if err := a.RevokeSessionsForDeviceId(user.Id, deviceID, ""); err != nil {
|
||||
if err := a.RevokeSessionsForDeviceId(c, user.Id, deviceID, ""); err != nil {
|
||||
err.StatusCode = http.StatusInternalServerError
|
||||
return err
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
if session, err = a.CreateSession(session); err != nil {
|
||||
if session, err = a.CreateSession(c, session); err != nil {
|
||||
err.StatusCode = http.StatusInternalServerError
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -887,7 +887,7 @@ func (a *App) sendNoUsersNotifiedByGroupInChannel(c request.CTX, sender *model.U
|
||||
// sendOutOfChannelMentions sends an ephemeral post to the sender of a post if any of the given potential mentions
|
||||
// are outside of the post's channel. Returns whether or not an ephemeral post was sent.
|
||||
func (a *App) sendOutOfChannelMentions(c request.CTX, sender *model.User, post *model.Post, channel *model.Channel, potentialMentions []string) (bool, error) {
|
||||
outOfChannelUsers, outOfGroupsUsers, err := a.filterOutOfChannelMentions(sender, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupsUsers, err := a.filterOutOfChannelMentions(c, sender, post, channel, potentialMentions)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -901,10 +901,10 @@ func (a *App) sendOutOfChannelMentions(c request.CTX, sender *model.User, post *
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *App) FilterUsersByVisible(viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError) {
|
||||
func (a *App) FilterUsersByVisible(c request.CTX, viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError) {
|
||||
result := []*model.User{}
|
||||
for _, user := range otherUsers {
|
||||
canSee, err := a.UserCanSeeOtherUser(viewer.Id, user.Id)
|
||||
canSee, err := a.UserCanSeeOtherUser(c, viewer.Id, user.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -915,7 +915,7 @@ func (a *App) FilterUsersByVisible(viewer *model.User, otherUsers []*model.User)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *App) filterOutOfChannelMentions(sender *model.User, post *model.Post, channel *model.Channel, potentialMentions []string) ([]*model.User, []*model.User, error) {
|
||||
func (a *App) filterOutOfChannelMentions(c request.CTX, sender *model.User, post *model.Post, channel *model.Channel, potentialMentions []string) ([]*model.User, []*model.User, error) {
|
||||
if post.IsSystemMessage() {
|
||||
return nil, nil, nil
|
||||
}
|
||||
@@ -936,7 +936,7 @@ func (a *App) filterOutOfChannelMentions(sender *model.User, post *model.Post, c
|
||||
// Filter out inactive users and bots
|
||||
allUsers := model.UserSlice(users).FilterByActive(true)
|
||||
allUsers = allUsers.FilterWithoutBots()
|
||||
allUsers, appErr := a.FilterUsersByVisible(sender, allUsers)
|
||||
allUsers, appErr := a.FilterUsersByVisible(c, sender, allUsers)
|
||||
if appErr != nil {
|
||||
return nil, nil, appErr
|
||||
}
|
||||
|
||||
@@ -1067,7 +1067,7 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) {
|
||||
func TestSendPushNotifications(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
_, err := th.App.CreateSession(&model.Session{
|
||||
_, err := th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser.Id,
|
||||
DeviceId: "test",
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
@@ -1407,14 +1407,14 @@ func TestAllPushNotifications(t *testing.T) {
|
||||
var testData []userSession
|
||||
for i := 0; i < 10; i++ {
|
||||
u := th.CreateUser()
|
||||
sess, err := th.App.CreateSession(&model.Session{
|
||||
sess, err := th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
// We don't need to track the 2nd session.
|
||||
_, err = th.App.CreateSession(&model.Session{
|
||||
_, err = th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
|
||||
@@ -319,7 +319,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{user2.Username, user3.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, outOfChannelUsers, 2)
|
||||
@@ -332,7 +332,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{user2.Username, user3.Username, user4.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(guest, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, guest, post, channel, potentialMentions)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Len(t, outOfChannelUsers, 1)
|
||||
@@ -346,7 +346,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
}
|
||||
potentialMentions := []string{user2.Username, user3.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -360,7 +360,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
}
|
||||
potentialMentions := []string{user2.Username, user3.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, directChannel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, directChannel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -374,7 +374,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
}
|
||||
potentialMentions := []string{user2.Username, user3.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, groupChannel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, groupChannel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -389,7 +389,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{inactiveUser.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -403,7 +403,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{botUser.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -414,7 +414,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{"foo", "bar"}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, channel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, channel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, outOfChannelUsers)
|
||||
@@ -448,7 +448,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) {
|
||||
post := &model.Post{}
|
||||
potentialMentions := []string{nonChannelMember.Username, nonGroupMember.Username}
|
||||
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(user1, post, constrainedChannel, potentialMentions)
|
||||
outOfChannelUsers, outOfGroupUsers, err := th.App.filterOutOfChannelMentions(th.Context, user1, post, constrainedChannel, potentialMentions)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, outOfChannelUsers, 1)
|
||||
|
||||
@@ -146,8 +146,8 @@ func (a *App) GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.
|
||||
return oauthApps, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthImplicitRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
session, err := a.GetOAuthAccessTokenForImplicitFlow(userID, authRequest)
|
||||
func (a *App) GetOAuthImplicitRedirect(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
session, err := a.GetOAuthAccessTokenForImplicitFlow(c, userID, authRequest)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (a *App) GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRe
|
||||
return uri.String(), nil
|
||||
}
|
||||
|
||||
func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
func (a *App) AllowOAuthAppAccessToUser(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.Author
|
||||
case model.AuthCodeResponseType:
|
||||
redirectURI, err = a.GetOAuthCodeRedirect(userID, authRequest)
|
||||
case model.ImplicitResponseType:
|
||||
redirectURI, err = a.GetOAuthImplicitRedirect(userID, authRequest)
|
||||
redirectURI, err = a.GetOAuthImplicitRedirect(c, userID, authRequest)
|
||||
default:
|
||||
return authRequest.RedirectURI + "?error=unsupported_response_type&state=" + authRequest.State, nil
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.Author
|
||||
return redirectURI, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
func (a *App) GetOAuthAccessTokenForImplicitFlow(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *mod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
session, err := a.newSession(oauthApp, user)
|
||||
session, err := a.newSession(c, oauthApp, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *mod
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
func (a *App) GetOAuthAccessTokenForCodeFlow(c *request.Context, clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
if accessData != nil {
|
||||
if accessData.IsExpired() {
|
||||
var access *model.AccessResponse
|
||||
access, err := a.newSessionUpdateToken(oauthApp, accessData, user)
|
||||
access, err := a.newSessionUpdateToken(c, oauthApp, accessData, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
} else {
|
||||
var session *model.Session
|
||||
// Create a new session and return new access token
|
||||
session, err := a.newSession(oauthApp, user)
|
||||
session, err := a.newSession(c, oauthApp, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound)
|
||||
}
|
||||
|
||||
access, err := a.newSessionUpdateToken(oauthApp, accessData, user)
|
||||
access, err := a.newSessionUpdateToken(c, oauthApp, accessData, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
return accessRsp, nil
|
||||
}
|
||||
|
||||
func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session, *model.AppError) {
|
||||
func (a *App) newSession(c *request.Context, app *model.OAuthApp, user *model.User) (*model.Session, *model.AppError) {
|
||||
// Set new token an session
|
||||
session := &model.Session{UserId: user.Id, Roles: user.Roles, IsOAuth: true}
|
||||
session.GenerateCSRF()
|
||||
@@ -393,7 +393,7 @@ func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session,
|
||||
session.AddProp(model.SessionPropOs, "OAuth2")
|
||||
session.AddProp(model.SessionPropBrowser, "OAuth2")
|
||||
|
||||
session, err := a.Srv().Store().Session().Save(session)
|
||||
session, err := a.Srv().Store().Session().Save(c, session)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("newSession", "api.oauth.get_access_token.internal_session.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
@@ -403,13 +403,13 @@ func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session,
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) newSessionUpdateToken(app *model.OAuthApp, accessData *model.AccessData, user *model.User) (*model.AccessResponse, *model.AppError) {
|
||||
func (a *App) newSessionUpdateToken(c *request.Context, app *model.OAuthApp, accessData *model.AccessData, user *model.User) (*model.AccessResponse, *model.AppError) {
|
||||
// Remove the previous session
|
||||
if err := a.Srv().Store().Session().Remove(accessData.Token); err != nil {
|
||||
mlog.Warn("error removing access data token from session", mlog.Err(err))
|
||||
}
|
||||
|
||||
session, err := a.newSession(app, user)
|
||||
session, err := a.newSession(c, app, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (a *App) GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*mod
|
||||
return apps, nil
|
||||
}
|
||||
|
||||
func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError {
|
||||
func (a *App) DeauthorizeOAuthAppForUser(c *request.Context, userID, appID string) *model.AppError {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -505,7 +505,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError {
|
||||
}
|
||||
|
||||
for _, ad := range accessData {
|
||||
if err := a.RevokeAccessToken(ad.Token); err != nil {
|
||||
if err := a.RevokeAccessToken(c, ad.Token); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -548,8 +548,8 @@ func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *m
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func (a *App) RevokeAccessToken(token string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAccessToken(token); err != nil {
|
||||
func (a *App) RevokeAccessToken(c *request.Context, token string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAccessToken(c, token); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, platform.GetTokenError):
|
||||
return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
@@ -678,7 +678,7 @@ func (a *App) CompleteSwitchWithOAuth(c *request.Context, service string, userDa
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", MissingAccountError, nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
if err := a.RevokeAllSessions(c, user.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -969,7 +969,7 @@ func (a *App) SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *h
|
||||
return authURL, nil
|
||||
}
|
||||
|
||||
func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *model.AppError) {
|
||||
func (a *App) SwitchOAuthToEmail(c *request.Context, email, password, requesterId string) (string, *model.AppError) {
|
||||
if a.Srv().License() != nil && !*a.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer {
|
||||
return "", model.NewAppError("oauthToEmail", "api.user.oauth_to_email.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -991,11 +991,11 @@ func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("error sending signin change email", mlog.Err(err))
|
||||
c.Logger().Error("error sending signin change email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
if err := a.RevokeAllSessions(requesterId); err != nil {
|
||||
if err := a.RevokeAllSessions(c, requesterId); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -49,26 +49,26 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
|
||||
State: "123",
|
||||
}
|
||||
|
||||
session, err := th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
|
||||
session, err := th.App.GetOAuthAccessTokenForImplicitFlow(th.Context, th.BasicUser.Id, authRequest)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, session)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.Context, th.BasicUser.Id, authRequest)
|
||||
assert.NotNil(t, err, "should fail - oauth2 disabled")
|
||||
assert.Nil(t, session)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
authRequest.ClientId = "junk"
|
||||
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.Context, th.BasicUser.Id, authRequest)
|
||||
assert.NotNil(t, err, "should fail - bad client id")
|
||||
assert.Nil(t, session)
|
||||
|
||||
authRequest.ClientId = oapp.Id
|
||||
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow("junk", authRequest)
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.Context, "junk", authRequest)
|
||||
assert.NotNil(t, err, "should fail - bad user id")
|
||||
assert.Nil(t, session)
|
||||
}
|
||||
@@ -85,9 +85,9 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
th.App.SetSessionExpireInHours(session, 24)
|
||||
|
||||
var err *model.AppError
|
||||
session, err = th.App.CreateSession(session)
|
||||
session, err = th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
err = th.App.RevokeAccessToken(session.Token)
|
||||
err = th.App.RevokeAccessToken(th.Context, session.Token)
|
||||
require.NotNil(t, err, "Should have failed does not have an access token")
|
||||
require.Equal(t, http.StatusBadRequest, err.StatusCode)
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
session.IsOAuth = true
|
||||
th.App.ch.srv.platform.SetSessionExpireInHours(session, 24)
|
||||
|
||||
session, _ = th.App.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(th.Context, session)
|
||||
|
||||
accessData := &model.AccessData{}
|
||||
accessData.Token = session.Token
|
||||
@@ -619,7 +619,7 @@ func TestDeauthorizeOAuthApp(t *testing.T) {
|
||||
redirectUrl, err := th.App.GetOAuthCodeRedirect(th.BasicUser.Id, authRequest)
|
||||
assert.Nil(t, err)
|
||||
|
||||
dErr := th.App.DeauthorizeOAuthAppForUser(th.BasicUser.Id, oapp.Id)
|
||||
dErr := th.App.DeauthorizeOAuthAppForUser(th.Context, th.BasicUser.Id, oapp.Id)
|
||||
assert.Nil(t, dErr)
|
||||
|
||||
uri, uErr := url.Parse(redirectUrl)
|
||||
@@ -670,7 +670,7 @@ func TestDeactivatedUserOAuthApp(t *testing.T) {
|
||||
_, appErr := th.App.UpdateActive(th.Context, th.BasicUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
resp, accErr := th.App.GetOAuthAccessTokenForCodeFlow(oapp.Id, model.AccessTokenGrantType, oapp.CallbackUrls[0], code, oapp.ClientSecret, "")
|
||||
resp, accErr := th.App.GetOAuthAccessTokenForCodeFlow(th.Context, oapp.Id, model.AccessTokenGrantType, oapp.CallbackUrls[0], code, oapp.ClientSecret, "")
|
||||
assert.Nil(t, resp)
|
||||
require.NotNil(t, accErr, "Should not get access token")
|
||||
require.Equal(t, http.StatusBadRequest, accErr.StatusCode)
|
||||
|
||||
@@ -659,7 +659,7 @@ func (a *OpenTracingAppLayer) AdjustTeamsFromProductLimits(teamLimits *model.Tea
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) AllowOAuthAppAccessToUser(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.AllowOAuthAppAccessToUser")
|
||||
|
||||
@@ -671,7 +671,7 @@ func (a *OpenTracingAppLayer) AllowOAuthAppAccessToUser(userID string, authReque
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.AllowOAuthAppAccessToUser(userID, authRequest)
|
||||
resultVar0, resultVar1 := a.app.AllowOAuthAppAccessToUser(c, userID, authRequest)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -2461,7 +2461,7 @@ func (a *OpenTracingAppLayer) CreateScheme(scheme *model.Scheme) (*model.Scheme,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateSession(session *model.Session) (*model.Session, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateSession(c *request.Context, session *model.Session) (*model.Session, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateSession")
|
||||
|
||||
@@ -2473,7 +2473,7 @@ func (a *OpenTracingAppLayer) CreateSession(session *model.Session) (*model.Sess
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.CreateSession(session)
|
||||
resultVar0, resultVar1 := a.app.CreateSession(c, session)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -2857,7 +2857,7 @@ func (a *OpenTracingAppLayer) DeactivateMfa(userID string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DeauthorizeOAuthAppForUser(userID string, appID string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) DeauthorizeOAuthAppForUser(c *request.Context, userID string, appID string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeauthorizeOAuthAppForUser")
|
||||
|
||||
@@ -2869,7 +2869,7 @@ func (a *OpenTracingAppLayer) DeauthorizeOAuthAppForUser(userID string, appID st
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.DeauthorizeOAuthAppForUser(userID, appID)
|
||||
resultVar0 := a.app.DeauthorizeOAuthAppForUser(c, userID, appID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -3593,7 +3593,7 @@ func (a *OpenTracingAppLayer) DeleteToken(token *model.Token) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) DemoteUserToGuest(c *request.Context, user *model.User) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DemoteUserToGuest")
|
||||
|
||||
@@ -3659,7 +3659,7 @@ func (a *OpenTracingAppLayer) DisablePlugin(id string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DisableUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) DisableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DisableUserAccessToken")
|
||||
|
||||
@@ -3671,7 +3671,7 @@ func (a *OpenTracingAppLayer) DisableUserAccessToken(token *model.UserAccessToke
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.DisableUserAccessToken(token)
|
||||
resultVar0 := a.app.DisableUserAccessToken(c, token)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -4042,7 +4042,7 @@ func (a *OpenTracingAppLayer) EnablePlugin(id string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) EnableUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) EnableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.EnableUserAccessToken")
|
||||
|
||||
@@ -4054,7 +4054,7 @@ func (a *OpenTracingAppLayer) EnableUserAccessToken(token *model.UserAccessToken
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.EnableUserAccessToken(token)
|
||||
resultVar0 := a.app.EnableUserAccessToken(c, token)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -4103,7 +4103,7 @@ func (a *OpenTracingAppLayer) EnvironmentConfig(filter func(reflect.StructField)
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) ExecuteCommand(c request.CTX, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) ExecuteCommand(c *request.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ExecuteCommand")
|
||||
|
||||
@@ -4508,7 +4508,7 @@ func (a *OpenTracingAppLayer) FilterNonGroupTeamMembers(userIDs []string, team *
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) FilterUsersByVisible(viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) FilterUsersByVisible(c request.CTX, viewer *model.User, otherUsers []*model.User) ([]*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.FilterUsersByVisible")
|
||||
|
||||
@@ -4520,7 +4520,7 @@ func (a *OpenTracingAppLayer) FilterUsersByVisible(viewer *model.User, otherUser
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.FilterUsersByVisible(viewer, otherUsers)
|
||||
resultVar0, resultVar1 := a.app.FilterUsersByVisible(c, viewer, otherUsers)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7482,7 +7482,7 @@ func (a *OpenTracingAppLayer) GetNumberOfChannelsOnTeam(c request.CTX, teamID st
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetOAuthAccessTokenForCodeFlow(clientId string, grantType string, redirectURI string, code string, secret string, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetOAuthAccessTokenForCodeFlow(c *request.Context, clientId string, grantType string, redirectURI string, code string, secret string, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetOAuthAccessTokenForCodeFlow")
|
||||
|
||||
@@ -7494,7 +7494,7 @@ func (a *OpenTracingAppLayer) GetOAuthAccessTokenForCodeFlow(clientId string, gr
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, code, secret, refreshToken)
|
||||
resultVar0, resultVar1 := a.app.GetOAuthAccessTokenForCodeFlow(c, clientId, grantType, redirectURI, code, secret, refreshToken)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7504,7 +7504,7 @@ func (a *OpenTracingAppLayer) GetOAuthAccessTokenForCodeFlow(clientId string, gr
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetOAuthAccessTokenForImplicitFlow(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetOAuthAccessTokenForImplicitFlow")
|
||||
|
||||
@@ -7516,7 +7516,7 @@ func (a *OpenTracingAppLayer) GetOAuthAccessTokenForImplicitFlow(userID string,
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetOAuthAccessTokenForImplicitFlow(userID, authRequest)
|
||||
resultVar0, resultVar1 := a.app.GetOAuthAccessTokenForImplicitFlow(c, userID, authRequest)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7614,7 +7614,7 @@ func (a *OpenTracingAppLayer) GetOAuthCodeRedirect(userID string, authRequest *m
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetOAuthImplicitRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetOAuthImplicitRedirect(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetOAuthImplicitRedirect")
|
||||
|
||||
@@ -7626,7 +7626,7 @@ func (a *OpenTracingAppLayer) GetOAuthImplicitRedirect(userID string, authReques
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetOAuthImplicitRedirect(userID, authRequest)
|
||||
resultVar0, resultVar1 := a.app.GetOAuthImplicitRedirect(c, userID, authRequest)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -9234,7 +9234,7 @@ func (a *OpenTracingAppLayer) GetSession(token string) (*model.Session, *model.A
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSessionById(sessionID string) (*model.Session, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetSessionById(c *request.Context, sessionID string) (*model.Session, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSessionById")
|
||||
|
||||
@@ -9246,7 +9246,7 @@ func (a *OpenTracingAppLayer) GetSessionById(sessionID string) (*model.Session,
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSessionById(sessionID)
|
||||
resultVar0, resultVar1 := a.app.GetSessionById(c, sessionID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -9273,7 +9273,7 @@ func (a *OpenTracingAppLayer) GetSessionLengthInMillis(session *model.Session) i
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSessions(userID string) ([]*model.Session, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetSessions(c *request.Context, userID string) ([]*model.Session, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSessions")
|
||||
|
||||
@@ -9285,7 +9285,7 @@ func (a *OpenTracingAppLayer) GetSessions(userID string) ([]*model.Session, *mod
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSessions(userID)
|
||||
resultVar0, resultVar1 := a.app.GetSessions(c, userID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -9808,7 +9808,7 @@ func (a *OpenTracingAppLayer) GetTeamIdFromQuery(query url.Values) (string, *mod
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetTeamMember(teamID string, userID string) (*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetTeamMember(c request.CTX, teamID string, userID string) (*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTeamMember")
|
||||
|
||||
@@ -9820,7 +9820,7 @@ func (a *OpenTracingAppLayer) GetTeamMember(teamID string, userID string) (*mode
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetTeamMember(teamID, userID)
|
||||
resultVar0, resultVar1 := a.app.GetTeamMember(c, teamID, userID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -9874,7 +9874,7 @@ func (a *OpenTracingAppLayer) GetTeamMembersByIds(teamID string, userIDs []strin
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetTeamMembersForUser(userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetTeamMembersForUser(c request.CTX, userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTeamMembersForUser")
|
||||
|
||||
@@ -9886,7 +9886,7 @@ func (a *OpenTracingAppLayer) GetTeamMembersForUser(userID string, excludeTeamID
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetTeamMembersForUser(userID, excludeTeamID, includeDeleted)
|
||||
resultVar0, resultVar1 := a.app.GetTeamMembersForUser(c, userID, excludeTeamID, includeDeleted)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -11223,7 +11223,7 @@ func (a *OpenTracingAppLayer) GetVerifyEmailToken(token string) (*model.Token, *
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestrictions, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetViewUsersRestrictions(c request.CTX, userID string) (*model.ViewUsersRestrictions, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetViewUsersRestrictions")
|
||||
|
||||
@@ -11235,7 +11235,7 @@ func (a *OpenTracingAppLayer) GetViewUsersRestrictions(userID string) (*model.Vi
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetViewUsersRestrictions(userID)
|
||||
resultVar0, resultVar1 := a.app.GetViewUsersRestrictions(c, userID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -11456,7 +11456,7 @@ func (a *OpenTracingAppLayer) HasPermissionToChannel(c request.CTX, askingUserId
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool {
|
||||
func (a *OpenTracingAppLayer) HasPermissionToChannelByPost(c request.CTX, askingUserId string, postID string, permission *model.Permission) bool {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HasPermissionToChannelByPost")
|
||||
|
||||
@@ -11468,7 +11468,7 @@ func (a *OpenTracingAppLayer) HasPermissionToChannelByPost(askingUserId string,
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.HasPermissionToChannelByPost(askingUserId, postID, permission)
|
||||
resultVar0 := a.app.HasPermissionToChannelByPost(c, askingUserId, postID, permission)
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
@@ -11490,7 +11490,7 @@ func (a *OpenTracingAppLayer) HasPermissionToReadChannel(c request.CTX, userID s
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool {
|
||||
func (a *OpenTracingAppLayer) HasPermissionToTeam(c request.CTX, askingUserId string, teamID string, permission *model.Permission) bool {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HasPermissionToTeam")
|
||||
|
||||
@@ -11502,7 +11502,7 @@ func (a *OpenTracingAppLayer) HasPermissionToTeam(askingUserId string, teamID st
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.HasPermissionToTeam(askingUserId, teamID, permission)
|
||||
resultVar0 := a.app.HasPermissionToTeam(c, askingUserId, teamID, permission)
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
@@ -14387,7 +14387,7 @@ func (a *OpenTracingAppLayer) RestoreTeam(teamID string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RestrictUsersGetByPermissions(userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) RestrictUsersGetByPermissions(c request.CTX, userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RestrictUsersGetByPermissions")
|
||||
|
||||
@@ -14399,7 +14399,7 @@ func (a *OpenTracingAppLayer) RestrictUsersGetByPermissions(userID string, optio
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.RestrictUsersGetByPermissions(userID, options)
|
||||
resultVar0, resultVar1 := a.app.RestrictUsersGetByPermissions(c, userID, options)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -14409,7 +14409,7 @@ func (a *OpenTracingAppLayer) RestrictUsersGetByPermissions(userID string, optio
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RestrictUsersSearchByPermissions(userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) RestrictUsersSearchByPermissions(c request.CTX, userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RestrictUsersSearchByPermissions")
|
||||
|
||||
@@ -14421,7 +14421,7 @@ func (a *OpenTracingAppLayer) RestrictUsersSearchByPermissions(userID string, op
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.RestrictUsersSearchByPermissions(userID, options)
|
||||
resultVar0, resultVar1 := a.app.RestrictUsersSearchByPermissions(c, userID, options)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -14446,7 +14446,7 @@ func (a *OpenTracingAppLayer) ReturnSessionToPool(session *model.Session) {
|
||||
a.app.ReturnSessionToPool(session)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeAccessToken(token string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeAccessToken(c *request.Context, token string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeAccessToken")
|
||||
|
||||
@@ -14458,7 +14458,7 @@ func (a *OpenTracingAppLayer) RevokeAccessToken(token string) *model.AppError {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeAccessToken(token)
|
||||
resultVar0 := a.app.RevokeAccessToken(c, token)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -14468,7 +14468,7 @@ func (a *OpenTracingAppLayer) RevokeAccessToken(token string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeAllSessions(userID string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeAllSessions(c *request.Context, userID string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeAllSessions")
|
||||
|
||||
@@ -14480,7 +14480,7 @@ func (a *OpenTracingAppLayer) RevokeAllSessions(userID string) *model.AppError {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeAllSessions(userID)
|
||||
resultVar0 := a.app.RevokeAllSessions(c, userID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -14490,7 +14490,7 @@ func (a *OpenTracingAppLayer) RevokeAllSessions(userID string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeSession(session *model.Session) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeSession(c *request.Context, session *model.Session) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeSession")
|
||||
|
||||
@@ -14502,7 +14502,7 @@ func (a *OpenTracingAppLayer) RevokeSession(session *model.Session) *model.AppEr
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeSession(session)
|
||||
resultVar0 := a.app.RevokeSession(c, session)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -14512,7 +14512,7 @@ func (a *OpenTracingAppLayer) RevokeSession(session *model.Session) *model.AppEr
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeSessionById(sessionID string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeSessionById(c *request.Context, sessionID string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeSessionById")
|
||||
|
||||
@@ -14524,7 +14524,7 @@ func (a *OpenTracingAppLayer) RevokeSessionById(sessionID string) *model.AppErro
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeSessionById(sessionID)
|
||||
resultVar0 := a.app.RevokeSessionById(c, sessionID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -14534,7 +14534,7 @@ func (a *OpenTracingAppLayer) RevokeSessionById(sessionID string) *model.AppErro
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeSessionsForDeviceId(c *request.Context, userID string, deviceID string, currentSessionId string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeSessionsForDeviceId")
|
||||
|
||||
@@ -14546,7 +14546,7 @@ func (a *OpenTracingAppLayer) RevokeSessionsForDeviceId(userID string, deviceID
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeSessionsForDeviceId(userID, deviceID, currentSessionId)
|
||||
resultVar0 := a.app.RevokeSessionsForDeviceId(c, userID, deviceID, currentSessionId)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -14578,7 +14578,7 @@ func (a *OpenTracingAppLayer) RevokeSessionsFromAllUsers() *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) RevokeUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RevokeUserAccessToken")
|
||||
|
||||
@@ -14590,7 +14590,7 @@ func (a *OpenTracingAppLayer) RevokeUserAccessToken(token *model.UserAccessToken
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.RevokeUserAccessToken(token)
|
||||
resultVar0 := a.app.RevokeUserAccessToken(c, token)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -16714,7 +16714,7 @@ func (a *OpenTracingAppLayer) SwitchLdapToEmail(c *request.Context, ldapPassword
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SwitchOAuthToEmail(email string, password string, requesterId string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) SwitchOAuthToEmail(c *request.Context, email string, password string, requesterId string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SwitchOAuthToEmail")
|
||||
|
||||
@@ -16726,7 +16726,7 @@ func (a *OpenTracingAppLayer) SwitchOAuthToEmail(email string, password string,
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.SwitchOAuthToEmail(email, password, requesterId)
|
||||
resultVar0, resultVar1 := a.app.SwitchOAuthToEmail(c, email, password, requesterId)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17094,7 +17094,7 @@ func (a *OpenTracingAppLayer) UnregisterPluginCommand(pluginID string, teamID st
|
||||
a.app.UnregisterPluginCommand(pluginID, teamID, trigger)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateActive(c request.CTX, user *model.User, active bool) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateActive(c *request.Context, user *model.User, active bool) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateActive")
|
||||
|
||||
@@ -17116,7 +17116,7 @@ func (a *OpenTracingAppLayer) UpdateActive(c request.CTX, user *model.User, acti
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateBotActive(c request.CTX, botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateBotActive(c *request.Context, botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateBotActive")
|
||||
|
||||
@@ -17970,7 +17970,7 @@ func (a *OpenTracingAppLayer) UpdateTeam(team *model.Team) (*model.Team, *model.
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateTeamMemberRoles(teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateTeamMemberRoles(c request.CTX, teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateTeamMemberRoles")
|
||||
|
||||
@@ -17982,7 +17982,7 @@ func (a *OpenTracingAppLayer) UpdateTeamMemberRoles(teamID string, userID string
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateTeamMemberRoles(teamID, userID, newRoles)
|
||||
resultVar0, resultVar1 := a.app.UpdateTeamMemberRoles(c, teamID, userID, newRoles)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17992,7 +17992,7 @@ func (a *OpenTracingAppLayer) UpdateTeamMemberRoles(teamID string, userID string
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateTeamMemberSchemeRoles(teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UpdateTeamMemberSchemeRoles(c request.CTX, teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateTeamMemberSchemeRoles")
|
||||
|
||||
@@ -18004,7 +18004,7 @@ func (a *OpenTracingAppLayer) UpdateTeamMemberSchemeRoles(teamID string, userID
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UpdateTeamMemberSchemeRoles(teamID, userID, isSchemeGuest, isSchemeUser, isSchemeAdmin)
|
||||
resultVar0, resultVar1 := a.app.UpdateTeamMemberSchemeRoles(c, teamID, userID, isSchemeGuest, isSchemeUser, isSchemeAdmin)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -18190,7 +18190,7 @@ func (a *OpenTracingAppLayer) UpdateUser(c request.CTX, user *model.User, sendNo
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateUserActive(c request.CTX, userID string, active bool) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserActive")
|
||||
|
||||
@@ -18567,7 +18567,7 @@ func (a *OpenTracingAppLayer) UserAlreadyNotifiedOnRequiredFeature(user string,
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UserCanSeeOtherUser")
|
||||
|
||||
@@ -18579,7 +18579,7 @@ func (a *OpenTracingAppLayer) UserCanSeeOtherUser(userID string, otherUserId str
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.UserCanSeeOtherUser(userID, otherUserId)
|
||||
resultVar0, resultVar1 := a.app.UserCanSeeOtherUser(c, userID, otherUserId)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
||||
@@ -33,12 +33,12 @@ func (s *permissionsServiceWrapper) HasPermissionTo(userID string, permission *m
|
||||
return s.app.HasPermissionTo(userID, permission)
|
||||
}
|
||||
|
||||
func (s *permissionsServiceWrapper) HasPermissionToTeam(userID string, teamID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToTeam(userID, teamID, permission)
|
||||
func (s *permissionsServiceWrapper) HasPermissionToTeam(c *request.Context, userID string, teamID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToTeam(c, userID, teamID, permission)
|
||||
}
|
||||
|
||||
func (s *permissionsServiceWrapper) HasPermissionToChannel(askingUserID string, channelID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToChannel(request.EmptyContext(s.app.Log()), askingUserID, channelID, permission)
|
||||
func (s *permissionsServiceWrapper) HasPermissionToChannel(c *request.Context, askingUserID string, channelID string, permission *model.Permission) bool {
|
||||
return s.app.HasPermissionToChannel(c, askingUserID, channelID, permission)
|
||||
}
|
||||
|
||||
func (s *permissionsServiceWrapper) RolesGrantPermission(roleNames []string, permissionId string) bool {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
)
|
||||
|
||||
type TestHelper struct {
|
||||
Context *request.Context
|
||||
Service *PlatformService
|
||||
Suite SuiteIFace
|
||||
|
||||
@@ -52,7 +54,7 @@ func (ms *mockSuite) GetSession(token string) (*model.Session, *model.AppError)
|
||||
return &model.Session{}, nil
|
||||
}
|
||||
func (ms *mockSuite) RolesGrantPermission(roleNames []string, permissionId string) bool { return true }
|
||||
func (ms *mockSuite) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError) {
|
||||
func (ms *mockSuite) UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -158,6 +160,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
||||
}
|
||||
|
||||
th := &TestHelper{
|
||||
Context: request.TestContext(tb),
|
||||
Service: ps,
|
||||
Suite: &mockSuite{},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package platform
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
@@ -49,6 +49,8 @@ func (ps *PlatformService) License() *model.License {
|
||||
}
|
||||
|
||||
func (ps *PlatformService) LoadLicense() {
|
||||
c := request.EmptyContext(ps.logger)
|
||||
|
||||
// ENV var overrides all other sources of license.
|
||||
licenseStr := os.Getenv(LicenseEnv)
|
||||
if licenseStr != "" {
|
||||
@@ -97,7 +99,7 @@ func (ps *PlatformService) LoadLicense() {
|
||||
}
|
||||
}
|
||||
|
||||
record, nErr := ps.Store.License().Get(sqlstore.WithMaster(context.Background()), licenseId)
|
||||
record, nErr := ps.Store.License().Get(sqlstore.RequestContextWithMaster(c), licenseId)
|
||||
if nErr != nil {
|
||||
ps.logger.Error("License key from https://mattermost.com required to unlock enterprise features.", mlog.Err(nErr))
|
||||
ps.SetLicense(nil)
|
||||
|
||||
@@ -7,6 +7,8 @@ package mocks
|
||||
import (
|
||||
model "github.com/mattermost/mattermost/server/public/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
request "github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
// SuiteIFace is an autogenerated mock type for the SuiteIFace type
|
||||
@@ -56,23 +58,23 @@ func (_m *SuiteIFace) RolesGrantPermission(roleNames []string, permissionId stri
|
||||
return r0
|
||||
}
|
||||
|
||||
// UserCanSeeOtherUser provides a mock function with given fields: userID, otherUserId
|
||||
func (_m *SuiteIFace) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError) {
|
||||
ret := _m.Called(userID, otherUserId)
|
||||
// UserCanSeeOtherUser provides a mock function with given fields: c, userID, otherUserId
|
||||
func (_m *SuiteIFace) UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError) {
|
||||
ret := _m.Called(c, userID, otherUserId)
|
||||
|
||||
var r0 bool
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string, string) (bool, *model.AppError)); ok {
|
||||
return rf(userID, otherUserId)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string) (bool, *model.AppError)); ok {
|
||||
return rf(c, userID, otherUserId)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string) bool); ok {
|
||||
r0 = rf(userID, otherUserId)
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, string) bool); ok {
|
||||
r0 = rf(c, userID, otherUserId)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
r1 = rf(userID, otherUserId)
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, string) *model.AppError); ok {
|
||||
r1 = rf(c, userID, otherUserId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func (ps *PlatformService) ReturnSessionToPool(session *model.Session) {
|
||||
@@ -20,10 +19,10 @@ func (ps *PlatformService) ReturnSessionToPool(session *model.Session) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PlatformService) CreateSession(session *model.Session) (*model.Session, error) {
|
||||
func (ps *PlatformService) CreateSession(c *request.Context, session *model.Session) (*model.Session, error) {
|
||||
session.Token = ""
|
||||
|
||||
session, err := ps.Store.Session().Save(session)
|
||||
session, err := ps.Store.Session().Save(c, session)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -33,12 +32,12 @@ func (ps *PlatformService) CreateSession(session *model.Session) (*model.Session
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) GetSessionContext(ctx context.Context, token string) (*model.Session, error) {
|
||||
return ps.Store.Session().Get(ctx, token)
|
||||
func (ps *PlatformService) GetSessionContext(c *request.Context, token string) (*model.Session, error) {
|
||||
return ps.Store.Session().Get(c, token)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) GetSessions(userID string) ([]*model.Session, error) {
|
||||
return ps.Store.Session().GetSessions(userID)
|
||||
func (ps *PlatformService) GetSessions(c *request.Context, userID string) ([]*model.Session, error) {
|
||||
return ps.Store.Session().GetSessions(c, userID)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) AddSessionToCache(session *model.Session) {
|
||||
@@ -97,7 +96,7 @@ func (ps *PlatformService) ClearAllUsersSessionCache() {
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PlatformService) GetSession(token string) (*model.Session, error) {
|
||||
func (ps *PlatformService) GetSession(c *request.Context, token string) (*model.Session, error) {
|
||||
var session = ps.sessionPool.Get().(*model.Session)
|
||||
if err := ps.sessionCache.Get(token, session); err == nil {
|
||||
if m := ps.metricsIFace; m != nil {
|
||||
@@ -113,11 +112,11 @@ func (ps *PlatformService) GetSession(token string) (*model.Session, error) {
|
||||
return session, nil
|
||||
}
|
||||
|
||||
return ps.GetSessionContext(sqlstore.WithMaster(context.Background()), token)
|
||||
return ps.GetSessionContext(c, token)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) GetSessionByID(sessionID string) (*model.Session, error) {
|
||||
return ps.Store.Session().Get(context.Background(), sessionID)
|
||||
func (ps *PlatformService) GetSessionByID(c *request.Context, sessionID string) (*model.Session, error) {
|
||||
return ps.Store.Session().Get(c, sessionID)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RevokeSessionsFromAllUsers() error {
|
||||
@@ -135,16 +134,16 @@ func (ps *PlatformService) RevokeSessionsFromAllUsers() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) error {
|
||||
sessions, err := ps.Store.Session().GetSessions(userID)
|
||||
func (ps *PlatformService) RevokeSessionsForDeviceId(c *request.Context, userID string, deviceID string, currentSessionId string) error {
|
||||
sessions, err := ps.Store.Session().GetSessions(c, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, session := range sessions {
|
||||
if session.DeviceId == deviceID && session.Id != currentSessionId {
|
||||
mlog.Debug("Revoking sessionId for userId. Re-login with the same device Id", mlog.String("session_id", session.Id), mlog.String("user_id", userID))
|
||||
if err := ps.RevokeSession(session); err != nil {
|
||||
mlog.Warn("Could not revoke session for device", mlog.String("device_id", deviceID), mlog.Err(err))
|
||||
c.Logger().Debug("Revoking sessionId for userId. Re-login with the same device Id", mlog.String("session_id", session.Id), mlog.String("user_id", userID))
|
||||
if err := ps.RevokeSession(c, session); err != nil {
|
||||
c.Logger().Warn("Could not revoke session for device", mlog.String("device_id", deviceID), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,9 +151,9 @@ func (ps *PlatformService) RevokeSessionsForDeviceId(userID string, deviceID str
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RevokeSession(session *model.Session) error {
|
||||
func (ps *PlatformService) RevokeSession(c *request.Context, session *model.Session) error {
|
||||
if session.IsOAuth {
|
||||
if err := ps.RevokeAccessToken(session.Token); err != nil {
|
||||
if err := ps.RevokeAccessToken(c, session.Token); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -168,8 +167,8 @@ func (ps *PlatformService) RevokeSession(session *model.Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RevokeAccessToken(token string) error {
|
||||
session, _ := ps.GetSession(token)
|
||||
func (ps *PlatformService) RevokeAccessToken(c *request.Context, token string) error {
|
||||
session, _ := ps.GetSession(c, token)
|
||||
|
||||
defer ps.ReturnSessionToPool(session)
|
||||
|
||||
@@ -223,8 +222,8 @@ func (ps *PlatformService) ExtendSessionExpiry(session *model.Session, newExpiry
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) UpdateSessionsIsGuest(userID string, isGuest bool) error {
|
||||
sessions, err := ps.GetSessions(userID)
|
||||
func (ps *PlatformService) UpdateSessionsIsGuest(c *request.Context, userID string, isGuest bool) error {
|
||||
sessions, err := ps.GetSessions(c, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -241,14 +240,14 @@ func (ps *PlatformService) UpdateSessionsIsGuest(userID string, isGuest bool) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) RevokeAllSessions(userID string) error {
|
||||
sessions, err := ps.Store.Session().GetSessions(userID)
|
||||
func (ps *PlatformService) RevokeAllSessions(c *request.Context, userID string) error {
|
||||
sessions, err := ps.Store.Session().GetSessions(c, userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", err.Error(), GetSessionError)
|
||||
}
|
||||
for _, session := range sessions {
|
||||
if session.IsOAuth {
|
||||
ps.RevokeAccessToken(session.Token)
|
||||
ps.RevokeAccessToken(c, session.Token)
|
||||
} else {
|
||||
if err := ps.Store.Session().Remove(session.Id); err != nil {
|
||||
return fmt.Errorf("%s: %w", err.Error(), DeleteSessionError)
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
err := th.Service.RevokeAccessToken(model.NewRandomString(16))
|
||||
err := th.Service.RevokeAccessToken(th.Context, model.NewRandomString(16))
|
||||
require.Error(t, err, "Should have failed due to an incorrect token")
|
||||
|
||||
session := &model.Session{}
|
||||
@@ -115,8 +115,8 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
session.Roles = model.SystemUserRoleId
|
||||
th.Service.SetSessionExpireInHours(session, 24)
|
||||
|
||||
session, _ = th.Service.CreateSession(session)
|
||||
err = th.Service.RevokeAccessToken(session.Token)
|
||||
session, _ = th.Service.CreateSession(th.Context, session)
|
||||
err = th.Service.RevokeAccessToken(th.Context, session.Token)
|
||||
require.Error(t, err, "Should have failed does not have an access token")
|
||||
|
||||
accessData := &model.AccessData{}
|
||||
@@ -129,6 +129,6 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
_, nErr := th.Service.Store.OAuth().SaveAccessData(accessData)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
err = th.Service.RevokeAccessToken(accessData.Token)
|
||||
err = th.Service.RevokeAccessToken(th.Context, accessData.Token)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -701,7 +702,11 @@ func (wc *WebConn) ShouldSendEventToGuest(msg *model.WebSocketEvent) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
canSee, err := wc.Suite.UserCanSeeOtherUser(wc.UserId, userID)
|
||||
// In the future, other methods in WebConn will use a request.Context.
|
||||
// For now, it's fine to create it here.
|
||||
c := request.EmptyContext(wc.Platform.logger)
|
||||
|
||||
canSee, err := wc.Suite.UserCanSeeOtherUser(c, wc.UserId, userID)
|
||||
if err != nil {
|
||||
mlog.Error("webhub.shouldSendEvent.", mlog.Err(err))
|
||||
return false
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,7 +24,7 @@ const (
|
||||
type SuiteIFace interface {
|
||||
GetSession(token string) (*model.Session, *model.AppError)
|
||||
RolesGrantPermission(roleNames []string, permissionId string) bool
|
||||
UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError)
|
||||
UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError)
|
||||
}
|
||||
|
||||
type webConnActivityMessage struct {
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestHubStopWithMultipleConnections(t *testing.T) {
|
||||
s := httptest.NewServer(dummyWebsocketHandler(t))
|
||||
defer s.Close()
|
||||
|
||||
session, err := th.Service.CreateSession(&model.Session{
|
||||
session, err := th.Service.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -88,7 +88,7 @@ func TestHubStopRaceCondition(t *testing.T) {
|
||||
// So we just use this quick hack for the test.
|
||||
s := httptest.NewServer(dummyWebsocketHandler(t))
|
||||
|
||||
session, err := th.Service.CreateSession(&model.Session{
|
||||
session, err := th.Service.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -153,8 +153,8 @@ func TestHubSessionRevokeRace(t *testing.T) {
|
||||
|
||||
mockSessionStore := mocks.SessionStore{}
|
||||
mockSessionStore.On("UpdateLastActivityAt", "id1", mock.Anything).Return(nil)
|
||||
mockSessionStore.On("Save", mock.AnythingOfType("*model.Session")).Return(sess1, nil)
|
||||
mockSessionStore.On("Get", mock.Anything, "id1").Return(sess1, nil)
|
||||
mockSessionStore.On("Save", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.Session")).Return(sess1, nil)
|
||||
mockSessionStore.On("Get", mock.AnythingOfType("*request.Context"), mock.Anything, "id1").Return(sess1, nil)
|
||||
mockSessionStore.On("Remove", "id1").Return(nil)
|
||||
|
||||
mockStatusStore := mocks.StatusStore{}
|
||||
@@ -179,7 +179,7 @@ func TestHubSessionRevokeRace(t *testing.T) {
|
||||
s := httptest.NewServer(dummyWebsocketHandler(t))
|
||||
defer s.Close()
|
||||
|
||||
session, err := th.Service.CreateSession(&model.Session{
|
||||
session, err := th.Service.CreateSession(th.Context, &model.Session{
|
||||
UserId: "testid",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -464,7 +464,7 @@ func TestHubIsRegistered(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
session, err := th.Service.CreateSession(&model.Session{
|
||||
session, err := th.Service.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -488,7 +488,7 @@ func TestHubIsRegistered(t *testing.T) {
|
||||
assert.True(t, th.Service.SessionIsRegistered(*wc2.session.Load()))
|
||||
assert.True(t, th.Service.SessionIsRegistered(*wc3.session.Load()))
|
||||
|
||||
session4, err := th.Service.CreateSession(&model.Session{
|
||||
session4, err := th.Service.CreateSession(th.Context, &model.Session{
|
||||
UserId: th.BasicUser2.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -213,7 +213,7 @@ func (api *PluginAPI) GetTeamMembers(teamID string, page, perPage int) ([]*model
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
return api.app.GetTeamMember(teamID, userID)
|
||||
return api.app.GetTeamMember(api.ctx, teamID, userID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetTeamMembersForUser(userID string, page int, perPage int) ([]*model.TeamMember, *model.AppError) {
|
||||
@@ -221,7 +221,7 @@ func (api *PluginAPI) GetTeamMembersForUser(userID string, page int, perPage int
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateTeamMemberRoles(teamID, userID, newRoles string) (*model.TeamMember, *model.AppError) {
|
||||
return api.app.UpdateTeamMemberRoles(teamID, userID, newRoles)
|
||||
return api.app.UpdateTeamMemberRoles(api.ctx, teamID, userID, newRoles)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetTeamStats(teamID string) (*model.TeamStats, *model.AppError) {
|
||||
@@ -283,15 +283,15 @@ func (api *PluginAPI) DeletePreferencesForUser(userID string, preferences []mode
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetSession(sessionID string) (*model.Session, *model.AppError) {
|
||||
return api.app.GetSessionById(sessionID)
|
||||
return api.app.GetSessionById(api.ctx, sessionID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreateSession(session *model.Session) (*model.Session, *model.AppError) {
|
||||
return api.app.CreateSession(session)
|
||||
return api.app.CreateSession(api.ctx, session)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ExtendSessionExpiry(sessionID string, expiresAt int64) *model.AppError {
|
||||
session, err := api.app.ch.srv.platform.GetSessionByID(sessionID)
|
||||
session, err := api.app.ch.srv.platform.GetSessionByID(api.ctx, sessionID)
|
||||
if err != nil {
|
||||
return model.NewAppError("extendSessionExpiry", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (api *PluginAPI) ExtendSessionExpiry(sessionID string, expiresAt int64) *mo
|
||||
}
|
||||
|
||||
func (api *PluginAPI) RevokeSession(sessionID string) *model.AppError {
|
||||
return api.app.RevokeSessionById(sessionID)
|
||||
return api.app.RevokeSessionById(api.ctx, sessionID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
|
||||
@@ -317,7 +317,7 @@ func (api *PluginAPI) RevokeUserAccessToken(tokenID string) *model.AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.app.RevokeUserAccessToken(accessToken)
|
||||
return api.app.RevokeUserAccessToken(api.ctx, accessToken)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
|
||||
@@ -963,7 +963,7 @@ func (api *PluginAPI) HasPermissionTo(userID string, permission *model.Permissio
|
||||
}
|
||||
|
||||
func (api *PluginAPI) HasPermissionToTeam(userID, teamID string, permission *model.Permission) bool {
|
||||
return api.app.HasPermissionToTeam(userID, teamID, permission)
|
||||
return api.app.HasPermissionToTeam(api.ctx, userID, teamID, permission)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool {
|
||||
|
||||
@@ -1834,7 +1834,7 @@ func (*MockSlashCommandProvider) GetCommand(a *App, T i18n.TranslateFunc) *model
|
||||
}
|
||||
}
|
||||
|
||||
func (mscp *MockSlashCommandProvider) DoCommand(a *App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (mscp *MockSlashCommandProvider) DoCommand(a *App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
mscp.Args = args
|
||||
mscp.Message = message
|
||||
return &model.CommandResponse{
|
||||
@@ -2226,14 +2226,14 @@ func TestSendPushNotification(t *testing.T) {
|
||||
var userSessions []userSession
|
||||
for i := 0; i < 3; i++ {
|
||||
u := th.CreateUser()
|
||||
sess, err := th.App.CreateSession(&model.Session{
|
||||
sess, err := th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
// We don't need to track the 2nd session.
|
||||
_, err = th.App.CreateSession(&model.Session{
|
||||
_, err = th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
|
||||
@@ -1473,14 +1473,14 @@ func TestHookNotificationWillBePushed(t *testing.T) {
|
||||
var userSessions []userSession
|
||||
for i := 0; i < 3; i++ {
|
||||
u := th.CreateUser()
|
||||
sess, err := th.App.CreateSession(&model.Session{
|
||||
sess, err := th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
// We don't need to track the 2nd session.
|
||||
_, err = th.App.CreateSession(&model.Session{
|
||||
_, err = th.App.CreateSession(th.Context, &model.Session{
|
||||
UserId: u.Id,
|
||||
DeviceId: "deviceID" + u.Id,
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
|
||||
@@ -2205,9 +2205,9 @@ func (a *App) GetPostInfo(c request.CTX, postID string) (*model.PostInfo, *model
|
||||
}
|
||||
|
||||
if team.Type == model.TeamOpen {
|
||||
hasPermissionToAccessTeam = a.HasPermissionToTeam(userID, team.Id, model.PermissionJoinPublicTeams)
|
||||
hasPermissionToAccessTeam = a.HasPermissionToTeam(c, userID, team.Id, model.PermissionJoinPublicTeams)
|
||||
} else if team.Type == model.TeamInvite {
|
||||
hasPermissionToAccessTeam = a.HasPermissionToTeam(userID, team.Id, model.PermissionJoinPrivateTeams)
|
||||
hasPermissionToAccessTeam = a.HasPermissionToTeam(c, userID, team.Id, model.PermissionJoinPrivateTeams)
|
||||
}
|
||||
} else {
|
||||
// This happens in case of DMs and GMs.
|
||||
@@ -2240,7 +2240,7 @@ func (a *App) GetPostInfo(c request.CTX, postID string) (*model.PostInfo, *model
|
||||
HasJoinedChannel: channelMemberErr == nil,
|
||||
}
|
||||
if team != nil {
|
||||
_, teamMemberErr := a.GetTeamMember(team.Id, userID)
|
||||
_, teamMemberErr := a.GetTeamMember(c, team.Id, userID)
|
||||
|
||||
info.TeamId = team.Id
|
||||
info.TeamType = team.Type
|
||||
|
||||
@@ -2864,11 +2864,11 @@ func TestGetPostIfAuthorized(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, post)
|
||||
|
||||
session1, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
session1, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}})
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, session1)
|
||||
|
||||
session2, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser2.Id, Props: model.StringMap{}})
|
||||
session2, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser2.Id, Props: model.StringMap{}})
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, session2)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"net/http"
|
||||
@@ -12,14 +11,15 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/users"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppError) {
|
||||
session, err := a.ch.srv.platform.CreateSession(session)
|
||||
func (a *App) CreateSession(c *request.Context, session *model.Session) (*model.Session, *model.AppError) {
|
||||
session, err := a.ch.srv.platform.CreateSession(c, session)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
@@ -64,10 +64,14 @@ func (a *App) GetRemoteClusterSession(token string, remoteId string) (*model.Ses
|
||||
}
|
||||
|
||||
func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
// Create a context as GetSession is used in a lot of places where no context is current present.
|
||||
// Once more of the codebase is migrated to use a context, GetSession should accept one.
|
||||
c := request.EmptyContext(a.Log())
|
||||
|
||||
var session *model.Session
|
||||
// We intentionally skip the error check here, we only want to check if the token is valid.
|
||||
// If we don't have the session we are going to create one with the token eventually.
|
||||
if session, _ = a.ch.srv.platform.GetSession(token); session != nil {
|
||||
if session, _ = a.ch.srv.platform.GetSession(c, token); session != nil {
|
||||
if session.Token != token {
|
||||
return nil, model.NewAppError("GetSession", "api.context.invalid_token.error", map[string]any{"Token": token, "Error": ""}, "session token is different from the one in DB", http.StatusUnauthorized)
|
||||
}
|
||||
@@ -79,7 +83,7 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
|
||||
var appErr *model.AppError
|
||||
if session == nil || session.Id == "" {
|
||||
session, appErr = a.createSessionForUserAccessToken(token)
|
||||
session, appErr = a.createSessionForUserAccessToken(c, token)
|
||||
if appErr != nil {
|
||||
detailedError := ""
|
||||
statusCode := http.StatusUnauthorized
|
||||
@@ -87,7 +91,7 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
detailedError = appErr.Error()
|
||||
statusCode = appErr.StatusCode
|
||||
} else {
|
||||
mlog.Warn("Error while creating session for user access token", mlog.Err(appErr))
|
||||
c.Logger().Warn("Error while creating session for user access token", mlog.Err(appErr))
|
||||
}
|
||||
return nil, model.NewAppError("GetSession", "api.context.invalid_token.error", map[string]any{"Token": token, "Error": detailedError}, "", statusCode)
|
||||
}
|
||||
@@ -111,9 +115,9 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
// gets called from (*WebConn).isMemberOfTeam and revoking a session involves
|
||||
// clearing the webconn cache, which needs the hub again.
|
||||
a.Srv().Go(func() {
|
||||
err := a.RevokeSessionById(session.Id)
|
||||
err := a.RevokeSessionById(c, session.Id)
|
||||
if err != nil {
|
||||
mlog.Warn("Error while revoking session", mlog.Err(err))
|
||||
c.Logger().Warn("Error while revoking session", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
return nil, model.NewAppError("GetSession", "api.context.invalid_token.error", map[string]any{"Token": token, "Error": ""}, "idle timeout", http.StatusUnauthorized)
|
||||
@@ -123,8 +127,8 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSessions(userID string) ([]*model.Session, *model.AppError) {
|
||||
sessions, err := a.ch.srv.platform.GetSessions(userID)
|
||||
func (a *App) GetSessions(c *request.Context, userID string) ([]*model.Session, *model.AppError) {
|
||||
sessions, err := a.ch.srv.platform.GetSessions(c, userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetSessions", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -132,8 +136,8 @@ func (a *App) GetSessions(userID string) ([]*model.Session, *model.AppError) {
|
||||
return sessions, nil
|
||||
}
|
||||
|
||||
func (a *App) RevokeAllSessions(userID string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAllSessions(userID); err != nil {
|
||||
func (a *App) RevokeAllSessions(c *request.Context, userID string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAllSessions(c, userID); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, platform.GetSessionError):
|
||||
return model.NewAppError("RevokeAllSessions", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
@@ -186,16 +190,16 @@ func (a *App) ClearSessionCacheForAllUsersSkipClusterSend() {
|
||||
a.Srv().Platform().ClearSessionCacheForAllUsersSkipClusterSend()
|
||||
}
|
||||
|
||||
func (a *App) RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeSessionsForDeviceId(userID, deviceID, currentSessionId); err != nil {
|
||||
func (a *App) RevokeSessionsForDeviceId(c *request.Context, userID string, deviceID string, currentSessionId string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeSessionsForDeviceId(c, userID, deviceID, currentSessionId); err != nil {
|
||||
return model.NewAppError("RevokeSessionsForDeviceId", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSessionById(sessionID string) (*model.Session, *model.AppError) {
|
||||
session, err := a.ch.srv.platform.GetSessionByID(sessionID)
|
||||
func (a *App) GetSessionById(c *request.Context, sessionID string) (*model.Session, *model.AppError) {
|
||||
session, err := a.ch.srv.platform.GetSessionByID(c, sessionID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetSessionById", "app.session.get.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
@@ -203,16 +207,17 @@ func (a *App) GetSessionById(sessionID string) (*model.Session, *model.AppError)
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) RevokeSessionById(sessionID string) *model.AppError {
|
||||
session, err := a.GetSessionById(sessionID)
|
||||
func (a *App) RevokeSessionById(c *request.Context, sessionID string) *model.AppError {
|
||||
session, err := a.GetSessionById(c, sessionID)
|
||||
if err != nil {
|
||||
return model.NewAppError("RevokeSessionById", "app.session.get.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
return a.RevokeSession(session)
|
||||
|
||||
return a.RevokeSession(c, session)
|
||||
}
|
||||
|
||||
func (a *App) RevokeSession(session *model.Session) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeSession(session); err != nil {
|
||||
func (a *App) RevokeSession(c *request.Context, session *model.Session) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeSession(c, session); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, platform.DeleteSessionError):
|
||||
return model.NewAppError("RevokeSession", "app.session.remove.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
@@ -346,7 +351,7 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Session, *model.AppError) {
|
||||
func (a *App) createSessionForUserAccessToken(c *request.Context, tokenString string) (*model.Session, *model.AppError) {
|
||||
token, nErr := a.Srv().Store().UserAccessToken().GetByToken(tokenString)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "", http.StatusUnauthorized).Wrap(nErr)
|
||||
@@ -356,7 +361,7 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio
|
||||
return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "inactive_token", http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
user, nErr := a.Srv().Store().User().Get(context.Background(), token.UserId)
|
||||
user, nErr := a.Srv().Store().User().Get(c.Context(), token.UserId)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -394,7 +399,7 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio
|
||||
}
|
||||
a.ch.srv.platform.SetSessionExpireInHours(session, model.SessionUserAccessTokenExpiryHours)
|
||||
|
||||
session, nErr = a.Srv().Store().Session().Save(session)
|
||||
session, nErr = a.Srv().Store().Session().Save(c, session)
|
||||
if nErr != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
@@ -410,9 +415,9 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *App) RevokeUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
var session *model.Session
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(context.Background(), token.Token)
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(c, token.Token)
|
||||
|
||||
if err := a.Srv().Store().UserAccessToken().Delete(token.Id); err != nil {
|
||||
return model.NewAppError("RevokeUserAccessToken", "app.user_access_token.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
@@ -422,12 +427,12 @@ func (a *App) RevokeUserAccessToken(token *model.UserAccessToken) *model.AppErro
|
||||
return nil
|
||||
}
|
||||
|
||||
return a.RevokeSession(session)
|
||||
return a.RevokeSession(c, session)
|
||||
}
|
||||
|
||||
func (a *App) DisableUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *App) DisableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
var session *model.Session
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(context.Background(), token.Token)
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(c, token.Token)
|
||||
|
||||
if err := a.Srv().Store().UserAccessToken().UpdateTokenDisable(token.Id); err != nil {
|
||||
return model.NewAppError("DisableUserAccessToken", "app.user_access_token.update_token_disable.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
@@ -437,12 +442,12 @@ func (a *App) DisableUserAccessToken(token *model.UserAccessToken) *model.AppErr
|
||||
return nil
|
||||
}
|
||||
|
||||
return a.RevokeSession(session)
|
||||
return a.RevokeSession(c, session)
|
||||
}
|
||||
|
||||
func (a *App) EnableUserAccessToken(token *model.UserAccessToken) *model.AppError {
|
||||
func (a *App) EnableUserAccessToken(c *request.Context, token *model.UserAccessToken) *model.AppError {
|
||||
var session *model.Session
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(context.Background(), token.Token)
|
||||
session, _ = a.ch.srv.platform.GetSessionContext(c, token.Token)
|
||||
|
||||
err := a.Srv().Store().UserAccessToken().UpdateTokenEnable(token.Id)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -23,7 +22,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
||||
UserId: model.NewId(),
|
||||
}
|
||||
|
||||
session, _ = th.App.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(th.Context, session)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("compliance"))
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 5 })
|
||||
@@ -51,7 +50,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
||||
IsOAuth: true,
|
||||
}
|
||||
|
||||
session, _ = th.App.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(th.Context, session)
|
||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||
nErr = th.App.Srv().Store().Session().UpdateLastActivityAt(session.Id, time)
|
||||
require.NoError(t, nErr)
|
||||
@@ -66,7 +65,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
||||
}
|
||||
session.AddProp(model.SessionPropType, model.SessionTypeUserAccessToken)
|
||||
|
||||
session, _ = th.App.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(th.Context, session)
|
||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||
nErr = th.App.Srv().Store().Session().UpdateLastActivityAt(session.Id, time)
|
||||
require.NoError(t, nErr)
|
||||
@@ -84,7 +83,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
||||
UserId: model.NewId(),
|
||||
}
|
||||
|
||||
session, _ = th.App.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(th.Context, session)
|
||||
time = session.LastActivityAt - (1000 * 60 * 6)
|
||||
nErr = th.App.Srv().Store().Session().UpdateLastActivityAt(session.Id, time)
|
||||
require.NoError(t, nErr)
|
||||
@@ -103,7 +102,7 @@ func TestUpdateSessionOnPromoteDemote(t *testing.T) {
|
||||
t.Run("Promote Guest to User updates the session", func(t *testing.T) {
|
||||
guest := th.CreateGuest()
|
||||
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: guest.Id, Props: model.StringMap{model.SessionPropIsGuest: "true"}})
|
||||
session, err := th.App.CreateSession(th.Context, &model.Session{UserId: guest.Id, Props: model.StringMap{model.SessionPropIsGuest: "true"}})
|
||||
require.Nil(t, err)
|
||||
|
||||
rsession, err := th.App.GetSession(session.Token)
|
||||
@@ -127,7 +126,7 @@ func TestUpdateSessionOnPromoteDemote(t *testing.T) {
|
||||
t.Run("Demote User to Guest updates the session", func(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: user.Id, Props: model.StringMap{model.SessionPropIsGuest: "false"}})
|
||||
session, err := th.App.CreateSession(th.Context, &model.Session{UserId: user.Id, Props: model.StringMap{model.SessionPropIsGuest: "false"}})
|
||||
require.Nil(t, err)
|
||||
|
||||
rsession, err := th.App.GetSession(session.Token)
|
||||
@@ -164,7 +163,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
UserId: model.NewId(),
|
||||
DeviceId: model.NewId(),
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -178,7 +177,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
model.UserAuthServiceIsMobile: "true",
|
||||
},
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -193,7 +192,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
model.UserAuthServiceIsSaml: "true",
|
||||
},
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -207,7 +206,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
model.UserAuthServiceIsOAuth: "true",
|
||||
},
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -220,7 +219,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
Props: map[string]string{
|
||||
model.UserAuthServiceIsSaml: "true",
|
||||
}}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -231,7 +230,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) {
|
||||
session := &model.Session{
|
||||
UserId: model.NewId(),
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
sessionLength := th.App.GetSessionLengthInMillis(session)
|
||||
@@ -254,7 +253,7 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) {
|
||||
UserId: model.NewId(),
|
||||
ExpiresAt: expires,
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
ok := th.App.ExtendSessionExpiryIfNeeded(session)
|
||||
@@ -268,7 +267,7 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) {
|
||||
session := &model.Session{
|
||||
UserId: model.NewId(),
|
||||
}
|
||||
session, err := th.App.CreateSession(session)
|
||||
session, err := th.App.CreateSession(th.Context, session)
|
||||
require.Nil(t, err)
|
||||
|
||||
expires := model.GetMillis() + th.App.GetSessionLengthInMillis(session)
|
||||
@@ -298,7 +297,7 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("%s session beyond threshold should update ExpiresAt based on feature enabled", test.name), func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExtendSessionLengthWithActivity = test.enabled })
|
||||
|
||||
session, err := th.App.CreateSession(test.session)
|
||||
session, err := th.App.CreateSession(th.Context, test.session)
|
||||
require.Nil(t, err)
|
||||
|
||||
expires := model.GetMillis() + th.App.GetSessionLengthInMillis(session) - hourMillis
|
||||
@@ -317,12 +316,12 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) {
|
||||
require.False(t, session.IsExpired())
|
||||
|
||||
// check cache was updated
|
||||
cachedSession, errGet := th.App.ch.srv.platform.GetSession(session.Token)
|
||||
cachedSession, errGet := th.App.ch.srv.platform.GetSession(th.Context, session.Token)
|
||||
require.NoError(t, errGet)
|
||||
require.Equal(t, session.ExpiresAt, cachedSession.ExpiresAt)
|
||||
|
||||
// check database was updated.
|
||||
storedSession, nErr := th.App.Srv().Store().Session().Get(context.Background(), session.Token)
|
||||
storedSession, nErr := th.App.Srv().Store().Session().Get(th.Context, session.Token)
|
||||
require.NoError(t, nErr)
|
||||
require.Equal(t, session.ExpiresAt, storedSession.ExpiresAt)
|
||||
})
|
||||
|
||||
@@ -122,7 +122,7 @@ func (cfg *AutoUserCreator) createRandomUser(c request.CTX) (*model.User, error)
|
||||
}
|
||||
|
||||
if cfg.JoinTime != 0 {
|
||||
teamMember, appErr := cfg.app.GetTeamMember(cfg.team.Id, ruser.Id)
|
||||
teamMember, appErr := cfg.app.GetTeamMember(c, cfg.team.Id, ruser.Id)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (*AwayProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*AwayProvider) DoCommand(a *app.App, _ request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*AwayProvider) DoCommand(a *app.App, _ *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
a.SetStatusAwayIfNeeded(args.UserId, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_away.success")}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*HeaderProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (*HeaderProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*PurposeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comm
|
||||
}
|
||||
}
|
||||
|
||||
func (*PurposeProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*PurposeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
|
||||
@@ -38,7 +38,7 @@ func (*RenameProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (*RenameProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*RenameProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
|
||||
@@ -37,7 +37,7 @@ func (*CodeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*CodeProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*CodeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if message == "" {
|
||||
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (*CustomStatusProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model
|
||||
}
|
||||
}
|
||||
|
||||
func (*CustomStatusProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !*a.Config().TeamSettings.EnableCustomUserStatuses {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (*DndProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*DndProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*DndProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
a.SetStatusDoNotDisturb(args.UserId)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_dnd.success")}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (*EchoProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*EchoProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*EchoProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if message == "" {
|
||||
return &model.CommandResponse{Text: args.T("api.command_echo.message.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ func (*CollapseProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
|
||||
}
|
||||
}
|
||||
|
||||
func (*ExpandProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*ExpandProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return setCollapsePreference(a, args, false)
|
||||
}
|
||||
|
||||
func (*CollapseProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*CollapseProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return setCollapsePreference(a, args, true)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func (*ExportLinkProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.C
|
||||
}
|
||||
}
|
||||
|
||||
func (*ExportLinkProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*ExportLinkProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.SessionHasPermissionTo(*c.Session(), model.PermissionManageSystem) {
|
||||
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_exportlink.permission.app_error")}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (*groupmsgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
|
||||
}
|
||||
}
|
||||
|
||||
func (*groupmsgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*groupmsgProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
targetUsers := map[string]*model.User{}
|
||||
targetUsersSlice := []string{args.UserId}
|
||||
invalidUsernames := []string{}
|
||||
@@ -55,7 +55,7 @@ func (*groupmsgProvider) DoCommand(a *app.App, c request.CTX, args *model.Comman
|
||||
continue
|
||||
}
|
||||
|
||||
canSee, err := a.UserCanSeeOtherUser(args.UserId, targetUser.Id)
|
||||
canSee, err := a.UserCanSeeOtherUser(c, args.UserId, targetUser.Id)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_groupmsg.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (h *HelpProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HelpProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (h *HelpProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
helpLink := *a.Config().SupportSettings.HelpLink
|
||||
|
||||
if helpLink == "" {
|
||||
|
||||
@@ -48,14 +48,14 @@ func (*InviteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InviteProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (i *InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return &model.CommandResponse{
|
||||
Text: i.doCommand(a, c, args, message),
|
||||
ResponseType: model.CommandResponseTypeEphemeral,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InviteProvider) doCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) string {
|
||||
func (i *InviteProvider) doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) string {
|
||||
if message == "" {
|
||||
return args.T("api.command_invite.missing_message.app_error")
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ func (*InvitePeopleProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model
|
||||
}
|
||||
}
|
||||
|
||||
func (*InvitePeopleProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.HasPermissionToTeam(args.UserId, args.TeamId, model.PermissionInviteUser) {
|
||||
func (*InvitePeopleProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.HasPermissionToTeam(c, args.UserId, args.TeamId, model.PermissionInviteUser) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
if !a.HasPermissionToTeam(args.UserId, args.TeamId, model.PermissionAddUserToTeam) {
|
||||
if !a.HasPermissionToTeam(c, args.UserId, args.TeamId, model.PermissionAddUserToTeam) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (*JoinProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*JoinProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*JoinProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channelName := strings.ToLower(message)
|
||||
|
||||
if strings.HasPrefix(message, "~") {
|
||||
|
||||
@@ -34,7 +34,7 @@ func (*LeaveProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comman
|
||||
}
|
||||
}
|
||||
|
||||
func (*LeaveProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*LeaveProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var channel *model.Channel
|
||||
var noChannelErr *model.AppError
|
||||
if channel, noChannelErr = a.GetChannel(c, args.ChannelId); noChannelErr != nil {
|
||||
@@ -54,7 +54,7 @@ func (*LeaveProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandAr
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
member, err := a.GetTeamMember(team.Id, args.UserId)
|
||||
member, err := a.GetTeamMember(c, team.Id, args.UserId)
|
||||
if err != nil || member.DeleteAt != 0 {
|
||||
return &model.CommandResponse{GotoLocation: args.SiteURL + "/"}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (*LoadTestProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
|
||||
}
|
||||
}
|
||||
|
||||
func (lt *LoadTestProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (lt *LoadTestProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
commandResponse, err := lt.doCommand(a, c, args, message)
|
||||
if err != nil {
|
||||
c.Logger().Error("failed command /"+CmdTest, mlog.Err(err))
|
||||
@@ -148,7 +148,7 @@ func (lt *LoadTestProvider) DoCommand(a *app.App, c request.CTX, args *model.Com
|
||||
return commandResponse
|
||||
}
|
||||
|
||||
func (lt *LoadTestProvider) doCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
func (lt *LoadTestProvider) doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
//This command is only available when EnableTesting is true
|
||||
if !*a.Config().ServiceSettings.EnableTesting {
|
||||
return &model.CommandResponse{}, nil
|
||||
@@ -291,7 +291,7 @@ func (*LoadTestProvider) SetupCommand(a *app.App, c request.CTX, args *model.Com
|
||||
return &model.CommandResponse{Text: "Created environment", ResponseType: model.CommandResponseTypeEphemeral}, nil
|
||||
}
|
||||
|
||||
func (*LoadTestProvider) ActivateUserCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
func (*LoadTestProvider) ActivateUserCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
user_id := strings.TrimSpace(strings.TrimPrefix(message, "activate_user"))
|
||||
if err := a.UpdateUserActive(c, user_id, true); err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to activate user", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
@@ -300,7 +300,7 @@ func (*LoadTestProvider) ActivateUserCommand(a *app.App, c request.CTX, args *mo
|
||||
return &model.CommandResponse{Text: "Activated user", ResponseType: model.CommandResponseTypeEphemeral}, nil
|
||||
}
|
||||
|
||||
func (*LoadTestProvider) DeActivateUserCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
func (*LoadTestProvider) DeActivateUserCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
|
||||
user_id := strings.TrimSpace(strings.TrimPrefix(message, "deactivate_user"))
|
||||
if err := a.UpdateUserActive(c, user_id, false); err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to deactivate user", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*LogoutProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (*LogoutProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*LogoutProvider) DoCommand(a *app.App, _ *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
// Actual logout is handled client side.
|
||||
return &model.CommandResponse{GotoLocation: "/login"}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (h *MarketplaceProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *mode
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MarketplaceProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (h *MarketplaceProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
// This command is handled client-side and shouldn't hit the server.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_marketplace.unsupported.app_error"),
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*MeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
}
|
||||
|
||||
func (*MeProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*MeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.CommandResponseTypeInChannel,
|
||||
Type: model.PostTypeMe,
|
||||
|
||||
@@ -40,7 +40,7 @@ func (*msgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*msgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*msgProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
splitMessage := strings.SplitN(message, " ", 2)
|
||||
|
||||
parsedMessage := ""
|
||||
@@ -62,7 +62,7 @@ func (*msgProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
|
||||
canSee, err := a.UserCanSeeOtherUser(args.UserId, userProfile.Id)
|
||||
canSee, err := a.UserCanSeeOtherUser(c, args.UserId, userProfile.Id)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (*MuteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*MuteProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*MuteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var channel *model.Channel
|
||||
var noChannelErr *model.AppError
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (*OfflineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comm
|
||||
}
|
||||
}
|
||||
|
||||
func (*OfflineProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*OfflineProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
a.SetStatusOffline(args.UserId, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_offline.success")}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (*OnlineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
|
||||
}
|
||||
}
|
||||
|
||||
func (*OnlineProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*OnlineProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
a.SetStatusOnline(args.UserId, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_online.success")}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (rp *RemoteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Co
|
||||
}
|
||||
}
|
||||
|
||||
func (rp *RemoteProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (rp *RemoteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.HasPermissionTo(args.UserId, model.PermissionManageSecureConnections) {
|
||||
return responsef(args.T("api.command_remote.permission_required", map[string]any{"Permission": "manage_secure_connections"}))
|
||||
}
|
||||
|
||||
@@ -57,15 +57,15 @@ func (*KickProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
|
||||
}
|
||||
}
|
||||
|
||||
func (*RemoveProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*RemoveProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return doCommand(a, c, args, message)
|
||||
}
|
||||
|
||||
func (*KickProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*KickProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return doCommand(a, c, args, message)
|
||||
}
|
||||
|
||||
func doCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := a.GetChannel(c, args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{
|
||||
|
||||
@@ -35,7 +35,7 @@ func (search *SearchProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *mode
|
||||
}
|
||||
}
|
||||
|
||||
func (search *SearchProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (search *SearchProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
// This command is handled client-side and shouldn't hit the server.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_search.unsupported.app_error"),
|
||||
|
||||
@@ -35,7 +35,7 @@ func (settings *SettingsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *
|
||||
}
|
||||
}
|
||||
|
||||
func (settings *SettingsProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (settings *SettingsProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
// This command is handled client-side and shouldn't hit the server.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_settings.unsupported.app_error"),
|
||||
|
||||
@@ -119,7 +119,7 @@ func (sp *ShareProvider) getAutoCompleteUnInviteRemote(a *app.App, _ *model.Comm
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *ShareProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (sp *ShareProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.HasPermissionTo(args.UserId, model.PermissionManageSharedChannels) {
|
||||
return responsef(args.T("api.command_share.permission_required", map[string]any{"Permission": "manage_shared_channels"}))
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*ShortcutsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Co
|
||||
}
|
||||
}
|
||||
|
||||
func (*ShortcutsProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*ShortcutsProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
// This command is handled client-side and shouldn't hit the server.
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_shortcuts.unsupported.app_error"),
|
||||
|
||||
@@ -35,7 +35,7 @@ func (*ShrugProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comman
|
||||
}
|
||||
}
|
||||
|
||||
func (*ShrugProvider) DoCommand(a *app.App, c request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
func (*ShrugProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
rmsg := `¯\\\_(ツ)\_/¯`
|
||||
if message != "" {
|
||||
rmsg = message + " " + rmsg
|
||||
|
||||
@@ -33,7 +33,7 @@ func (a *App) createDefaultChannelMemberships(c request.CTX, params model.Create
|
||||
return err
|
||||
}
|
||||
|
||||
tmem, err := a.GetTeamMember(channel.TeamId, userChannel.UserID)
|
||||
tmem, err := a.GetTeamMember(c, channel.TeamId, userChannel.UserID)
|
||||
if err != nil && err.Id != "app.team.get_member.missing.app_error" {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Singer should be in team and channel
|
||||
_, err = th.App.GetTeamMember(singersTeam.Id, singer1.Id)
|
||||
_, err = th.App.GetTeamMember(th.Context, singersTeam.Id, singer1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Scientist should not be in team or channel
|
||||
_, err = th.App.GetTeamMember(nerdsTeam.Id, scientist1.Id)
|
||||
_, err = th.App.GetTeamMember(th.Context, nerdsTeam.Id, scientist1.Id)
|
||||
if err.Id != "app.team.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Scientist should be in team but not the channel
|
||||
_, err = th.App.GetTeamMember(nerdsTeam.Id, scientist1.Id)
|
||||
_, err = th.App.GetTeamMember(th.Context, nerdsTeam.Id, scientist1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
// Singer should not be in team or channel
|
||||
tMember, err := th.App.GetTeamMember(singersTeam.Id, singer1.Id)
|
||||
tMember, err := th.App.GetTeamMember(th.Context, singersTeam.Id, singer1.Id)
|
||||
if err != nil {
|
||||
t.Errorf("error retrieving team member: %s", err.Error())
|
||||
}
|
||||
@@ -608,7 +608,7 @@ func TestSyncSyncableRoles(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
for _, user := range []*model.User{user1, user2} {
|
||||
tm, err := th.App.GetTeamMember(team.Id, user.Id)
|
||||
tm, err := th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, tm.SchemeAdmin)
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ type teamServiceWrapper struct {
|
||||
app AppIface
|
||||
}
|
||||
|
||||
func (w *teamServiceWrapper) GetMember(teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
return w.app.GetTeamMember(teamID, userID)
|
||||
func (w *teamServiceWrapper) GetMember(c request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
return w.app.GetTeamMember(c, teamID, userID)
|
||||
}
|
||||
|
||||
func (w *teamServiceWrapper) CreateMember(ctx *request.Context, teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
@@ -420,8 +420,8 @@ func (a *App) GetSchemeRolesForTeam(teamID string) (string, string, string, *mod
|
||||
return model.TeamGuestRoleId, model.TeamUserRoleId, model.TeamAdminRoleId, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateTeamMemberRoles(teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError) {
|
||||
member, nErr := a.Srv().Store().Team().GetMember(context.Background(), teamID, userID)
|
||||
func (a *App) UpdateTeamMemberRoles(c request.CTX, teamID string, userID string, newRoles string) (*model.TeamMember, *model.AppError) {
|
||||
member, nErr := a.Srv().Store().Team().GetMember(c, teamID, userID)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -504,8 +504,8 @@ func (a *App) UpdateTeamMemberRoles(teamID string, userID string, newRoles strin
|
||||
return member, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateTeamMemberSchemeRoles(teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError) {
|
||||
member, err := a.GetTeamMember(teamID, userID)
|
||||
func (a *App) UpdateTeamMemberSchemeRoles(c request.CTX, teamID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError) {
|
||||
member, err := a.GetTeamMember(c, teamID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -759,7 +759,7 @@ func (a *App) AddUserToTeamByInviteId(c *request.Context, inviteId string, userI
|
||||
}
|
||||
|
||||
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)
|
||||
teamMember, alreadyAdded, err := a.ch.srv.teamService.JoinUserToTeam(c, team, user)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
var conflictErr *store.ErrConflict
|
||||
@@ -793,7 +793,7 @@ func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User,
|
||||
TeamID: team.Id,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
if _, err := a.createInitialSidebarCategories(user.Id, opts); err != nil {
|
||||
if _, err := a.createInitialSidebarCategories(c, user.Id, opts); err != nil {
|
||||
mlog.Warn(
|
||||
"Encountered an issue creating default sidebar categories.",
|
||||
mlog.String("user_id", user.Id),
|
||||
@@ -993,8 +993,8 @@ func (a *App) GetTeamsForUser(userID string) ([]*model.Team, *model.AppError) {
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
teamMember, err := a.Srv().Store().Team().GetMember(sqlstore.WithMaster(context.Background()), teamID, userID)
|
||||
func (a *App) GetTeamMember(c request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
teamMember, err := a.Srv().Store().Team().GetMember(sqlstore.RequestContextWithMaster(c), teamID, userID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -1008,8 +1008,8 @@ func (a *App) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.Ap
|
||||
return teamMember, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTeamMembersForUser(userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError) {
|
||||
teamMembers, err := a.Srv().Store().Team().GetTeamsForUser(context.Background(), userID, excludeTeamID, includeDeleted)
|
||||
func (a *App) GetTeamMembersForUser(c request.CTX, userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError) {
|
||||
teamMembers, err := a.Srv().Store().Team().GetTeamsForUser(c, userID, excludeTeamID, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetTeamMembersForUser", "app.team.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -1237,7 +1237,7 @@ func (a *App) postProcessTeamMemberLeave(c request.CTX, teamMember *model.TeamMe
|
||||
}
|
||||
|
||||
func (a *App) LeaveTeam(c request.CTX, team *model.Team, user *model.User, requestorId string) *model.AppError {
|
||||
teamMember, err := a.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, err := a.GetTeamMember(c, team.Id, user.Id)
|
||||
if err != nil {
|
||||
return model.NewAppError("LeaveTeam", "api.team.remove_user_from_team.missing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -1027,7 +1027,7 @@ func TestLeaveTeamPanic(t *testing.T) {
|
||||
mockLicenseStore.On("Get", "").Return(&model.LicenseRecord{}, nil)
|
||||
|
||||
mockTeamStore := mocks.TeamStore{}
|
||||
mockTeamStore.On("GetMember", sqlstore.WithMaster(context.Background()), "myteam", "userID").Return(&model.TeamMember{TeamId: "myteam", UserId: "userID"}, nil)
|
||||
mockTeamStore.On("GetMember", sqlstore.RequestContextWithMaster(th.Context), "myteam", "userID").Return(&model.TeamMember{TeamId: "myteam", UserId: "userID"}, nil)
|
||||
mockTeamStore.On("UpdateMember", mock.Anything).Return(nil, errors.New("repro error")) // This is the line that triggers the error
|
||||
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
@@ -1297,7 +1297,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, ruser.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, "team_user")
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.Context, th.BasicTeam.Id, ruser.Id, "team_user")
|
||||
require.NotNil(t, err, "Should fail when try to modify the guest role")
|
||||
})
|
||||
|
||||
@@ -1308,7 +1308,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, ruser.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, "team_guest")
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.Context, th.BasicTeam.Id, ruser.Id, "team_guest")
|
||||
require.NotNil(t, err, "Should fail when try to modify the guest role")
|
||||
})
|
||||
|
||||
@@ -1319,7 +1319,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, ruser.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, "team_user team_admin")
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.Context, th.BasicTeam.Id, ruser.Id, "team_user team_admin")
|
||||
require.Nil(t, err, "Should work when you not modify guest role")
|
||||
})
|
||||
|
||||
@@ -1333,7 +1333,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
_, err = th.App.CreateRole(&model.Role{Name: "custom", DisplayName: "custom", Description: "custom"})
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, "team_guest custom")
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.Context, th.BasicTeam.Id, ruser.Id, "team_guest custom")
|
||||
require.Nil(t, err, "Should work when you not modify guest role")
|
||||
})
|
||||
|
||||
@@ -1344,7 +1344,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
_, _, err := th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, ruser.Id, "")
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, "team_guest team_user")
|
||||
_, err = th.App.UpdateTeamMemberRoles(th.Context, th.BasicTeam.Id, ruser.Id, "team_guest team_user")
|
||||
require.NotNil(t, err, "Should work when you not modify guest role")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
package teams
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func (ts *TeamService) CreateTeam(team *model.Team) (*model.Team, error) {
|
||||
@@ -130,7 +129,7 @@ func (ts *TeamService) PatchTeam(teamID string, patch *model.TeamPatch) (*model.
|
||||
// 1. a pointer to the team member, if successful
|
||||
// 2. a boolean: true if the user has a non-deleted team member for that team already, otherwise false.
|
||||
// 3. a pointer to an AppError if something went wrong.
|
||||
func (ts *TeamService) JoinUserToTeam(team *model.Team, user *model.User) (*model.TeamMember, bool, error) {
|
||||
func (ts *TeamService) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User) (*model.TeamMember, bool, error) {
|
||||
if !ts.IsTeamEmailAllowed(user, team) {
|
||||
return nil, false, AcceptedDomainError
|
||||
}
|
||||
@@ -155,7 +154,7 @@ func (ts *TeamService) JoinUserToTeam(team *model.Team, user *model.User) (*mode
|
||||
tm.SchemeAdmin = true
|
||||
}
|
||||
|
||||
rtm, err := ts.store.GetMember(context.Background(), team.Id, user.Id)
|
||||
rtm, err := ts.store.GetMember(c, team.Id, user.Id)
|
||||
if err != nil {
|
||||
// Membership appears to be missing. Lets try to add.
|
||||
tmr, nErr := ts.store.SaveMember(tm, *ts.config().TeamSettings.MaxUsersPerTeam)
|
||||
@@ -221,8 +220,8 @@ func (ts *TeamService) RemoveTeamMember(teamMember *model.TeamMember) error {
|
||||
}
|
||||
|
||||
// GetMember return the team member from the team.
|
||||
func (ts *TeamService) GetMember(teamID string, userID string) (*model.TeamMember, error) {
|
||||
member, err := ts.store.GetMember(context.Background(), teamID, userID)
|
||||
func (ts *TeamService) GetMember(c request.CTX, teamID string, userID string) (*model.TeamMember, error) {
|
||||
member, err := ts.store.GetMember(c, teamID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
ruser := th.CreateUser(&user)
|
||||
defer th.DeleteUser(&user)
|
||||
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(team, ruser)
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(th.Context, team, ruser)
|
||||
require.False(t, alreadyAdded, "Should return already added equal to false")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -69,10 +69,10 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
ruser := th.CreateUser(&user)
|
||||
defer th.DeleteUser(&user)
|
||||
|
||||
_, _, err := th.service.JoinUserToTeam(team, ruser)
|
||||
_, _, err := th.service.JoinUserToTeam(th.Context, team, ruser)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(team, ruser)
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(th.Context, team, ruser)
|
||||
require.True(t, alreadyAdded, "Should return already added")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -82,12 +82,12 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
ruser := th.CreateUser(&user)
|
||||
defer th.DeleteUser(&user)
|
||||
|
||||
member, _, err := th.service.JoinUserToTeam(team, ruser)
|
||||
member, _, err := th.service.JoinUserToTeam(th.Context, team, ruser)
|
||||
require.NoError(t, err)
|
||||
err = th.service.RemoveTeamMember(member)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(team, ruser)
|
||||
_, alreadyAdded, err := th.service.JoinUserToTeam(th.Context, team, ruser)
|
||||
require.False(t, alreadyAdded, "Should return already added equal to false")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -101,10 +101,10 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
defer th.DeleteUser(&user1)
|
||||
defer th.DeleteUser(&user2)
|
||||
|
||||
_, _, err := th.service.JoinUserToTeam(team, ruser1)
|
||||
_, _, err := th.service.JoinUserToTeam(th.Context, team, ruser1)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.service.JoinUserToTeam(team, ruser2)
|
||||
_, _, err = th.service.JoinUserToTeam(th.Context, team, ruser2)
|
||||
require.Error(t, err, "Should fail")
|
||||
})
|
||||
|
||||
@@ -118,14 +118,14 @@ func TestJoinUserToTeam(t *testing.T) {
|
||||
defer th.DeleteUser(&user1)
|
||||
defer th.DeleteUser(&user2)
|
||||
|
||||
member, _, err := th.service.JoinUserToTeam(team, ruser1)
|
||||
member, _, err := th.service.JoinUserToTeam(th.Context, team, ruser1)
|
||||
require.NoError(t, err)
|
||||
err = th.service.RemoveTeamMember(member)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.service.JoinUserToTeam(team, ruser2)
|
||||
_, _, err = th.service.JoinUserToTeam(th.Context, team, ruser2)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.service.JoinUserToTeam(team, ruser1)
|
||||
_, _, err = th.service.JoinUserToTeam(th.Context, team, ruser1)
|
||||
require.Error(t, err, "Should fail")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (a *App) CreateUploadSession(c request.CTX, us *model.UploadSession) (*mode
|
||||
}
|
||||
|
||||
func (a *App) GetUploadSession(c request.CTX, uploadId string) (*model.UploadSession, *model.AppError) {
|
||||
us, err := a.Srv().Store().UploadSession().Get(c.Context(), uploadId)
|
||||
us, err := a.Srv().Store().UploadSession().Get(c, uploadId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
|
||||
@@ -917,7 +917,7 @@ func (a *App) UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPa
|
||||
return a.UpdatePasswordSendEmail(c, user, newPassword, T("api.user.update_password.menu"))
|
||||
}
|
||||
|
||||
func (a *App) userDeactivated(c request.CTX, userID string) *model.AppError {
|
||||
func (a *App) userDeactivated(c *request.Context, userID string) *model.AppError {
|
||||
a.SetStatusOffline(userID, false)
|
||||
|
||||
user, err := a.GetUser(userID)
|
||||
@@ -966,7 +966,7 @@ func (a *App) invalidateUserChannelMembersCaches(c request.CTX, userID string) *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model.User, *model.AppError) {
|
||||
func (a *App) UpdateActive(c *request.Context, user *model.User, active bool) (*model.User, *model.AppError) {
|
||||
user.UpdateAt = model.GetMillis()
|
||||
if active {
|
||||
user.DeleteAt = 0
|
||||
@@ -990,7 +990,7 @@ func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model
|
||||
ruser := userUpdate.New
|
||||
|
||||
if !active {
|
||||
if err := a.RevokeAllSessions(ruser.Id); err != nil {
|
||||
if err := a.RevokeAllSessions(c, ruser.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := a.userDeactivated(c, ruser.Id); err != nil {
|
||||
@@ -1023,7 +1023,7 @@ func (a *App) DeactivateGuests(c *request.Context) *model.AppError {
|
||||
}
|
||||
|
||||
for _, userID := range userIDs {
|
||||
if err := a.Srv().Platform().RevokeAllSessions(userID); err != nil {
|
||||
if err := a.Srv().Platform().RevokeAllSessions(c, userID); err != nil {
|
||||
return model.NewAppError("DeactivateGuests", "app.user.update_active_for_multiple_users.updating.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
@@ -1300,7 +1300,7 @@ func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool
|
||||
return newUser, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateUserActive(c request.CTX, userID string, active bool) *model.AppError {
|
||||
func (a *App) UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError {
|
||||
user, err := a.GetUser(userID)
|
||||
|
||||
if err != nil {
|
||||
@@ -2155,8 +2155,8 @@ func (a *App) UpdateOAuthUserAttrs(c *request.Context, userData io.Reader, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) RestrictUsersGetByPermissions(userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError) {
|
||||
restrictions, err := a.GetViewUsersRestrictions(userID)
|
||||
func (a *App) RestrictUsersGetByPermissions(c request.CTX, userID string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError) {
|
||||
restrictions, err := a.GetViewUsersRestrictions(c, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2211,8 +2211,8 @@ func (a *App) filterNonGroupUsers(userIDs []string, groupUsers []*model.User) ([
|
||||
return nonMemberIds, nil
|
||||
}
|
||||
|
||||
func (a *App) RestrictUsersSearchByPermissions(userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError) {
|
||||
restrictions, err := a.GetViewUsersRestrictions(userID)
|
||||
func (a *App) RestrictUsersSearchByPermissions(c request.CTX, userID string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError) {
|
||||
restrictions, err := a.GetViewUsersRestrictions(c, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2221,12 +2221,12 @@ func (a *App) RestrictUsersSearchByPermissions(userID string, options *model.Use
|
||||
return options, nil
|
||||
}
|
||||
|
||||
func (a *App) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError) {
|
||||
func (a *App) UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError) {
|
||||
if userID == otherUserId {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
restrictions, err := a.GetViewUsersRestrictions(userID)
|
||||
restrictions, err := a.GetViewUsersRestrictions(c, userID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -2267,7 +2267,7 @@ func (a *App) userBelongsToChannels(userID string, channelIDs []string) (bool, *
|
||||
return belongs, nil
|
||||
}
|
||||
|
||||
func (a *App) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestrictions, *model.AppError) {
|
||||
func (a *App) GetViewUsersRestrictions(c request.CTX, userID string) (*model.ViewUsersRestrictions, *model.AppError) {
|
||||
if a.HasPermissionTo(userID, model.PermissionViewMembers) {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -2279,7 +2279,7 @@ func (a *App) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestricti
|
||||
|
||||
teamIDsWithPermission := []string{}
|
||||
for _, teamID := range teamIDs {
|
||||
if a.HasPermissionToTeam(userID, teamID, model.PermissionViewMembers) {
|
||||
if a.HasPermissionToTeam(c, userID, teamID, model.PermissionViewMembers) {
|
||||
teamIDsWithPermission = append(teamIDsWithPermission, teamID)
|
||||
}
|
||||
}
|
||||
@@ -2322,12 +2322,12 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
c.Logger().Warn("Failed to get user on promote guest to user", mlog.Err(err))
|
||||
} else {
|
||||
a.sendUpdatedUserEvent(*promotedUser)
|
||||
if uErr := a.ch.srv.platform.UpdateSessionsIsGuest(promotedUser.Id, promotedUser.IsGuest()); uErr != nil {
|
||||
if uErr := a.ch.srv.platform.UpdateSessionsIsGuest(c, promotedUser.Id, promotedUser.IsGuest()); uErr != nil {
|
||||
c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", promotedUser.Id), mlog.Err(uErr))
|
||||
}
|
||||
}
|
||||
|
||||
teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true)
|
||||
teamMembers, err := a.GetTeamMembersForUser(c, user.Id, "", true)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get team members for user on promote guest to user", mlog.Err(err))
|
||||
}
|
||||
@@ -2359,7 +2359,7 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
|
||||
// DemoteUserToGuest Convert user's roles and all his membership's roles from
|
||||
// regular user roles to guest roles.
|
||||
func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError {
|
||||
func (a *App) DemoteUserToGuest(c *request.Context, user *model.User) *model.AppError {
|
||||
demotedUser, nErr := a.ch.srv.userService.DemoteUserToGuest(user)
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
if nErr != nil {
|
||||
@@ -2367,11 +2367,11 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
}
|
||||
|
||||
a.sendUpdatedUserEvent(*demotedUser)
|
||||
if uErr := a.ch.srv.platform.UpdateSessionsIsGuest(demotedUser.Id, demotedUser.IsGuest()); uErr != nil {
|
||||
if uErr := a.ch.srv.platform.UpdateSessionsIsGuest(c, demotedUser.Id, demotedUser.IsGuest()); uErr != nil {
|
||||
c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", demotedUser.Id), mlog.Err(uErr))
|
||||
}
|
||||
|
||||
teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true)
|
||||
teamMembers, err := a.GetTeamMembersForUser(c, user.Id, "", true)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get team members for users on demote user to guest", mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -1223,7 +1223,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
th.LinkUserToTeam(user1, team1)
|
||||
th.LinkUserToTeam(user1, team2)
|
||||
|
||||
th.App.UpdateTeamMemberRoles(team1.Id, user1.Id, "team_user team_admin")
|
||||
th.App.UpdateTeamMemberRoles(th.Context, team1.Id, user1.Id, "team_user team_admin")
|
||||
|
||||
team1channel1 := th.CreateChannel(th.Context, team1)
|
||||
team1channel2 := th.CreateChannel(th.Context, team1)
|
||||
@@ -1262,7 +1262,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("VIEW_MEMBERS permission granted at system level", func(t *testing.T) {
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(user1.Id)
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(th.Context, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Nil(t, restrictions)
|
||||
@@ -1279,7 +1279,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
require.Nil(t, addPermission(teamUserRole, model.PermissionViewMembers.Id))
|
||||
defer removePermission(teamUserRole, model.PermissionViewMembers.Id)
|
||||
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(user1.Id)
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(th.Context, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.NotNil(t, restrictions)
|
||||
@@ -1295,7 +1295,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
require.Nil(t, removePermission(systemUserRole, model.PermissionViewMembers.Id))
|
||||
defer addPermission(systemUserRole, model.PermissionViewMembers.Id)
|
||||
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(user1.Id)
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(th.Context, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.NotNil(t, restrictions)
|
||||
@@ -1315,7 +1315,7 @@ func TestGetViewUsersRestrictions(t *testing.T) {
|
||||
require.Nil(t, addPermission(teamAdminRole, model.PermissionViewMembers.Id))
|
||||
defer removePermission(teamAdminRole, model.PermissionViewMembers.Id)
|
||||
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(user1.Id)
|
||||
restrictions, err := th.App.GetViewUsersRestrictions(th.Context, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.NotNil(t, restrictions)
|
||||
@@ -1355,7 +1355,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest := th.CreateGuest()
|
||||
require.Equal(t, "system_guest", guest.Roles)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeGuest)
|
||||
require.False(t, teamMember.SchemeUser)
|
||||
@@ -1365,7 +1365,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest, err = th.App.GetUser(guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_user", guest.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
@@ -1375,7 +1375,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest := th.CreateGuest()
|
||||
require.Equal(t, "system_guest", guest.Roles)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeGuest)
|
||||
require.False(t, teamMember.SchemeUser)
|
||||
@@ -1389,7 +1389,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest, err = th.App.GetUser(guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_user", guest.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
@@ -1403,7 +1403,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest := th.CreateGuest()
|
||||
require.Equal(t, "system_guest", guest.Roles)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeGuest)
|
||||
require.False(t, teamMember.SchemeUser)
|
||||
@@ -1421,7 +1421,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest, err = th.App.GetUser(guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_user", guest.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeGuest)
|
||||
assert.True(t, teamMember.SchemeUser)
|
||||
@@ -1439,7 +1439,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
guest := th.CreateGuest()
|
||||
require.Equal(t, "system_guest", guest.Roles)
|
||||
th.LinkUserToTeam(guest, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, guest.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, guest.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeGuest)
|
||||
require.False(t, teamMember.SchemeUser)
|
||||
@@ -1470,7 +1470,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
require.Equal(t, "system_user", user.Roles)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeUser)
|
||||
require.False(t, teamMember.SchemeGuest)
|
||||
@@ -1518,7 +1518,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
require.Equal(t, "system_user", user.Roles)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeUser)
|
||||
require.False(t, teamMember.SchemeGuest)
|
||||
@@ -1528,7 +1528,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user, err = th.App.GetUser(user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_guest", user.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
@@ -1538,7 +1538,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
require.Equal(t, "system_user", user.Roles)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeUser)
|
||||
require.False(t, teamMember.SchemeGuest)
|
||||
@@ -1552,7 +1552,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user, err = th.App.GetUser(user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_guest", user.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
@@ -1566,7 +1566,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
require.Equal(t, "system_user", user.Roles)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeUser)
|
||||
require.False(t, teamMember.SchemeGuest)
|
||||
@@ -1584,7 +1584,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
user, err = th.App.GetUser(user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_guest", user.Roles)
|
||||
teamMember, err = th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, th.BasicTeam.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.True(t, teamMember.SchemeGuest)
|
||||
@@ -1605,9 +1605,9 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
team := th.CreateTeam()
|
||||
|
||||
th.LinkUserToTeam(user, team)
|
||||
th.App.UpdateTeamMemberRoles(team.Id, user.Id, "team_user team_admin")
|
||||
th.App.UpdateTeamMemberRoles(th.Context, team.Id, user.Id, "team_user team_admin")
|
||||
|
||||
teamMember, err := th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, err := th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, err)
|
||||
require.True(t, teamMember.SchemeUser)
|
||||
require.True(t, teamMember.SchemeAdmin)
|
||||
@@ -1631,7 +1631,7 @@ func TestDemoteUserToGuest(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "system_guest", user.Roles)
|
||||
|
||||
teamMember, err = th.App.GetTeamMember(team.Id, user.Id)
|
||||
teamMember, err = th.App.GetTeamMember(th.Context, team.Id, user.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, teamMember.SchemeUser)
|
||||
assert.False(t, teamMember.SchemeAdmin)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
func TestWebConnShouldSendEvent(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
session, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
{
|
||||
UserId: th.BasicUser.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
@@ -39,7 +39,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
|
||||
basicUserWc.SetSessionToken(session.Token)
|
||||
basicUserWc.SetSessionExpiresAt(session.ExpiresAt)
|
||||
|
||||
session2, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser2.Id, Roles: th.BasicUser2.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
session2, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser2.Id, Roles: th.BasicUser2.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
{
|
||||
UserId: th.BasicUser2.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
@@ -61,7 +61,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
|
||||
basicUser2Wc.SetSessionToken(session2.Token)
|
||||
basicUser2Wc.SetSessionExpiresAt(session2.ExpiresAt)
|
||||
|
||||
session3, err := th.App.CreateSession(&model.Session{UserId: th.SystemAdminUser.Id, Roles: th.SystemAdminUser.GetRawRoles()})
|
||||
session3, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.SystemAdminUser.Id, Roles: th.SystemAdminUser.GetRawRoles()})
|
||||
require.Nil(t, err)
|
||||
|
||||
adminUserWc := &platform.WebConn{
|
||||
@@ -77,7 +77,7 @@ func TestWebConnShouldSendEvent(t *testing.T) {
|
||||
adminUserWc.SetSessionToken(session3.Token)
|
||||
adminUserWc.SetSessionExpiresAt(session3.ExpiresAt)
|
||||
|
||||
session4, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
session4, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles(), TeamMembers: []*model.TeamMember{
|
||||
{
|
||||
UserId: th.BasicUser.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
|
||||
Ссылка в новой задаче
Block a user