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
# Authorize
before_action :group
before_action :authorize_admin_group!
before_action :ensure_feature_available!
respond_to :html
......@@ -68,4 +69,10 @@ class Groups::HooksController < Groups::ApplicationController
:wiki_page_events
)
end
def ensure_feature_available!
unless @group.feature_available?(:group_webhooks)
render_404
end
end
end
......@@ -221,7 +221,7 @@ module EE
def execute_hooks(data, hooks_scope = :push_hooks)
super
if group
if group && feature_available?(:group_webhooks)
group.hooks.send(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s)
end
......
......@@ -19,10 +19,11 @@
%span
LDAP Group
= nav_link(path: 'hooks#index') do
= link_to group_hooks_path(@group), title: 'Webhooks' do
%span
Webhooks
- if @group.feature_available?(:group_webhooks)
= nav_link(path: 'hooks#index') do
= link_to group_hooks_path(@group), title: 'Webhooks' do
%span
Webhooks
= nav_link(path: 'audit_events#index') do
= link_to group_audit_events_path(@group), title: 'Audit Events' do
......
......@@ -9,28 +9,56 @@ describe Groups::HooksController do
sign_in(user)
end
describe 'POST #create' do
it 'sets all parameters' do
hook_params = {
job_events: true,
confidential_issues_events: true,
enable_ssl_verification: true,
issues_events: true,
merge_requests_events: true,
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)
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
it 'sets all parameters' do
hook_params = {
job_events: true,
confidential_issues_events: true,
enable_ssl_verification: true,
issues_events: true,
merge_requests_events: true,
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
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
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
let(:namespace) { build_stubbed(: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