2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-08 18:35:52 -05:00
|
|
|
#mixin for all guardian methods dealing with group permissions
|
|
|
|
module GroupGuardian
|
2020-08-19 10:41:40 -04:00
|
|
|
# Creating Method
|
|
|
|
def can_create_group?
|
|
|
|
is_admin? || (SiteSetting.moderators_manage_categories_and_groups && is_moderator?)
|
|
|
|
end
|
|
|
|
|
2015-01-08 18:35:52 -05:00
|
|
|
# Edit authority for groups means membership changes only.
|
|
|
|
# Automatic groups are not represented in the GROUP_USERS
|
|
|
|
# table and thus do not allow membership changes.
|
|
|
|
def can_edit_group?(group)
|
2021-07-28 07:04:04 -04:00
|
|
|
!group.automatic &&
|
|
|
|
(can_admin_group?(group) || group.users.where("group_users.owner").include?(user))
|
2020-08-19 10:41:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_admin_group?(group)
|
|
|
|
is_admin? ||
|
|
|
|
(
|
|
|
|
SiteSetting.moderators_manage_categories_and_groups && is_moderator? && can_see?(group) &&
|
|
|
|
group.id != Group::AUTO_GROUPS[:admins]
|
|
|
|
)
|
2015-12-07 17:19:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_see_group_messages?(group)
|
2020-09-08 20:58:21 -04:00
|
|
|
return true if is_admin?
|
2020-10-05 12:38:08 -04:00
|
|
|
return true if is_moderator? && group.id == Group::AUTO_GROUPS[:moderators]
|
2022-09-25 23:58:40 -04:00
|
|
|
return false if user.blank?
|
2020-09-08 20:58:21 -04:00
|
|
|
|
2022-10-04 20:50:20 -04:00
|
|
|
user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) &&
|
2022-09-25 23:58:40 -04:00
|
|
|
group.users.include?(user)
|
2015-01-08 18:35:52 -05:00
|
|
|
end
|
2021-12-09 07:30:27 -05:00
|
|
|
|
|
|
|
def can_associate_groups?
|
|
|
|
is_admin? && AssociatedGroup.has_provider?
|
|
|
|
end
|
2015-01-08 18:35:52 -05:00
|
|
|
end
|