@attribute_sortkey ||= {
'id' => nil,
'uuid' => '000',
- 'owner' => '001',
+ 'owner_uuid' => '001',
'created_at' => '002',
'modified_at' => '003',
- 'modified_by_user' => '004',
- 'modified_by_client' => '005',
+ 'modified_by_user_uuid' => '004',
+ 'modified_by_client_uuid' => '005',
'name' => '050',
'tail_kind' => '100',
'tail_uuid' => '100',
def self.columns
return @columns unless @columns.nil?
@columns = []
+ @attribute_info ||= {}
return @columns if $arvados_api_client.arvados_schema[self.to_s.to_sym].nil?
$arvados_api_client.arvados_schema[self.to_s.to_sym].each do |coldef|
k = coldef[:name].to_sym
serialize k, coldef[:type].constantize
end
attr_accessible k
+ @attribute_info[k] = coldef
end
attr_reader :etag
attr_reader :kind
def self.column(name, sql_type = nil, default = nil, null = true)
ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
+ def self.attribute_info
+ self.columns
+ @attribute_info
+ end
def self.find(uuid)
if uuid.class != String or uuid.length < 27 then
raise 'argument to find() must be a uuid string. Acceptable formats: warehouse locator or string with format xxxxx-xxxxx-xxxxxxxxxxxxxxx'
end
new.private_reload(uuid)
end
+ def self.order(*args)
+ ArvadosResourceList.new(self).order(*args)
+ end
def self.where(*args)
ArvadosResourceList.new(self).where(*args)
end
@kind = resp[:kind]
# these attrs can be modified by "save" -- we should update our copies
- %w(uuid owner created_at
- modified_at modified_by_user modified_by_client
+ %w(uuid owner_uuid created_at
+ modified_at modified_by_user_uuid modified_by_client_uuid
).each do |attr|
- self.send(attr + '=', resp[attr.to_sym])
+ if self.respond_to? "#{attr}=".to_sym
+ self.send(attr + '=', resp[attr.to_sym])
+ end
end
self
def save!
self.save or raise Exception.new("Save failed")
end
+
+ def destroy
+ if etag || uuid
+ postdata = { '_method' => 'DELETE' }
+ resp = $arvados_api_client.api(self.class, '/' + uuid, postdata)
+ resp[:etag] && resp[:uuid] && resp
+ else
+ true
+ end
+ end
+
def links(*args)
o = {}
o.merge!(args.pop) if args[-1].is_a? Hash
}
end
+ def self.creatable?
+ current_user
+ end
+
def editable?
- (current_user and
+ (current_user and current_user.is_active and
(current_user.is_admin or
- current_user.uuid == self.owner))
+ current_user.uuid == self.owner_uuid))
end
def attribute_editable?(attr)
- if "created_at modified_at modified_by_user modified_by_client updated_at".index(attr.to_s)
+ if "created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at".index(attr.to_s)
+ false
+ elsif not (current_user.andand.is_active)
false
- elsif "uuid owner".index(attr.to_s)
- current_user and current_user.is_admin
+ elsif "uuid owner_uuid".index(attr.to_s) or current_user.is_admin
+ current_user.is_admin
else
- true
+ current_user.uuid == self.owner_uuid or current_user.uuid == self.uuid
end
end
self
end
- def current_user
+ def self.current_user
+ Thread.current[:user] ||= User.current if Thread.current[:arvados_api_token]
Thread.current[:user]
end
+ def current_user
+ self.class.current_user
+ end
end