From 5ded553a8bd897f0e3aae38935e1c82824d787fa Mon Sep 17 00:00:00 2001 From: Toks Date: Wed, 28 Oct 2015 10:35:17 -0400 Subject: [PATCH] #2470 keep track of what was gained/lost --- app/logical/user_promotion.rb | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/logical/user_promotion.rb b/app/logical/user_promotion.rb index 5d0ac28fa..bae317121 100644 --- a/app/logical/user_promotion.rb +++ b/app/logical/user_promotion.rb @@ -1,5 +1,5 @@ class UserPromotion - attr_reader :user, :promoter, :new_level, :options + attr_reader :user, :promoter, :new_level, :options, :old_can_approve_posts, :old_can_upload_free def initialize(user, promoter, new_level, options = {}) @user = user @@ -11,6 +11,9 @@ class UserPromotion def promote! validate + @old_can_approve_posts = user.can_approve_posts? + @old_can_upload_free = user.can_upload_free? + user.level = new_level user.can_approve_posts = options[:can_approve_posts] user.can_upload_free = options[:can_upload_free] @@ -43,27 +46,27 @@ private def build_messages messages = [] - if user.can_approve_posts? - messages << "You can approve posts." - else - messages << "You cannot approve posts." - end - - if user.can_upload_free? - messages << "You can upload posts without limit." - else - messages << "You cannot upload posts without limit." - end - if user.level_changed? if user.level > user.level_was - messages << "You have been promoted to a #{user.level_string} level account." + messages << "You have been promoted to a #{user.level_string} level account from #{user.level_string_was}." elsif user.level < user.level_was - messages << "You have been demoted to a #{user.level_string} level account." + messages << "You have been demoted to a #{user.level_string} level account from #{user.level_string_was}." end end - messages.join(" ") + if user.can_approve_posts? && !old_can_approve_posts + messages << "You gained the ability to approve posts." + elsif !user.can_approve_posts? && old_can_approve_posts + messages << "You lost the ability to approve posts." + end + + if user.can_upload_free? && !old_can_upload_free + messages << "You gained the ability to upload posts without limit." + elsif !user.can_upload_free? && old_can_upload_free + messages << "You lost the ability to upload posts without limit." + end + + messages.join("\n") end def create_dmail