discourse/app/services/username_changer.rb

24 lines
526 B
Ruby
Raw Normal View History

class UsernameChanger
2017-07-28 09:20:09 +08:00
def initialize(user, new_username, actor = nil)
@user = user
@new_username = new_username
@actor = actor
end
2017-07-28 09:20:09 +08:00
def self.change(user, new_username, actor = nil)
self.new(user, new_username, actor).change
end
def change
if @actor && @user.username != @new_username
StaffActionLogger.new(@actor).log_username_change(@user, @user.username, @new_username)
end
# future work: update mentions and quotes
@user.username = @new_username
@user.save
end
end