Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Add name column for webhook and change dashboard messages for webhook
Browse files Browse the repository at this point in the history
activities
  • Loading branch information
Fabian Baumanis committed Jan 23, 2018
1 parent bce67d5 commit a3f814d
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 9 deletions.
9 changes: 8 additions & 1 deletion app/controllers/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ def set_webhook
end

def webhook_params
params.require(:webhook).permit(:url, :request_method, :content_type, :username, :password)
params.require(:webhook).permit(
:name,
:url,
:request_method,
:content_type,
:username,
:password
)
end
end
4 changes: 3 additions & 1 deletion app/models/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# enabled :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255)
#
# Indexes
#
Expand Down Expand Up @@ -152,7 +153,8 @@ def update_activities!
namespace_id: namespace.id,
namespace_name: namespace.clean_name,
webhook_url: url,
webhook_host: host
webhook_host: host,
webhook_name: name
}
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/public_activity/webhook/_update.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ li
strong
= "#{activity.owner.username} updated webhook "
- if activity.trackable
= link_to activity.trackable.host, [activity.trackable.namespace, activity.trackable]
= link_to activity.trackable.name, [activity.trackable.namespace, activity.trackable]
- else
= activity.parameters[:webhook_host]
= " under the "
Expand Down
3 changes: 3 additions & 0 deletions app/views/webhooks/_detail.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
col.col-20
col.col-80
tbody
tr
th Name
td= webhook.name
tr
th Request method
td= webhook.request_method
Expand Down
1 change: 1 addition & 0 deletions app/views/webhooks/_webhook.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tr id="webhook_#{webhook.id}"
td= webhook.name
td= link_to webhook.url, [namespace, webhook]
td= webhook.request_method
td= webhook.content_type
Expand Down
2 changes: 1 addition & 1 deletion app/views/webhooks/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$('#float-alert p').html("<%= escape_javascript(@webhook.errors.full_messages.join('<br/>')) %>");
$('#float-alert').fadeIn(setTimeOutAlertDelay());
<% else %>
$('#float-alert p').html("Webhook '<%= @webhook.host %>' has been created successfully");
$('#float-alert p').html("Webhook '<%= @webhook.name %>' has been created successfully");
$('#float-alert').fadeIn(setTimeOutAlertDelay());

$('#add_webhook_form').fadeOut();
Expand Down
5 changes: 5 additions & 0 deletions app/views/webhooks/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.webhooks-wrapper
#add_webhook_form.collapse
= form_for :webhook, url: namespace_webhooks_path(@namespace), remote: true, html: {id: 'new-webhook-form', class: 'form-horizontal', role: 'form'} do |f|
.form-group
= f.label :name, {class: 'control-label col-md-2'}
.col-md-7
= f.text_field(:name, class: 'form-control', required: true, placeholder: "Name of the Webhook")
.form-group
= f.label :url, {class: 'control-label col-md-2'}
.col-md-7
Expand Down Expand Up @@ -63,6 +67,7 @@
col.col-20
thead
tr
th Name
th URL
th Request method
th Content type
Expand Down
6 changes: 5 additions & 1 deletion app/views/webhooks/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
i.fa.fa-close
| Edit webhook
.panel-body
.form-group
= f.label :name, {class: 'control-label col-md-2'}
.col-md-7
= f.text_field(:name, class: 'form-control', required: true, placeholder: "Name of the webhook")
.form-group
= f.label :request_method, {class: 'control-label col-md-2'}
.col-md-7
Expand Down Expand Up @@ -39,7 +43,7 @@
'#{@webhook.host}
' webhook
small
a[data-placement="right" data-toggle="popover" data-container=".panel-heading" data-content="<b>Request method</b>: URL endpoint where the HTTP request is sent to.<br/><b>Content type</b>: Description of the webhook request content.<br/><b>Username</b>: Username used for basic HTTP auth.<br/><b>Password</b>: Password used for basic HTTP auth." data-original-title="What's this?" tabindex="0" data-html="true"]
a[data-placement="right" data-toggle="popover" data-container=".panel-heading" data-content="<b>Name</b>: Name of the webhook.<br><b>Request method</b>: URL endpoint where the HTTP request is sent to.<br/><b>Content type</b>: Description of the webhook request content.<br/><b>Username</b>: Username used for basic HTTP auth.<br/><b>Password</b>: Password used for basic HTTP auth." data-original-title="What's this?" tabindex="0" data-html="true"]
i.fa.fa-info-circle
- if can_manage_namespace?(@namespace)
.pull-right
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160411150441_create_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def change
t.integer :request_method
t.integer :content_type
t.boolean :enabled, default: false

t.timestamps null: false
end
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180109114124_add_name_to_webhooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToWebhooks < ActiveRecord::Migration
def change
add_column :webhooks, :name, :string, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171220095321) do
ActiveRecord::Schema.define(version: 20180109114124) do

create_table "activities", force: :cascade do |t|
t.integer "trackable_id", limit: 4
Expand Down Expand Up @@ -213,6 +213,7 @@
t.boolean "enabled", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", limit: 255
end

add_index "webhooks", ["namespace_id"], name: "index_webhooks_on_namespace_id", using: :btree
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/webhooks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# enabled :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255)
#
# Indexes
#
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# enabled :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255)
#
# Indexes
#
Expand All @@ -22,6 +23,7 @@

FactoryGirl.define do
factory :webhook do
name "webhook"
url "http://www.example.com"
request_method "POST"
content_type "application/json"
Expand Down
8 changes: 6 additions & 2 deletions spec/features/webhooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@
find("#add_webhook_btn").click
wait_for_effect_on("#add_webhook_form")

fill_in "Url", with: "url-here"
fill_in "Name", with: "name"
fill_in "Url", with: "http://url-here"
click_button "Create"

wait_for_ajax
wait_for_effect_on("#float-alert")

expect(page).to have_css("#float-alert")
expect(page).to have_content("Webhook 'url-here' has been created successfully")
expect(page).to have_content("Webhook 'name' has been created successfully")

# Check that it created a link to it and that it's accessible.
expect(namespace.webhooks.count).to eql webhooks_count + 1
Expand All @@ -60,6 +61,7 @@
expect(page).to have_current_path(namespace_webhook_path(namespace, webhook))
end


it 'The "Create new webhook" link has a toggle effect', js: true do
visit namespace_webhooks_path(namespace)

Expand Down Expand Up @@ -115,12 +117,14 @@
visit namespace_webhook_path(namespace, webhook)

find(".edit-webhook-link").click
fill_in "Name", with: "new_name"
fill_in "webhook_url", with: "http://new-webhook-url"
fill_in "Username", with: "new-username"
fill_in "Password", with: "password"
click_button "Save"
wait_for_ajax

expect(page).to have_content("new_name")
expect(page).to have_content("new-webhook-url webhook")
expect(page).to have_content("new-username")
expect(page).to have_content("***********")
Expand Down
1 change: 1 addition & 0 deletions spec/models/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# enabled :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# name :string(255)
#
# Indexes
#
Expand Down

0 comments on commit a3f814d

Please sign in to comment.