Commit f66daa0b authored by Stan Hu's avatar Stan Hu

Disable push and tag push events for the primary Geo system hook

Closes #1752
parent de5170d2
......@@ -141,6 +141,8 @@ class GeoNode < ActiveRecord::Base
if self.primary?
self.oauth_application = nil
update_clone_url
self.system_hook.push_events = false
self.system_hook.tag_push_events = false
else
update_oauth_application!
update_system_hook!
......
class RemovePushEventsFromGeoPrimarySystemHook < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
# Older version of Geo added push and tag push events to the
# primary system hook. This would cause unnecessary hooks to be
# fired.
def up
return unless geo_enabled?
execute <<-SQL
UPDATE web_hooks
SET push_events = false, tag_push_events = false WHERE
type = 'SystemHook' AND
id = (
SELECT system_hook_id FROM geo_nodes WHERE
host = #{quote(Gitlab.config.gitlab.host)} AND
port = #{quote(Gitlab.config.gitlab.port)} AND
relative_url_root = #{quote(Gitlab.config.gitlab.relative_url_root)});
SQL
end
def geo_enabled?
select_all("SELECT 1 FROM geo_nodes").present?
end
end
......@@ -46,6 +46,20 @@ describe GeoNode, type: :model do
end
end
context 'system hooks' do
it 'primary creates a system hook with no push events' do
hook = primary_node.system_hook
expect(hook.push_events).to be_falsey
expect(hook.tag_push_events).to be_falsey
end
it 'secondary creates a system hook with push events' do
hook = new_node.system_hook
expect(hook.push_events).to be_truthy
expect(hook.tag_push_events).to be_truthy
end
end
context 'prevent locking yourself out' do
subject do
GeoNode.new(host: Gitlab.config.gitlab.host,
......
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