diff --git a/app/models/article.rb b/app/models/article.rb
index 06145af..f62769c 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -42,6 +42,13 @@ class Article < ActiveRecord::Base
pending_categorizations.clear
end
+ before_save do |article|
+ if article.parent
+ article.public_article = article.parent.public_article
+ end
+ true
+ end
+
acts_as_taggable
N_('Tag list')
@@ -156,6 +163,10 @@ class Article < ActiveRecord::Base
!cat.is_a?(ProductCategory)
end
+ def public?
+ profile.public? && public_article
+ end
+
private
def sanitize_tag_list
diff --git a/app/models/product.rb b/app/models/product.rb
index 0304166..798b3e4 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -63,4 +63,8 @@ class Product < ActiveRecord::Base
enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => id)
end
+ def public?
+ enterprise.public_profile
+ end
+
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 6db0a78..38aa5ed 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -304,16 +304,24 @@ class Profile < ActiveRecord::Base
false
end
- after_create :insert_default_homepage_and_feed
- def insert_default_homepage_and_feed
+ after_create :insert_default_article_set
+ def insert_default_article_set
+ # a default homepage
hp = default_homepage(:name => _("%s's home page") % self.name, :body => _("
This is a default homepage created for %s. It can be changed though the control panel.
") % self.name, :advertise => false)
hp.profile = self
hp.save!
self.home_page = hp
self.save!
+ # a default rss feed
feed = RssFeed.new(:name => 'feed')
self.articles << feed
+
+ # a default private folder if public
+ if self.public?
+ folder = Folder.new(:name => _("Intranet"), :public_article => false)
+ self.articles << folder
+ end
end
# Adds a person as member of this Profile.
@@ -403,4 +411,7 @@ class Profile < ActiveRecord::Base
self[:theme] || environment.theme
end
+ def public?
+ public_profile
+ end
end
diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml
index e3af92f..d6dc105 100644
--- a/app/views/search/_display_results.rhtml
+++ b/app/views/search/_display_results.rhtml
@@ -38,7 +38,7 @@
<% hit_pos = 0 %>
<% results.each do |hit| %>
- <% next if hit.respond_to?(:public_profile) && !hit.public_profile %>
+ <% next if hit.respond_to?(:public?) && !hit.public? %>
<%= render :partial => partial_for_class(hit.class),
:object => hit,
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 1510fae..c47e546 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -347,6 +347,7 @@ class CmsControllerTest < Test::Unit::TestCase
end
should 'list folders at top level' do
+ Folder.destroy_all
f1 = Folder.new(:name => 'f1'); profile.articles << f1; f1.save!
f2 = Folder.new(:name => 'f2'); profile.articles << f2; f2.save!
@@ -542,4 +543,15 @@ class CmsControllerTest < Test::Unit::TestCase
assert_redirected_to @profile.articles.find_by_name('new-article-from-public-view').url
end
+ should 'create a private article child of private folder' do
+ folder = Folder.new(:name => 'my intranet', :public_article => false); profile.articles << folder; folder.save!
+
+ post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'}
+ folder.reload
+
+ assert !assigns(:article).public?
+ assert_equal 'new-private-article', folder.children[0].name
+ assert !folder.children[0].public?
+ end
+
end
diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb
index 49e1bd3..07bba13 100644
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -364,4 +364,45 @@ class ArticleTest < Test::Unit::TestCase
assert !article.display_to?(person2)
assert article.display_to?(person1)
end
+
+ should 'make new article private if created inside a private folder' do
+ profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile')
+ folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false)
+ article = Article.create!(:name => 'my private article', :profile => profile, :parent => folder)
+
+ assert !article.public_article
+ end
+
+ should 'respond to public? like public_article if profile is public' do
+ p = Profile.create!(:name => 'test profile', :identifier => 'test_profile')
+ a1 = Article.create!(:name => 'test public article', :profile => p)
+ a2 = Article.create!(:name => 'test private article', :profile => p, :public_article => false)
+
+ assert a1.public?
+ assert !a2.public?
+ end
+
+ should 'respond to public? as false if profile is private' do
+ p = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false)
+ a1 = Article.create!(:name => 'test public article', :profile => p)
+ a2 = Article.create!(:name => 'test private article', :profile => p, :public_article => false)
+
+ assert !a1.public?
+ assert !a2.public?
+ end
+
+ should 'save as private' do
+ profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile')
+ folder = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false)
+ article = TextileArticle.new(:name => 'my private article')
+ article.profile = profile
+ article.parent = folder
+ article.save!
+ article.reload
+
+ assert !article.public_article
+
+
+ end
+
end
diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb
index 1ccf2f9..06cc6fe 100644
--- a/test/unit/product_test.rb
+++ b/test/unit/product_test.rb
@@ -168,4 +168,16 @@ class ProductTest < Test::Unit::TestCase
assert !ProductCategorization.find(:first, :conditions => {:product_id => p, :category_id => cat})
end
+ should 'respond to public? as its enterprise public?' do
+ e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1')
+ p1 = Product.create!(:name => 'test product 1', :enterprise => e1)
+
+ assert p1.public?
+
+ e1.public_profile = false
+ e1.save!
+
+ assert !p1.public?
+ end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index c3da50b..c0f369c 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -794,6 +794,22 @@ class ProfileTest < Test::Unit::TestCase
assert_equal 'environment-stored-theme', p.theme
end
+ should 'respond to public? as public_profile' do
+ p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1')
+ p2 = Profile.create!(:name => 'test profile 2', :identifier => 'test_profile2', :public_profile => false)
+
+ assert p1.public?
+ assert !p2.public?
+ end
+
+ should 'create a initial private folder when a public profile is created' do
+ p1 = Profile.create!(:name => 'test profile 1', :identifier => 'test_profile1')
+ p2 = Profile.create!(:name => 'test profile 2', :identifier => 'test_profile2', :public_profile => false)
+
+ assert p1.articles.find(:first, :conditions => {:public_article => false})
+ assert !p2.articles.find(:first, :conditions => {:public_article => false})
+ end
+
private
def assert_invalid_identifier(id)
--
libgit2 0.21.2