mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 00:37:06 +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
68 lines
1.6 KiB
Ruby
68 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class GroupActionLogger
|
|
|
|
def initialize(acting_user, group)
|
|
@acting_user = acting_user
|
|
@group = group
|
|
end
|
|
|
|
def log_make_user_group_owner(target_user)
|
|
GroupHistory.create!(default_params.merge(
|
|
action: GroupHistory.actions[:make_user_group_owner],
|
|
target_user: target_user
|
|
))
|
|
end
|
|
|
|
def log_remove_user_as_group_owner(target_user)
|
|
GroupHistory.create!(default_params.merge(
|
|
action: GroupHistory.actions[:remove_user_as_group_owner],
|
|
target_user: target_user
|
|
))
|
|
end
|
|
|
|
def log_add_user_to_group(target_user, subject = nil)
|
|
GroupHistory.create!(default_params.merge(
|
|
action: GroupHistory.actions[:add_user_to_group],
|
|
target_user: target_user,
|
|
subject: subject
|
|
))
|
|
end
|
|
|
|
def log_remove_user_from_group(target_user, subject = nil)
|
|
GroupHistory.create!(default_params.merge(
|
|
action: GroupHistory.actions[:remove_user_from_group],
|
|
target_user: target_user,
|
|
subject: subject
|
|
))
|
|
end
|
|
|
|
def log_change_group_settings
|
|
@group.previous_changes.except(*excluded_attributes).each do |attribute_name, value|
|
|
next if value[0].blank? && value[1].blank?
|
|
|
|
GroupHistory.create!(default_params.merge(
|
|
action: GroupHistory.actions[:change_group_setting],
|
|
subject: attribute_name,
|
|
prev_value: value[0],
|
|
new_value: value[1]
|
|
))
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def excluded_attributes
|
|
[
|
|
:bio_cooked,
|
|
:updated_at,
|
|
:created_at,
|
|
:user_count
|
|
]
|
|
end
|
|
|
|
def default_params
|
|
{ group: @group, acting_user: @acting_user }
|
|
end
|
|
end
|