1 class AuthorizedKey < ArvadosModel
4 include CommonApiTemplate
5 before_create :permission_to_set_authorized_user_uuid
6 before_update :permission_to_set_authorized_user_uuid
8 belongs_to :authorized_user, :foreign_key => :authorized_user_uuid, :class_name => 'User', :primary_key => :uuid
10 api_accessible :user, extend: :common do |t|
13 t.add :authorized_user_uuid
18 def permission_to_set_authorized_user_uuid
19 # Anonymous users cannot do anything here
20 return false if !current_user
22 # Administrators can attach a key to any user account
23 return true if current_user.is_admin
25 # All users can attach keys to their own accounts
26 return true if current_user.uuid == authorized_user_uuid