Commit 85083b38 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added GeoNodeKey which will be used by readonly nodes to sync repos

parent 9dd9b607
......@@ -11,6 +11,8 @@
#
class GeoNode < ActiveRecord::Base
belongs_to :geo_node_key
default_value_for :schema, 'http'
default_value_for :port, 80
default_value_for :relative_url_root, ''
......
# == Schema Information
#
# Table name: keys
#
# id :integer not null, primary key
# user_id :integer
# created_at :datetime
# updated_at :datetime
# key :text
# title :string(255)
# type :string(255)
# fingerprint :string(255)
# public :boolean default(FALSE), not null
#
class GeoNodeKey < Key
has_many :geo_nodes
def orphaned?
self.geo_nodes.length == 0
end
def almost_orphaned?
self.geo_nodes.length == 1
end
def destroyed_when_orphaned?
true
end
end
class AddGeoNodeKeyToGeoNode < ActiveRecord::Migration
def change
change_table :geo_nodes do |t|
t.belongs_to :geo_node_key, index: true
end
end
end
......@@ -413,8 +413,10 @@ ActiveRecord::Schema.define(version: 20160302141317) do
t.integer "port"
t.string "relative_url_root"
t.boolean "primary"
t.integer "geo_node_key_id"
end
add_index "geo_nodes", ["geo_node_key_id"], name: "index_geo_nodes_on_geo_node_key_id", using: :btree
add_index "geo_nodes", ["host"], name: "index_geo_nodes_on_host", using: :btree
add_index "geo_nodes", ["primary"], name: "index_geo_nodes_on_primary", using: :btree
......
......@@ -20,6 +20,8 @@ module Gitlab
actor
when DeployKey
nil
when GeoNodeKey
nil
when Key
actor.user
end
......@@ -29,6 +31,10 @@ module Gitlab
actor if actor.is_a?(DeployKey)
end
def geo_node_key
actor if actor.is_a?(GeoNodeKey)
end
def can_push_to_branch?(ref)
return false unless user
......@@ -44,6 +50,8 @@ module Gitlab
user.can?(:read_project, project)
elsif deploy_key
deploy_key.projects.include?(project)
elsif geo_node_key
true
else
false
end
......@@ -77,7 +85,7 @@ module Gitlab
def download_access_check
if user
user_download_access_check
elsif deploy_key
elsif deploy_key || geo_node_key
build_status_object(true)
else
raise 'Wrong actor'
......
......@@ -115,6 +115,9 @@ FactoryGirl.define do
factory :deploy_key, class: 'DeployKey' do
end
factory :geo_node_key, class: 'GeoNodeKey' do
end
factory :personal_key do
user
end
......
......@@ -125,6 +125,17 @@ describe Gitlab::GitAccess, lib: true do
it { expect(subject.allowed?).to be_truthy }
end
end
describe 'geo node key permissions' do
let(:key) { build(:geo_node_key) }
let(:actor) { key }
context 'pull code' do
subject { access.download_access_check }
it { expect(subject.allowed?).to be_truthy }
end
end
end
describe 'push_access_check' do
......
# == Schema Information
#
# Table name: keys
#
# id :integer not null, primary key
# user_id :integer
# created_at :datetime
# updated_at :datetime
# key :text
# title :string(255)
# type :string(255)
# fingerprint :string(255)
# public :boolean default(FALSE), not null
#
require 'spec_helper'
describe GeoNodeKey, models: true do
let(:geo_node) { create(:geo_node) }
let(:geo_node_key) { create(:geo_node_key, geo_nodes: [geo_node]) }
describe 'Associations' do
it { is_expected.to have_many(:geo_nodes) }
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