diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 3559cd5..d8d715f 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -27,20 +27,13 @@ class CmsController < MyProfileController helper_method :file_types - protect_if :only => :upload_files do |c, user, profile| - article_id = c.params[:parent_id] - (!article_id.blank? && profile.articles.find(article_id).allow_create?(user)) || - (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) - end - - protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :publish_on_portal_community, :publish_on_communities, :search_communities_to_publish, :upload_files, :new] do |c, user, profile| + protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) end - protect_if :only => :new do |c, user, profile| - article = profile.articles.find_by_id(c.params[:parent_id]) - (!article.nil? && (article.allow_create?(user) || article.parent.allow_create?(user))) || - (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) + protect_if :only => [:new, :upload_files] do |c, user, profile| + parent = profile.articles.find_by_id(c.params[:parent_id]) + user && user.can_post_content?(profile, parent) end protect_if :only => :destroy do |c, user, profile| diff --git a/app/models/person.rb b/app/models/person.rb index 9973c1e..ae1451e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -123,6 +123,11 @@ roles] } self.tracked_notifications.exists?(activity) end + def can_post_content?(profile, parent=nil) + (!parent.nil? && (parent.allow_create?(self))) || + (self.has_permission?('post_content', profile) || self.has_permission?('publish_content', profile)) + end + # Sets the identifier for this person. Raises an exception when called on a # existing person (since peoples' identifiers cannot be changed) def identifier=(value) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 7a13921..3603a72 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1524,6 +1524,7 @@ class PersonTest < ActiveSupport::TestCase end end +<<<<<<< HEAD should 'have a list of suggested people to be friend' do person = create_user('person').person suggested_friend = fast_create(Person) @@ -1638,4 +1639,27 @@ class PersonTest < ActiveSupport::TestCase assert_equal false, person.follows?(nil) end + should 'allow posting content when has post_content permission' do + person = create_user('person').person + profile = mock + person.expects(:has_permission?).with('post_content', profile).returns(true) + assert person.can_post_content?(profile) + end + + should 'allow posting content when has publish_content permission' do + person = create_user('person').person + profile = mock + person.expects(:has_permission?).with('post_content', profile).returns(false) + person.expects(:has_permission?).with('publish_content', profile).returns(true) + assert person.can_post_content?(profile) + end + + should 'allow posting content when has permission in the parent' do + person = create_user('person').person + profile = mock + parent = mock + parent.expects(:allow_create?).with(person).returns(true) + assert person.can_post_content?(profile, parent) + end + end -- libgit2 0.21.2