Commit 5316aa63 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added repair authentication button for GeoNodes

parent 88af5b85
......@@ -22,6 +22,20 @@ class Admin::GeoNodesController < Admin::ApplicationController
redirect_to admin_geo_nodes_path, notice: 'Node was successfully removed.'
end
def repair
@node = GeoNode.find(params[:id])
if @node.primary? || !@node.missing_oauth_application?
redirect_to admin_geo_nodes_path, notice: "This node doesn't need to be repaired."
elsif @node.save
redirect_to admin_geo_nodes_path, notice: 'Node Authentication was successfully repaired.'
else
redirect_to admin_geo_nodes_path, alert: 'There was a problem repairing Node Authentication.'
end
end
private
def geo_node_params
params.require(:geo_node).permit(:url, :primary, geo_node_key_attributes: [:key])
end
......
......@@ -72,7 +72,6 @@ class GeoNode < ActiveRecord::Base
def build_dependents
self.build_geo_node_key if geo_node_key.nil?
self.build_oauth_application if oauth_application.nil?
end
def update_dependents_attributes
......@@ -81,6 +80,7 @@ class GeoNode < ActiveRecord::Base
if self.primary?
self.oauth_application = nil
else
self.build_oauth_application if oauth_application.nil?
self.oauth_application.name = "Geo node: #{self.url}" if self.geo_node_key
self.oauth_application.redirect_uri = oauth_callback_url
end
......
......@@ -52,4 +52,8 @@
%span.help-block #{node.primary ? 'Primary node' : 'Secondary node'}
.pull-right
- if node.missing_oauth_application?
= link_to repair_admin_geo_node_path(node), method: :post, class: 'btn btn-default, btn-sm' do
= icon('exclamation-triangle fw')
Repair authentication
= link_to 'Remove', admin_geo_node_path(node), data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-remove btn-sm'
......@@ -282,7 +282,11 @@ Rails.application.routes.draw do
get :download, on: :member
end
resources :geo_nodes, only: [:index, :create, :destroy]
resources :geo_nodes, only: [:index, :create, :destroy] do
member do
post :repair
end
end
resources :labels
......
......@@ -4,6 +4,8 @@ describe GeoNode, type: :model do
subject(:new_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab') }
subject(:new_primary_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab', primary: true) }
subject(:empty_node) { described_class.new(schema: nil, host: nil, port: nil, relative_url_root: nil) }
subject(:primary_node) { FactoryGirl.create(:geo_node, :primary) }
subject(:node) { FactoryGirl.create(:geo_node) }
let(:dummy_url) { 'https://localhost:3000/gitlab' }
......@@ -62,35 +64,22 @@ describe GeoNode, type: :model do
expect(new_node.geo_node_key).to be_present
end
it 'initializes a corresponding oauth application' do
expect(new_node.oauth_application).to be_present
end
it 'is valid' do
expect(new_node).to be_valid
end
end
context 'on create' do
before(:each) do
new_node.geo_node_key_attributes = geo_node_key_attributes
new_primary_node.geo_node_key_attributes = geo_node_key_attributes
end
it 'saves a corresponding key' do
new_node.save!
expect(new_node.geo_node_key).to be_persisted
expect(node.geo_node_key).to be_persisted
end
it 'saves a corresponding oauth application if it is a secondary node' do
new_node.save!
expect(new_node.oauth_application).to be_persisted
expect(node.oauth_application).to be_persisted
end
it 'has no oauth_application if it is a primary node' do
new_primary_node.save!
expect(new_primary_node.oauth_application).not_to be_present
expect(primary_node.oauth_application).not_to be_present
end
end
end
......@@ -169,17 +158,18 @@ describe GeoNode, type: :model do
describe '#missing_oauth_application?' do
context 'on a primary node' do
it 'returns false' do
expect(new_primary_node).not_to be_missing_oauth_application
expect(primary_node).not_to be_missing_oauth_application
end
end
it 'returns false when present' do
expect(new_node).not_to be_missing_oauth_application
expect(node).not_to be_missing_oauth_application
end
it 'returns true when it is not present' do
new_node.oauth_application = nil
expect(new_node).to be_missing_oauth_application
node.oauth_application.destroy!
node.reload
expect(node).to be_missing_oauth_application
end
end
end
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