2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-09 07:35:52 +08:00
|
|
|
#mixin for all guardian methods dealing with group permissions
|
|
|
|
module GroupGuardian
|
|
|
|
|
2020-08-19 22:41:40 +08:00
|
|
|
# Creating Method
|
|
|
|
def can_create_group?
|
|
|
|
is_admin? ||
|
|
|
|
(
|
|
|
|
SiteSetting.moderators_manage_categories_and_groups &&
|
|
|
|
is_moderator?
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-01-09 07:35:52 +08: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)
|
2019-04-16 09:31:51 +08:00
|
|
|
!group.automatic && can_log_group_changes?(group)
|
2016-12-11 23:36:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_log_group_changes?(group)
|
2020-08-19 22:41:40 +08:00
|
|
|
can_admin_group?(group) || group.users.where('group_users.owner').include?(user)
|
|
|
|
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-08 06:19:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_see_group_messages?(group)
|
2018-02-12 14:26:22 +08:00
|
|
|
SiteSetting.enable_personal_messages? && (
|
2018-02-03 05:35:32 +08:00
|
|
|
is_admin? || group.users.include?(user)
|
|
|
|
)
|
2015-01-09 07:35:52 +08:00
|
|
|
end
|
|
|
|
end
|