projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into 10293-cwl-cr-output
[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 8ae3e43fecdd5dd371e41ec9d0d5ecc9b4d8deca..18d5647cc929e760a72ed48ed709a9d18b8da8a3 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
@@
-199,6
+207,7
@@
class ArvadosModel < ActiveRecord::Base
# authorized users themselves) is an object's owner_uuid, that
# object is readable.
owner_uuids = user_uuids + users_list.flat_map { |u| u.groups_i_can(:read) }
# authorized users themselves) is an object's owner_uuid, that
# object is readable.
owner_uuids = user_uuids + users_list.flat_map { |u| u.groups_i_can(:read) }
+ owner_uuids.uniq!
sql_conds = []
sql_table = kwargs.fetch(:table_name, table_name)
sql_conds = []
sql_table = kwargs.fetch(:table_name, table_name)
@@
-251,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}
@@
-500,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
@@
-606,7
+636,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