3775: Merge branch 'master' into 3775-fetch-git-repo
[arvados.git] / apps / workbench / app / models / arvados_base.rb
index 6d427fdda1114658f09b3ed054e1856636a5cc1e..e0e93b9e2d0828cef0149f95fe51c817260ef3c7 100644 (file)
@@ -131,6 +131,10 @@ class ArvadosBase < ActiveRecord::Base
     ArvadosResourceList.new(self).limit(*args)
   end
 
+  def self.select(*args)
+    ArvadosResourceList.new(self).select(*args)
+  end
+
   def self.eager(*args)
     ArvadosResourceList.new(self).eager(*args)
   end
@@ -163,7 +167,9 @@ class ArvadosBase < ActiveRecord::Base
   def save
     obdata = {}
     self.class.columns.each do |col|
-      obdata[col.name.to_sym] = self.send(col.name.to_sym)
+      unless self.send(col.name.to_sym).nil? and !self.changed.include?(col.name)
+          obdata[col.name.to_sym] = self.send(col.name.to_sym)
+      end
     end
     obdata.delete :id
     postdata = { self.class.to_s.underscore => obdata }
@@ -299,6 +305,11 @@ class ArvadosBase < ActiveRecord::Base
     self.to_s.underscore.humanize
   end
 
+  # Array of strings that are names of attributes that should be rendered as textile.
+  def textile_attributes
+    []
+  end
+
   def self.creatable?
     current_user
   end
@@ -307,16 +318,22 @@ class ArvadosBase < ActiveRecord::Base
     false
   end
 
+  # can this class of object be copied into a project?
+  # override to false on indivudal model classes for which this should not be true
+  def self.copies_to_projects?
+    self.goes_in_projects?
+  end
+
   def editable?
     (current_user and current_user.is_active and
      (current_user.is_admin or
       current_user.uuid == self.owner_uuid or
       new_record? or
-      (writable_by.include? current_user.uuid rescue false)))
+      (writable_by.include? current_user.uuid rescue false))) or false
   end
 
   def attribute_editable?(attr, ever=nil)
-    if "created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at".index(attr.to_s)
+    if %w(created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at).include? attr.to_s
       false
     elsif not (current_user.andand.is_active)
       false
@@ -362,7 +379,7 @@ class ArvadosBase < ActiveRecord::Base
     self.class.to_s.underscore
   end
 
-  def friendly_link_name
+  def friendly_link_name lookup=nil
     (name if self.respond_to? :name) || default_name
   end