1 class Repository < ArvadosModel
4 include CommonApiTemplate
6 # Order is important here. We must validate the owner before we can
9 validate :name_format, :if => Proc.new { |r| r.errors[:owner_uuid].empty? }
10 validates(:name, uniqueness: true, allow_nil: false)
12 api_accessible :user, extend: :common do |t|
18 def self.attributes_required_columns
19 super.merge({"push_url" => ["name"], "fetch_url" => ["name"]})
23 "git@git.%s.arvadosapi.com:%s.git" % [Rails.configuration.uuid_prefix, name]
31 # Find where the repository is stored on the API server's filesystem,
32 # and return that path, or nil if not found.
33 # This method is only for the API server's internal use, and should not
34 # be exposed through the public API. Following our current gitolite
35 # setup, it searches for repositories stored by UUID, then name; and it
36 # prefers bare repositories over checkouts.
37 [["%s.git"], ["%s", ".git"]].each do |repo_base, *join_args|
38 [:uuid, :name].each do |path_attr|
39 git_dir = File.join(Rails.configuration.git_repositories_dir,
40 repo_base % send(path_attr), *join_args)
41 return git_dir if File.exist?(git_dir)
49 def permission_to_update
52 elsif current_user.is_admin
55 current_user.uuid == owner_uuid
62 User.find_by_uuid(owner_uuid)
66 if owner.nil? or (owner.username.nil? and (owner.uuid != system_user_uuid))
67 errors.add(:owner_uuid, "must refer to a user with a username")
73 if owner.uuid == system_user_uuid
75 errmsg_start = "must be"
77 prefix_match = Regexp.escape(owner.username + "/")
78 errmsg_start = "must be the owner's username, then '/', then"
80 if not /^#{prefix_match}[A-Za-z][A-Za-z0-9]*$/.match(name)
82 "#{errmsg_start} a letter followed by alphanumerics")