Skip to content

Commit

Permalink
Fix approvals and rejections (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantarian authored Apr 15, 2024
1 parent 8d9f890 commit 4ec0a48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions app/controllers/character_point_adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def update
end

def approve
resolve_request :approved => true
resolve_request approve: true
end

def reject
resolve_request :approved => false
resolve_request approve: false
end

protected
Expand Down Expand Up @@ -106,14 +106,14 @@ def check_ajax
end
end

def resolve_request(approved: false)
def resolve_request(approve: false)
if @character_point_adjustment.is_provisional?
approved ? @character_point_adjustment.approve(current_user) : @character_point_adjustment.reject(current_user)
approve ? @character_point_adjustment.approve(current_user) : @character_point_adjustment.reject(current_user)
if @character_point_adjustment.save
UserMailer.character_point_adjustment_approval(@character_point_adjustment).deliver_now
flash[:notice] = "Character Point adjustment #{approved ? "approved" : "rejected"}."
flash[:notice] = "Character Point adjustment #{approve ? "approved" : "rejected"}."
else
flash[:error] = "Character Point adjustment #{approved ? "approval" : "rejection"} failed."
flash[:error] = "Character Point adjustment #{approve ? "approval" : "rejection"} failed."
end
else
flash[:notice] = "Adjustment has already been #{@character_point_adjustment.approved ? "approved" : "rejected"}."
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/death_threshold_adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def update
end

def approve
approve_or_reject_adjustment :state => true
resolve_request(approve: true)
end

def reject
approve_or_reject_adjustment :state => false
resolve_request(approve: false)
end

protected
Expand Down Expand Up @@ -106,14 +106,14 @@ def check_ajax
end
end

def approve_or_reject_adjustment(state)
def resolve_request(approve: false)
if @death_threshold_adjustment.is_provisional?
(state ? @death_threshold_adjustment.approve(current_user) : @death_threshold_adjustment.reject(current_user))
(approve ? @death_threshold_adjustment.approve(current_user) : @death_threshold_adjustment.reject(current_user))
if @death_threshold_adjustment.save
UserMailer.death_threshold_adjustment_approval(@death_threshold_adjustment).deliver_now
flash[:notice] = "Death Threshold adjustment #{state ? "approved" : "rejected"}."
flash[:notice] = "Death Threshold adjustment #{approve ? "approved" : "rejected"}."
else
flash[:error] = "Death Threshold adjustment #{state ? "approval" : "rejection"} failed."
flash[:error] = "Death Threshold adjustment #{approve ? "approval" : "rejection"} failed."
end
else
flash[:error] = "Adjustment has already been #{@death_threshold_adjustment.approved ? "approved" : "rejected"}."
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/monster_point_adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def update
end

def approve
approve_or_reject_adjustment true, I18n.t("user.monster_point_adjustment.success.approved"), I18n.t("user.monster_point_adjustment.failure.approved")
resolve_request true, I18n.t("user.monster_point_adjustment.success.approved"), I18n.t("user.monster_point_adjustment.failure.approved")
end

def reject
approve_or_reject_adjustment false, I18n.t("user.monster_point_adjustment.success.rejected"), I18n.t("user.monster_point_adjustment.failure.rejected")
resolve_request false, I18n.t("user.monster_point_adjustment.success.rejected"), I18n.t("user.monster_point_adjustment.failure.rejected")
end

protected
Expand Down Expand Up @@ -100,9 +100,9 @@ def check_ajax
end
end

def approve_or_reject_adjustment(state, success_message, failure_message)
def resolve_request(approve, success_message, failure_message)
if @monster_point_adjustment.is_provisional?
(state ? @monster_point_adjustment.approve(current_user) : @monster_point_adjustment.reject(current_user))
(approve ? @monster_point_adjustment.approve(current_user) : @monster_point_adjustment.reject(current_user))
if @monster_point_adjustment.save
UserMailer.monster_point_adjustment_approval(@monster_point_adjustment).deliver_now
flash[:notice] = success_message
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/monster_point_declarations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def update
end

def approve
approve_or_reject_declaration true, I18n.t("user.monster_point_declaration.success.approved"), I18n.t("user.monster_point_declaration.failure.approved")
resolve_request true, I18n.t("user.monster_point_declaration.success.approved"), I18n.t("user.monster_point_declaration.failure.approved")
end

def reject
approve_or_reject_declaration false, I18n.t("user.monster_point_declaration.success.rejected"), I18n.t("user.monster_point_declaration.failure.rejected")
resolve_request false, I18n.t("user.monster_point_declaration.success.rejected"), I18n.t("user.monster_point_declaration.failure.rejected")
end

protected
Expand Down Expand Up @@ -100,9 +100,9 @@ def check_ajax
end
end

def approve_or_reject_declaration(state, success_message, failure_message)
def resolve_request(approve, success_message, failure_message)
if @monster_point_declaration.is_provisional?
(state ? @monster_point_declaration.approve(current_user) : @monster_point_declaration.reject(current_user))
(approve ? @monster_point_declaration.approve(current_user) : @monster_point_declaration.reject(current_user))
if @monster_point_declaration.save
UserMailer.monster_point_declaration_approval(@monster_point_declaration).deliver_now
flash[:notice] = success_message
Expand Down

0 comments on commit 4ec0a48

Please sign in to comment.