Commit 784d472e authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-license-check-group-webhooks' into 'master'

Add a license check for group-webhooks

Closes #2576

See merge request !2280
parents 2570140b 8b9dde86
......@@ -7,7 +7,7 @@ module EE
def method_missing(method_sym, *arguments, &block)
case method_sym.to_s
when /\Acheck_group_(.*)_available!\z/
when /\Acheck_(.*)_available!\z/
check_group_feature_available!($1.to_sym)
else
super
......
class Groups::AnalyticsController < Groups::ApplicationController
before_action :group
before_action :check_group_contribution_analytics_available!
before_action :check_contribution_analytics_available!
layout 'group'
......
......@@ -35,7 +35,7 @@ class Groups::ApplicationController < ApplicationController
def build_canonical_path(group)
params[:group_id] = group.to_param
url_for(params)
end
end
......@@ -2,6 +2,7 @@ class Groups::HooksController < Groups::ApplicationController
# Authorize
before_action :group
before_action :authorize_admin_group!
before_action :check_group_webhooks_available!
respond_to :html
......
......@@ -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
......
......@@ -10,6 +10,7 @@ class License < ActiveRecord::Base
FAST_FORWARD_MERGE_FEATURE = 'GitLab_FastForwardMerge'.freeze
FILE_LOCK_FEATURE = 'GitLab_FileLocks'.freeze
GEO_FEATURE = 'GitLab_Geo'.freeze
GROUP_WEBHOOKS_FEATURE = 'GroupWebhooks'.freeze
ISSUABLE_DEFAULT_TEMPLATES_FEATURE = 'GitLab_IssuableDefaultTemplates'.freeze
ISSUE_BOARDS_FOCUS_MODE_FEATURE = 'IssueBoardsFocusMode'.freeze
ISSUE_BOARD_MILESTONE_FEATURE = 'IssueBoardMilestone'.freeze
......@@ -37,6 +38,7 @@ class License < ActiveRecord::Base
export_issues: EXPORT_ISSUES_FEATURE,
fast_forward_merge: FAST_FORWARD_MERGE_FEATURE,
file_lock: FILE_LOCK_FEATURE,
group_webhooks: GROUP_WEBHOOKS_FEATURE,
issuable_default_templates: ISSUABLE_DEFAULT_TEMPLATES_FEATURE,
issue_board_focus_mode: ISSUE_BOARDS_FOCUS_MODE_FEATURE,
issue_board_milestone: ISSUE_BOARD_MILESTONE_FEATURE,
......@@ -58,6 +60,7 @@ class License < ActiveRecord::Base
{ ELASTIC_SEARCH_FEATURE => 1 },
{ EXPORT_ISSUES_FEATURE => 1 },
{ FAST_FORWARD_MERGE_FEATURE => 1 },
{ GROUP_WEBHOOKS_FEATURE => 1 },
{ ISSUABLE_DEFAULT_TEMPLATES_FEATURE => 1 },
{ ISSUE_BOARDS_FOCUS_MODE_FEATURE => 1 },
{ ISSUE_BOARD_MILESTONE_FEATURE => 1 },
......@@ -99,6 +102,7 @@ class License < ActiveRecord::Base
{ FAST_FORWARD_MERGE_FEATURE => 1 },
{ FILE_LOCK_FEATURE => 1 },
{ GEO_FEATURE => 1 },
{ GROUP_WEBHOOKS_FEATURE => 1 },
{ ISSUABLE_DEFAULT_TEMPLATES_FEATURE => 1 },
{ ISSUE_BOARDS_FOCUS_MODE_FEATURE => 1 },
{ ISSUE_BOARD_MILESTONE_FEATURE => 1 },
......
......@@ -13,24 +13,4 @@
%span
Projects
- if ldap_enabled?
= nav_link(path: 'ldap_group_links#index') do
= link_to group_ldap_group_links_path(@group), title: 'LDAP Group' do
%span
LDAP Group
= 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
%span
Audit Events
- if @group.shared_runners_enabled? && @group.shared_runners_minutes_limit_enabled?
= nav_link(path: 'pipeline_quota#index') do
= link_to group_pipeline_quota_path(@group), title: 'Pipelines quota' do
%span
Pipelines quota
= render 'groups/ee/settings_nav'
- if ldap_enabled?
= nav_link(path: 'ldap_group_links#index') do
= link_to group_ldap_group_links_path(@group), title: 'LDAP Group' do
%span
LDAP Group
- 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
%span
Audit Events
- if @group.shared_runners_enabled? && @group.shared_runners_minutes_limit_enabled?
= nav_link(path: 'pipeline_quota#index') do
= link_to group_pipeline_quota_path(@group), title: 'Pipelines quota' do
%span
Pipelines quota
......@@ -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