projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
5737: Merge branch 'master' into 5737-ruby231
[arvados.git]
/
services
/
api
/
app
/
models
/
arvados_model.rb
diff --git
a/services/api/app/models/arvados_model.rb
b/services/api/app/models/arvados_model.rb
index 7b8f12ba54c2aa96ca98726c4c804e412982cda6..aed0309591e4ecbfa4c309747daee695417b16c8 100644
(file)
--- a/
services/api/app/models/arvados_model.rb
+++ b/
services/api/app/models/arvados_model.rb
@@
-1,10
+1,12
@@
require 'has_uuid'
require 'has_uuid'
+require 'record_filters'
class ArvadosModel < ActiveRecord::Base
self.abstract_class = true
include CurrentApiClient # current_user, current_api_client, etc.
include DbCurrentTime
class ArvadosModel < ActiveRecord::Base
self.abstract_class = true
include CurrentApiClient # current_user, current_api_client, etc.
include DbCurrentTime
+ extend RecordFilters
attr_protected :created_at
attr_protected :modified_by_user_uuid
attr_protected :created_at
attr_protected :modified_by_user_uuid
@@
-40,7
+42,13
@@
class ArvadosModel < ActiveRecord::Base
class AlreadyLockedError < StandardError
def http_status
class AlreadyLockedError < StandardError
def http_status
- 403
+ 422
+ end
+ end
+
+ class InvalidStateTransitionError < StandardError
+ def http_status
+ 422
end
end
end
end
@@
-231,7
+239,7
@@
class ArvadosModel < ActiveRecord::Base
end
def logged_attributes
end
def logged_attributes
- attributes.except
*Rails.configuration.unlogged_attributes
+ attributes.except
(*Rails.configuration.unlogged_attributes)
end
def self.full_text_searchable_columns
end
def self.full_text_searchable_columns
@@
-252,8
+260,29
@@
class ArvadosModel < ActiveRecord::Base
"to_tsvector('english', ' ' || #{parts.join(" || ' ' || ")})"
end
"to_tsvector('english', ' ' || #{parts.join(" || ' ' || ")})"
end
+ def self.apply_filters query, filters
+ ft = record_filters filters, self
+ if not ft[:cond_out].any?
+ return query
+ end
+ query.where('(' + ft[:cond_out].join(') AND (') + ')',
+ *ft[:param_out])
+ end
+
protected
protected
+ def self.deep_sort_hash(x)
+ if x.is_a? Hash
+ x.sort.collect do |k, v|
+ [k, deep_sort_hash(v)]
+ end.to_h
+ elsif x.is_a? Array
+ x.collect { |v| deep_sort_hash(v) }
+ else
+ x
+ end
+ end
+
def ensure_ownership_path_leads_to_user
if new_record? or owner_uuid_changed?
uuid_in_path = {owner_uuid => true, uuid => true}
def ensure_ownership_path_leads_to_user
if new_record? or owner_uuid_changed?
uuid_in_path = {owner_uuid => true, uuid => true}
@@
-461,7
+490,7
@@
class ArvadosModel < ActiveRecord::Base
end
def foreign_key_attributes
end
def foreign_key_attributes
- attributes.keys.select { |a| a.match
/_uuid$/
}
+ attributes.keys.select { |a| a.match
(/_uuid$/)
}
end
def skip_uuid_read_permission_check
end
def skip_uuid_read_permission_check
@@
-476,7
+505,7
@@
class ArvadosModel < ActiveRecord::Base
foreign_key_attributes.each do |attr|
attr_value = send attr
if attr_value.is_a? String and
foreign_key_attributes.each do |attr|
attr_value = send attr
if attr_value.is_a? String and
- attr_value.match
/^[0-9a-f]{32,}(\+[@\w]+)*$/
+ attr_value.match
(/^[0-9a-f]{32,}(\+[@\w]+)*$/)
begin
send "#{attr}=", Collection.normalize_uuid(attr_value)
rescue
begin
send "#{attr}=", Collection.normalize_uuid(attr_value)
rescue
@@
-501,7
+530,7
@@
class ArvadosModel < ActiveRecord::Base
end
def self.uuid_like_pattern
end
def self.uuid_like_pattern
- "
_____
-#{uuid_prefix}-_______________"
+ "
#{Rails.configuration.uuid_prefix}
-#{uuid_prefix}-_______________"
end
def self.uuid_regex
end
def self.uuid_regex
@@
-555,13
+584,12
@@
class ArvadosModel < ActiveRecord::Base
unless uuid.is_a? String
return nil
end
unless uuid.is_a? String
return nil
end
- resource_class = nil
uuid.match HasUuid::UUID_REGEX do |re|
return uuid_prefixes[re[1]] if uuid_prefixes[re[1]]
end
uuid.match HasUuid::UUID_REGEX do |re|
return uuid_prefixes[re[1]] if uuid_prefixes[re[1]]
end
- if uuid.match
/.+@.+/
+ if uuid.match
(/.+@.+/)
return Email
end
return Email
end
@@
-607,7
+635,7
@@
class ArvadosModel < ActiveRecord::Base
end
def log_destroy
end
def log_destroy
- log_change('de
stroy
') do |log|
+ log_change('de
lete
') do |log|
log.fill_properties('old', etag(@old_attributes), @old_logged_attributes)
log.update_to nil
end
log.fill_properties('old', etag(@old_attributes), @old_logged_attributes)
log.update_to nil
end