Module: CategoryGuardian
- Included in:
- Guardian
- Defined in:
- lib/guardian/category_guardian.rb
Overview
mixin for all guardian methods dealing with category permissions
Instance Method Summary collapse
-
#allowed_category_ids ⇒ Object
all allowed category ids.
-
#can_create_category?(parent = nil) ⇒ Boolean
Creating Method.
- #can_delete_category?(category) ⇒ Boolean
-
#can_edit_category?(category) ⇒ Boolean
Editing Method.
- #can_edit_category_description?(category) ⇒ Boolean
- #can_edit_serialized_category?(category_id:, read_restricted:) ⇒ Boolean
- #can_post_in_category?(category) ⇒ Boolean
- #can_see_category?(category) ⇒ Boolean
- #can_see_serialized_category?(category_id:, read_restricted: true) ⇒ Boolean
- #secure_category_ids ⇒ Object
- #topic_featured_link_allowed_category_ids ⇒ Object
Instance Method Details
#allowed_category_ids ⇒ Object
all allowed category ids
64 65 66 67 68 69 70 |
# File 'lib/guardian/category_guardian.rb', line 64 def allowed_category_ids @allowed_category_ids ||= begin unrestricted = Category.where(read_restricted: false).pluck(:id) unrestricted.concat(secure_category_ids) end end |
#can_create_category?(parent = nil) ⇒ Boolean
Creating Method
6 7 8 |
# File 'lib/guardian/category_guardian.rb', line 6 def can_create_category?(parent = nil) is_admin? || (SiteSetting.moderators_manage_categories_and_groups && is_moderator?) end |
#can_delete_category?(category) ⇒ Boolean
27 28 29 30 |
# File 'lib/guardian/category_guardian.rb', line 27 def can_delete_category?(category) can_edit_category?(category) && category.topic_count <= 0 && !category.uncategorized? && !category.has_children? end |
#can_edit_category?(category) ⇒ Boolean
Editing Method
11 12 13 14 15 16 17 |
# File 'lib/guardian/category_guardian.rb', line 11 def can_edit_category?(category) is_admin? || ( SiteSetting.moderators_manage_categories_and_groups && is_moderator? && can_see_category?(category) ) end |
#can_edit_category_description?(category) ⇒ Boolean
55 56 57 |
# File 'lib/guardian/category_guardian.rb', line 55 def can_edit_category_description?(category) can_perform_action_available_to_group_moderators?(category.topic) end |
#can_edit_serialized_category?(category_id:, read_restricted:) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/guardian/category_guardian.rb', line 19 def can_edit_serialized_category?(category_id:, read_restricted:) is_admin? || ( SiteSetting.moderators_manage_categories_and_groups && is_moderator? && can_see_serialized_category?(category_id: category_id, read_restricted: read_restricted) ) end |
#can_post_in_category?(category) ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/guardian/category_guardian.rb', line 48 def can_post_in_category?(category) return false unless category return false if is_anonymous? return true if is_admin? Category.post_create_allowed(self).exists?(id: category.id) end |
#can_see_category?(category) ⇒ Boolean
40 41 42 43 44 45 46 |
# File 'lib/guardian/category_guardian.rb', line 40 def can_see_category?(category) return false unless category return true if is_admin? && !SiteSetting.suppress_secured_categories_from_admin return true if !category.read_restricted return true if is_staged? && category.email_in.present? && category.email_in_allow_strangers secure_category_ids.include?(category.id) end |
#can_see_serialized_category?(category_id:, read_restricted: true) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/guardian/category_guardian.rb', line 32 def can_see_serialized_category?(category_id:, read_restricted: true) # Guard to ensure only a boolean is passed in read_restricted = true unless !!read_restricted == read_restricted return true if !read_restricted secure_category_ids.include?(category_id) end |
#secure_category_ids ⇒ Object
59 60 61 |
# File 'lib/guardian/category_guardian.rb', line 59 def secure_category_ids @secure_category_ids ||= @user.secure_category_ids end |
#topic_featured_link_allowed_category_ids ⇒ Object
72 73 74 75 |
# File 'lib/guardian/category_guardian.rb', line 72 def topic_featured_link_allowed_category_ids @topic_featured_link_allowed_category_ids = Category.where(topic_featured_link_allowed: true).pluck(:id) end |