Commit 7ad4d842 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Linked GeoNode with auto generated system hook.

parent b39935f7
......@@ -13,6 +13,7 @@
class GeoNode < ActiveRecord::Base
belongs_to :geo_node_key, dependent: :destroy
belongs_to :oauth_application, class_name: 'Doorkeeper::Application', dependent: :destroy
belongs_to :system_hook, dependent: :destroy
default_values schema: 'http',
host: lambda { Gitlab.config.gitlab.host },
......@@ -61,8 +62,8 @@ class GeoNode < ActiveRecord::Base
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_wikis").to_s
end
def notify_key_url
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_key").to_s
def geo_events_url
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/receive_events").to_s
end
def oauth_callback_url
......@@ -89,13 +90,19 @@ class GeoNode < ActiveRecord::Base
def update_dependents_attributes
self.geo_node_key.title = "Geo node: #{self.url}" if self.geo_node_key
self.token = SecureRandom.hex(20) if self.token.empty?
if self.primary?
self.oauth_application = nil
else
# OAuth Application
self.build_oauth_application if oauth_application.nil?
self.oauth_application.name = "Geo node: #{self.url}"
self.oauth_application.redirect_uri = oauth_callback_url
# SystemHook
self.build_system_hook if system_hook.nil?
self.system_hook.url = geo_events_url
self.system_hook.token = token
end
end
......
class AddTokenToGeoNode < ActiveRecord::Migration
def change
add_column :geo_nodes, :token, :string
# Add token to existing nodes
GeoNode.where(token: nil).each do |node|
node.token = SecureRandom.hex(20)
node.save!
end
end
end
class AddSystemHookToGeoNode < ActiveRecord::Migration
def change
change_table :geo_nodes do |t|
t.references :system_hook
end
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160414032323) do
ActiveRecord::Schema.define(version: 20160414064845) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -421,6 +421,7 @@ ActiveRecord::Schema.define(version: 20160414032323) do
t.integer "geo_node_key_id"
t.integer "oauth_application_id"
t.string "token"
t.integer "system_hook_id"
end
add_index "geo_nodes", ["geo_node_key_id"], name: "index_geo_nodes_on_geo_node_key_id", using: :btree
......
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