OSDN Git Service

t#29705:create story show
[pettanr/pettanr.git] / app / models / story.rb
index ba150a0..5bfb195 100644 (file)
@@ -23,6 +23,17 @@ class Story < ActiveRecord::Base
     self.author_id == au.id
   end
   
+  def visible? au
+    if au == nil
+      return false if MagicNumber['run_mode'] == 1
+    elsif au.is_a?(Author)
+      return true if self.comic.own?(au)
+    else
+      return false
+    end
+    self.comic.visible? au
+  end
+  
   def self.default_panel_size
     30
   end
@@ -90,6 +101,14 @@ class Story < ActiveRecord::Base
     Story.find(:all, opt)
   end
   
+  def self.show sid, au
+    opt = {}
+    opt.merge!(Story.show_opt)
+    res = Story.find sid, opt
+    raise ActiveRecord::Forbidden unless res.visible?(au)
+    res
+  end
+  
   def self.edit sid, au
     opt = {}
     opt.merge!(Story.show_opt)