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,6 +19,7 @@ ...@@ -19,6 +19,7 @@
%span %span
LDAP Group LDAP Group
- if @group.feature_available?(:group_webhooks)
= nav_link(path: 'hooks#index') do = nav_link(path: 'hooks#index') do
= link_to group_hooks_path(@group), title: 'Webhooks' do = link_to group_hooks_path(@group), title: 'Webhooks' do
%span %span
......
...@@ -9,6 +9,19 @@ describe Groups::HooksController do ...@@ -9,6 +9,19 @@ describe Groups::HooksController do
sign_in(user) sign_in(user)
end end
context 'with group_webhooks enabled' do
before do
stub_licensed_features(group_webhooks: true)
end
describe 'GET #index' do
it 'is successfull' do
get :index, group_id: group.to_param
expect(response).to have_http_status(200)
end
end
describe 'POST #create' do describe 'POST #create' do
it 'sets all parameters' do it 'sets all parameters' do
hook_params = { hook_params = {
...@@ -33,4 +46,19 @@ describe Groups::HooksController do ...@@ -33,4 +46,19 @@ describe Groups::HooksController do
expect(group.hooks.first).to have_attributes(hook_params) expect(group.hooks.first).to have_attributes(hook_params)
end end
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
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