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|
19 def self.attributes_required_columns
20 super.merge("clone_urls" => ["name"],
21 "fetch_url" => ["name"],
22 "push_url" => ["name"])
25 # Deprecated. Use clone_urls instead.
30 # Deprecated. Use clone_urls instead.
36 [ssh_clone_url, https_clone_url].compact
40 # Find where the repository is stored on the API server's filesystem,
41 # and return that path, or nil if not found.
42 # This method is only for the API server's internal use, and should not
43 # be exposed through the public API. Following our current gitolite
44 # setup, it searches for repositories stored by UUID, then name; and it
45 # prefers bare repositories over checkouts.
46 [["%s.git"], ["%s", ".git"]].each do |repo_base, *join_args|
47 [:uuid, :name].each do |path_attr|
48 git_dir = File.join(Rails.configuration.git_repositories_dir,
49 repo_base % send(path_attr), *join_args)
50 return git_dir if File.exist?(git_dir)
58 def permission_to_update
61 elsif current_user.is_admin
64 current_user.uuid == owner_uuid
71 User.find_by_uuid(owner_uuid)
75 if owner.nil? or (owner.username.nil? and (owner.uuid != system_user_uuid))
76 errors.add(:owner_uuid, "must refer to a user with a username")
82 if owner.uuid == system_user_uuid
84 errmsg_start = "must be"
86 prefix_match = Regexp.escape(owner.username + "/")
87 errmsg_start = "must be the owner's username, then '/', then"
89 if not (/^#{prefix_match}[A-Za-z][A-Za-z0-9]*$/.match(name))
91 "#{errmsg_start} a letter followed by alphanumerics")
97 _clone_url :git_repo_ssh_base, 'git@git.%s.arvadosapi.com:'
101 _clone_url :git_repo_https_base, 'https://git.%s.arvadosapi.com/'
104 def _clone_url config_var, default_base_fmt
105 configured_base = Rails.configuration.send config_var
106 return nil if configured_base == false
107 prefix = new_record? ? Rails.configuration.uuid_prefix : uuid[0,5]
108 if prefix == Rails.configuration.uuid_prefix and configured_base != true
109 base = configured_base
111 base = default_base_fmt % prefix
113 '%s%s.git' % [base, name]