OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / app / models / panel_picture.rb
index 31c4305..0dbcdc2 100644 (file)
@@ -12,6 +12,18 @@ class PanelPicture < ActiveRecord::Base
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
+  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 flip
     res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
     res += '/' unless res.empty?
@@ -80,4 +92,20 @@ class PanelPicture < ActiveRecord::Base
     PanelPicture.find(:all, opt)
   end
   
+  def self.show cid, au
+    opt = {}
+    opt.merge!(PanelPicture.show_opt)
+    res = PanelPicture.find(cid, opt)
+    raise ActiveRecord::Forbidden unless res.visible?(au)
+    res
+  end
+  
+  def self.show_opt
+    {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
+  end
+  
+  def self.show_json_opt
+    {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
+  end
+  
 end