mirror of
https://github.com/discourse/discourse.git
synced 2025-05-01 20:44:37 +08:00
Setting to prevent logging details when anonymizing
This commit is contained in:
parent
003b03d939
commit
0f66a99eb2
@ -1,7 +1,11 @@
|
|||||||
class UserAnonymizer
|
class UserAnonymizer
|
||||||
|
|
||||||
|
attr_reader :user_history
|
||||||
|
|
||||||
def initialize(user, actor = nil)
|
def initialize(user, actor = nil)
|
||||||
@user = user
|
@user = user
|
||||||
@actor = actor
|
@actor = actor
|
||||||
|
@user_history = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_anonymous(user, actor = nil)
|
def self.make_anonymous(user, actor = nil)
|
||||||
@ -49,11 +53,18 @@ class UserAnonymizer
|
|||||||
@user.user_open_ids.find_each { |x| x.destroy }
|
@user.user_open_ids.find_each { |x| x.destroy }
|
||||||
@user.api_key.try(:destroy)
|
@user.api_key.try(:destroy)
|
||||||
|
|
||||||
UserHistory.create(action: UserHistory.actions[:anonymize_user],
|
history_details = {
|
||||||
|
action: UserHistory.actions[:anonymize_user],
|
||||||
target_user_id: @user.id,
|
target_user_id: @user.id,
|
||||||
acting_user_id: @actor ? @actor.id : @user.id,
|
acting_user_id: @actor ? @actor.id : @user.id,
|
||||||
email: prev_email,
|
}
|
||||||
details: "username: #{prev_username}")
|
|
||||||
|
if SiteSetting.log_anonymizer_details?
|
||||||
|
history_details[:email] = prev_email
|
||||||
|
history_details[:details] = "username: #{prev_username}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@user_history = UserHistory.create(history_details)
|
||||||
end
|
end
|
||||||
@user
|
@user
|
||||||
end
|
end
|
||||||
|
@ -1384,6 +1384,7 @@ en:
|
|||||||
faq_url: "If you have a FAQ hosted elsewhere that you want to use, provide the full URL here."
|
faq_url: "If you have a FAQ hosted elsewhere that you want to use, provide the full URL here."
|
||||||
tos_url: "If you have a Terms of Service document hosted elsewhere that you want to use, provide the full URL here."
|
tos_url: "If you have a Terms of Service document hosted elsewhere that you want to use, provide the full URL here."
|
||||||
privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here."
|
privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here."
|
||||||
|
log_anonymizer_details: "Whether to keep a user's details in the log after being anonymized. When complying to GDPR you'll need to turn this off."
|
||||||
|
|
||||||
newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_threshold` posts before being considered spam."
|
newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_threshold` posts before being considered spam."
|
||||||
|
|
||||||
|
@ -1219,6 +1219,8 @@ legal:
|
|||||||
faq_url:
|
faq_url:
|
||||||
client: true
|
client: true
|
||||||
default: ''
|
default: ''
|
||||||
|
log_anonymizer_details:
|
||||||
|
default: true
|
||||||
|
|
||||||
backups:
|
backups:
|
||||||
enable_backups:
|
enable_backups:
|
||||||
|
@ -101,8 +101,30 @@ describe UserAnonymizer do
|
|||||||
expect(user.uploaded_avatar_id).to eq(nil)
|
expect(user.uploaded_avatar_id).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs the action" do
|
it "logs the action with the original details" do
|
||||||
expect { make_anonymous }.to change { UserHistory.count }.by(1)
|
SiteSetting.log_anonymizer_details = true
|
||||||
|
helper = UserAnonymizer.new(user, admin)
|
||||||
|
orig_email = user.email
|
||||||
|
orig_username = user.username
|
||||||
|
helper.make_anonymous
|
||||||
|
|
||||||
|
history = helper.user_history
|
||||||
|
expect(history).to be_present
|
||||||
|
expect(history.email).to eq(orig_email)
|
||||||
|
expect(history.details).to match(orig_username)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "logs the action without the original details" do
|
||||||
|
SiteSetting.log_anonymizer_details = false
|
||||||
|
helper = UserAnonymizer.new(user, admin)
|
||||||
|
orig_email = user.email
|
||||||
|
orig_username = user.username
|
||||||
|
helper.make_anonymous
|
||||||
|
|
||||||
|
history = helper.user_history
|
||||||
|
expect(history).to be_present
|
||||||
|
expect(history.email).not_to eq(orig_email)
|
||||||
|
expect(history.details).not_to match(orig_username)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes external auth assocations" do
|
it "removes external auth assocations" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user