Add required authorization to all pages
[cs356-p2-videostore.git] / app / controllers / video_policy_controller.rb
1 class VideoPolicyController < ApplicationController
2
3   # Make sure that a user logs in before doing any action here
4   before_filter :authorize, :only => [:index, :list, :show]
5
6   # Only managers can do the following actions
7   before_filter :manager, :only => [:new, :create, :edit, :update, :destroy]
8
9   def index
10     list
11     render :action => 'list'
12   end
13
14   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15   verify :method => :post, :only => [ :destroy, :create, :update ],
16          :redirect_to => { :action => :list }
17
18   def list
19     @video_policy_pages, @video_policies = paginate :video_policies, :per_page => 10
20   end
21
22   def show
23     @video_policy = VideoPolicy.find(params[:id])
24   end
25
26   def new
27     @video_policy = VideoPolicy.new
28   end
29
30   def create
31     @video_policy = VideoPolicy.new(params[:video_policy])
32     if @video_policy.save
33       flash[:notice] = 'VideoPolicy was successfully created.'
34       redirect_to :action => 'list'
35     else
36       render :action => 'new'
37     end
38   end
39
40   def edit
41     @video_policy = VideoPolicy.find(params[:id])
42   end
43
44   def update
45     @video_policy = VideoPolicy.find(params[:id])
46     if @video_policy.update_attributes(params[:video_policy])
47       flash[:notice] = 'VideoPolicy was successfully updated.'
48       redirect_to :action => 'show', :id => @video_policy
49     else
50       render :action => 'edit'
51     end
52   end
53
54   def destroy
55     VideoPolicy.find(params[:id]).destroy
56     redirect_to :action => 'list'
57   end
58 end