Commit b68de6c7 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Add license check for group webhooks

- Hide the `webhooks` link from the group-settings page
- All group-webhooks-pages render a 404
- Don't execute webhooks if the feature is disabled
parent 884117e1
...@@ -2,6 +2,7 @@ class Groups::HooksController < Groups::ApplicationController ...@@ -2,6 +2,7 @@ class Groups::HooksController < Groups::ApplicationController
# Authorize # Authorize
before_action :group before_action :group
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :ensure_feature_available!
respond_to :html respond_to :html
...@@ -68,4 +69,10 @@ class Groups::HooksController < Groups::ApplicationController ...@@ -68,4 +69,10 @@ class Groups::HooksController < Groups::ApplicationController
:wiki_page_events :wiki_page_events
) )
end end
def ensure_feature_available!
unless @group.feature_available?(:group_webhooks)
render_404
end
end
end end
...@@ -221,7 +221,7 @@ module EE ...@@ -221,7 +221,7 @@ module EE
def execute_hooks(data, hooks_scope = :push_hooks) def execute_hooks(data, hooks_scope = :push_hooks)
super super
if group if group && feature_available?(:group_webhooks)
group.hooks.send(hooks_scope).each do |hook| group.hooks.send(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s) hook.async_execute(data, hooks_scope.to_s)
end end
......
...@@ -19,10 +19,11 @@ ...@@ -19,10 +19,11 @@
%span %span
LDAP Group LDAP Group
= nav_link(path: 'hooks#index') do - if @group.feature_available?(:group_webhooks)
= link_to group_hooks_path(@group), title: 'Webhooks' do = nav_link(path: 'hooks#index') do
%span = link_to group_hooks_path(@group), title: 'Webhooks' do
Webhooks %span
Webhooks
= nav_link(path: 'audit_events#index') do = nav_link(path: 'audit_events#index') do
= link_to group_audit_events_path(@group), title: 'Audit Events' do = link_to group_audit_events_path(@group), title: 'Audit Events' do
......
...@@ -9,28 +9,56 @@ describe Groups::HooksController do ...@@ -9,28 +9,56 @@ describe Groups::HooksController do
sign_in(user) sign_in(user)
end end
describe 'POST #create' do context 'with group_webhooks enabled' do
it 'sets all parameters' do before do
hook_params = { stub_licensed_features(group_webhooks: true)
job_events: true, end
confidential_issues_events: true,
enable_ssl_verification: true, describe 'GET #index' do
issues_events: true, it 'is successfull' do
merge_requests_events: true, get :index, group_id: group.to_param
note_events: true,
pipeline_events: true, expect(response).to have_http_status(200)
push_events: true, end
tag_push_events: true, end
token: "TEST TOKEN",
url: "http://example.com", describe 'POST #create' do
wiki_page_events: true it 'sets all parameters' do
} hook_params = {
job_events: true,
post :create, group_id: group.to_param, hook: hook_params confidential_issues_events: true,
enable_ssl_verification: true,
expect(response).to have_http_status(302) issues_events: true,
expect(group.hooks.size).to eq(1) merge_requests_events: true,
expect(group.hooks.first).to have_attributes(hook_params) note_events: true,
pipeline_events: true,
push_events: true,
tag_push_events: true,
token: "TEST TOKEN",
url: "http://example.com",
wiki_page_events: true
}
post :create, group_id: group.to_param, hook: hook_params
expect(response).to have_http_status(302)
expect(group.hooks.size).to eq(1)
expect(group.hooks.first).to have_attributes(hook_params)
end
end
end
context 'with group_webhooks disabled' do
before do
stub_licensed_features(group_webhooks: false)
end
describe 'GET #index' do
it 'renders a 404' do
get :index, group_id: group.to_param
expect(response).to have_http_status(404)
end
end end
end end
end end
require 'spec_helper'
feature 'Edit group settings', feature: true do
given(:user) { create(:user) }
given(:group) { create(:group, path: 'foo') }
background do
group.add_owner(user)
sign_in(user)
end
context 'with webhook feature enabled' do
it 'shows the menu item' do
stub_licensed_features(group_webhooks: true)
visit edit_group_path(group)
within('.sub-nav') do
expect(page).to have_link('Webhooks')
end
end
end
context 'with webhook feature enabled' do
it 'shows the menu item' do
stub_licensed_features(group_webhooks: false)
visit edit_group_path(group)
within('.sub-nav') do
expect(page).not_to have_link('Webhooks')
end
end
end
end
...@@ -27,6 +27,34 @@ describe Project, models: true do ...@@ -27,6 +27,34 @@ describe Project, models: true do
end end
end end
describe "#execute_hooks" do
context "group hooks" do
let(:group) { create(:group) }
let(:project) { create(:empty_project, namespace: group) }
let(:group_hook) { create(:group_hook, group: group, push_events: true) }
it 'executes the hook when the feature is enabled' do
stub_licensed_features(group_webhooks: true)
fake_service = double
expect(WebHookService).to receive(:new)
.with(group_hook, { some: 'info' }, 'push_hooks') { fake_service }
expect(fake_service).to receive(:async_execute)
project.execute_hooks(some: 'info')
end
it 'does not execute the hook when the feature is disabled' do
stub_licensed_features(group_webhooks: false)
expect(WebHookService).not_to receive(:new)
.with(group_hook, { some: 'info' }, 'push_hooks')
project.execute_hooks(some: 'info')
end
end
end
describe '#feature_available?' do describe '#feature_available?' do
let(:namespace) { build_stubbed(:namespace) } let(:namespace) { build_stubbed(:namespace) }
let(:project) { build_stubbed(:project, namespace: namespace) } let(:project) { build_stubbed(:project, namespace: namespace) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment