summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-01-03 10:35:36 -0500
committerJoram Wilander <jwawilander@gmail.com>2018-01-03 10:35:36 -0500
commite5dad3cf681fb038ce5dd3dcf7b5468d59b8ea8e (patch)
treed3040d03a076b5e3b0d991bcb5d4d703f9a45c07 /app
parent15cc4497588537f3f9b81d6f97228fae946fa008 (diff)
downloadchat-e5dad3cf681fb038ce5dd3dcf7b5468d59b8ea8e.tar.gz
chat-e5dad3cf681fb038ce5dd3dcf7b5468d59b8ea8e.tar.bz2
chat-e5dad3cf681fb038ce5dd3dcf7b5468d59b8ea8e.zip
[PLT-8173] Strip the post_ prefix on incoming webhook overrides. (#8019)
Diffstat (limited to 'app')
-rw-r--r--app/webhook.go20
-rw-r--r--app/webhook_test.go84
2 files changed, 52 insertions, 52 deletions
diff --git a/app/webhook.go b/app/webhook.go
index 5ed71e992..14dec3daa 100644
--- a/app/webhook.go
+++ b/app/webhook.go
@@ -278,14 +278,14 @@ func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.C
hook.TeamId = channel.TeamId
if !a.Config().ServiceSettings.EnablePostUsernameOverride {
- hook.PostUsername = ""
+ hook.Username = ""
}
if !a.Config().ServiceSettings.EnablePostIconOverride {
- hook.PostIconURL = ""
+ hook.IconURL = ""
}
- if hook.PostUsername != "" && !model.IsValidUsername(hook.PostUsername) {
- return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.invalid_post_username.app_error", nil, "", http.StatusBadRequest)
+ if hook.Username != "" && !model.IsValidUsername(hook.Username) {
+ return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.invalid_username.app_error", nil, "", http.StatusBadRequest)
}
if result := <-a.Srv.Store.Webhook().SaveIncoming(hook); result.Err != nil {
@@ -301,14 +301,14 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook)
}
if !a.Config().ServiceSettings.EnablePostUsernameOverride {
- updatedHook.PostUsername = oldHook.PostUsername
+ updatedHook.Username = oldHook.Username
}
if !a.Config().ServiceSettings.EnablePostIconOverride {
- updatedHook.PostIconURL = oldHook.PostIconURL
+ updatedHook.IconURL = oldHook.IconURL
}
- if updatedHook.PostUsername != "" && !model.IsValidUsername(updatedHook.PostUsername) {
- return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.invalid_post_username.app_error", nil, "", http.StatusBadRequest)
+ if updatedHook.Username != "" && !model.IsValidUsername(updatedHook.Username) {
+ return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.invalid_username.app_error", nil, "", http.StatusBadRequest)
}
updatedHook.Id = oldHook.Id
@@ -630,12 +630,12 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "", http.StatusForbidden)
}
- overrideUsername := hook.PostUsername
+ overrideUsername := hook.Username
if req.Username != "" {
overrideUsername = req.Username
}
- overrideIconUrl := hook.PostIconURL
+ overrideIconUrl := hook.IconURL
if req.IconURL != "" {
overrideIconUrl = req.IconURL
}
diff --git a/app/webhook_test.go b/app/webhook_test.go
index 048c8361d..47303ee93 100644
--- a/app/webhook_test.go
+++ b/app/webhook_test.go
@@ -53,11 +53,11 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
EnablePostUsernameOverride: false,
EnablePostIconOverride: false,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: ":invalid and ignored:",
- PostIconURL: "ignored",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: ":invalid and ignored:",
+ IconURL: "ignored",
},
ExpectedError: false,
@@ -72,10 +72,10 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
EnablePostUsernameOverride: true,
EnablePostIconOverride: false,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: ":invalid:",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: ":invalid:",
},
ExpectedError: true,
@@ -103,20 +103,20 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
EnablePostUsernameOverride: true,
EnablePostIconOverride: true,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: "valid",
- PostIconURL: "http://example.com/icon",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: "valid",
+ IconURL: "http://example.com/icon",
},
ExpectedError: false,
ExpectedIncomingWebhook: &model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: "valid",
- PostIconURL: "http://example.com/icon",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: "valid",
+ IconURL: "http://example.com/icon",
},
},
} {
@@ -144,8 +144,8 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
assert.Equal(tc.ExpectedIncomingWebhook.DisplayName, createdHook.DisplayName)
assert.Equal(tc.ExpectedIncomingWebhook.Description, createdHook.Description)
assert.Equal(tc.ExpectedIncomingWebhook.ChannelId, createdHook.ChannelId)
- assert.Equal(tc.ExpectedIncomingWebhook.PostUsername, createdHook.PostUsername)
- assert.Equal(tc.ExpectedIncomingWebhook.PostIconURL, createdHook.PostIconURL)
+ assert.Equal(tc.ExpectedIncomingWebhook.Username, createdHook.Username)
+ assert.Equal(tc.ExpectedIncomingWebhook.IconURL, createdHook.IconURL)
}
})
}
@@ -191,11 +191,11 @@ func TestUpdateIncomingWebhook(t *testing.T) {
EnablePostUsernameOverride: false,
EnablePostIconOverride: false,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: ":invalid and ignored:",
- PostIconURL: "ignored",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: ":invalid and ignored:",
+ IconURL: "ignored",
},
ExpectedError: false,
@@ -210,10 +210,10 @@ func TestUpdateIncomingWebhook(t *testing.T) {
EnablePostUsernameOverride: true,
EnablePostIconOverride: false,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: ":invalid:",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: ":invalid:",
},
ExpectedError: true,
@@ -241,20 +241,20 @@ func TestUpdateIncomingWebhook(t *testing.T) {
EnablePostUsernameOverride: true,
EnablePostIconOverride: true,
IncomingWebhook: model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: "valid",
- PostIconURL: "http://example.com/icon",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: "valid",
+ IconURL: "http://example.com/icon",
},
ExpectedError: false,
ExpectedIncomingWebhook: &model.IncomingWebhook{
- DisplayName: "title",
- Description: "description",
- ChannelId: th.BasicChannel.Id,
- PostUsername: "valid",
- PostIconURL: "http://example.com/icon",
+ DisplayName: "title",
+ Description: "description",
+ ChannelId: th.BasicChannel.Id,
+ Username: "valid",
+ IconURL: "http://example.com/icon",
},
},
} {
@@ -289,8 +289,8 @@ func TestUpdateIncomingWebhook(t *testing.T) {
assert.Equal(tc.ExpectedIncomingWebhook.DisplayName, updatedHook.DisplayName)
assert.Equal(tc.ExpectedIncomingWebhook.Description, updatedHook.Description)
assert.Equal(tc.ExpectedIncomingWebhook.ChannelId, updatedHook.ChannelId)
- assert.Equal(tc.ExpectedIncomingWebhook.PostUsername, updatedHook.PostUsername)
- assert.Equal(tc.ExpectedIncomingWebhook.PostIconURL, updatedHook.PostIconURL)
+ assert.Equal(tc.ExpectedIncomingWebhook.Username, updatedHook.Username)
+ assert.Equal(tc.ExpectedIncomingWebhook.IconURL, updatedHook.IconURL)
}
})
}