MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898) * Change fields of config structs to pointers and set defaults MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Fix tests that go broken during switching config structs to pointers MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Apply changes of current master while switching config structs to pointers MM-10658 https://github.com/mattermost/mattermost-server/issues/8841 * Fix new config pointer uses * Fix app tests * Fix mail test * remove debugging statement * fix TestUpdateConfig * assign config consistently * initialize AmazonS3Region in TestS3TestConnection * initialize fields for TestEmailTest * fix TestCheckMandatoryS3Fields
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0c981aa010
Коммит
2ca222033c
16
app/admin.go
16
app/admin.go
@@ -51,8 +51,8 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
var lines []string
|
||||
|
||||
if a.Config().LogSettings.EnableFile {
|
||||
file, err := os.Open(utils.GetLogFileLocation(a.Config().LogSettings.FileLocation))
|
||||
if *a.Config().LogSettings.EnableFile {
|
||||
file, err := os.Open(utils.GetLogFileLocation(*a.Config().LogSettings.FileLocation))
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -221,17 +221,17 @@ func (a *App) RecycleDatabaseConnection() {
|
||||
}
|
||||
|
||||
func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
|
||||
if len(cfg.EmailSettings.SMTPServer) == 0 {
|
||||
if len(*cfg.EmailSettings.SMTPServer) == 0 {
|
||||
return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// if the user hasn't changed their email settings, fill in the actual SMTP password so that
|
||||
// the user can verify an existing SMTP connection
|
||||
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
|
||||
if cfg.EmailSettings.SMTPServer == a.Config().EmailSettings.SMTPServer &&
|
||||
cfg.EmailSettings.SMTPPort == a.Config().EmailSettings.SMTPPort &&
|
||||
cfg.EmailSettings.SMTPUsername == a.Config().EmailSettings.SMTPUsername {
|
||||
cfg.EmailSettings.SMTPPassword = a.Config().EmailSettings.SMTPPassword
|
||||
if *cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
|
||||
if *cfg.EmailSettings.SMTPServer == *a.Config().EmailSettings.SMTPServer &&
|
||||
*cfg.EmailSettings.SMTPPort == *a.Config().EmailSettings.SMTPPort &&
|
||||
*cfg.EmailSettings.SMTPUsername == *a.Config().EmailSettings.SMTPUsername {
|
||||
*cfg.EmailSettings.SMTPPassword = *a.Config().EmailSettings.SMTPPassword
|
||||
} else {
|
||||
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func (a *App) CheckUserPreflightAuthenticationCriteria(user *model.User, mfaToke
|
||||
}
|
||||
|
||||
func (a *App) CheckUserPostflightAuthenticationCriteria(user *model.User) *model.AppError {
|
||||
if !user.EmailVerified && a.Config().EmailSettings.RequireEmailVerification {
|
||||
if !user.EmailVerified && *a.Config().EmailSettings.RequireEmailVerification {
|
||||
return model.NewAppError("Login", "api.user.login.not_verified.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.EnableIncomingWebhooks = true
|
||||
cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
*cfg.ServiceSettings.EnableIncomingWebhooks = true
|
||||
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
})
|
||||
|
||||
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
|
||||
@@ -394,7 +394,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
||||
|
||||
isBotPost := !builtIn
|
||||
|
||||
if a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if *a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if len(command.Username) != 0 {
|
||||
post.AddProp("override_username", command.Username)
|
||||
isBotPost = true
|
||||
@@ -404,7 +404,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
||||
}
|
||||
}
|
||||
|
||||
if a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if *a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if len(command.IconURL) != 0 {
|
||||
post.AddProp("override_icon_url", command.IconURL)
|
||||
isBotPost = true
|
||||
|
||||
@@ -28,7 +28,7 @@ func (me *InvitePeopleProvider) GetTrigger() string {
|
||||
|
||||
func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
|
||||
autoComplete := true
|
||||
if !a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations {
|
||||
if !*a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations {
|
||||
autoComplete = false
|
||||
}
|
||||
return &model.Command{
|
||||
@@ -49,7 +49,7 @@ func (me *InvitePeopleProvider) DoCommand(a *App, args *model.CommandArgs, messa
|
||||
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if !a.Config().EmailSettings.SendEmailNotifications {
|
||||
if !*a.Config().EmailSettings.SendEmailNotifications {
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.email_off")}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ func (me *LoadTestProvider) GetTrigger() string {
|
||||
}
|
||||
|
||||
func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
|
||||
if !a.Config().ServiceSettings.EnableTesting {
|
||||
if !*a.Config().ServiceSettings.EnableTesting {
|
||||
return nil
|
||||
}
|
||||
return &model.Command{
|
||||
@@ -88,7 +88,7 @@ func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Co
|
||||
|
||||
func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
//This command is only available when EnableTesting is true
|
||||
if !a.Config().ServiceSettings.EnableTesting {
|
||||
if !*a.Config().ServiceSettings.EnableTesting {
|
||||
return &model.CommandResponse{}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
assert.NotEqual(t, args.ChannelId, post.ChannelId)
|
||||
|
||||
// Override username config is turned off. No override should occur.
|
||||
th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
|
||||
*th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
|
||||
resp.ChannelId = ""
|
||||
command.Username = "Command username"
|
||||
resp.Username = "Response username"
|
||||
@@ -136,7 +136,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, post.Props["override_username"])
|
||||
|
||||
th.App.Config().ServiceSettings.EnablePostUsernameOverride = true
|
||||
*th.App.Config().ServiceSettings.EnablePostUsernameOverride = true
|
||||
|
||||
// Override username config is turned on. Override username through command property.
|
||||
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||
@@ -152,10 +152,10 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
assert.Equal(t, resp.Username, post.Props["override_username"])
|
||||
assert.Equal(t, "true", post.Props["from_webhook"])
|
||||
|
||||
th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
|
||||
*th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
|
||||
|
||||
// Override icon url config is turned off. No override should occur.
|
||||
th.App.Config().ServiceSettings.EnablePostIconOverride = false
|
||||
*th.App.Config().ServiceSettings.EnablePostIconOverride = false
|
||||
command.IconURL = "Command icon url"
|
||||
resp.IconURL = "Response icon url"
|
||||
|
||||
@@ -163,7 +163,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, post.Props["override_icon_url"])
|
||||
|
||||
th.App.Config().ServiceSettings.EnablePostIconOverride = true
|
||||
*th.App.Config().ServiceSettings.EnablePostIconOverride = true
|
||||
|
||||
// Override icon url config is turned on. Override icon url through command property.
|
||||
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
|
||||
|
||||
@@ -313,25 +313,25 @@ func (a *App) Desanitize(cfg *model.Config) {
|
||||
if *cfg.FileSettings.PublicLinkSalt == model.FAKE_SETTING {
|
||||
*cfg.FileSettings.PublicLinkSalt = *actual.FileSettings.PublicLinkSalt
|
||||
}
|
||||
if cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING {
|
||||
if *cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING {
|
||||
cfg.FileSettings.AmazonS3SecretAccessKey = actual.FileSettings.AmazonS3SecretAccessKey
|
||||
}
|
||||
|
||||
if cfg.EmailSettings.InviteSalt == model.FAKE_SETTING {
|
||||
if *cfg.EmailSettings.InviteSalt == model.FAKE_SETTING {
|
||||
cfg.EmailSettings.InviteSalt = actual.EmailSettings.InviteSalt
|
||||
}
|
||||
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
|
||||
if *cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
|
||||
cfg.EmailSettings.SMTPPassword = actual.EmailSettings.SMTPPassword
|
||||
}
|
||||
|
||||
if cfg.GitLabSettings.Secret == model.FAKE_SETTING {
|
||||
cfg.GitLabSettings.Secret = actual.GitLabSettings.Secret
|
||||
if *cfg.GitLabSettings.Secret == model.FAKE_SETTING {
|
||||
*cfg.GitLabSettings.Secret = *actual.GitLabSettings.Secret
|
||||
}
|
||||
|
||||
if *cfg.SqlSettings.DataSource == model.FAKE_SETTING {
|
||||
*cfg.SqlSettings.DataSource = *actual.SqlSettings.DataSource
|
||||
}
|
||||
if cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING {
|
||||
if *cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING {
|
||||
cfg.SqlSettings.AtRestEncryptKey = actual.SqlSettings.AtRestEncryptKey
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestConfigListener(t *testing.T) {
|
||||
|
||||
originalSiteName := th.App.Config().TeamSettings.SiteName
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.TeamSettings.SiteName = "test123"
|
||||
*cfg.TeamSettings.SiteName = "test123"
|
||||
})
|
||||
|
||||
listenerCalled := false
|
||||
@@ -60,9 +60,9 @@ func TestConfigListener(t *testing.T) {
|
||||
t.Fatal("listener called twice")
|
||||
}
|
||||
|
||||
if oldConfig.TeamSettings.SiteName != "test123" {
|
||||
if *oldConfig.TeamSettings.SiteName != "test123" {
|
||||
t.Fatal("old config contains incorrect site name")
|
||||
} else if newConfig.TeamSettings.SiteName != originalSiteName {
|
||||
} else if *newConfig.TeamSettings.SiteName != *originalSiteName {
|
||||
t.Fatal("new config contains incorrect site name")
|
||||
}
|
||||
|
||||
|
||||
@@ -340,8 +340,8 @@ func (a *App) trackConfig() {
|
||||
a.SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{
|
||||
"enable_public_links": cfg.FileSettings.EnablePublicLink,
|
||||
"driver_name": *cfg.FileSettings.DriverName,
|
||||
"isdefault_directory": isDefault(cfg.FileSettings.Directory, model.FILE_SETTINGS_DEFAULT_DIRECTORY),
|
||||
"isabsolute_directory": filepath.IsAbs(cfg.FileSettings.Directory),
|
||||
"isdefault_directory": isDefault(*cfg.FileSettings.Directory, model.FILE_SETTINGS_DEFAULT_DIRECTORY),
|
||||
"isabsolute_directory": filepath.IsAbs(*cfg.FileSettings.Directory),
|
||||
"amazon_s3_ssl": *cfg.FileSettings.AmazonS3SSL,
|
||||
"amazon_s3_sse": *cfg.FileSettings.AmazonS3SSE,
|
||||
"amazon_s3_signv2": *cfg.FileSettings.AmazonS3SignV2,
|
||||
|
||||
@@ -341,7 +341,7 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
|
||||
}
|
||||
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&t=%s", siteURL, url.QueryEscape(data), url.QueryEscape(token.Token))
|
||||
|
||||
if !a.Config().EmailSettings.SendEmailNotifications {
|
||||
if !*a.Config().EmailSettings.SendEmailNotifications {
|
||||
mlog.Info(fmt.Sprintf("sending invitation to %v %v", invite, bodyPage.Props["Link"]))
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
sender: sender,
|
||||
}
|
||||
|
||||
if a.Config().EmailSettings.SendEmailNotifications {
|
||||
if *a.Config().EmailSettings.SendEmailNotifications {
|
||||
for _, id := range mentionedUsersList {
|
||||
if profileMap[id] == nil {
|
||||
continue
|
||||
@@ -180,7 +180,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
|
||||
//If email verification is required and user email is not verified don't send email.
|
||||
if a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
|
||||
if *a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
|
||||
mlog.Error(fmt.Sprintf("Skipped sending notification email to %v, address not verified. [details: user_id=%v]", profileMap[id].Email, id))
|
||||
continue
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
message.Add("channel_type", channel.Type)
|
||||
message.Add("channel_display_name", notification.GetChannelName(model.SHOW_USERNAME, ""))
|
||||
message.Add("channel_name", channel.Name)
|
||||
message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, a.Config().ServiceSettings.EnablePostUsernameOverride))
|
||||
message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, *a.Config().ServiceSettings.EnablePostUsernameOverride))
|
||||
message.Add("team_id", team.Id)
|
||||
|
||||
if len(post.FileIds) != 0 && fchan != nil {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
team = teams[0]
|
||||
} else {
|
||||
// in case the user hasn't joined any teams we send them to the select_team page
|
||||
team = &model.Team{Name: "select_team", DisplayName: a.Config().TeamSettings.SiteName}
|
||||
team = &model.Team{Name: "select_team", DisplayName: *a.Config().TeamSettings.SiteName}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
}
|
||||
|
||||
channelName := notification.GetChannelName(nameFormat, "")
|
||||
senderName := notification.GetSenderName(nameFormat, a.Config().ServiceSettings.EnablePostUsernameOverride)
|
||||
senderName := notification.GetSenderName(nameFormat, *a.Config().ServiceSettings.EnablePostUsernameOverride)
|
||||
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
if license := a.License(); license != nil && *license.Features.EmailNotificationContents {
|
||||
@@ -91,13 +91,13 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
|
||||
var subjectText string
|
||||
if channel.Type == model.CHANNEL_DIRECT {
|
||||
subjectText = getDirectMessageNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, senderName, useMilitaryTime)
|
||||
subjectText = getDirectMessageNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, senderName, useMilitaryTime)
|
||||
} else if channel.Type == model.CHANNEL_GROUP {
|
||||
subjectText = getGroupMessageNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType, useMilitaryTime)
|
||||
subjectText = getGroupMessageNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType, useMilitaryTime)
|
||||
} else if *a.Config().EmailSettings.UseChannelInEmailNotifications {
|
||||
subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channelName+")", useMilitaryTime)
|
||||
subjectText = getNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channelName+")", useMilitaryTime)
|
||||
} else {
|
||||
subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime)
|
||||
subjectText = getNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime)
|
||||
}
|
||||
|
||||
teamURL := a.GetSiteURL() + "/" + team.Name
|
||||
|
||||
@@ -79,11 +79,11 @@ func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, chann
|
||||
msg.ChannelName = channelName
|
||||
}
|
||||
|
||||
if ou, ok := post.Props["override_username"].(string); ok && cfg.ServiceSettings.EnablePostUsernameOverride {
|
||||
if ou, ok := post.Props["override_username"].(string); ok && *cfg.ServiceSettings.EnablePostUsernameOverride {
|
||||
msg.OverrideUsername = ou
|
||||
}
|
||||
|
||||
if oi, ok := post.Props["override_icon_url"].(string); ok && cfg.ServiceSettings.EnablePostIconOverride {
|
||||
if oi, ok := post.Props["override_icon_url"].(string); ok && *cfg.ServiceSettings.EnablePostIconOverride {
|
||||
msg.OverrideIconUrl = oi
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (a *App) sendPushNotification(notification *postNotification, user *model.U
|
||||
}
|
||||
|
||||
channelName := notification.GetChannelName(nameFormat, user.Id)
|
||||
senderName := notification.GetSenderName(nameFormat, cfg.ServiceSettings.EnablePostUsernameOverride)
|
||||
senderName := notification.GetSenderName(nameFormat, *cfg.ServiceSettings.EnablePostUsernameOverride)
|
||||
|
||||
c := a.Srv.PushNotificationsHub.GetGoChannelFromUserId(user.Id)
|
||||
c <- PushNotification{
|
||||
|
||||
42
app/oauth.go
42
app/oauth.go
@@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("CreateOAuthApp", "api.oauth.register_oauth_app.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("UpdateOauthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp
|
||||
}
|
||||
|
||||
func (a *App) DeleteOAuthApp(appId string) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func (a *App) DeleteOAuthApp(appId string) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppErro
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (a *App) GetOAuthCodeRedirect(userId string, authRequest *model.AuthorizeRe
|
||||
}
|
||||
|
||||
func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *mod
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ func (a *App) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, ser
|
||||
}
|
||||
|
||||
func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetAuthorizedAppsForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*mod
|
||||
}
|
||||
|
||||
func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("RegenerateOAuthAppSecret", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ func (a *App) GetOAuthStateToken(token string) (*model.Token, *model.AppError) {
|
||||
|
||||
func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
|
||||
sso := a.Config().GetSSOService(service)
|
||||
if sso == nil || !sso.Enable {
|
||||
if sso == nil || !*sso.Enable {
|
||||
return "", model.NewAppError("GetAuthorizationCode", "api.user.get_authorization_code.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -683,9 +683,9 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
|
||||
|
||||
http.SetCookie(w, oauthCookie)
|
||||
|
||||
clientId := sso.Id
|
||||
endpoint := sso.AuthEndpoint
|
||||
scope := sso.Scope
|
||||
clientId := *sso.Id
|
||||
endpoint := *sso.AuthEndpoint
|
||||
scope := *sso.Scope
|
||||
|
||||
tokenExtra := generateOAuthStateTokenExtra(props["email"], props["action"], cookieValue)
|
||||
stateToken, err := a.CreateOAuthStateToken(tokenExtra)
|
||||
@@ -718,7 +718,7 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
|
||||
|
||||
func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.AppError) {
|
||||
sso := a.Config().GetSSOService(service)
|
||||
if sso == nil || !sso.Enable {
|
||||
if sso == nil || !*sso.Enable {
|
||||
return nil, "", nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -770,13 +770,13 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
teamId := stateProps["team_id"]
|
||||
|
||||
p := url.Values{}
|
||||
p.Set("client_id", sso.Id)
|
||||
p.Set("client_secret", sso.Secret)
|
||||
p.Set("client_id", *sso.Id)
|
||||
p.Set("client_secret", *sso.Secret)
|
||||
p.Set("code", code)
|
||||
p.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
|
||||
p.Set("redirect_uri", redirectUri)
|
||||
|
||||
req, requestErr := http.NewRequest("POST", sso.TokenEndpoint, strings.NewReader(p.Encode()))
|
||||
req, requestErr := http.NewRequest("POST", *sso.TokenEndpoint, strings.NewReader(p.Encode()))
|
||||
if requestErr != nil {
|
||||
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, requestErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -808,7 +808,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
|
||||
p = url.Values{}
|
||||
p.Set("access_token", ar.AccessToken)
|
||||
req, requestErr = http.NewRequest("GET", sso.UserApiEndpoint, strings.NewReader(""))
|
||||
req, requestErr = http.NewRequest("GET", *sso.UserApiEndpoint, strings.NewReader(""))
|
||||
if requestErr != nil {
|
||||
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]interface{}{"Service": service}, requestErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
|
||||
oapp := &model.OAuthApp{
|
||||
Name: "fakeoauthapp" + model.NewRandomString(10),
|
||||
@@ -45,13 +45,13 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, session)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(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 })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
authRequest.ClientId = "junk"
|
||||
|
||||
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
|
||||
@@ -105,7 +105,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
|
||||
*th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
|
||||
|
||||
a1 := &model.OAuthApp{}
|
||||
a1.CreatorId = model.NewId()
|
||||
@@ -154,18 +154,18 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
th := Setup()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.GitLabSettings.Enable = enable
|
||||
*cfg.GitLabSettings.Enable = enable
|
||||
|
||||
if tokenEndpoint {
|
||||
cfg.GitLabSettings.TokenEndpoint = serverURL + "/token"
|
||||
*cfg.GitLabSettings.TokenEndpoint = serverURL + "/token"
|
||||
} else {
|
||||
cfg.GitLabSettings.TokenEndpoint = ""
|
||||
*cfg.GitLabSettings.TokenEndpoint = ""
|
||||
}
|
||||
|
||||
if userEndpoint {
|
||||
cfg.GitLabSettings.UserApiEndpoint = serverURL + "/user"
|
||||
*cfg.GitLabSettings.UserApiEndpoint = serverURL + "/user"
|
||||
} else {
|
||||
cfg.GitLabSettings.UserApiEndpoint = ""
|
||||
*cfg.GitLabSettings.UserApiEndpoint = ""
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -477,7 +477,7 @@ func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppErr
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) {
|
||||
if !api.app.Config().FileSettings.EnablePublicLink {
|
||||
if !*api.app.Config().FileSettings.EnablePublicLink {
|
||||
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func (a *App) normalizeDomains(domains string) []string {
|
||||
func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) bool {
|
||||
email = strings.ToLower(email)
|
||||
// First check per team allowedDomains, then app wide restrictions
|
||||
for _, restriction := range []string{allowedDomains, a.Config().TeamSettings.RestrictCreationToDomains} {
|
||||
for _, restriction := range []string{allowedDomains, *a.Config().TeamSettings.RestrictCreationToDomains} {
|
||||
domains := a.normalizeDomains(restriction)
|
||||
if len(domains) <= 0 {
|
||||
continue
|
||||
@@ -103,7 +103,7 @@ func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
validDomains := a.normalizeDomains(a.Config().TeamSettings.RestrictCreationToDomains)
|
||||
validDomains := a.normalizeDomains(*a.Config().TeamSettings.RestrictCreationToDomains)
|
||||
if len(validDomains) > 0 {
|
||||
for _, domain := range a.normalizeDomains(team.AllowedDomains) {
|
||||
matched := false
|
||||
|
||||
16
app/user.go
16
app/user.go
@@ -161,7 +161,7 @@ func (a *App) CreateUserFromSignup(user *model.User) (*model.User, *model.AppErr
|
||||
}
|
||||
|
||||
func (a *App) IsUserSignUpAllowed() *model.AppError {
|
||||
if !a.Config().EmailSettings.EnableSignUpWithEmail || !*a.Config().TeamSettings.EnableUserCreation {
|
||||
if !*a.Config().EmailSettings.EnableSignUpWithEmail || !*a.Config().TeamSettings.EnableUserCreation {
|
||||
err := model.NewAppError("IsUserSignUpAllowed", "api.user.create_user.signup_email_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (a *App) IsFirstUserAccount() bool {
|
||||
}
|
||||
|
||||
func (a *App) CreateUser(user *model.User) (*model.User, *model.AppError) {
|
||||
if !user.IsLDAPUser() && !user.IsSAMLUser() && !CheckUserDomain(user, a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
if !user.IsLDAPUser() && !user.IsSAMLUser() && !CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
return nil, model.NewAppError("CreateUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -698,7 +698,7 @@ func getFont(initialFont string) (*truetype.Font, error) {
|
||||
|
||||
func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) {
|
||||
if len(*a.Config().FileSettings.DriverName) == 0 {
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont)
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
|
||||
if appErr != nil {
|
||||
return nil, false, appErr
|
||||
}
|
||||
@@ -709,7 +709,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
|
||||
data, err := a.ReadFile(path)
|
||||
if err != nil {
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont)
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
|
||||
if appErr != nil {
|
||||
return nil, false, appErr
|
||||
}
|
||||
@@ -726,7 +726,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
}
|
||||
|
||||
func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError) {
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont)
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
@@ -734,7 +734,7 @@ func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError)
|
||||
}
|
||||
|
||||
func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont)
|
||||
img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
@@ -994,7 +994,7 @@ func (a *App) sendUpdatedUserEvent(user model.User) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
if !CheckUserDomain(user, a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
if !CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
result := <-a.Srv.Store.User().Get(user.Id)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
@@ -1019,7 +1019,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
}
|
||||
})
|
||||
|
||||
if a.Config().EmailSettings.RequireEmailVerification {
|
||||
if *a.Config().EmailSettings.RequireEmailVerification {
|
||||
a.Srv.Go(func() {
|
||||
if err := a.SendEmailVerification(rusers[0]); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
|
||||
defer th.App.PermanentDeleteUser(user)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.TeamSettings.RestrictCreationToDomains = "foo.com"
|
||||
*cfg.TeamSettings.RestrictCreationToDomains = "foo.com"
|
||||
})
|
||||
|
||||
_, err := th.App.UpdateUser(user, false)
|
||||
|
||||
@@ -25,7 +25,7 @@ const (
|
||||
)
|
||||
|
||||
func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -133,11 +133,11 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
|
||||
if len(webhookResp.Attachments) > 0 {
|
||||
webhookResp.Props["attachments"] = webhookResp.Attachments
|
||||
}
|
||||
if a.Config().ServiceSettings.EnablePostUsernameOverride && hook.Username != "" && webhookResp.Username == "" {
|
||||
if *a.Config().ServiceSettings.EnablePostUsernameOverride && hook.Username != "" && webhookResp.Username == "" {
|
||||
webhookResp.Username = hook.Username
|
||||
}
|
||||
|
||||
if a.Config().ServiceSettings.EnablePostIconOverride && hook.IconURL != "" && webhookResp.IconURL == "" {
|
||||
if *a.Config().ServiceSettings.EnablePostIconOverride && hook.IconURL != "" && webhookResp.IconURL == "" {
|
||||
webhookResp.IconURL = hook.IconURL
|
||||
}
|
||||
if _, err := a.CreateWebhookPost(hook.CreatorId, channel, text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil {
|
||||
@@ -264,7 +264,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
metrics.IncrementWebhookPost()
|
||||
}
|
||||
|
||||
if a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if *a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if len(overrideUsername) != 0 {
|
||||
post.AddProp("override_username", overrideUsername)
|
||||
} else {
|
||||
@@ -272,7 +272,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
}
|
||||
}
|
||||
|
||||
if a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if *a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if len(overrideIconUrl) != 0 {
|
||||
post.AddProp("override_icon_url", overrideIconUrl)
|
||||
}
|
||||
@@ -305,17 +305,17 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
}
|
||||
|
||||
func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
hook.UserId = creatorId
|
||||
hook.TeamId = channel.TeamId
|
||||
|
||||
if !a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if !*a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
hook.Username = ""
|
||||
}
|
||||
if !a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if !*a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
hook.IconURL = ""
|
||||
}
|
||||
|
||||
@@ -331,14 +331,14 @@ func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.C
|
||||
}
|
||||
|
||||
func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if !a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if !*a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
updatedHook.Username = oldHook.Username
|
||||
}
|
||||
if !a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if !*a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
updatedHook.IconURL = oldHook.IconURL
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook)
|
||||
}
|
||||
|
||||
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.
|
||||
}
|
||||
|
||||
func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) (
|
||||
}
|
||||
|
||||
func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebho
|
||||
}
|
||||
|
||||
func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
|
||||
}
|
||||
|
||||
func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook)
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebho
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksForTeamPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) (
|
||||
}
|
||||
|
||||
func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return model.NewAppError("DeleteOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("RegenOutgoingWebhookToken", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.Out
|
||||
}
|
||||
|
||||
func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError {
|
||||
if !a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
|
||||
@@ -122,11 +122,11 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
||||
*cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
||||
})
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
||||
|
||||
createdHook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &tc.IncomingWebhook)
|
||||
if tc.ExpectedError && err == nil {
|
||||
@@ -253,7 +253,7 @@ func TestUpdateIncomingWebhook(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
|
||||
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
@@ -263,11 +263,11 @@ func TestUpdateIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
defer th.App.DeleteIncomingWebhook(hook.Id)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
||||
*cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
|
||||
})
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
|
||||
|
||||
updatedHook, err := th.App.UpdateIncomingWebhook(hook, &tc.IncomingWebhook)
|
||||
if tc.ExpectedError && err == nil {
|
||||
@@ -292,7 +292,7 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
|
||||
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
if err != nil {
|
||||
@@ -492,7 +492,7 @@ func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||
|
||||
createdHook, err := th.App.CreateOutgoingWebhook(&outgoingWebhook)
|
||||
|
||||
@@ -609,9 +609,9 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
cfg.ServiceSettings.EnablePostUsernameOverride = testCase.EnablePostUsernameOverride
|
||||
cfg.ServiceSettings.EnablePostIconOverride = testCase.EnablePostIconOverride
|
||||
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
*cfg.ServiceSettings.EnablePostUsernameOverride = testCase.EnablePostUsernameOverride
|
||||
*cfg.ServiceSettings.EnablePostIconOverride = testCase.EnablePostIconOverride
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -673,7 +673,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.AllowedUntrustedInternalConnections = model.NewString("127.0.0.1")
|
||||
cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
*cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
||||
})
|
||||
|
||||
t.Run("with a valid response", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user