Commit 1c211c7895f7fe67191329fc837693eebc9df423

Authored by Gabriela Navarro
1 parent 1121fdb7

create_topics: Corrections for merge-request.

(ActionItem2997)

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
app/controllers/my_profile/cms_controller.rb
@@ -30,8 +30,8 @@ class CmsController &lt; MyProfileController @@ -30,8 +30,8 @@ class CmsController &lt; MyProfileController
30 30
31 protect_if :only => :new do |c, user, profile| 31 protect_if :only => :new do |c, user, profile|
32 article_id = c.params[:parent_id] 32 article_id = c.params[:parent_id]
33 - (!article_id.blank? && profile.articles.find(article_id).forum? && profile.articles.find(article_id).allows_create_topics ) &&  
34 - (profile.community? && profile.members.include?(user)) || (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) 33 + (!article_id.blank? && (profile.articles.find(article_id).allow_create?(user) || profile.articles.find(article_id).parent.allow_create?(user))) ||
  34 + (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)))
35 end 35 end
36 36
37 protect_if :only => [:destroy, :publish] do |c, user, profile| 37 protect_if :only => [:destroy, :publish] do |c, user, profile|
app/helpers/article_helper.rb
@@ -51,11 +51,11 @@ module ArticleHelper @@ -51,11 +51,11 @@ module ArticleHelper
51 content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions') 51 content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions')
52 ) : '') + 52 ) : '') +
53 53
54 - (article.forum? ? 54 + (article.forum? && article.profile.community? ?
55 content_tag( 55 content_tag(
56 'div', 56 'div',
57 - check_box(:article, :allows_create_topics) +  
58 - content_tag('label', _('Allow member to create topics'), :for => 'article_allows_create_topics') 57 + check_box(:article, :allows_members_to_create_topics) +
  58 + content_tag('label', _('Allow member to create topics'), :for => 'article_allows_members_to_create_topics')
59 ) : '') 59 ) : '')
60 ) 60 )
61 end 61 end
app/models/forum.rb
@@ -5,7 +5,7 @@ class Forum &lt; Folder @@ -5,7 +5,7 @@ class Forum &lt; Folder
5 5
6 settings_items :terms_of_use, :type => :string, :default => "" 6 settings_items :terms_of_use, :type => :string, :default => ""
7 settings_items :has_terms_of_use, :type => :boolean, :default => false 7 settings_items :has_terms_of_use, :type => :boolean, :default => false
8 - settings_items :allows_create_topics, :type => :boolean, :default => true 8 + settings_items :allows_members_to_create_topics, :type => :boolean, :default => false
9 has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' 9 has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people'
10 10
11 before_save do |forum| 11 before_save do |forum|
@@ -68,6 +68,10 @@ class Forum &lt; Folder @@ -68,6 +68,10 @@ class Forum &lt; Folder
68 end 68 end
69 69
70 def can_create_topic?(user, profile) 70 def can_create_topic?(user, profile)
71 - return profile.community? && profile.members.include?(user) && self.allows_create_topics 71 + return profile.community? && profile.members.include?(user) && self.allows_members_to_create_topics
  72 + end
  73 +
  74 + def allow_create?(user)
  75 + super || can_create_topic?(user, profile)
72 end 76 end
73 end 77 end
app/views/content_viewer/_article_toolbar.rhtml
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 <%= expirable_button @page, :spread, content, url if url %> 26 <%= expirable_button @page, :spread, content, url if url %>
27 <% end %> 27 <% end %>
28 28
29 - <% if !@page.gallery? && ( @page.allow_create?(user) || (@page.forum? && @page.can_create_topic?(user, profile))) %> 29 + <% if !@page.gallery? && (@page.allow_create?(user) || (@page.parent && @page.parent.allow_create?(user))) %>
30 <% if @page.translatable? && !@page.native_translation.language.blank? && !remove_content_button(:locale) %> 30 <% if @page.translatable? && !@page.native_translation.language.blank? && !remove_content_button(:locale) %>
31 <% content = _('Add translation') %> 31 <% content = _('Add translation') %>
32 <% parent_id = (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)) %> 32 <% parent_id = (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)) %>
features/forum.feature
@@ -230,7 +230,7 @@ Feature: forum @@ -230,7 +230,7 @@ Feature: forum
230 Then I should not see "New discussion topic" 230 Then I should not see "New discussion topic"
231 231
232 @selenium 232 @selenium
233 - Scenario: community member should be able to create the discussion topic button 233 + Scenario: community member should be able to create a topic with the discussion topic button
234 Given the following community 234 Given the following community
235 | identifier | name | owner | 235 | identifier | name | owner |
236 | sample-community | Sample Community | joaosilva | 236 | sample-community | Sample Community | joaosilva |
@@ -252,4 +252,35 @@ Feature: forum @@ -252,4 +252,35 @@ Feature: forum
252 And I follow "Text article with visual editor" 252 And I follow "Text article with visual editor"
253 And I fill in "Title" with "Test" 253 And I fill in "Title" with "Test"
254 And I press "Save" 254 And I press "Save"
255 - Then I should see "Test"  
256 \ No newline at end of file 255 \ No newline at end of file
  256 + Then I should see "Test"
  257 +
  258 + @selenium
  259 + Scenario: community member should be able to create a topic on a topic page
  260 + Given the following community
  261 + | identifier | name | owner |
  262 + | sample-community | Sample Community | joaosilva |
  263 + And the following forums
  264 + | owner | name |
  265 + | sample-community | Forum |
  266 + And the following users
  267 + | login | name |
  268 + | mariasilva | Maria Silva|
  269 + And "Maria Silva" is a member of "Sample Community"
  270 + And I am logged in as "joaosilva"
  271 + When I go to /sample-community/forum
  272 + And I follow "Configure forum"
  273 + And I check "Allow member to create topics"
  274 + And I press "Save"
  275 + And I am logged in as "mariasilva"
  276 + And I go to /sample-community/forum
  277 + And I follow "New discussion topic"
  278 + And I follow "Text article with visual editor"
  279 + And I fill in "Title" with "Test"
  280 + And I press "Save"
  281 + And I go to /sample-community/forum/test
  282 + And I follow "New discussion topic"
  283 + And I follow "Text article with visual editor"
  284 + And I fill in "Title" with "Test inside the topic page"
  285 + And I press "Save"
  286 + And I go to /sample-community/forum
  287 + Then I should see "Test inside the topic page"
257 \ No newline at end of file 288 \ No newline at end of file