From 10eab96c5d6345f794dd9d4dbf5ec988f1adad8b Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 11 May 2012 12:30:40 -0300 Subject: [PATCH] Any community members can edit - backend --- app/models/article.rb | 6 +++++- test/fixtures/roles.yml | 4 +--- test/unit/article_test.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 4c27775..124afcd 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -26,6 +26,7 @@ class Article < ActiveRecord::Base settings_items :display_hits, :type => :boolean, :default => true settings_items :author_name, :type => :string, :default => "" + settings_items :allow_members_to_edit, :type => :boolean, :default => false belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' @@ -410,12 +411,15 @@ class Article < ActiveRecord::Base alias :allow_delete? :allow_post_content? alias :allow_spread? :allow_post_content? - alias :allow_edit? :allow_post_content? def allow_create?(user) allow_post_content?(user) || allow_publish_content?(user) end + def allow_edit?(user) + allow_post_content?(user) || allow_members_to_edit && user.is_member_of?(profile) + end + def comments_updated ferret_update end diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index c0486a4..d0f1bdf 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -58,9 +58,7 @@ profile_member: name: 'Profile Member' system: true permissions: - - edit_profile - - post_content - - manage_products + - invite_members profile_moderator: id: 7 environment_id: 1 diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index c05cb13..77b7cd7 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1638,4 +1638,31 @@ class ArticleTest < ActiveSupport::TestCase assert_equal [c1,c2,c5], Article.text_articles end + should 'not allow all community members to edit by default' do + community = fast_create(Community) + admin = create_user('community-admin').person + member = create_user.person + + community.add_admin(admin) + community.add_member(member) + a = Article.new(:profile => community) + + assert_equal false, a.allow_members_to_edit + assert_equal false, a.allow_edit?(member) + end + + should 'be able to allow all members of a community to edit' do + community = fast_create(Community) + admin = create_user('community-admin').person + member = create_user.person + + community.add_admin(admin) + community.add_member(member) + a = Article.new(:profile => community) + + a.allow_members_to_edit = true + + assert_equal true, a.allow_edit?(member) + end + end -- libgit2 0.21.2