OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / app / models / panel_color.rb
index f97eb55..d9d1713 100644 (file)
@@ -11,6 +11,18 @@ class PanelColor < ActiveRecord::Base
   def overwrite
   end
   
+  def visible? au
+    if au == nil
+      return false if MagicNumber['run_mode'] == 1
+    elsif au.is_a?(Author)
+    elsif au.is_a?(Admin)
+      return true
+    else
+      return false
+    end
+    self.panel.publish?
+  end
+  
   def self.default_page_size
     25
   end
@@ -56,4 +68,20 @@ class PanelColor < ActiveRecord::Base
     PanelColor.find(:all, opt)
   end
   
+  def self.show cid, au
+    opt = {}
+    opt.merge!(PanelColor.show_opt)
+    res = PanelColor.find(cid, opt)
+    raise ActiveRecord::Forbidden unless res.visible?(au)
+    res
+  end
+  
+  def self.show_opt
+    {:include => {:panel => {:author => {}} }}
+  end
+  
+  def self.show_json_opt
+    {:include => {:panel => {:include => {:author => {}}} }}
+  end
+  
 end