diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index ed29140..36d3882 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -30,8 +30,8 @@ class CmsController < MyProfileController protect_if :only => :new do |c, user, profile| article_id = c.params[:parent_id] - (!article_id.blank? && profile.articles.find(article_id).forum? && profile.articles.find(article_id).allows_create_topics ) && - (profile.community? && profile.members.include?(user)) || (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) + (!article_id.blank? && (profile.articles.find(article_id).allow_create?(user) || profile.articles.find(article_id).parent.allow_create?(user))) || + (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) end protect_if :only => [:destroy, :publish] do |c, user, profile| diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index aa6bac9..cadd116 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -51,11 +51,11 @@ module ArticleHelper content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions') ) : '') + - (article.forum? ? + (article.forum? && article.profile.community? ? content_tag( 'div', - check_box(:article, :allows_create_topics) + - content_tag('label', _('Allow member to create topics'), :for => 'article_allows_create_topics') + check_box(:article, :allows_members_to_create_topics) + + content_tag('label', _('Allow member to create topics'), :for => 'article_allows_members_to_create_topics') ) : '') ) end diff --git a/app/models/forum.rb b/app/models/forum.rb index 2303916..e3a4285 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -5,7 +5,7 @@ class Forum < Folder settings_items :terms_of_use, :type => :string, :default => "" settings_items :has_terms_of_use, :type => :boolean, :default => false - settings_items :allows_create_topics, :type => :boolean, :default => true + settings_items :allows_members_to_create_topics, :type => :boolean, :default => false has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' before_save do |forum| @@ -68,6 +68,10 @@ class Forum < Folder end def can_create_topic?(user, profile) - return profile.community? && profile.members.include?(user) && self.allows_create_topics + return profile.community? && profile.members.include?(user) && self.allows_members_to_create_topics + end + + def allow_create?(user) + super || can_create_topic?(user, profile) end end diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml index 6faff83..b36ffa3 100644 --- a/app/views/content_viewer/_article_toolbar.rhtml +++ b/app/views/content_viewer/_article_toolbar.rhtml @@ -26,7 +26,7 @@ <%= expirable_button @page, :spread, content, url if url %> <% end %> - <% if !@page.gallery? && ( @page.allow_create?(user) || (@page.forum? && @page.can_create_topic?(user, profile))) %> + <% if !@page.gallery? && (@page.allow_create?(user) || (@page.parent && @page.parent.allow_create?(user))) %> <% if @page.translatable? && !@page.native_translation.language.blank? && !remove_content_button(:locale) %> <% content = _('Add translation') %> <% parent_id = (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)) %> diff --git a/features/forum.feature b/features/forum.feature index dc2fe91..8f9d79a 100644 --- a/features/forum.feature +++ b/features/forum.feature @@ -230,7 +230,7 @@ Feature: forum Then I should not see "New discussion topic" @selenium - Scenario: community member should be able to create the discussion topic button + Scenario: community member should be able to create a topic with the discussion topic button Given the following community | identifier | name | owner | | sample-community | Sample Community | joaosilva | @@ -252,4 +252,35 @@ Feature: forum And I follow "Text article with visual editor" And I fill in "Title" with "Test" And I press "Save" - Then I should see "Test" \ No newline at end of file + Then I should see "Test" + + @selenium + Scenario: community member should be able to create a topic on a topic page + Given the following community + | identifier | name | owner | + | sample-community | Sample Community | joaosilva | + And the following forums + | owner | name | + | sample-community | Forum | + And the following users + | login | name | + | mariasilva | Maria Silva| + And "Maria Silva" is a member of "Sample Community" + And I am logged in as "joaosilva" + When I go to /sample-community/forum + And I follow "Configure forum" + And I check "Allow member to create topics" + And I press "Save" + And I am logged in as "mariasilva" + And I go to /sample-community/forum + And I follow "New discussion topic" + And I follow "Text article with visual editor" + And I fill in "Title" with "Test" + And I press "Save" + And I go to /sample-community/forum/test + And I follow "New discussion topic" + And I follow "Text article with visual editor" + And I fill in "Title" with "Test inside the topic page" + And I press "Save" + And I go to /sample-community/forum + Then I should see "Test inside the topic page" \ No newline at end of file -- libgit2 0.21.2