Commit 10eab96c5d6345f794dd9d4dbf5ec988f1adad8b

Authored by Antonio Terceiro
1 parent bbb067b5

Any community members can edit - backend

(ActionItem2345)
app/models/article.rb
@@ -26,6 +26,7 @@ class Article < ActiveRecord::Base @@ -26,6 +26,7 @@ class Article < ActiveRecord::Base
26 26
27 settings_items :display_hits, :type => :boolean, :default => true 27 settings_items :display_hits, :type => :boolean, :default => true
28 settings_items :author_name, :type => :string, :default => "" 28 settings_items :author_name, :type => :string, :default => ""
  29 + settings_items :allow_members_to_edit, :type => :boolean, :default => false
29 30
30 belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' 31 belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id'
31 32
@@ -410,12 +411,15 @@ class Article < ActiveRecord::Base @@ -410,12 +411,15 @@ class Article < ActiveRecord::Base
410 411
411 alias :allow_delete? :allow_post_content? 412 alias :allow_delete? :allow_post_content?
412 alias :allow_spread? :allow_post_content? 413 alias :allow_spread? :allow_post_content?
413 - alias :allow_edit? :allow_post_content?  
414 414
415 def allow_create?(user) 415 def allow_create?(user)
416 allow_post_content?(user) || allow_publish_content?(user) 416 allow_post_content?(user) || allow_publish_content?(user)
417 end 417 end
418 418
  419 + def allow_edit?(user)
  420 + allow_post_content?(user) || allow_members_to_edit && user.is_member_of?(profile)
  421 + end
  422 +
419 def comments_updated 423 def comments_updated
420 ferret_update 424 ferret_update
421 end 425 end
test/fixtures/roles.yml
@@ -58,9 +58,7 @@ profile_member: @@ -58,9 +58,7 @@ profile_member:
58 name: 'Profile Member' 58 name: 'Profile Member'
59 system: true 59 system: true
60 permissions: 60 permissions:
61 - - edit_profile  
62 - - post_content  
63 - - manage_products 61 + - invite_members
64 profile_moderator: 62 profile_moderator:
65 id: 7 63 id: 7
66 environment_id: 1 64 environment_id: 1
test/unit/article_test.rb
@@ -1638,4 +1638,31 @@ class ArticleTest < ActiveSupport::TestCase @@ -1638,4 +1638,31 @@ class ArticleTest < ActiveSupport::TestCase
1638 assert_equal [c1,c2,c5], Article.text_articles 1638 assert_equal [c1,c2,c5], Article.text_articles
1639 end 1639 end
1640 1640
  1641 + should 'not allow all community members to edit by default' do
  1642 + community = fast_create(Community)
  1643 + admin = create_user('community-admin').person
  1644 + member = create_user.person
  1645 +
  1646 + community.add_admin(admin)
  1647 + community.add_member(member)
  1648 + a = Article.new(:profile => community)
  1649 +
  1650 + assert_equal false, a.allow_members_to_edit
  1651 + assert_equal false, a.allow_edit?(member)
  1652 + end
  1653 +
  1654 + should 'be able to allow all members of a community to edit' do
  1655 + community = fast_create(Community)
  1656 + admin = create_user('community-admin').person
  1657 + member = create_user.person
  1658 +
  1659 + community.add_admin(admin)
  1660 + community.add_member(member)
  1661 + a = Article.new(:profile => community)
  1662 +
  1663 + a.allow_members_to_edit = true
  1664 +
  1665 + assert_equal true, a.allow_edit?(member)
  1666 + end
  1667 +
1641 end 1668 end