Skip to content

Commit

Permalink
Cleanup usage of global logger (#26835)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei committed Apr 24, 2024
1 parent 92a6c65 commit 30d450c
Show file tree
Hide file tree
Showing 45 changed files with 221 additions and 215 deletions.
4 changes: 2 additions & 2 deletions server/channels/api4/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func requestTrueUpReview(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

status, appErr := c.App.GetOrCreateTrueUpReviewStatus()
status, appErr := c.App.GetOrCreateTrueUpReviewStatus(c.AppContext)
if appErr != nil {
c.Err = appErr
return
Expand Down Expand Up @@ -394,7 +394,7 @@ func trueUpReviewStatus(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

status, appErr := c.App.GetOrCreateTrueUpReviewStatus()
status, appErr := c.App.GetOrCreateTrueUpReviewStatus(c.AppContext)
if appErr != nil {
c.Err = appErr
}
Expand Down
2 changes: 1 addition & 1 deletion server/channels/api4/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

err = c.App.DeleteOAuthApp(oauthApp.Id)
err = c.App.DeleteOAuthApp(c.AppContext, oauthApp.Id)
if err != nil {
c.Err = err
return
Expand Down
2 changes: 1 addition & 1 deletion server/channels/api4/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func getMarketplacePlugins(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

plugins, appErr := c.App.GetMarketplacePlugins(filter)
plugins, appErr := c.App.GetMarketplacePlugins(c.AppContext, filter)
if appErr != nil {
c.Err = appErr
return
Expand Down
2 changes: 1 addition & 1 deletion server/channels/api4/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ func setPostReminder(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

appErr := c.App.SetPostReminder(c.Params.PostId, c.Params.UserId, reminder.TargetTime)
appErr := c.App.SetPostReminder(c.AppContext, c.Params.PostId, c.Params.UserId, reminder.TargetTime)
if appErr != nil {
c.Err = appErr
return
Expand Down
8 changes: 4 additions & 4 deletions server/channels/api4/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var invitesWithError []*model.EmailInviteWithError
var appErr *model.AppError
if emailList != nil {
invitesWithError, appErr = c.App.InviteNewUsersToTeamGracefully(memberInvite, c.Params.TeamId, c.AppContext.Session().UserId, "")
invitesWithError, appErr = c.App.InviteNewUsersToTeamGracefully(c.AppContext, memberInvite, c.Params.TeamId, c.AppContext.Session().UserId, "")
}

if invitesWithError != nil {
Expand Down Expand Up @@ -1458,7 +1458,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {

w.Write(js)
} else {
appErr := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.AppContext.Session().UserId)
appErr := c.App.InviteNewUsersToTeam(c.AppContext, emailList, c.Params.TeamId, c.AppContext.Session().UserId)
if appErr != nil {
c.Err = appErr
return
Expand Down Expand Up @@ -1528,7 +1528,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
var appErr *model.AppError

if guestsInvite.Emails != nil {
invitesWithError, appErr = c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
invitesWithError, appErr = c.App.InviteGuestsToChannelsGracefully(c.AppContext, c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
}

if appErr != nil {
Expand All @@ -1549,7 +1549,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)

w.Write(js)
} else {
appErr := c.App.InviteGuestsToChannels(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
appErr := c.App.InviteGuestsToChannels(c.AppContext, c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
if appErr != nil {
c.Err = appErr
return
Expand Down
14 changes: 7 additions & 7 deletions server/channels/api4/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3534,30 +3534,30 @@ func TestInviteGuestsToTeam(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictCreationToDomains = "@global.com,@common.com" })

t.Run("team domain restrictions should not affect inviting guests", func(t *testing.T) {
err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: emailList, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
err := th.App.InviteGuestsToChannels(th.Context, th.BasicTeam.Id, &model.GuestsInvite{Emails: emailList, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
require.Nil(t, err, "guest user invites should not be affected by team restrictions")
})

t.Run("guest restrictions should affect guest users", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.RestrictCreationToDomains = "@guest.com" })

err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
err := th.App.InviteGuestsToChannels(th.Context, th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
require.NotNil(t, err, "guest user invites should be affected by the guest domain restrictions")

res, err := th.App.InviteGuestsToChannelsGracefully(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]", "[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
res, err := th.App.InviteGuestsToChannelsGracefully(th.Context, th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]", "[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
require.Nil(t, err)
require.Len(t, res, 2)
require.NotNil(t, res[0].Error)
require.Nil(t, res[1].Error)

err = th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
err = th.App.InviteGuestsToChannels(th.Context, th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"[email protected]"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
require.Nil(t, err, "whitelisted guest user email should be allowed by the guest domain restrictions")
})

t.Run("guest restrictions should not affect inviting new team members", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.RestrictCreationToDomains = "@guest.com" })

err := th.App.InviteNewUsersToTeam([]string{"[email protected]"}, th.BasicTeam.Id, th.BasicUser.Id)
err := th.App.InviteNewUsersToTeam(th.Context, []string{"[email protected]"}, th.BasicTeam.Id, th.BasicUser.Id)
require.Nil(t, err, "non guest user invites should not be affected by the guest domain restrictions")
})

Expand All @@ -3576,12 +3576,12 @@ func TestInviteGuestsToTeam(t *testing.T) {
Channels: []string{th.BasicChannel.Id},
Message: "test message",
}
err = th.App.InviteGuestsToChannels(th.BasicTeam.Id, invite, th.BasicUser.Id)
err = th.App.InviteGuestsToChannels(th.Context, th.BasicTeam.Id, invite, th.BasicUser.Id)
require.NotNil(t, err)
assert.Equal(t, "app.email.rate_limit_exceeded.app_error", err.Id)
assert.Equal(t, http.StatusRequestEntityTooLarge, err.StatusCode)

_, appErr := th.App.InviteGuestsToChannelsGracefully(th.BasicTeam.Id, invite, th.BasicUser.Id)
_, appErr := th.App.InviteGuestsToChannelsGracefully(th.Context, th.BasicTeam.Id, invite, th.BasicUser.Id)
require.NotNil(t, appErr)
assert.Equal(t, "app.email.rate_limit_exceeded.app_error", err.Id)
assert.Equal(t, http.StatusRequestEntityTooLarge, err.StatusCode)
Expand Down
4 changes: 2 additions & 2 deletions server/channels/api4/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
defer c.LogAuditRec(auditRec)
audit.AddEventParameter(auditRec, "email", email)

sent, err := c.App.SendPasswordReset(email, c.App.GetSiteURL())
sent, err := c.App.SendPasswordReset(c.AppContext, email, c.App.GetSiteURL())
if err != nil {
if *c.App.Config().ServiceSettings.ExperimentalEnableHardenedMode {
ReturnStatusOK(w)
Expand Down Expand Up @@ -2452,7 +2452,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
accessToken.UserId = c.Params.UserId
accessToken.Token = ""

token, err := c.App.CreateUserAccessToken(&accessToken)
token, err := c.App.CreateUserAccessToken(c.AppContext, &accessToken)
if err != nil {
c.Err = err
return
Expand Down
36 changes: 18 additions & 18 deletions server/channels/app/app_iface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30d450c

Please sign in to comment.