OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index 8d31b6d..322abfe 100644 (file)
@@ -1,8 +1,14 @@
 class ResourcePicturesController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update]
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+  else
+    before_filter :authenticate_resource_reader, :only => [:index, :show, :credit]
+    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+  end
   before_filter :authenticate_admin!, :only => [:list, :browse]
-  before_filter :authenticate_artist, :only => [:new, :create]
 
   # GET /resource_pictures
   # GET /resource_pictures.json
@@ -20,7 +26,7 @@ class ResourcePicturesController < ApplicationController
   # GET /resource_pictures/1
   # GET /resource_pictures/1.json
   def show
-    @resource_picture = ResourcePicture.show(params[:id], @author)
+    @resource_picture = ResourcePicture.show(params[:id], [@user, @admin, @demand_user])
 
     respond_to do |format|
       opt = {:type => @resource_picture.mime_type, :disposition=>"inline"}
@@ -33,7 +39,7 @@ class ResourcePicturesController < ApplicationController
   end
   
   def credit
-    @resource_picture = ResourcePicture.show(params[:id], @author)
+    @resource_picture = ResourcePicture.show(params[:id], [@user, @admin, @demand_user])
 
     respond_to do |format|
       format.html { render :layout => false } # show.html.erb
@@ -86,6 +92,20 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
+  def destroy
+    @resource_picture = ResourcePicture.edit(params[:id], @artist)
+
+    respond_to do |format|
+      if @resource_picture.unpublish
+        format.html { redirect_to :controller => '/home', :action => :resource_picture }
+        format.json { head :ok }
+      else
+        format.html { redirect_to resource_picture_path(@resource_picture) }
+        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+  
   def count
     @resource_picture = {:count => ResourcePicture.visible_count}
     respond_to do |format|