Commit 02b1304485b559e13783fa8cb2d174b70d7a9892
Exists in
master
and in
28 other branches
Merge branch 'AI2997-create_topics_forum' of https://gitlab.com/unb-gama/noosfero
Showing
5 changed files
with
141 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -24,10 +24,16 @@ class CmsController < MyProfileController |
| 24 | 24 | (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile))) |
| 25 | 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 | 28 | user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)) |
| 29 | 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).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 | |
| 36 | + | |
| 31 | 37 | protect_if :only => [:destroy, :publish] do |c, user, profile| |
| 32 | 38 | profile.articles.find(c.params[:id]).allow_post_content?(user) |
| 33 | 39 | end | ... | ... |
app/helpers/article_helper.rb
| ... | ... | @@ -49,8 +49,14 @@ module ArticleHelper |
| 49 | 49 | 'div', |
| 50 | 50 | check_box(:article, :display_versions) + |
| 51 | 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? && article.profile.community? ? | |
| 55 | + content_tag( | |
| 56 | + 'div', | |
| 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 | + ) : '') | |
| 54 | 60 | ) |
| 55 | 61 | end |
| 56 | 62 | ... | ... |
app/models/forum.rb
| ... | ... | @@ -5,6 +5,7 @@ class Forum < Folder |
| 5 | 5 | |
| 6 | 6 | settings_items :terms_of_use, :type => :string, :default => "" |
| 7 | 7 | settings_items :has_terms_of_use, :type => :boolean, :default => false |
| 8 | + settings_items :allows_members_to_create_topics, :type => :boolean, :default => false | |
| 8 | 9 | has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' |
| 9 | 10 | |
| 10 | 11 | before_save do |forum| |
| ... | ... | @@ -66,4 +67,11 @@ class Forum < Folder |
| 66 | 67 | self.users_with_agreement.exists? user |
| 67 | 68 | end |
| 68 | 69 | |
| 70 | + def can_create_topic?(user, profile) | |
| 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) | |
| 76 | + end | |
| 69 | 77 | end | ... | ... |
app/views/content_viewer/_article_toolbar.rhtml
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 | <%= expirable_button @page, :spread, content, url if url %> |
| 27 | 27 | <% end %> |
| 28 | 28 | |
| 29 | - <% if !@page.gallery? && @page.allow_create?(user) %> | |
| 29 | + <% if !@page.gallery? && (@page.allow_create?(user) || (@page.parent && @page.parent.allow_create?(user))) %> | |
| 30 | 30 | <% if @page.translatable? && !@page.native_translation.language.blank? && !remove_content_button(:locale) %> |
| 31 | 31 | <% content = _('Add translation') %> |
| 32 | 32 | <% parent_id = (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)) %> | ... | ... |
features/forum.feature
| ... | ... | @@ -166,3 +166,121 @@ Feature: forum |
| 166 | 166 | | Post one | joaosilva | Hi all | Hi all | |
| 167 | 167 | When I go to /joaosilva/forum |
| 168 | 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 a topic with 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" | |
| 256 | + | |
| 257 | + @selenium | |
| 258 | + Scenario: community member should be able to create a topic on a topic page | |
| 259 | + Given the following community | |
| 260 | + | identifier | name | owner | | |
| 261 | + | sample-community | Sample Community | joaosilva | | |
| 262 | + And the following forums | |
| 263 | + | owner | name | | |
| 264 | + | sample-community | Forum | | |
| 265 | + And the following users | |
| 266 | + | login | name | | |
| 267 | + | mariasilva | Maria Silva| | |
| 268 | + And "Maria Silva" is a member of "Sample Community" | |
| 269 | + And I am logged in as "joaosilva" | |
| 270 | + When I go to /sample-community/forum | |
| 271 | + And I follow "Configure forum" | |
| 272 | + And I check "Allow member to create topics" | |
| 273 | + And I press "Save" | |
| 274 | + And I am logged in as "mariasilva" | |
| 275 | + And I go to /sample-community/forum | |
| 276 | + And I follow "New discussion topic" | |
| 277 | + And I follow "Text article with visual editor" | |
| 278 | + And I fill in "Title" with "Test" | |
| 279 | + And I press "Save" | |
| 280 | + And I go to /sample-community/forum/test | |
| 281 | + And I follow "New discussion topic" | |
| 282 | + And I follow "Text article with visual editor" | |
| 283 | + And I fill in "Title" with "Test inside the topic page" | |
| 284 | + And I press "Save" | |
| 285 | + And I go to /sample-community/forum | |
| 286 | + Then I should see "Test inside the topic page" | |
| 169 | 287 | \ No newline at end of file | ... | ... |