OSDN Git Service

t#30473:fix authenticate
[pettanr/pettanr.git] / app / controllers / system_pictures_controller.rb
1 class SystemPicturesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => []
5   else
6     before_filter :authenticate_resource_reader, :only => [:index, :show]
7     before_filter :authenticate_user, :only => []
8   end
9   before_filter :authenticate_admin!, :only => [:list, :browse, :new, :create]
10
11   # GET /system_pictures
12   # GET /system_pictures.json
13   def index
14     @page = SystemPicture.page params[:page]
15     @page_size = SystemPicture.page_size params[:page_size]
16     @system_pictures = SystemPicture.list(@page, @page_size)
17
18     respond_to do |format|
19       format.html # index.html.erb
20       format.json { render json: @system_pictures.to_json(SystemPicture.list_json_opt) }
21     end
22   end
23
24   # GET /system_pictures/1
25   # GET /system_pictures/1.json
26   def show
27     @system_picture = SystemPicture.show(params[:id], @author)
28     
29     respond_to do |format|
30       opt = {:type => @system_picture.mime_type, :disposition=>"inline"}
31       format.png { send_data(@system_picture.restore, opt ) }
32       format.gif { send_data(@system_picture.restore, opt ) }
33       format.jpeg { send_data(@system_picture.restore, opt ) }
34       format.html # show.html.erb
35       format.json { render json: @system_picture.to_json(SystemPicture.show_json_opt)}
36     end
37   end
38
39   def list
40     @system_pictures = SystemPicture.all
41
42     respond_to do |format|
43       format.html { render layout: 'system' }
44       format.json { render json: @system_pictures }
45     end
46   end
47
48   def browse
49     @system_picture = SystemPicture.find(params[:id])
50
51     respond_to do |format|
52       format.html { render layout: 'system' }
53       format.json { render json: @system_picture}
54     end
55   end
56
57 end