Commit 37024235645ce4258b53dc5b8f931a2ebf4d31bb
1 parent
1100d1b7
Exists in
master
Display pairwise content in read only mode
Showing
8 changed files
with
76 additions
and
17 deletions
Show diff stats
controllers/profile/pairwise_plugin_profile_controller.rb
... | ... | @@ -31,6 +31,7 @@ class PairwisePluginProfileController < ProfileController |
31 | 31 | |
32 | 32 | def choose |
33 | 33 | @pairwise_content = find_content(params) |
34 | + return render_access_denied if @pairwise_content.archived? | |
34 | 35 | vote = @pairwise_content.vote_to(params[:prompt_id], params[:direction], user_identifier, params[:appearance_id]) |
35 | 36 | if request.xhr? |
36 | 37 | render 'content_viewer/load_prompt.rjs' |
... | ... | @@ -153,4 +154,3 @@ class PairwisePluginProfileController < ProfileController |
153 | 154 | |
154 | 155 | |
155 | 156 | end |
156 | - | ... | ... |
lib/pairwise_plugin/pairwise_content.rb
... | ... | @@ -54,15 +54,24 @@ class PairwisePlugin::PairwiseContent < Article |
54 | 54 | 'Question managed by pairwise' |
55 | 55 | end |
56 | 56 | |
57 | + def css_class_name | |
58 | + cl = "pairwise-plugin_pairwise-content" | |
59 | + cl += archived? ? " archived" : " active" | |
60 | + end | |
61 | + | |
57 | 62 | def to_html(options = {}) |
58 | 63 | source = options["source"] |
59 | 64 | embeded = options.has_key? "embeded" |
60 | 65 | prompt_id = options["prompt_id"] |
61 | 66 | pairwise_content = self |
62 | - if not Environment.default.enabled_plugins.include? "PairwisePlugin" | |
67 | + if not environment.plugin_enabled?(PairwisePlugin) | |
63 | 68 | proc do |
64 | 69 | render :file => 'content_viewer/closed_pool' |
65 | 70 | end |
71 | + elsif pairwise_content.archived? | |
72 | + proc do | |
73 | + render :file => 'content_viewer/read_only', :locals => {:pairwise_content => pairwise_content} | |
74 | + end | |
66 | 75 | else |
67 | 76 | proc do |
68 | 77 | locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } | ... | ... |
public/style.css
test/functional/profile/pairwise_plugin_profile_controller_test.rb
... | ... | @@ -271,4 +271,20 @@ class PairwisePluginProfileControllerTest < ActionController::TestCase |
271 | 271 | assert_redirected_to @content.url |
272 | 272 | assert_equal "Only logged user could suggest new ideas", flash[:error] |
273 | 273 | end |
274 | + | |
275 | + should 'not register a vote when pairwise is archived' do | |
276 | + login_as(@user.user.login) | |
277 | + @content.update_attribute(:archived, true) | |
278 | + PairwisePluginProfileController.any_instance.expects(:find_content).returns(@content).at_least_once | |
279 | + | |
280 | + get :choose, | |
281 | + :profile => @profile.identifier, | |
282 | + :id => @content.id, | |
283 | + :question_id => @question.id, | |
284 | + :prompt_id => @question.prompt.id, | |
285 | + :appearance_id => @question.appearance_id, | |
286 | + :direction => 'left' | |
287 | + assert_response 403 | |
288 | + end | |
289 | + | |
274 | 290 | end | ... | ... |
test/unit/pairwise_plugin/pairwise_content_test.rb
... | ... | @@ -18,7 +18,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
18 | 18 | |
19 | 19 | def setup |
20 | 20 | pairwise_env_settings = { :api_host => "http://localhost:3030/", |
21 | - :username => "abner.oliveira@serpro.gov.br", | |
21 | + :username => "abner.oliveira@serpro.gov.br", | |
22 | 22 | :password => "serpro" |
23 | 23 | } |
24 | 24 | @profile = create_user('testing').person |
... | ... | @@ -39,7 +39,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
39 | 39 | question = @http_stub_fixtures.create_question(2, 'Question 2', 'Choice X\nChoice Y') |
40 | 40 | assert_not_nil question |
41 | 41 | assert_equal 2, question.id |
42 | - assert_equal 'Question 2', question.name | |
42 | + assert_equal 'Question 2', question.name | |
43 | 43 | end |
44 | 44 | |
45 | 45 | should 'provide proper short description' do |
... | ... | @@ -77,7 +77,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
77 | 77 | end |
78 | 78 | |
79 | 79 | should 'add error to base when the question does not exist' do |
80 | - Response = Struct.new(:code, :message) | |
80 | + Response = Struct.new(:code, :message) | |
81 | 81 | |
82 | 82 | @response = Response.new(422, "Any error") |
83 | 83 | |
... | ... | @@ -97,15 +97,15 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
97 | 97 | #expectations |
98 | 98 | pairwise_content = PairwiseContentFixtures.new_pairwise_content |
99 | 99 | pairwise_content.profile = @profile |
100 | - pairwise_content.expects(:valid?).returns(true) | |
100 | + pairwise_content.expects(:valid?).returns(true) | |
101 | 101 | pairwise_content.expects(:create_pairwise_question).returns(question) |
102 | 102 | pairwise_content.expects(:toggle_autoactivate_ideas).at_least_once |
103 | 103 | #save should call before_save which sends the question to pairwise |
104 | 104 | pairwise_content.save! |
105 | - | |
105 | + | |
106 | 106 | #after save pairwise_question_id should store question id generated by pairwise |
107 | 107 | assert_equal question.id, pairwise_content.pairwise_question_id |
108 | - end | |
108 | + end | |
109 | 109 | |
110 | 110 | should 'send changes in choices to pairwise service' do |
111 | 111 | @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) |
... | ... | @@ -121,7 +121,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
121 | 121 | end |
122 | 122 | |
123 | 123 | should 'send new choices to pairwise_service' do |
124 | - @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) | |
124 | + @question = Pairwise::Question.new(:id => @pairwise_content.pairwise_question_id, :name => 'Question 1', :active => false) | |
125 | 125 | @pairwise_content.expects('new_record?').returns(false).at_least_once |
126 | 126 | @pairwise_content.expects('valid?').returns(true).at_least_once |
127 | 127 | |
... | ... | @@ -170,7 +170,7 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
170 | 170 | pairwise_content.stubs(:valid? => true) |
171 | 171 | pairwise_content.stubs(:send_question_to_service => true) |
172 | 172 | pairwise_content.join_choices(choices_to_join, parent_choice, user=nil) |
173 | - | |
173 | + | |
174 | 174 | choices_related = PairwisePlugin::ChoicesRelated.related_choices_for(parent_choice) |
175 | 175 | assert_equal 2, choices_related.size |
176 | 176 | assert_equal 1, choices_related.select { |c| c.choice_id == 2}.size |
... | ... | @@ -182,12 +182,12 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
182 | 182 | # end |
183 | 183 | |
184 | 184 | should 'ask skip prompt reasons' do |
185 | - prompt = Pairwise::Prompt.new({"left_choice_text"=>"Choice 1", "right_choice_text"=>"New inactive choice", "left_choice_id"=>1300, "right_choice_id"=>1302, "id"=>194, "tracking"=>nil, "votes_count"=>0}) | |
185 | + prompt = Pairwise::Prompt.new({"left_choice_text"=>"Choice 1", "right_choice_text"=>"New inactive choice", "left_choice_id"=>1300, "right_choice_id"=>1302, "id"=>194, "tracking"=>nil, "votes_count"=>0}) | |
186 | 186 | reasons = @pairwise_content.ask_skip_reasons(prompt) |
187 | 187 | |
188 | 188 | assert_not_nil reasons |
189 | 189 | assert_equal 7, reasons.size |
190 | - | |
190 | + | |
191 | 191 | assert reasons[0].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[0][:text] |
192 | 192 | assert reasons[1].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[1][:text] |
193 | 193 | assert reasons[2].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[2][:text] |
... | ... | @@ -196,4 +196,35 @@ class PairwisePlugin::PairwiseContentTest < ActiveSupport::TestCase |
196 | 196 | assert reasons[5].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[4][:text] |
197 | 197 | assert reasons[6].include? PairwisePlugin::PairwiseContent::REASONS_ARRAY[5][:text] |
198 | 198 | end |
199 | + | |
200 | + should 'append active class in article view when it is not archived' do | |
201 | + @pairwise_content.expects(:archived?).returns(false) | |
202 | + assert_equal 'pairwise-plugin_pairwise-content active', @pairwise_content.css_class_name | |
203 | + end | |
204 | + | |
205 | + should 'append archived class in article view when it is archived' do | |
206 | + @pairwise_content.expects(:archived?).returns(true) | |
207 | + assert_equal 'pairwise-plugin_pairwise-content archived', @pairwise_content.css_class_name | |
208 | + end | |
209 | + | |
210 | + should 'render read only view when the pairwise content is archived' do | |
211 | + @profile.environment.enable_plugin(PairwisePlugin) | |
212 | + expects(:render).with(:file => 'content_viewer/read_only', :locals => {:pairwise_content => @pairwise_content}) | |
213 | + @pairwise_content.expects(:archived?).returns(true) | |
214 | + instance_eval(&@pairwise_content.to_html) | |
215 | + end | |
216 | + | |
217 | + should 'render normal view when the pairwise content is not archived' do | |
218 | + @profile.environment.enable_plugin(PairwisePlugin) | |
219 | + expects(:render).with(:file => 'content_viewer/prompt', :locals => {:pairwise_content => @pairwise_content, :source => nil, :embeded => false, :prompt_id => nil }) | |
220 | + @pairwise_content.expects(:archived?).returns(false) | |
221 | + instance_eval(&@pairwise_content.to_html) | |
222 | + end | |
223 | + | |
224 | + should 'render nothing when the plugin is not enabled' do | |
225 | + @profile.environment.disable_plugin(PairwisePlugin) | |
226 | + expects(:render).with(:file => 'content_viewer/closed_pool') | |
227 | + instance_eval(&@pairwise_content.to_html) | |
228 | + end | |
229 | + | |
199 | 230 | end | ... | ... |
views/content_viewer/_menu.html.erb
1 | 1 | <% extend PairwisePlugin::Helpers::ViewerHelper %> |
2 | 2 | |
3 | 3 | <ul class="pairwise_menu"> |
4 | - <li> | |
5 | - <%= pairwise_tab_remote_link _('Pairwise Vote'), pairwise_content.prompt_url, pairwise_content, embeded, :class => active_tab == :prompt ? 'active' : '' %> | |
6 | - </li> | |
4 | + <% unless pairwise_content.archived? %> | |
5 | + <li> | |
6 | + <%= pairwise_tab_remote_link _('Pairwise Vote'), pairwise_content.prompt_url, pairwise_content, embeded, :class => active_tab == :prompt ? 'active' : '' %> | |
7 | + </li> | |
8 | + <% end %> | |
7 | 9 | <li><%= pairwise_tab_remote_link _('Results'), pairwise_content.result_url, pairwise_content, embeded, :class => active_tab == :results ? 'active' : '' %></li> |
8 | 10 | <% if !embeded && pairwise_content.allow_edit?(user) %> |
9 | 11 | <li><%= pairwise_edit_link _('Edit'), pairwise_content %></li> | ... | ... |
views/content_viewer/_result.html.erb