Commit e833fc77060d5f80d0827677a472bb8949d40e9f
1 parent
1a1eab27
Exists in
master
and in
16 other branches
refactoring display_filter to filter all article of friends marked as show_to_followers
Showing
6 changed files
with
22 additions
and
8 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -504,9 +504,9 @@ class Article < ActiveRecord::Base |
504 | 504 | where( |
505 | 505 | [ |
506 | 506 | "published = ? OR last_changed_by_id = ? OR profile_id = ? OR ? |
507 | - OR (show_to_followers = ? AND ? AND profile_id = ?)", true, user.id, user.id, | |
507 | + OR (show_to_followers = ? AND ? AND profile_id IN (?))", true, user.id, user.id, | |
508 | 508 | profile.nil? ? false : user.has_permission?(:view_private_content, profile), |
509 | - true, user.follows?(profile), (profile.nil? ? nil : profile.id) | |
509 | + true, (profile.nil? ? true : user.follows?(profile)), ( profile.nil? ? (user.friends.select('profiles.id')) : [profile.id]) | |
510 | 510 | ] |
511 | 511 | ) |
512 | 512 | } | ... | ... |
plugins/event/lib/event_plugin/event_block.rb
... | ... | @@ -26,8 +26,8 @@ class EventPlugin::EventBlock < Block |
26 | 26 | end |
27 | 27 | |
28 | 28 | def events(user = nil) |
29 | - events = events_source.events | |
30 | - events = events.published.order('start_date') | |
29 | + events = events_source.events.order('start_date') | |
30 | + events = user.nil? ? events.public : events.display_filter(user,nil) | |
31 | 31 | |
32 | 32 | if future_only |
33 | 33 | events = events.where('start_date >= ?', Date.today) | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require_relative '../../../test/test_helper' | ... | ... |
plugins/event/test/unit/event_block_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
1 | +require_relative '../test_helper' | |
2 | 2 | |
3 | -class EventPlugin::EventBlockTest < ActiveSupport::TestCase | |
3 | +class EventBlockTest < ActiveSupport::TestCase | |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @env = Environment.default |
... | ... | @@ -165,7 +165,7 @@ class EventPlugin::EventBlockTest < ActiveSupport::TestCase |
165 | 165 | |
166 | 166 | def visibility_content_test_from_a_profile(profile) |
167 | 167 | @block.box.owner = @env |
168 | - ev = fast_create Event, :name => '2 de Julho', :profile_id => profile.id | |
168 | + ev = Event.create!(:name => '2 de Julho', :profile => profile) | |
169 | 169 | @block.all_env_events = true |
170 | 170 | |
171 | 171 | # Do not list event from private profile for non logged visitor | ... | ... |
plugins/event/test/unit/event_plugin_test.rb
test/unit/article_test.rb
... | ... | @@ -1970,6 +1970,19 @@ class ArticleTest < ActiveSupport::TestCase |
1970 | 1970 | assert_equal [a], Article.display_filter(user, p) |
1971 | 1971 | end |
1972 | 1972 | |
1973 | + should 'display_filter show person private content to friends when no profile is passed as parameter' do | |
1974 | + user = create_user('someuser').person | |
1975 | + p = fast_create(Person) | |
1976 | + user.add_friend(p) | |
1977 | + user.stubs(:has_permission?).with(:view_private_content, p).returns(false) | |
1978 | + Article.delete_all | |
1979 | + a = fast_create(Article, :published => false, :show_to_followers => true, :profile_id => p.id) | |
1980 | + fast_create(Article, :published => false, :show_to_followers => false, :profile_id => p.id) | |
1981 | + fast_create(Article, :published => false, :show_to_followers => false, :profile_id => p.id) | |
1982 | + assert_equal [a], Article.display_filter(user, nil) | |
1983 | + end | |
1984 | + | |
1985 | + | |
1973 | 1986 | should 'display_filter show community private content to members' do |
1974 | 1987 | user = create_user('someuser').person |
1975 | 1988 | p = fast_create(Community) | ... | ... |