Commit f8dfd63b6d5dce44e02d2ced8ebf4cfa5f4f7fcd
Exists in
master
and in
29 other branches
Merge branch 'privacy_fix' into 'master'
Article privacy fixies * Fix article privacy to not consider invisible profiles * Change feed published method to consider it's parent privacy * Closes #148 See merge request !723
Showing
5 changed files
with
48 additions
and
4 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -29,9 +29,14 @@ class Article < ActiveRecord::Base |
| 29 | 29 | def initialize(*params) |
| 30 | 30 | super |
| 31 | 31 | |
| 32 | - if !params.blank? && params.first.has_key?(:profile) && !params.first[:profile].blank? | |
| 33 | - profile = params.first[:profile] | |
| 34 | - self.published = false unless profile.public? | |
| 32 | + if !params.blank? | |
| 33 | + if params.first.has_key?(:profile) && !params.first[:profile].blank? | |
| 34 | + profile = params.first[:profile] | |
| 35 | + self.published = false unless profile.public_profile | |
| 36 | + end | |
| 37 | + | |
| 38 | + self.published = params.first["published"] if params.first.has_key?("published") | |
| 39 | + self.published = params.first[:published] if params.first.has_key?(:published) | |
| 35 | 40 | end |
| 36 | 41 | |
| 37 | 42 | end | ... | ... |
app/models/rss_feed.rb
| ... | ... | @@ -14,7 +14,7 @@ class RssFeed < Article |
| 14 | 14 | |
| 15 | 15 | # store setting in body |
| 16 | 16 | serialize :body, Hash |
| 17 | - | |
| 17 | + | |
| 18 | 18 | def body |
| 19 | 19 | self[:body] ||= {} |
| 20 | 20 | end |
| ... | ... | @@ -89,6 +89,14 @@ class RssFeed < Article |
| 89 | 89 | ) |
| 90 | 90 | end |
| 91 | 91 | |
| 92 | + def published? | |
| 93 | + if self.parent | |
| 94 | + self.parent.published? | |
| 95 | + else | |
| 96 | + self.published | |
| 97 | + end | |
| 98 | + end | |
| 99 | + | |
| 92 | 100 | def self.short_description |
| 93 | 101 | _('RSS Feed') |
| 94 | 102 | end | ... | ... |
test/unit/community_test.rb
| ... | ... | @@ -39,7 +39,9 @@ class CommunityTest < ActiveSupport::TestCase |
| 39 | 39 | community = create(Community, :environment => Environment.default, :name => 'my new community') |
| 40 | 40 | |
| 41 | 41 | assert_kind_of Blog, community.articles.find_by_path(blog.path) |
| 42 | + assert community.articles.find_by_path(blog.path).published? | |
| 42 | 43 | assert_kind_of RssFeed, community.articles.find_by_path(blog.feed.path) |
| 44 | + assert community.articles.find_by_path(blog.feed.path).published? | |
| 43 | 45 | end |
| 44 | 46 | |
| 45 | 47 | should 'have contact_person' do | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -181,7 +181,9 @@ class PersonTest < ActiveSupport::TestCase |
| 181 | 181 | person = create(User).person |
| 182 | 182 | |
| 183 | 183 | assert_kind_of Blog, person.articles.find_by_path(blog.path) |
| 184 | + assert person.articles.find_by_path(blog.path).published? | |
| 184 | 185 | assert_kind_of RssFeed, person.articles.find_by_path(blog.feed.path) |
| 186 | + assert person.articles.find_by_path(blog.feed.path).published? | |
| 185 | 187 | end |
| 186 | 188 | |
| 187 | 189 | should 'create a default set of blocks' do | ... | ... |
test/unit/rss_feed_test.rb
| ... | ... | @@ -262,4 +262,31 @@ class RssFeedTest < ActiveSupport::TestCase |
| 262 | 262 | assert_equal [es_post], blog.feed.fetch_articles |
| 263 | 263 | end |
| 264 | 264 | |
| 265 | + should 'a feed have the same privacy of its parent' do | |
| 266 | + profile = create_user('testuser').person | |
| 267 | + blog = create(Blog, :name => 'blog-test', :profile => profile) | |
| 268 | + feed = blog.feed | |
| 269 | + | |
| 270 | + assert blog.published? | |
| 271 | + assert feed.published? | |
| 272 | + | |
| 273 | + feed.published = false | |
| 274 | + feed.save | |
| 275 | + | |
| 276 | + assert blog.published? | |
| 277 | + assert feed.published? | |
| 278 | + | |
| 279 | + blog.published = false | |
| 280 | + blog.save | |
| 281 | + feed.reload | |
| 282 | + | |
| 283 | + assert !blog.published? | |
| 284 | + assert !feed.published? | |
| 285 | + | |
| 286 | + feed.published = true | |
| 287 | + feed.save | |
| 288 | + | |
| 289 | + assert !blog.published? | |
| 290 | + assert !feed.published? | |
| 291 | + end | |
| 265 | 292 | end | ... | ... |