1 class ApiClientAuthorization < ArvadosModel
3 include CommonApiTemplate
7 after_initialize :assign_random_api_token
8 serialize :scopes, Array
10 api_accessible :user, extend: :common do |t|
15 t.add :created_by_ip_address
16 t.add :default_owner_uuid
19 t.add :last_used_by_ip_address
23 UNLOGGED_CHANGES = ['last_used_at', 'last_used_by_ip_address', 'updated_at']
25 def assign_random_api_token
26 self.api_token ||= rand(2**256).to_s(36)
33 self.user_id_changed? ? User.find(self.user_id_was).andand.uuid : self.user.andand.uuid
35 def owner_uuid_changed?
47 self.api_token_changed?
50 def modified_by_client_uuid
53 def modified_by_client_uuid=(x) end
55 def modified_by_user_uuid
58 def modified_by_user_uuid=(x) end
63 def modified_at=(x) end
66 attrs = attributes.dup
67 attrs.delete('api_token')
73 def permission_to_create
74 current_user.andand.is_admin or (current_user.andand.id == self.user_id)
77 def permission_to_update
78 (permission_to_create and
79 not self.user_id_changed? and
80 not self.owner_uuid_changed?)
84 super unless (changed - UNLOGGED_CHANGES).empty?