favgroups: make private favgroups a Gold-only option.
Make private favgroups a Gold-only option. This is for consistency with private favorites and upvotes being Gold-only options. Existing Members with private favgroups are allowed to keep them, as long as they don't disable privacy. If they disable it, then they can't re-enable it again without upgrading to Gold first.
This commit is contained in:
@@ -10,6 +10,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
validate :creator_can_create_favorite_groups, :on => :create
|
||||
validate :validate_number_of_posts
|
||||
validate :validate_posts
|
||||
validate :validate_can_enable_privacy
|
||||
|
||||
array_attribute :post_ids, parse: /\d+/, cast: :to_i
|
||||
|
||||
@@ -83,6 +84,12 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def validate_can_enable_privacy
|
||||
if is_public_change == [true, false] && !Pundit.policy!(creator, self).can_enable_privacy?
|
||||
errors.add(:base, "Can't enable privacy without a Gold account")
|
||||
end
|
||||
end
|
||||
|
||||
def self.normalize_name(name)
|
||||
name.gsub(/[[:space:]]+/, "_")
|
||||
end
|
||||
@@ -112,7 +119,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def pretty_name
|
||||
name.tr("_", " ")
|
||||
name&.tr("_", " ")
|
||||
end
|
||||
|
||||
def posts
|
||||
@@ -166,6 +173,18 @@ class FavoriteGroup < ApplicationRecord
|
||||
post_ids.include?(post_id)
|
||||
end
|
||||
|
||||
def is_private=(value)
|
||||
self.is_public = !ActiveModel::Type::Boolean.new.cast(value)
|
||||
end
|
||||
|
||||
def is_private
|
||||
!is_public?
|
||||
end
|
||||
|
||||
def is_private?
|
||||
!is_public?
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:creator]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user