Merge branch 'master' into 5493-getting-started-modal
[arvados.git] / services / api / app / models / repository.rb
1 class Repository < ArvadosModel
2   include HasUuid
3   include KindAndEtag
4   include CommonApiTemplate
5
6   api_accessible :user, extend: :common do |t|
7     t.add :name
8     t.add :fetch_url
9     t.add :push_url
10   end
11
12   def push_url
13     super || self.name && "git@git.#{Rails.configuration.uuid_prefix}.arvadosapi.com:#{self.name}.git"
14   end
15
16   def fetch_url
17     super || push_url
18   end
19
20   protected
21
22   def permission_to_create
23     current_user and current_user.is_admin
24   end
25
26   def permission_to_update
27     return false if not current_user
28     return true if current_user.is_admin
29     # For normal objects, this is a way to check whether you have
30     # write permission. Repositories should be brought closer to the
31     # normal permission model during #4253. Meanwhile, we'll
32     # special-case this so arv-git-httpd can detect write permission:
33     return super if changed_attributes.keys - ['modified_at', 'updated_at'] == []
34     false
35   end
36 end