From 1121fdb76050dd788cfe7b724e2c84832a710db3 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Wed, 12 Feb 2014 17:07:51 -0200 Subject: [PATCH] create_topics: Add logic to show the create topic button to community members --- app/controllers/my_profile/cms_controller.rb | 8 +++++++- app/helpers/article_helper.rb | 8 +++++++- app/models/forum.rb | 4 ++++ app/views/content_viewer/_article_toolbar.rhtml | 2 +- features/forum.feature | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 6c8db1f..ed29140 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -24,10 +24,16 @@ class CmsController < MyProfileController (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, :upload_files] 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_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))) + end + protect_if :only => [:destroy, :publish] do |c, user, profile| profile.articles.find(c.params[:id]).allow_post_content?(user) end diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index ea9046d..aa6bac9 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -49,8 +49,14 @@ module ArticleHelper 'div', check_box(:article, :display_versions) + content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions') - ) : '') + ) : '') + + (article.forum? ? + content_tag( + 'div', + check_box(:article, :allows_create_topics) + + content_tag('label', _('Allow member to create topics'), :for => 'article_allows_create_topics') + ) : '') ) end diff --git a/app/models/forum.rb b/app/models/forum.rb index 0081452..2303916 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -5,6 +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 has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' before_save do |forum| @@ -66,4 +67,7 @@ class Forum < Folder self.users_with_agreement.exists? user end + def can_create_topic?(user, profile) + return profile.community? && profile.members.include?(user) && self.allows_create_topics + end end diff --git a/app/views/content_viewer/_article_toolbar.rhtml b/app/views/content_viewer/_article_toolbar.rhtml index 139d249..6faff83 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) %> + <% if !@page.gallery? && ( @page.allow_create?(user) || (@page.forum? && @page.can_create_topic?(user, profile))) %> <% 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 11a6327..dc2fe91 100644 --- a/features/forum.feature +++ b/features/forum.feature @@ -166,3 +166,90 @@ Feature: forum | Post one | joaosilva | Hi all | Hi all | When I go to /joaosilva/forum Then I should see "Joao" linking to "http://localhost/joaosilva" + + @selenium + Scenario: community member should be able to see the discussion topic button + 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 + Then I should see "New discussion topic" + + @selenium + Scenario: a non community member should not be able to see the discussion topic button + 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 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 + Then I should not see "New discussion topic" + + @selenium + Scenario: community member should not be able to see the discussion topic button + 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 uncheck "Allow member to create topics" + And I press "Save" + And I am logged in as "mariasilva" + And I go to /sample-community/forum + Then I should not see "New discussion topic" + + @selenium + Scenario: community member should be able to create the discussion topic button + 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" + Then I should see "Test" \ No newline at end of file -- libgit2 0.21.2