Skip to content

Commit

Permalink
Change content of edit profile email (thewca#10642)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj authored Jan 15, 2025
1 parent eb7f9c5 commit 5c57c9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
15 changes: 14 additions & 1 deletion app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,29 @@ def contact
end
end

private def requestor_info(user, edit_others_profile_mode)
if !edit_others_profile_mode
requestor_role = "Self"
elsif user.any_kind_of_delegate?
requestor_role = "Delegate"
else
requestor_role = "Unknown"
end
"#{user.name} (#{requestor_role})"
end

def edit_profile_action
formValues = JSON.parse(params.require(:formValues), symbolize_names: true)
edited_profile_details = formValues[:editedProfileDetails]
edit_profile_reason = formValues[:editProfileReason]
attachment = params[:attachment]
wca_id = formValues[:wcaId]
person = Person.find_by(wca_id: wca_id)
edit_others_profile_mode = current_user&.wca_id != wca_id

if current_user.nil?
return render status: :unauthorized, json: { error: "Cannot request profile change without login" }
elsif current_user.wca_id != wca_id && !current_user.has_permission?(:can_request_to_edit_others_profile)
elsif edit_others_profile_mode && !current_user.has_permission?(:can_request_to_edit_others_profile)
return render status: :unauthorized, json: { error: "Cannot request to change others profile" }
end

Expand Down Expand Up @@ -147,6 +159,7 @@ def edit_profile_action
wca_id: wca_id,
changes_requested: changes_requested_humanized(changes_requested),
edit_profile_reason: edit_profile_reason,
requestor: requestor_info(current_user, edit_others_profile_mode),
ticket: ticket,
document: attachment,
request: request,
Expand Down
3 changes: 2 additions & 1 deletion app/models/contact_edit_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ContactEditProfile < ContactForm
attribute :wca_id
attribute :changes_requested
attribute :edit_profile_reason
attribute :requestor
attribute :ticket
attribute :document, attachment: true

Expand All @@ -18,7 +19,7 @@ def to_email
end

def subject
Time.now.strftime("Edit Profile request by #{wca_id} on %d %b %Y at %R")
Time.now.strftime("Edit Profile request for the profile of #{wca_id} at %d %b %Y at %R")
end

def headers
Expand Down
3 changes: 2 additions & 1 deletion app/views/mail_form/contact_edit_profile.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Hey WRT,</p>
<p>
<%= @resource.wca_id %> requested following change in their profile:
We received following change request for the profile of <%= @resource.wca_id %>:
</p>
<table>
<body>
Expand All @@ -16,6 +16,7 @@
</body>
</table>
<p>Edit Reason: <%= @resource.edit_profile_reason %></p>
<p>Requestor: <%= @resource.requestor %></p>
<p>You can edit this person using <%= link_to "this ticket", ticket_url(@resource.ticket.id) %>.</p>
<% if @resource.document.present? %>
<p>Note: There is a proof attachment to this email.</p>
Expand Down

0 comments on commit 5c57c9e

Please sign in to comment.