Merge branch 'master' into 10645-cr-mounts-display
[arvados.git] / apps / workbench / app / models / arvados_base.rb
index e7db4728c80486160ae19fdbe259cc7f771960f0..5d6a4c94b9bebb581d771ce4b0557f3ba828e119 100644 (file)
@@ -76,8 +76,10 @@ 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()
         end
@@ -142,6 +144,10 @@ 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
@@ -332,7 +338,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 +361,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