Commit d2879e8d3784f2f714a5519fc6f9ca012c54cacf
Committed by
Antonio Terceiro
1 parent
8cf6fdcf
Exists in
master
and in
28 other branches
Refactoring the public/private article's logic
* This patch will centralize the logic of public/private article in the 'published' attribute. * Removing the public_article attribute from the code replacing it by published. * Creating two new migrations: 1. Setting the published attribute to false when the article has the public_article attribute false. This will grant that all the articles that aren't public now continue unpublished. 2. Removing the public_article attribute from the schema.
Showing
10 changed files
with
84 additions
and
94 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| @@ -26,11 +26,6 @@ class ContentViewerController < ApplicationController | @@ -26,11 +26,6 @@ class ContentViewerController < ApplicationController | ||
| 26 | end | 26 | end |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | - # only show unpublished articles to those who can edit then | ||
| 30 | - if @page && !@page.published && !@page.allow_post_content?(user) | ||
| 31 | - @page = nil | ||
| 32 | - end | ||
| 33 | - | ||
| 34 | # page not found, give error | 29 | # page not found, give error |
| 35 | if @page.nil? | 30 | if @page.nil? |
| 36 | render_not_found(@path) | 31 | render_not_found(@path) |
app/models/article.rb
| @@ -84,13 +84,6 @@ class Article < ActiveRecord::Base | @@ -84,13 +84,6 @@ class Article < ActiveRecord::Base | ||
| 84 | pending_categorizations.clear | 84 | pending_categorizations.clear |
| 85 | end | 85 | end |
| 86 | 86 | ||
| 87 | - before_save do |article| | ||
| 88 | - if article.parent | ||
| 89 | - article.public_article = article.parent.public_article | ||
| 90 | - end | ||
| 91 | - true | ||
| 92 | - end | ||
| 93 | - | ||
| 94 | acts_as_taggable | 87 | acts_as_taggable |
| 95 | N_('Tag list') | 88 | N_('Tag list') |
| 96 | 89 | ||
| @@ -123,11 +116,10 @@ class Article < ActiveRecord::Base | @@ -123,11 +116,10 @@ class Article < ActiveRecord::Base | ||
| 123 | options = { :limit => limit, | 116 | options = { :limit => limit, |
| 124 | :conditions => [ | 117 | :conditions => [ |
| 125 | "advertise = ? AND | 118 | "advertise = ? AND |
| 126 | - public_article = ? AND | ||
| 127 | published = ? AND | 119 | published = ? AND |
| 128 | profiles.visible = ? AND | 120 | profiles.visible = ? AND |
| 129 | profiles.public_profile = ? AND | 121 | profiles.public_profile = ? AND |
| 130 | - ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog' | 122 | + ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog' |
| 131 | ], | 123 | ], |
| 132 | :include => 'profile', | 124 | :include => 'profile', |
| 133 | :order => 'articles.published_at desc, articles.id desc' | 125 | :order => 'articles.published_at desc, articles.id desc' |
| @@ -221,16 +213,32 @@ class Article < ActiveRecord::Base | @@ -221,16 +213,32 @@ class Article < ActiveRecord::Base | ||
| 221 | false | 213 | false |
| 222 | end | 214 | end |
| 223 | 215 | ||
| 216 | + def published? | ||
| 217 | + if self.published | ||
| 218 | + if self.parent && !self.parent.published? | ||
| 219 | + return false | ||
| 220 | + end | ||
| 221 | + true | ||
| 222 | + else | ||
| 223 | + false | ||
| 224 | + end | ||
| 225 | + end | ||
| 226 | + | ||
| 224 | named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] } | 227 | named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] } |
| 225 | 228 | ||
| 229 | + def display_unpublished_article_to?(user) | ||
| 230 | + self.author == user || allow_view_private_content?(user) || user == self.profile || | ||
| 231 | + user.is_admin?(self.profile.environment) || user.is_admin?(self.profile) | ||
| 232 | + end | ||
| 233 | + | ||
| 226 | def display_to?(user) | 234 | def display_to?(user) |
| 227 | - if self.public_article | 235 | + if self.published? |
| 228 | self.profile.display_info_to?(user) | 236 | self.profile.display_info_to?(user) |
| 229 | else | 237 | else |
| 230 | if user.nil? | 238 | if user.nil? |
| 231 | false | 239 | false |
| 232 | else | 240 | else |
| 233 | - (user == self.profile) || user.has_permission?('view_private_content', self.profile) | 241 | + self.display_unpublished_article_to?(user) |
| 234 | end | 242 | end |
| 235 | end | 243 | end |
| 236 | end | 244 | end |
| @@ -243,6 +251,10 @@ class Article < ActiveRecord::Base | @@ -243,6 +251,10 @@ class Article < ActiveRecord::Base | ||
| 243 | user && user.has_permission?('publish_content', profile) | 251 | user && user.has_permission?('publish_content', profile) |
| 244 | end | 252 | end |
| 245 | 253 | ||
| 254 | + def allow_view_private_content?(user = nil) | ||
| 255 | + user && user.has_permission?('view_private_content', profile) | ||
| 256 | + end | ||
| 257 | + | ||
| 246 | def comments_updated | 258 | def comments_updated |
| 247 | ferret_update | 259 | ferret_update |
| 248 | end | 260 | end |
| @@ -252,9 +264,10 @@ class Article < ActiveRecord::Base | @@ -252,9 +264,10 @@ class Article < ActiveRecord::Base | ||
| 252 | end | 264 | end |
| 253 | 265 | ||
| 254 | def public? | 266 | def public? |
| 255 | - profile.visible? && profile.public? && public_article | 267 | + profile.visible? && profile.public? && published? |
| 256 | end | 268 | end |
| 257 | 269 | ||
| 270 | + | ||
| 258 | def copy(options) | 271 | def copy(options) |
| 259 | attrs = attributes.reject! { |key, value| article_attr_blacklist.include?(key) } | 272 | attrs = attributes.reject! { |key, value| article_attr_blacklist.include?(key) } |
| 260 | attrs.merge!(options) | 273 | attrs.merge!(options) |
app/models/profile.rb
| @@ -447,7 +447,7 @@ private :generate_url, :url_options | @@ -447,7 +447,7 @@ private :generate_url, :url_options | ||
| 447 | 447 | ||
| 448 | # a default private folder if public | 448 | # a default private folder if public |
| 449 | if self.public? | 449 | if self.public? |
| 450 | - folder = Folder.new(:name => _("Intranet"), :public_article => false) | 450 | + folder = Folder.new(:name => _("Intranet"), :published => false) |
| 451 | self.articles << folder | 451 | self.articles << folder |
| 452 | end | 452 | end |
| 453 | end | 453 | end |
| @@ -692,7 +692,7 @@ private :generate_url, :url_options | @@ -692,7 +692,7 @@ private :generate_url, :url_options | ||
| 692 | if user.nil? | 692 | if user.nil? |
| 693 | false | 693 | false |
| 694 | else | 694 | else |
| 695 | - (user == self) || (user.is_admin?(self.environment)) || (user.memberships.include?(self)) | 695 | + (user == self) || (user.is_admin?(self.environment)) || user.is_admin?(self) || user.memberships.include?(self) |
| 696 | end | 696 | end |
| 697 | end | 697 | end |
| 698 | end | 698 | end |
db/migrate/084_set_public_article_into_published_attribute.rb
0 → 100644
| @@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
| 1 | +class RemovePublicArticle < ActiveRecord::Migration | ||
| 2 | + def self.up | ||
| 3 | + remove_column :articles, :public_article | ||
| 4 | + end | ||
| 5 | + | ||
| 6 | + def self.down | ||
| 7 | + add_column :articles, :public_article, :boolean, :default => true | ||
| 8 | + execute('update articles set public_article = (1>0)') | ||
| 9 | + end | ||
| 10 | +end |
script/apply-template
| @@ -8,7 +8,7 @@ env = Environment.default | @@ -8,7 +8,7 @@ env = Environment.default | ||
| 8 | 8 | ||
| 9 | def move_articles_to_blog(profile) | 9 | def move_articles_to_blog(profile) |
| 10 | profile.articles.each { |article| | 10 | profile.articles.each { |article| |
| 11 | - if !article.blog? && !article.is_a?(RssFeed) && article.public_article | 11 | + if !article.blog? && !article.is_a?(RssFeed) && article.published? |
| 12 | puts 'including ' + article.path + ' in the blog' | 12 | puts 'including ' + article.path + ' in the blog' |
| 13 | article.parent = profile.blog | 13 | article.parent = profile.blog |
| 14 | article.save! | 14 | article.save! |
test/functional/cms_controller_test.rb
| @@ -624,14 +624,14 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -624,14 +624,14 @@ class CmsControllerTest < Test::Unit::TestCase | ||
| 624 | end | 624 | end |
| 625 | 625 | ||
| 626 | should 'create a private article child of private folder' do | 626 | should 'create a private article child of private folder' do |
| 627 | - folder = Folder.new(:name => 'my intranet', :public_article => false); profile.articles << folder; folder.save! | 627 | + folder = Folder.new(:name => 'my intranet', :published => false); profile.articles << folder; folder.save! |
| 628 | 628 | ||
| 629 | post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'} | 629 | post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'} |
| 630 | folder.reload | 630 | folder.reload |
| 631 | 631 | ||
| 632 | - assert !assigns(:article).public? | 632 | + assert !assigns(:article).published? |
| 633 | assert_equal 'new-private-article', folder.children[0].name | 633 | assert_equal 'new-private-article', folder.children[0].name |
| 634 | - assert !folder.children[0].public? | 634 | + assert !folder.children[0].published? |
| 635 | end | 635 | end |
| 636 | 636 | ||
| 637 | should 'load communities for that the user belongs' do | 637 | should 'load communities for that the user belongs' do |
test/functional/content_viewer_controller_test.rb
| @@ -293,10 +293,10 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -293,10 +293,10 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 293 | assert_response 404 | 293 | assert_response 404 |
| 294 | end | 294 | end |
| 295 | 295 | ||
| 296 | - should 'show unpublished articles as unexisting' do | 296 | + should 'show access denied to unpublished articles' do |
| 297 | profile.articles.create!(:name => 'test', :published => false) | 297 | profile.articles.create!(:name => 'test', :published => false) |
| 298 | get :view_page, :profile => profile.identifier, :page => [ 'test' ] | 298 | get :view_page, :profile => profile.identifier, :page => [ 'test' ] |
| 299 | - assert_response 404 | 299 | + assert_response 403 |
| 300 | end | 300 | end |
| 301 | 301 | ||
| 302 | should 'show unpublished articles to the user himself' do | 302 | should 'show unpublished articles to the user himself' do |
| @@ -307,19 +307,9 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -307,19 +307,9 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 307 | assert_response :success | 307 | assert_response :success |
| 308 | end | 308 | end |
| 309 | 309 | ||
| 310 | - should 'show unpublished articles to members' do | ||
| 311 | - community = Community.create!(:name => 'testcomm') | ||
| 312 | - community.articles.create!(:name => 'test', :published => false) | ||
| 313 | - community.add_member(profile) | ||
| 314 | - | ||
| 315 | - login_as(profile.identifier) | ||
| 316 | - get :view_page, :profile => community.identifier, :page => [ 'test' ] | ||
| 317 | - assert_response :success | ||
| 318 | - end | ||
| 319 | - | ||
| 320 | should 'not show private content to members' do | 310 | should 'not show private content to members' do |
| 321 | community = Community.create!(:name => 'testcomm') | 311 | community = Community.create!(:name => 'testcomm') |
| 322 | - Folder.create!(:name => 'test', :profile => community, :public_article => false) | 312 | + Folder.create!(:name => 'test', :profile => community, :published => false) |
| 323 | community.add_member(profile) | 313 | community.add_member(profile) |
| 324 | 314 | ||
| 325 | login_as(profile.identifier) | 315 | login_as(profile.identifier) |
| @@ -332,7 +322,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -332,7 +322,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 332 | 322 | ||
| 333 | should 'show private content to profile moderators' do | 323 | should 'show private content to profile moderators' do |
| 334 | community = Community.create!(:name => 'testcomm') | 324 | community = Community.create!(:name => 'testcomm') |
| 335 | - community.articles.create!(:name => 'test', :public_article => false) | 325 | + community.articles.create!(:name => 'test', :published => false) |
| 336 | community.add_moderator(profile) | 326 | community.add_moderator(profile) |
| 337 | 327 | ||
| 338 | login_as(profile.identifier) | 328 | login_as(profile.identifier) |
| @@ -344,7 +334,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -344,7 +334,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 344 | 334 | ||
| 345 | should 'show private content to profile admins' do | 335 | should 'show private content to profile admins' do |
| 346 | community = Community.create!(:name => 'testcomm') | 336 | community = Community.create!(:name => 'testcomm') |
| 347 | - community.articles.create!(:name => 'test', :public_article => false) | 337 | + community.articles.create!(:name => 'test', :published => false) |
| 348 | community.add_admin(profile) | 338 | community.add_admin(profile) |
| 349 | 339 | ||
| 350 | login_as(profile.identifier) | 340 | login_as(profile.identifier) |
| @@ -430,7 +420,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -430,7 +420,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 430 | 420 | ||
| 431 | should 'not give access to private articles if logged off' do | 421 | should 'not give access to private articles if logged off' do |
| 432 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 422 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 433 | - intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 423 | + intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 434 | 424 | ||
| 435 | @request.stubs(:ssl?).returns(true) | 425 | @request.stubs(:ssl?).returns(true) |
| 436 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] | 426 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] |
| @@ -441,7 +431,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -441,7 +431,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 441 | should 'not give access to private articles if logged in but not member' do | 431 | should 'not give access to private articles if logged in but not member' do |
| 442 | login_as('testinguser') | 432 | login_as('testinguser') |
| 443 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 433 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 444 | - intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 434 | + intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 445 | 435 | ||
| 446 | @request.stubs(:ssl?).returns(true) | 436 | @request.stubs(:ssl?).returns(true) |
| 447 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] | 437 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] |
| @@ -452,7 +442,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -452,7 +442,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 452 | should 'not give access to private articles if logged in and only member' do | 442 | should 'not give access to private articles if logged in and only member' do |
| 453 | person = create_user('test_user').person | 443 | person = create_user('test_user').person |
| 454 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 444 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 455 | - intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 445 | + intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 456 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) | 446 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
| 457 | login_as('test_user') | 447 | login_as('test_user') |
| 458 | 448 | ||
| @@ -465,7 +455,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -465,7 +455,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 465 | should 'give access to private articles if logged in and moderator' do | 455 | should 'give access to private articles if logged in and moderator' do |
| 466 | person = create_user('test_user').person | 456 | person = create_user('test_user').person |
| 467 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 457 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 468 | - intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 458 | + intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 469 | profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) | 459 | profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) |
| 470 | login_as('test_user') | 460 | login_as('test_user') |
| 471 | 461 | ||
| @@ -478,7 +468,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -478,7 +468,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 478 | should 'give access to private articles if logged in and admin' do | 468 | should 'give access to private articles if logged in and admin' do |
| 479 | person = create_user('test_user').person | 469 | person = create_user('test_user').person |
| 480 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 470 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 481 | - intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 471 | + intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 482 | profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) | 472 | profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) |
| 483 | login_as('test_user') | 473 | login_as('test_user') |
| 484 | 474 | ||
| @@ -507,21 +497,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -507,21 +497,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 507 | 497 | ||
| 508 | should 'require SSL for viewing non-public articles' do | 498 | should 'require SSL for viewing non-public articles' do |
| 509 | Environment.default.update_attribute(:enable_ssl, true) | 499 | Environment.default.update_attribute(:enable_ssl, true) |
| 510 | - page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) | 500 | + page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :published => false) |
| 511 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] | 501 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] |
| 512 | assert_redirected_to :protocol => 'https://', :profile => 'testinguser', :page => [ 'myarticle' ] | 502 | assert_redirected_to :protocol => 'https://', :profile => 'testinguser', :page => [ 'myarticle' ] |
| 513 | end | 503 | end |
| 514 | 504 | ||
| 515 | should 'avoid SSL for viewing public articles' do | 505 | should 'avoid SSL for viewing public articles' do |
| 516 | @request.expects(:ssl?).returns(true).at_least_once | 506 | @request.expects(:ssl?).returns(true).at_least_once |
| 517 | - page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => true) | 507 | + page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :published => true) |
| 518 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] | 508 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] |
| 519 | assert_redirected_to :protocol => 'http://', :profile => 'testinguser', :page => [ 'myarticle' ] | 509 | assert_redirected_to :protocol => 'http://', :profile => 'testinguser', :page => [ 'myarticle' ] |
| 520 | end | 510 | end |
| 521 | 511 | ||
| 522 | should 'not redirect to SSL if already on SSL' do | 512 | should 'not redirect to SSL if already on SSL' do |
| 523 | @request.expects(:ssl?).returns(true).at_least_once | 513 | @request.expects(:ssl?).returns(true).at_least_once |
| 524 | - page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) | 514 | + page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :published => false) |
| 525 | login_as('testinguser') | 515 | login_as('testinguser') |
| 526 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] | 516 | get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] |
| 527 | assert_response :success | 517 | assert_response :success |
test/unit/article_test.rb
| @@ -160,8 +160,8 @@ class ArticleTest < Test::Unit::TestCase | @@ -160,8 +160,8 @@ class ArticleTest < Test::Unit::TestCase | ||
| 160 | p = create_user('usr1').person | 160 | p = create_user('usr1').person |
| 161 | Article.destroy_all | 161 | Article.destroy_all |
| 162 | 162 | ||
| 163 | - first = p.articles.build(:name => 'first', :public_article => true); first.save! | ||
| 164 | - second = p.articles.build(:name => 'second', :public_article => false); second.save! | 163 | + first = p.articles.build(:name => 'first', :published => true); first.save! |
| 164 | + second = p.articles.build(:name => 'second', :published => false); second.save! | ||
| 165 | 165 | ||
| 166 | assert_equal [ first ], Article.recent(nil) | 166 | assert_equal [ first ], Article.recent(nil) |
| 167 | end | 167 | end |
| @@ -202,8 +202,8 @@ class ArticleTest < Test::Unit::TestCase | @@ -202,8 +202,8 @@ class ArticleTest < Test::Unit::TestCase | ||
| 202 | 202 | ||
| 203 | now = Time.now | 203 | now = Time.now |
| 204 | 204 | ||
| 205 | - first = p.articles.build(:name => 'first', :public_article => true, :created_at => now, :published_at => now); first.save! | ||
| 206 | - second = p.articles.build(:name => 'second', :public_article => true, :updated_at => now, :published_at => now + 1.second); second.save! | 205 | + first = p.articles.build(:name => 'first', :published => true, :created_at => now, :published_at => now); first.save! |
| 206 | + second = p.articles.build(:name => 'second', :published => true, :updated_at => now, :published_at => now + 1.second); second.save! | ||
| 207 | 207 | ||
| 208 | assert_equal [ second, first ], Article.recent(2) | 208 | assert_equal [ second, first ], Article.recent(2) |
| 209 | 209 | ||
| @@ -443,21 +443,21 @@ class ArticleTest < Test::Unit::TestCase | @@ -443,21 +443,21 @@ class ArticleTest < Test::Unit::TestCase | ||
| 443 | assert !Article.new.accept_category?(ProductCategory.new) | 443 | assert !Article.new.accept_category?(ProductCategory.new) |
| 444 | end | 444 | end |
| 445 | 445 | ||
| 446 | - should 'accept public_article attribute' do | ||
| 447 | - assert_respond_to Article.new, :public_article | ||
| 448 | - assert_respond_to Article.new, :public_article= | 446 | + should 'accept published attribute' do |
| 447 | + assert_respond_to Article.new, :published | ||
| 448 | + assert_respond_to Article.new, :published= | ||
| 449 | end | 449 | end |
| 450 | 450 | ||
| 451 | should 'say that logged off user cannot see private article' do | 451 | should 'say that logged off user cannot see private article' do |
| 452 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 452 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 453 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 453 | + article = Article.create!(:name => 'test article', :profile => profile, :published => false) |
| 454 | 454 | ||
| 455 | assert !article.display_to?(nil) | 455 | assert !article.display_to?(nil) |
| 456 | end | 456 | end |
| 457 | 457 | ||
| 458 | should 'say that not member of profile cannot see private article' do | 458 | should 'say that not member of profile cannot see private article' do |
| 459 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 459 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 460 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 460 | + article = Article.create!(:name => 'test article', :profile => profile, :published => false) |
| 461 | person = create_user('test_user').person | 461 | person = create_user('test_user').person |
| 462 | 462 | ||
| 463 | assert !article.display_to?(person) | 463 | assert !article.display_to?(person) |
| @@ -465,7 +465,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -465,7 +465,7 @@ class ArticleTest < Test::Unit::TestCase | ||
| 465 | 465 | ||
| 466 | should 'say that member user can not see private article' do | 466 | should 'say that member user can not see private article' do |
| 467 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 467 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 468 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 468 | + article = Article.create!(:name => 'test article', :profile => profile, :published => false) |
| 469 | person = create_user('test_user').person | 469 | person = create_user('test_user').person |
| 470 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) | 470 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
| 471 | 471 | ||
| @@ -474,7 +474,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -474,7 +474,7 @@ class ArticleTest < Test::Unit::TestCase | ||
| 474 | 474 | ||
| 475 | should 'say that profile admin can see private article' do | 475 | should 'say that profile admin can see private article' do |
| 476 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 476 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 477 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 477 | + article = Article.create!(:name => 'test article', :profile => profile, :published => false) |
| 478 | person = create_user('test_user').person | 478 | person = create_user('test_user').person |
| 479 | profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) | 479 | profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) |
| 480 | 480 | ||
| @@ -483,7 +483,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -483,7 +483,7 @@ class ArticleTest < Test::Unit::TestCase | ||
| 483 | 483 | ||
| 484 | should 'say that profile moderator can see private article' do | 484 | should 'say that profile moderator can see private article' do |
| 485 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 485 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 486 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 486 | + article = Article.create!(:name => 'test article', :profile => profile, :published => false) |
| 487 | person = create_user('test_user').person | 487 | person = create_user('test_user').person |
| 488 | profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) | 488 | profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) |
| 489 | 489 | ||
| @@ -492,7 +492,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -492,7 +492,7 @@ class ArticleTest < Test::Unit::TestCase | ||
| 492 | 492 | ||
| 493 | should 'not show article to non member if article public but profile private' do | 493 | should 'not show article to non member if article public but profile private' do |
| 494 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) | 494 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) |
| 495 | - article = Article.create!(:name => 'test article', :profile => profile, :public_article => true) | 495 | + article = Article.create!(:name => 'test article', :profile => profile, :published => true) |
| 496 | person1 = create_user('test_user1').person | 496 | person1 = create_user('test_user1').person |
| 497 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) | 497 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) |
| 498 | person2 = create_user('test_user2').person | 498 | person2 = create_user('test_user2').person |
| @@ -504,54 +504,27 @@ class ArticleTest < Test::Unit::TestCase | @@ -504,54 +504,27 @@ class ArticleTest < Test::Unit::TestCase | ||
| 504 | 504 | ||
| 505 | should 'make new article private if created inside a private folder' do | 505 | should 'make new article private if created inside a private folder' do |
| 506 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 506 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 507 | - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 507 | + folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 508 | article = Article.create!(:name => 'my private article', :profile => profile, :parent => folder) | 508 | article = Article.create!(:name => 'my private article', :profile => profile, :parent => folder) |
| 509 | 509 | ||
| 510 | - assert !article.public_article | ||
| 511 | - end | ||
| 512 | - | ||
| 513 | - should 'respond to public? like public_article if profile is public' do | ||
| 514 | - p = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | ||
| 515 | - a1 = Article.create!(:name => 'test public article', :profile => p) | ||
| 516 | - a2 = Article.create!(:name => 'test private article', :profile => p, :public_article => false) | ||
| 517 | - | ||
| 518 | - assert a1.public? | ||
| 519 | - assert !a2.public? | ||
| 520 | - end | ||
| 521 | - | ||
| 522 | - should 'respond to public? as false if profile is private' do | ||
| 523 | - p = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) | ||
| 524 | - a1 = Article.create!(:name => 'test public article', :profile => p) | ||
| 525 | - a2 = Article.create!(:name => 'test private article', :profile => p, :public_article => false) | ||
| 526 | - | ||
| 527 | - assert !a1.public? | ||
| 528 | - assert !a2.public? | ||
| 529 | - end | ||
| 530 | - | ||
| 531 | - should 'respond to public? as false if profile is invisible' do | ||
| 532 | - profile = fast_create(Profile, :visible => false) | ||
| 533 | - article1 = fast_create(Article, :profile_id => profile.id) | ||
| 534 | - article2 = fast_create(Article, :profile_id => profile.id, :public_article => false) | ||
| 535 | - | ||
| 536 | - assert !article1.public? | ||
| 537 | - assert !article2.public? | 510 | + assert !article.published? |
| 538 | end | 511 | end |
| 539 | 512 | ||
| 540 | should 'save as private' do | 513 | should 'save as private' do |
| 541 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 514 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
| 542 | - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 515 | + folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) |
| 543 | article = TextileArticle.new(:name => 'my private article') | 516 | article = TextileArticle.new(:name => 'my private article') |
| 544 | article.profile = profile | 517 | article.profile = profile |
| 545 | article.parent = folder | 518 | article.parent = folder |
| 546 | article.save! | 519 | article.save! |
| 547 | article.reload | 520 | article.reload |
| 548 | 521 | ||
| 549 | - assert !article.public_article | 522 | + assert !article.published? |
| 550 | end | 523 | end |
| 551 | 524 | ||
| 552 | should 'not allow friends of private person see the article' do | 525 | should 'not allow friends of private person see the article' do |
| 553 | person = create_user('test_user').person | 526 | person = create_user('test_user').person |
| 554 | - article = Article.create!(:name => 'test article', :profile => person, :public_article => false) | 527 | + article = Article.create!(:name => 'test article', :profile => person, :published => false) |
| 555 | friend = create_user('test_friend').person | 528 | friend = create_user('test_friend').person |
| 556 | person.add_friend(friend) | 529 | person.add_friend(friend) |
| 557 | person.save! | 530 | person.save! |
| @@ -562,7 +535,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -562,7 +535,7 @@ class ArticleTest < Test::Unit::TestCase | ||
| 562 | 535 | ||
| 563 | should 'display private articles to people who can view private content' do | 536 | should 'display private articles to people who can view private content' do |
| 564 | person = create_user('test_user').person | 537 | person = create_user('test_user').person |
| 565 | - article = Article.create!(:name => 'test article', :profile => person, :public_article => false) | 538 | + article = Article.create!(:name => 'test article', :profile => person, :published => false) |
| 566 | 539 | ||
| 567 | admin_user = create_user('admin_user').person | 540 | admin_user = create_user('admin_user').person |
| 568 | admin_user.stubs(:has_permission?).with('view_private_content', article.profile).returns('true') | 541 | admin_user.stubs(:has_permission?).with('view_private_content', article.profile).returns('true') |
test/unit/profile_test.rb
| @@ -930,8 +930,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -930,8 +930,8 @@ class ProfileTest < Test::Unit::TestCase | ||
| 930 | p1 = create(Profile) | 930 | p1 = create(Profile) |
| 931 | p2 = create(Profile, :public_profile => false) | 931 | p2 = create(Profile, :public_profile => false) |
| 932 | 932 | ||
| 933 | - assert p1.articles.find(:first, :conditions => {:public_article => false}) | ||
| 934 | - assert !p2.articles.find(:first, :conditions => {:public_article => false}) | 933 | + assert p1.articles.find(:first, :conditions => {:published => false}) |
| 934 | + assert !p2.articles.find(:first, :conditions => {:published => false}) | ||
| 935 | end | 935 | end |
| 936 | 936 | ||
| 937 | should 'remove member with many roles' do | 937 | should 'remove member with many roles' do |