Commit 78a1f5fc916dec4de25e07270fb0e844bb2652a9

Authored by Francisco Júnior
2 parents 8d4a9509 970e8f50

Merge branch 'I324-display_private_article_to_all_community_members' into stable

app/helpers/article_helper.rb
@@ -77,12 +77,24 @@ module ArticleHelper @@ -77,12 +77,24 @@ module ArticleHelper
77 content_tag('div', 77 content_tag('div',
78 radio_button(:article, :published, false) + 78 radio_button(:article, :published, false) +
79 content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") 79 content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private")
  80 + ) + visibility_mode_options(article, tokenized_children))
  81 + end
  82 +
  83 + def visibility_mode_options(article, tokenized_children)
  84 + content_tag('div',
  85 +
  86 + content_tag('div',
  87 + radio_button(:article, :visibility_mode, 1) +
  88 + content_tag('label', _('For all community members'), :for => 'article_visibility_mode_1', :id => "label_private")) +
  89 + content_tag('div',
  90 + radio_button(:article, :visibility_mode, 0) +
  91 + content_tag('label', _('For community admins or specific users'), :for => 'article_visibility_mode_0', :id => "label_private")
80 ) + 92 ) +
81 (article.profile.community? ? content_tag('div', 93 (article.profile.community? ? content_tag('div',
82 content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") + 94 content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") +
83 token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'}, 95 token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'},
84 {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) : 96 {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) :
85 - '')) 97 + ''), :style => 'padding-left: 15px;')
86 end 98 end
87 99
88 def prepare_to_token_input(array) 100 def prepare_to_token_input(array)
app/models/article.rb
@@ -2,7 +2,7 @@ require 'hpricot' @@ -2,7 +2,7 @@ require 'hpricot'
2 2
3 class Article < ActiveRecord::Base 3 class Article < ActiveRecord::Base
4 4
5 - attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :published_at 5 + attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :published_at, :visibility_mode
6 6
7 acts_as_having_image 7 acts_as_having_image
8 8
@@ -498,7 +498,7 @@ class Article &lt; ActiveRecord::Base @@ -498,7 +498,7 @@ class Article &lt; ActiveRecord::Base
498 def display_unpublished_article_to?(user) 498 def display_unpublished_article_to?(user)
499 user == author || allow_view_private_content?(user) || user == profile || 499 user == author || allow_view_private_content?(user) || user == profile ||
500 user.is_admin?(profile.environment) || user.is_admin?(profile) || 500 user.is_admin?(profile.environment) || user.is_admin?(profile) ||
501 - article_privacy_exceptions.include?(user) 501 + article_privacy_exceptions.include?(user) || (visibility_mode == 1 && user.is_member_of?(profile))
502 end 502 end
503 503
504 def display_to?(user = nil) 504 def display_to?(user = nil)
@@ -656,6 +656,8 @@ class Article &lt; ActiveRecord::Base @@ -656,6 +656,8 @@ class Article &lt; ActiveRecord::Base
656 can_display_versions? && display_versions 656 can_display_versions? && display_versions
657 end 657 end
658 658
  659 + settings_items :visibility_mode, :type => :integer, :default => 0
  660 +
659 def get_version(version_number = nil) 661 def get_version(version_number = nil)
660 version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest 662 version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest
661 end 663 end
public/javascripts/article.js
@@ -167,18 +167,38 @@ jQuery(function($) { @@ -167,18 +167,38 @@ jQuery(function($) {
167 }); 167 });
168 168
169 function show_hide_token_input() { 169 function show_hide_token_input() {
170 - if($("#article_published_false").attr('checked')) 170 + if($("#article_visibility_mode_0").attr('checked'))
171 $("#text-input-search-exception-users").parent("div").css('display', 'block'); 171 $("#text-input-search-exception-users").parent("div").css('display', 'block');
172 else 172 else
173 $("#text-input-search-exception-users").parent("div").css('display', 'none'); 173 $("#text-input-search-exception-users").parent("div").css('display', 'none');
174 } 174 }
175 175
  176 + function show_hide_visibility_modes() {
  177 + if ($("#article_published_false").attr('checked'))
  178 + $("#article_visibility_mode_1").parent("div").parent("div").css("display", "block");
  179 + else
  180 + $("#article_visibility_mode_1").parent("div").parent("div").css("display", "none");
  181 + }
  182 +
176 if( $("#token-input-search-article-privacy-exceptions").length == 1 ) { 183 if( $("#token-input-search-article-privacy-exceptions").length == 1 ) {
  184 + show_hide_visibility_modes();
177 show_hide_token_input(); 185 show_hide_token_input();
178 186
  187 + $("#article_published_true").click(function() {
  188 + show_hide_visibility_modes();
  189 + });
  190 +
  191 + $("#article_published_false").click(function() {
  192 + show_hide_visibility_modes();
  193 + });
  194 +
179 //Hide / Show the text area 195 //Hide / Show the text area
180 - $("#article_published_false").click(show_hide_token_input);  
181 - $("#article_published_true").click(show_hide_token_input); 196 + $("#article_visibility_mode_0").click(function() {
  197 + show_hide_token_input();
  198 + });
  199 + $("#article_visibility_mode_1").click(function() {
  200 + show_hide_token_input();
  201 + });
182 } 202 }
183 203
184 }); 204 });
script/updatepo/data/pt.upo
@@ -81,3 +81,5 @@ msgid &quot;Select topic&quot;# msgstr &quot;Selecione um tópico&quot; @@ -81,3 +81,5 @@ msgid &quot;Select topic&quot;# msgstr &quot;Selecione um tópico&quot;
81 msgid "Hits"# msgstr "Mais Acessos" 81 msgid "Hits"# msgstr "Mais Acessos"
82 msgid "Most Recent"# msgstr "Mais Recentes" 82 msgid "Most Recent"# msgstr "Mais Recentes"
83 msgid "Order"# msgstr "Ordenação" 83 msgid "Order"# msgstr "Ordenação"
  84 +msgid "For community admins or specific users"# msgstr "Para administradores da comunidade ou usuários específicos"
  85 +msgid "For all community members"# msgstr "Para todos os usuários da comunidade"
test/unit/article_test.rb
@@ -720,6 +720,19 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -720,6 +720,19 @@ class ArticleTest &lt; ActiveSupport::TestCase
720 assert_equal true, a.can_display_hits? 720 assert_equal true, a.can_display_hits?
721 end 721 end
722 722
  723 + should 'have visibility_mode setting with default 0' do
  724 + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id)
  725 + assert_respond_to a, :visibility_mode
  726 + assert_equal 0, a.visibility_mode
  727 + end
  728 +
  729 + should 'set visibility_mode setting value to 1' do
  730 + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id)
  731 + a.visibility_mode = 1
  732 + a.save && a.reload
  733 + assert_equal 1, a.visibility_mode
  734 + end
  735 +
723 should 'return a view url when image' do 736 should 'return a view url when image' do
724 image = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) 737 image = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
725 738