User#grant_moderatorship_by_user!

This commit is contained in:
joshua stein 2016-02-10 08:39:10 -06:00
parent e0b7c25758
commit c3b62cc166
2 changed files with 22 additions and 1 deletions

View file

@ -24,7 +24,7 @@ class Hat < ActiveRecord::Base
h = "<span class=\"hat\" title=\"Granted by " <<
"#{self.granted_by_user.username} on " <<
"#{self.created_at.strftime("%Y-%m-%d")}"
if !hl && self.link.present?
h << " - #{self.link}"
end

View file

@ -209,6 +209,27 @@ class User < ActiveRecord::Base
end
end
def grant_moderatorship_by_user!(user)
User.transaction do
self.is_moderator = true
self.save!
m = Moderation.new
m.moderator_user_id = user.id
m.user_id = self.id
m.action = "Granted moderator status"
m.save!
h = Hat.new
h.user_id = self.id
h.granted_by_user_id = user.id
h.hat = "Sysop"
h.save!
end
true
end
def initiate_password_reset_for_ip(ip)
self.password_reset_token = "#{Time.now.to_i}-#{Utils.random_str(30)}"
self.save!