Commit 1121fdb76050dd788cfe7b724e2c84832a710db3
1 parent
abdf6fab
Exists in
master
and in
29 other branches
create_topics: Add logic to show the create topic button to community members
(ActionItem2997) Signed_off_by: Gabriela Navarro <navarro1703@gmail.com> Signed_off_by: Gustavo Jaruga <darksshades@gmail.com>
Showing
5 changed files
with
106 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -24,10 +24,16 @@ class CmsController < MyProfileController | @@ -24,10 +24,16 @@ class CmsController < MyProfileController | ||
24 | (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) | 24 | (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) |
25 | end | 25 | end |
26 | 26 | ||
27 | - protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files] do |c, user, profile| | 27 | + protect_if :except => [:suggest_an_article, :set_home_page, :edit, :destroy, :publish, :upload_files, :new] do |c, user, profile| |
28 | user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) | 28 | user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) |
29 | end | 29 | end |
30 | 30 | ||
31 | + protect_if :only => :new do |c, user, profile| | ||
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))) | ||
35 | + end | ||
36 | + | ||
31 | protect_if :only => [:destroy, :publish] do |c, user, profile| | 37 | protect_if :only => [:destroy, :publish] do |c, user, profile| |
32 | profile.articles.find(c.params[:id]).allow_post_content?(user) | 38 | profile.articles.find(c.params[:id]).allow_post_content?(user) |
33 | end | 39 | end |
app/helpers/article_helper.rb
@@ -49,8 +49,14 @@ module ArticleHelper | @@ -49,8 +49,14 @@ module ArticleHelper | ||
49 | 'div', | 49 | 'div', |
50 | check_box(:article, :display_versions) + | 50 | check_box(:article, :display_versions) + |
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? ? | ||
55 | + content_tag( | ||
56 | + 'div', | ||
57 | + check_box(:article, :allows_create_topics) + | ||
58 | + content_tag('label', _('Allow member to create topics'), :for => 'article_allows_create_topics') | ||
59 | + ) : '') | ||
54 | ) | 60 | ) |
55 | end | 61 | end |
56 | 62 |
app/models/forum.rb
@@ -5,6 +5,7 @@ class Forum < Folder | @@ -5,6 +5,7 @@ class Forum < 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 | 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' |
9 | 10 | ||
10 | before_save do |forum| | 11 | before_save do |forum| |
@@ -66,4 +67,7 @@ class Forum < Folder | @@ -66,4 +67,7 @@ class Forum < Folder | ||
66 | self.users_with_agreement.exists? user | 67 | self.users_with_agreement.exists? user |
67 | end | 68 | end |
68 | 69 | ||
70 | + def can_create_topic?(user, profile) | ||
71 | + return profile.community? && profile.members.include?(user) && self.allows_create_topics | ||
72 | + end | ||
69 | end | 73 | 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) %> | 29 | + <% if !@page.gallery? && ( @page.allow_create?(user) || (@page.forum? && @page.can_create_topic?(user, profile))) %> |
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
@@ -166,3 +166,90 @@ Feature: forum | @@ -166,3 +166,90 @@ Feature: forum | ||
166 | | Post one | joaosilva | Hi all | Hi all | | 166 | | Post one | joaosilva | Hi all | Hi all | |
167 | When I go to /joaosilva/forum | 167 | When I go to /joaosilva/forum |
168 | Then I should see "Joao" linking to "http://localhost/joaosilva" | 168 | Then I should see "Joao" linking to "http://localhost/joaosilva" |
169 | + | ||
170 | + @selenium | ||
171 | + Scenario: community member should be able to see the discussion topic button | ||
172 | + Given the following community | ||
173 | + | identifier | name | owner | | ||
174 | + | sample-community | Sample Community | joaosilva | | ||
175 | + And the following forums | ||
176 | + | owner | name | | ||
177 | + | sample-community | Forum | | ||
178 | + And the following users | ||
179 | + | login | name | | ||
180 | + | mariasilva | Maria Silva| | ||
181 | + And "Maria Silva" is a member of "Sample Community" | ||
182 | + And I am logged in as "joaosilva" | ||
183 | + When I go to /sample-community/forum | ||
184 | + And I follow "Configure forum" | ||
185 | + And I check "Allow member to create topics" | ||
186 | + And I press "Save" | ||
187 | + And I am logged in as "mariasilva" | ||
188 | + And I go to /sample-community/forum | ||
189 | + Then I should see "New discussion topic" | ||
190 | + | ||
191 | + @selenium | ||
192 | + Scenario: a non community member should not be able to see the discussion topic button | ||
193 | + Given the following community | ||
194 | + | identifier | name | owner | | ||
195 | + | sample-community | Sample Community | joaosilva | | ||
196 | + And the following forums | ||
197 | + | owner | name | | ||
198 | + | sample-community | Forum | | ||
199 | + And the following users | ||
200 | + | login | name | | ||
201 | + | mariasilva | Maria Silva| | ||
202 | + And I am logged in as "joaosilva" | ||
203 | + When I go to /sample-community/forum | ||
204 | + And I follow "Configure forum" | ||
205 | + And I check "Allow member to create topics" | ||
206 | + And I press "Save" | ||
207 | + And I am logged in as "mariasilva" | ||
208 | + And I go to /sample-community/forum | ||
209 | + Then I should not see "New discussion topic" | ||
210 | + | ||
211 | + @selenium | ||
212 | + Scenario: community member should not be able to see the discussion topic button | ||
213 | + Given the following community | ||
214 | + | identifier | name | owner | | ||
215 | + | sample-community | Sample Community | joaosilva | | ||
216 | + And the following forums | ||
217 | + | owner | name | | ||
218 | + | sample-community | Forum | | ||
219 | + And the following users | ||
220 | + | login | name | | ||
221 | + | mariasilva | Maria Silva| | ||
222 | + And "Maria Silva" is a member of "Sample Community" | ||
223 | + And I am logged in as "joaosilva" | ||
224 | + When I go to /sample-community/forum | ||
225 | + And I follow "Configure forum" | ||
226 | + And I uncheck "Allow member to create topics" | ||
227 | + And I press "Save" | ||
228 | + And I am logged in as "mariasilva" | ||
229 | + And I go to /sample-community/forum | ||
230 | + Then I should not see "New discussion topic" | ||
231 | + | ||
232 | + @selenium | ||
233 | + Scenario: community member should be able to create the discussion topic button | ||
234 | + Given the following community | ||
235 | + | identifier | name | owner | | ||
236 | + | sample-community | Sample Community | joaosilva | | ||
237 | + And the following forums | ||
238 | + | owner | name | | ||
239 | + | sample-community | Forum | | ||
240 | + And the following users | ||
241 | + | login | name | | ||
242 | + | mariasilva | Maria Silva| | ||
243 | + And "Maria Silva" is a member of "Sample Community" | ||
244 | + And I am logged in as "joaosilva" | ||
245 | + When I go to /sample-community/forum | ||
246 | + And I follow "Configure forum" | ||
247 | + And I check "Allow member to create topics" | ||
248 | + And I press "Save" | ||
249 | + And I am logged in as "mariasilva" | ||
250 | + And I go to /sample-community/forum | ||
251 | + And I follow "New discussion topic" | ||
252 | + And I follow "Text article with visual editor" | ||
253 | + And I fill in "Title" with "Test" | ||
254 | + And I press "Save" | ||
255 | + Then I should see "Test" | ||
169 | \ No newline at end of file | 256 | \ No newline at end of file |