X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ebdaedbc54c80730733c61cecb3998e26cf5ee7b..f308830adff32b6cccd7e0720dec20c42a1bed60:/apps/workbench/app/models/arvados_base.rb diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index c08d7475a7..8e1cfae8a2 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class ArvadosBase < ActiveRecord::Base self.abstract_class = true attr_accessor :attribute_sortkey @@ -76,10 +80,12 @@ class ArvadosBase < ActiveRecord::Base serialize k, coldef[:type].constantize end define_method k do - unless new_record? or @loaded_attributes.include? k - raise ActiveModel::MissingAttributeError, "missing attribute: #{k}" + unless new_record? or @loaded_attributes.include? k.to_s + Rails.logger.debug "BUG: access non-loaded attribute #{k}" + # We should... + # raise ActiveModel::MissingAttributeError, "missing attribute: #{k}" end - super + super() end @attribute_info[k] = coldef end @@ -142,10 +148,22 @@ class ArvadosBase < ActiveRecord::Base ArvadosResourceList.new(self).select(*args) end + def self.with_count(*args) + ArvadosResourceList.new(self).with_count(*args) + end + def self.distinct(*args) ArvadosResourceList.new(self).distinct(*args) end + def self.include_trash(*args) + ArvadosResourceList.new(self).include_trash(*args) + end + + def self.recursive(*args) + ArvadosResourceList.new(self).recursive(*args) + end + def self.eager(*args) ArvadosResourceList.new(self).eager(*args) end @@ -212,8 +230,8 @@ class ArvadosBase < ActiveRecord::Base end end - @new_record = false changes_applied + @new_record = false self end @@ -296,8 +314,8 @@ class ArvadosBase < ActiveRecord::Base end end @all_links = nil - @new_record = false changes_applied + @new_record = false self end @@ -332,7 +350,7 @@ class ArvadosBase < ActiveRecord::Base end def self.creatable? - current_user.andand.is_active + current_user.andand.is_active && api_exists?(:create) end def self.goes_in_projects? @@ -355,6 +373,14 @@ class ArvadosBase < ActiveRecord::Base (ArvadosBase.find(owner_uuid).writable_by.include? current_user.uuid rescue false)))) or false end + def deletable? + editable? + end + + def self.api_exists?(method) + arvados_api_client.discovery[:resources][self.to_s.underscore.pluralize.to_sym].andand[:methods].andand[method] + end + # Array of strings that are the names of attributes that can be edited # with X-Editable. def editable_attributes