mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 08:46:19 +08:00
df3886d6e5
This commit introduces a new site setting "google_oauth2_hd_groups". If enabled, group information will be fetched from Google during authentication, and stored in the Discourse database. These 'associated groups' can be connected to a Discourse group via the "Membership" tab of the group preferences UI. The majority of the implementation is generic, so we will be able to add support to more authentication methods in the near future. https://meta.discourse.org/t/managing-group-membership-via-authentication/175950
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
#mixin for all guardian methods dealing with group permissions
|
|
module GroupGuardian
|
|
|
|
# Creating Method
|
|
def can_create_group?
|
|
is_admin? ||
|
|
(
|
|
SiteSetting.moderators_manage_categories_and_groups &&
|
|
is_moderator?
|
|
)
|
|
end
|
|
|
|
# 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)
|
|
!group.automatic &&
|
|
(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]
|
|
)
|
|
end
|
|
|
|
def can_see_group_messages?(group)
|
|
return true if is_admin?
|
|
return true if is_moderator? && group.id == Group::AUTO_GROUPS[:moderators]
|
|
|
|
SiteSetting.enable_personal_messages? && group.users.include?(user)
|
|
end
|
|
|
|
def can_associate_groups?
|
|
is_admin? && AssociatedGroup.has_provider?
|
|
end
|
|
end
|