diff --git a/app/models/article.rb b/app/models/article.rb index 124afcd..f71f7b1 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -417,7 +417,7 @@ class Article < ActiveRecord::Base end def allow_edit?(user) - allow_post_content?(user) || allow_members_to_edit && user.is_member_of?(profile) + allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) end def comments_updated diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 77b7cd7..6c07d96 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1665,4 +1665,10 @@ class ArticleTest < ActiveSupport::TestCase assert_equal true, a.allow_edit?(member) end + should 'not crash on allow_edit without a current user' do + a = build(Article) + a.allow_members_to_edit = true + assert !a.allow_edit?(nil) + end + end -- libgit2 0.21.2