From f309c8f791e6ba4c8fabcbce9dd2e89635f81d98 Mon Sep 17 00:00:00 2001 From: Junior Silva Date: Thu, 15 May 2014 17:44:16 -0300 Subject: [PATCH] topic-forum: allow the author to edit and delete your own topic AI3135 --- app/models/article.rb | 6 ++++++ test/unit/article_test.rb | 10 ++++++++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index d1a0d99..fdef53a 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -489,6 +489,7 @@ class Article < ActiveRecord::Base end def allow_post_content?(user = nil) + return true if allow_edit_topic?(user) user && (user.has_permission?('post_content', profile) || allow_publish_content?(user) && (user == author)) end @@ -508,9 +509,14 @@ class Article < ActiveRecord::Base end def allow_edit?(user) + return true if allow_edit_topic?(user) allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) end + def allow_edit_topic?(user) + self.belongs_to_forum? && (user == author) && user.is_member_of?(profile) + end + def moderate_comments? moderate_comments == true end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 0a6a8a8..fa241f5 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1660,6 +1660,16 @@ class ArticleTest < ActiveSupport::TestCase a.allow_members_to_edit = true assert !a.allow_edit?(nil) end + + should 'allow author to edit topic' do + community = fast_create(Community) + author = fast_create(Person) + community.add_member(author) + forum = Forum.create(:profile => community, :name => 'Forum test', :body => 'Forum test') + post = fast_create(TextileArticle, :name => 'First post', :profile_id => community.id, :parent_id => forum.id, :last_changed_by_id => author.id) + + assert post.allow_edit?(author) + end should 'has a empty list of followers by default' do a = Article.new -- libgit2 0.21.2