Added ability to configure Slack integration's username (#1084)

closes https://github.com/TryGhost/Ghost/issues/9735
- add "Username" form to Slack integration
This commit is contained in:
Greg Hart 2019-01-21 04:26:21 -08:00 committed by Kevin Ansfield
parent 8fcd75de32
commit b235f68052
6 changed files with 42 additions and 6 deletions

View File

@ -34,6 +34,12 @@ export default Controller.extend({
this.get('slackSettings.errors').clear();
},
updateUsername(value) {
value = typeof value === 'string' ? value.trimLeft() : value;
this.set('slackSettings.username', value);
this.get('slackSettings.errors').clear();
},
triggerDirtyState() {
let slack = this.get('slackSettings');
let slackArray = this.get('slackArray');

View File

@ -6,6 +6,7 @@ import {isBlank} from '@ember/utils';
export default EmberObject.extend(ValidationEngine, {
// values entered here will act as defaults
url: '',
username: '',
validationType: 'slackIntegration',

View File

@ -57,6 +57,30 @@
</div>
</div>
</div>
<div class="gh-setting">
<div class="gh-setting-content gh-setting-content--no-action">
<div class="gh-setting-title">Username</div>
<div class="gh-setting-desc">The username to display messages from (defaults to "Ghost")</div>
<div class="gh-setting-content-extended">
{{#gh-form-group errors=slackSettings.errors hasValidated=slackSettings.hasValidated property="username"}}
{{gh-text-input
placeholder="Ghost"
name="slack[username]"
value=(readonly slackSettings.username)
input=(action "updateUsername" value="target.value")
keyEvents=(hash
Enter=(action "save")
)
focus-out=(action "triggerDirtyState")
data-test-slack-username-input=true
}}
{{#if slackSettings.errors.username}}
{{gh-error-message errors=slackSettings.errors property="username"}}
{{/if}}
{{/gh-form-group}}
</div>
</div>
</div>
</form>
{{gh-task-button "Send test notification" task=sendTestNotification successText="Sent" class="gh-btn gh-btn-green gh-btn-icon" disabled=testNotificationDisabled data-test-send-notification-button=true}}

View File

@ -14,7 +14,7 @@ export default Transform.extend({
}
if (isEmpty(settingsArray)) {
settingsArray.push({url: ''});
settingsArray.push({url: '', username: ''});
}
let slackObjs = settingsArray.map(itemDetails => SlackObject.create(itemDetails));
@ -27,8 +27,9 @@ export default Transform.extend({
if (isEmberArray(deserialized)) {
settingsArray = deserialized.map((item) => {
let url = (item.get('url') || '').trim();
let username = (item.get('username') || '').trim();
if (url) {
return {url};
return {url, username};
}
}).compact();
} else {

View File

@ -57,7 +57,7 @@ describe('Acceptance: Settings - Integrations - Slack', function () {
return await authenticateSession();
});
it('it validates and saves a slack url properly', async function () {
it('it validates and saves slack settings properly', async function () {
await visit('/settings/integrations/slack');
// has correct url
@ -71,6 +71,7 @@ describe('Acceptance: Settings - Integrations - Slack', function () {
// CMD-S shortcut works
await fillIn('[data-test-slack-url-input]', 'https://hooks.slack.com/services/1275958430');
await fillIn('[data-test-slack-username-input]', 'SlackBot');
await triggerEvent('.gh-app', 'keydown', {
keyCode: 83, // s
metaKey: ctrlOrCmd === 'command',
@ -82,6 +83,7 @@ describe('Acceptance: Settings - Integrations - Slack', function () {
let [result] = JSON.parse(params.settings.findBy('key', 'slack').value);
expect(result.url).to.equal('https://hooks.slack.com/services/1275958430');
expect(result.username).to.equal('SlackBot');
expect(find('[data-test-error="slack-url"'), 'inline validation response')
.to.not.exist;

View File

@ -9,12 +9,13 @@ describe('Unit: Transform: slack-settings', function () {
it('deserializes settings json', function () {
let transform = this.subject();
let serialized = '[{"url":"http://myblog.com/blogpost1"}]';
let serialized = '[{"url":"http://myblog.com/blogpost1","username":"SlackBot"}]';
let result = transform.deserialize(serialized);
expect(result.length).to.equal(1);
expect(result[0]).to.be.instanceof(SlackIntegration);
expect(result[0].get('url')).to.equal('http://myblog.com/blogpost1');
expect(result[0].get('username')).to.equal('SlackBot');
});
it('deserializes empty array', function () {
@ -25,16 +26,17 @@ describe('Unit: Transform: slack-settings', function () {
expect(result.length).to.equal(1);
expect(result[0]).to.be.instanceof(SlackIntegration);
expect(result[0].get('url')).to.equal('');
expect(result[0].get('username')).to.equal('');
});
it('serializes array of Slack settings', function () {
let transform = this.subject();
let deserialized = emberA([
SlackIntegration.create({url: 'http://myblog.com/blogpost1'})
SlackIntegration.create({url: 'http://myblog.com/blogpost1', username: 'SlackBot'})
]);
let result = transform.serialize(deserialized);
expect(result).to.equal('[{"url":"http://myblog.com/blogpost1"}]');
expect(result).to.equal('[{"url":"http://myblog.com/blogpost1","username":"SlackBot"}]');
});
it('serializes empty SlackIntegration objects', function () {