FIX: any subcategory permissions are valid if everyone has access to parent category (#7097)

FIX: any subcategory permissions are valid if everyone has access to parent category (#7097)

diff --git a/app/models/category.rb b/app/models/category.rb
index b404389..5949b4a 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -658,6 +658,9 @@ class Category < ActiveRecord::Base
 
   def check_permissions_compatibility(parent_permissions, child_permissions)
     parent_groups = parent_permissions.map(&:first)
+
+    return if parent_groups.include?(Group[:everyone].id)
+
     child_groups = child_permissions.map(&:first)
     only_in_subcategory = child_groups - parent_groups
 
diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb
index a5f8a48..ea64120 100644
--- a/spec/models/category_spec.rb
+++ b/spec/models/category_spec.rb
@@ -779,8 +779,8 @@ describe Category do
         expect(subcategory.valid?).to eq(true)
       end
 
-      it "is valid if no permissions are set on parent" do
-        parent_category.set_permissions(everyone: :full)
+      it "is valid if everyone has access to parent category" do
+        parent_category.set_permissions(everyone: :readonly)
         parent_category.save!
 
         subcategory.set_permissions(group => :create_post, group2 => :create_post)
@@ -814,10 +814,10 @@ describe Category do
 
       end
 
-      it "is valid if no permissions set on parent" do
+      it "is valid if everyone has access to parent category" do
         subcategory.set_permissions(group => :create_post)
         subcategory.save
-        parent_category.set_permissions(everyone: :full)
+        parent_category.set_permissions(everyone: :readonly)
 
         expect(parent_category.valid?).to eq(true)
       end

GitHub sha: fea5d4f3

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: