Commit e8325928a0213c9c68d12e485ea1657ffd4f55ec
Committed by
Daniela Feitosa
1 parent
d74fdaec
Exists in
master
and in
28 other branches
Make the l10n redirection configurable by profile
The profile has a new attribute to define if the guest must be automaticaly redirected to the article translation or not. Closes ActionItem2121
Showing
7 changed files
with
73 additions
and
33 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
app/models/profile.rb
... | ... | @@ -115,6 +115,7 @@ class Profile < ActiveRecord::Base |
115 | 115 | |
116 | 116 | acts_as_having_settings :field => :data |
117 | 117 | |
118 | + settings_items :redirect_l10n, :type => :boolean, :default => false | |
118 | 119 | settings_items :public_content, :type => :boolean, :default => true |
119 | 120 | settings_items :description |
120 | 121 | ... | ... |
app/views/profile_editor/edit.rhtml
... | ... | @@ -73,6 +73,12 @@ |
73 | 73 | </table> |
74 | 74 | <% end %> |
75 | 75 | |
76 | + <h2><%= _('Other options') %></h2> | |
77 | + <%= labelled_check_box( | |
78 | + _('Automatic redirect the visitor to the translated article of him language'), | |
79 | + 'profile_data[redirect_l10n]', true, @profile.redirect_l10n | |
80 | + )%> | |
81 | + | |
76 | 82 | <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> |
77 | 83 | |
78 | 84 | <% button_bar do %> | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +Feature: language redirection | |
2 | + As a guest | |
3 | + I want to see an article | |
4 | + | |
5 | + Background: | |
6 | + Given the following users | |
7 | + | login | name | | |
8 | + | manuel | Manuel Silva | | |
9 | + And the following articles | |
10 | + | owner | name | body | lang | translation_of | | |
11 | + | manuel | Meu Artigo | isso é um teste | pt | nil | | |
12 | + | manuel | My Article | this is a test | en | Meu Artigo | | |
13 | + | |
14 | + Scenario: view page in Pt as Pt guest | |
15 | + Given my browser prefers Portuguese | |
16 | + When I go to /manuel/meu-artigo | |
17 | + Then the site should be in Portuguese | |
18 | + | |
19 | + Scenario: view page in Pt as En guest with redirection disabled by default | |
20 | + Given my browser prefers English | |
21 | + When I go to /manuel/meu-artigo | |
22 | + Then the site should be in Portuguese | |
23 | + | |
24 | + Scenario: view page in Pt as En guest with redirection enabled | |
25 | + #Given manuel enabled translation redirection in his profile | |
26 | + # Testing the web UI | |
27 | + Given I am logged in as "manuel" | |
28 | + And my browser prefers English | |
29 | + And I go to manuel's profile editor | |
30 | + And I check "Automatic redirect the visitor to the translated article of him language" | |
31 | + And I press "save" | |
32 | + When I go to /manuel/meu-artigo | |
33 | + Then the site should be in English | |
34 | + | |
35 | + Scenario: view page in Pt as En guest with redirection disabled | |
36 | + Given manuel disabled translation redirection in his profile | |
37 | + And my browser prefers English | |
38 | + When I go to /manuel/meu-artigo | |
39 | + Then the site should be in Portuguese | |
40 | + | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -94,7 +94,20 @@ Given /^the following (articles|events|blogs|folders|forums|galleries)$/ do |con |
94 | 94 | parent = item.delete("parent") |
95 | 95 | owner = Profile[owner_identifier] |
96 | 96 | home = item.delete("homepage") |
97 | - result = klass.new(item.merge(:profile => owner)) | |
97 | + language = item.delete("lang") | |
98 | + translation_of_id = nil | |
99 | + if item["translation_of"] | |
100 | + if item["translation_of"] != "nil" | |
101 | + article = owner.articles.find_by_name(item["translation_of"]) | |
102 | + translation_of_id = article.id if article | |
103 | + end | |
104 | + item.delete("translation_of") | |
105 | + end | |
106 | + result = klass.new(item.merge( | |
107 | + :profile => owner, | |
108 | + :language => language, | |
109 | + :translation_of_id => translation_of_id | |
110 | + )) | |
98 | 111 | if parent |
99 | 112 | result.parent = Article.find_by_name(parent) |
100 | 113 | end |
... | ... | @@ -488,3 +501,10 @@ Then /^"([^\"]*)" profile should not exist$/ do |profile_selector| |
488 | 501 | profile.nil?.should be_true |
489 | 502 | end |
490 | 503 | end |
504 | + | |
505 | +Given /^([^\s]+) (enabled|disabled) translation redirection in (?:his|her) profile$/ do | |
506 | + |login, status| | |
507 | + profile = Profile[login] | |
508 | + profile.redirect_l10n = ( status == "enabled" ) | |
509 | + profile.save | |
510 | +end | ... | ... |
features/support/paths.rb
... | ... | @@ -36,7 +36,7 @@ module NavigationHelpers |
36 | 36 | when /^(.*)'s sitemap/ |
37 | 37 | '/profile/%s/sitemap' % Profile.find_by_name($1).identifier |
38 | 38 | |
39 | - when /^(.*)'s profile/ | |
39 | + when /^(.*)'s profile$/ | |
40 | 40 | '/profile/%s' % Profile.find_by_name($1).identifier |
41 | 41 | |
42 | 42 | when /^the profile$/ |
... | ... | @@ -48,6 +48,9 @@ module NavigationHelpers |
48 | 48 | when /^(.*)'s leave page/ |
49 | 49 | '/profile/%s/leave' % Profile.find_by_name($1).identifier |
50 | 50 | |
51 | + when /^(.*)'s profile editor$/ | |
52 | + "myprofile/manuel/profile_editor/edit" | |
53 | + | |
51 | 54 | when /^login page$/ |
52 | 55 | '/account/login' |
53 | 56 | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -1113,26 +1113,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
1113 | 1113 | assert_tag :a, :attributes => { :class => /article-translations-menu/, :onclick => /toggleSubmenu/ } |
1114 | 1114 | end |
1115 | 1115 | |
1116 | - should 'be redirected to translation if article is a root' do | |
1117 | - @request.env['HTTP_REFERER'] = 'http://some.path' | |
1118 | - FastGettext.stubs(:locale).returns('es') | |
1119 | - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') | |
1120 | - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) | |
1121 | - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path | |
1122 | - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path | |
1123 | - assert_equal es_article, assigns(:page) | |
1124 | - end | |
1125 | - | |
1126 | - should 'be redirected to translation' do | |
1127 | - @request.env['HTTP_REFERER'] = 'http://some.path' | |
1128 | - FastGettext.stubs(:locale).returns('en') | |
1129 | - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') | |
1130 | - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) | |
1131 | - get :view_page, :profile => @profile.identifier, :page => es_article.explode_path | |
1132 | - assert_redirected_to :profile => @profile.identifier, :page => en_article.explode_path | |
1133 | - assert_equal en_article, assigns(:page) | |
1134 | - end | |
1135 | - | |
1136 | 1116 | should 'not be redirected if already in translation' do |
1137 | 1117 | en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') |
1138 | 1118 | es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) |
... | ... | @@ -1161,16 +1141,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
1161 | 1141 | assert_equal en_article, assigns(:page) |
1162 | 1142 | end |
1163 | 1143 | |
1164 | - should 'be redirected if http_referer is nil' do | |
1165 | - en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') | |
1166 | - es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) | |
1167 | - @request.env['HTTP_REFERER'] = nil | |
1168 | - FastGettext.stubs(:locale).returns('es') | |
1169 | - get :view_page, :profile => @profile.identifier, :page => en_article.explode_path | |
1170 | - assert_redirected_to :profile => @profile.identifier, :page => es_article.explode_path | |
1171 | - assert_equal es_article, assigns(:page) | |
1172 | - end | |
1173 | - | |
1174 | 1144 | should 'not be redirected to transition if came from edit' do |
1175 | 1145 | en_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'en_article', :language => 'en') |
1176 | 1146 | es_article = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'es_article', :language => 'es', :translation_of_id => en_article) | ... | ... |