repo & project access separated. critical gitolite bugfix
This commit is contained in:
parent
2ca00bdb3e
commit
cb021e5831
12 changed files with 106 additions and 48 deletions
|
@ -23,7 +23,7 @@ class Key < ActiveRecord::Base
|
|||
c.update_keys(identifier, key)
|
||||
|
||||
projects.each do |project|
|
||||
c.update_project(project.path, project.repository_writers)
|
||||
c.update_project(project.path, project)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ class Key < ActiveRecord::Base
|
|||
c.delete_key(identifier)
|
||||
|
||||
projects.each do |project|
|
||||
c.update_project(project.path, project.repository_writers)
|
||||
c.update_project(project.path, project)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require "grit"
|
||||
|
||||
class Project < ActiveRecord::Base
|
||||
PROJECT_N = 0
|
||||
PROJECT_R = 1
|
||||
PROJECT_RW = 2
|
||||
PROJECT_RWA = 3
|
||||
|
||||
belongs_to :owner, :class_name => "User"
|
||||
|
||||
has_many :merge_requests, :dependent => :destroy
|
||||
|
@ -47,6 +52,16 @@ class Project < ActiveRecord::Base
|
|||
|
||||
scope :public_only, where(:private_flag => false)
|
||||
|
||||
|
||||
def self.access_options
|
||||
{
|
||||
"Denied" => PROJECT_N,
|
||||
"Read" => PROJECT_R,
|
||||
"Report" => PROJECT_RW,
|
||||
"Admin" => PROJECT_RWA
|
||||
}
|
||||
end
|
||||
|
||||
def repository
|
||||
@repository ||= Repository.new(self)
|
||||
end
|
||||
|
@ -109,21 +124,28 @@ class Project < ActiveRecord::Base
|
|||
users_projects.where(:project_id => self.id, :user_id => user.id).destroy if self.id
|
||||
end
|
||||
|
||||
def writers
|
||||
@writers ||= users_projects.includes(:user).where(:write => true).map(&:user)
|
||||
def repository_readers
|
||||
keys = Key.joins({:user => :users_projects}).
|
||||
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_R)
|
||||
keys.map(&:identifier)
|
||||
end
|
||||
|
||||
def repository_writers
|
||||
keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true)
|
||||
keys = Key.joins({:user => :users_projects}).
|
||||
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_RW)
|
||||
keys.map(&:identifier)
|
||||
end
|
||||
|
||||
def readers
|
||||
@readers ||= users_projects.includes(:user).where(:read => true).map(&:user)
|
||||
@readers ||= users_projects.includes(:user).where(:project_access => [PROJECT_R, PROJECT_RW, PROJECT_RWA]).map(&:user)
|
||||
end
|
||||
|
||||
def writers
|
||||
@writers ||= users_projects.includes(:user).where(:project_access => [PROJECT_RW, PROJECT_RWA]).map(&:user)
|
||||
end
|
||||
|
||||
def admins
|
||||
@admins ||=users_projects.includes(:user).where(:admin => true).map(&:user)
|
||||
@admins ||= users_projects.includes(:user).where(:project_access => PROJECT_RWA).map(&:user)
|
||||
end
|
||||
|
||||
def root_ref
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
require File.join(Rails.root, "lib", "gitlabhq", "git_host")
|
||||
|
||||
class Repository
|
||||
REPO_N = 0
|
||||
REPO_R = 1
|
||||
REPO_RW = 2
|
||||
|
||||
attr_accessor :project
|
||||
|
||||
def self.default_ref
|
||||
"master"
|
||||
end
|
||||
|
||||
def self.access_options
|
||||
{
|
||||
"Denied" => REPO_N,
|
||||
"Pull" => REPO_R,
|
||||
"Pull & Push" => REPO_RW
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(project)
|
||||
@project = project
|
||||
end
|
||||
|
@ -33,7 +45,7 @@ class Repository
|
|||
|
||||
def update_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.update_project(path, project.repository_writers)
|
||||
c.update_project(path, project)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,25 +4,20 @@ class UsersProject < ActiveRecord::Base
|
|||
|
||||
attr_protected :project_id, :project
|
||||
|
||||
after_commit :update_repository
|
||||
after_save :update_repository
|
||||
after_destroy :update_repository
|
||||
|
||||
validates_uniqueness_of :user_id, :scope => [:project_id]
|
||||
validates_presence_of :user_id
|
||||
validates_presence_of :project_id
|
||||
validate :user_has_a_role_selected
|
||||
|
||||
delegate :name, :email, :to => :user, :prefix => true
|
||||
|
||||
def update_repository
|
||||
Gitosis.new.configure do |c|
|
||||
c.update_project(project.path, project.repository)
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.update_project(project.path, project)
|
||||
end
|
||||
end
|
||||
|
||||
def user_has_a_role_selected
|
||||
errors.add(:base, "Please choose at least one Role in the Access list") unless read || write || admin
|
||||
end
|
||||
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue