Commit f309c8f791e6ba4c8fabcbce9dd2e89635f81d98
Committed by
Rodrigo Souto
1 parent
7e6f215a
Exists in
staging
and in
42 other branches
topic-forum: allow the author to edit and delete your own topic
AI3135
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
app/models/article.rb
@@ -489,6 +489,7 @@ class Article < ActiveRecord::Base | @@ -489,6 +489,7 @@ class Article < ActiveRecord::Base | ||
489 | end | 489 | end |
490 | 490 | ||
491 | def allow_post_content?(user = nil) | 491 | def allow_post_content?(user = nil) |
492 | + return true if allow_edit_topic?(user) | ||
492 | user && (user.has_permission?('post_content', profile) || allow_publish_content?(user) && (user == author)) | 493 | user && (user.has_permission?('post_content', profile) || allow_publish_content?(user) && (user == author)) |
493 | end | 494 | end |
494 | 495 | ||
@@ -508,9 +509,14 @@ class Article < ActiveRecord::Base | @@ -508,9 +509,14 @@ class Article < ActiveRecord::Base | ||
508 | end | 509 | end |
509 | 510 | ||
510 | def allow_edit?(user) | 511 | def allow_edit?(user) |
512 | + return true if allow_edit_topic?(user) | ||
511 | allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) | 513 | allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) |
512 | end | 514 | end |
513 | 515 | ||
516 | + def allow_edit_topic?(user) | ||
517 | + self.belongs_to_forum? && (user == author) && user.is_member_of?(profile) | ||
518 | + end | ||
519 | + | ||
514 | def moderate_comments? | 520 | def moderate_comments? |
515 | moderate_comments == true | 521 | moderate_comments == true |
516 | end | 522 | end |
test/unit/article_test.rb
@@ -1660,6 +1660,16 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1660,6 +1660,16 @@ class ArticleTest < ActiveSupport::TestCase | ||
1660 | a.allow_members_to_edit = true | 1660 | a.allow_members_to_edit = true |
1661 | assert !a.allow_edit?(nil) | 1661 | assert !a.allow_edit?(nil) |
1662 | end | 1662 | end |
1663 | + | ||
1664 | + should 'allow author to edit topic' do | ||
1665 | + community = fast_create(Community) | ||
1666 | + author = fast_create(Person) | ||
1667 | + community.add_member(author) | ||
1668 | + forum = Forum.create(:profile => community, :name => 'Forum test', :body => 'Forum test') | ||
1669 | + post = fast_create(TextileArticle, :name => 'First post', :profile_id => community.id, :parent_id => forum.id, :last_changed_by_id => author.id) | ||
1670 | + | ||
1671 | + assert post.allow_edit?(author) | ||
1672 | + end | ||
1663 | 1673 | ||
1664 | should 'has a empty list of followers by default' do | 1674 | should 'has a empty list of followers by default' do |
1665 | a = Article.new | 1675 | a = Article.new |