Commit 1377962b800b179c8e073186563ed2529472ec51

Authored by Dhruv Kapadia
1 parent fc64b664

Making sure authencation in place, removing legacy code

app/controllers/items_controller.rb
1 1 class ItemsController < ApplicationController
  2 + before_filter :authenticate
2 3 # GET /items
3 4 # GET /items.xml
4 5 def index
... ...
app/controllers/prompts_controller.rb
1 1 class PromptsController < InheritedResources::Base
2 2 respond_to :xml, :json
3   - actions :show, :index
  3 + actions :show
4 4 belongs_to :question
5   - has_scope :active, :boolean => true, :only => :index
6 5  
7 6 has_scope :voted_on_by
8   - before_filter :authenticate, :only => [:vote, :skip]
9   -
10   -
11   - def activate
12   - # turning off auth for now: @question = current_user.questions.find(params[:question_id])
13   - @question = Question.find(params[:question_id])
14   - @prompt = @question.prompts.find(params[:id])
15   - respond_to do |format|
16   - if @prompt.activate!
17   - format.xml { render :xml => @choice.to_xml, :status => :created }
18   - format.json { render :json => @choice.to_json, :status => :created }
19   - else
20   - format.xml { render :xml => @choice.errors, :status => :unprocessable_entity }
21   - format.json { render :json => @choice.to_json }
22   - end
23   - end
24   - end
25   -
  7 + before_filter :authenticate
26 8  
27 9 # To record a vote
28 10 # required parameters - prompt id, ordinality, visitor_identifer?
... ... @@ -65,26 +47,6 @@ class PromptsController &lt; InheritedResources::Base
65 47 end
66 48 end
67 49  
68   -
69   -
70   -
71   -
72   - def suspend
73   - @question = current_user.questions.find(params[:question_id])
74   - @prompt = @question.prompts.find(params[:id])
75   - respond_to do |format|
76   - if @prompt.suspend!
77   - format.xml { render :xml => @prompt.to_xml, :status => :created }
78   - format.json { render :json => @prompt.to_json, :status => :created }
79   - else
80   - format.xml { render :xml => @prompt.errors, :status => :unprocessable_entity }
81   - format.json { render :json => @prompt.to_json }
82   - end
83   - end
84   - end
85   -
86   -
87   -
88 50 def skip
89 51 logger.info "#{current_user.inspect} is skipping."
90 52 @question = Question.find(params[:question_id])
... ... @@ -134,47 +96,8 @@ class PromptsController &lt; InheritedResources::Base
134 96 end
135 97  
136 98  
137   - # GET /prompts
138   - # ==== Return
139   - # Array of length n. Prompts matching parameters
140   - # ==== Options (params)
141   - # question_id<String>:: Converted to integer. Must be greater than 0 and
142   - # belong to the current user. Must belong to user.
143   - # item_ids<String>:: Comma seperated list of items to include. May only
144   - # include commas and digits. Must belong to user. Optional value.
145   - # data<String>:: Flag for whether to include item data. Data included
146   - # if value is not nil.
147   - # ==== Raises
148   - # PermissionError:: If question or any item doesn't belong to current user.
149   -
150   - def index
151   - # turning off auth for now: @question = current_user.questions.find(params[:question_id])
152   - #authenticate
153   - @question = Question.find(params[:question_id])
154   - @prompts = @question.prompts
155   - #raise @question.inspect
156   - index! do |format|
157   - if !params[:voter_id].blank?
158   - format.xml { render :xml => User.find(params[:voter_id]).prompts_voted_on.to_xml(:include => [:items, :votes],
159   - :methods => [ :active_items_count,
160   - :all_items_count,
161   - :votes_count ]) }
162   - format.json { render :json => User.find(params[:voter_id]).prompts_voted_on.to_json(:include => [:items, :votes],
163   - :methods => [ :active_items_count,
164   - :all_items_count,
165   - :votes_count ]) }
166   - else
167   - format.xml { render :xml => params[:data].blank? ?
168   - @prompts.to_xml :
169   - @prompts.to_xml(:include => [:items])
170   - }
171   - format.json { render :json => params[:data].blank? ? @prompts.to_json : @prompts.to_json(:include => [:items]) }
172   - end
173   - end
174   - end
175   -
176 99 def show
177   - @question = Question.find(params[:question_id])
  100 + @question = current_user.questions.find(params[:question_id])
178 101 @prompt = @question.prompts.find(params[:id], :include => [{ :left_choice => :item }, { :right_choice => :item }])
179 102 show! do |format|
180 103 format.xml { render :xml => @prompt.to_xml(:methods => [:left_choice_text, :right_choice_text])}
... ...