Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/rooms/room_tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class Rooms::RoomTicketsController < ApplicationController
def send_email_for_tdx_ticket
message = room_ticket_params[:description]
tdx_email = room_ticket_params[:tdx_email]

if tdx_emails(@room.floor.building).none? { |_, email| email == tdx_email }
render json: { errors: ['Invalid email address.'] }, status: :unprocessable_entity and return
email_options, errors = tdx_emails(@room.floor.building)
if email_options.none? { |_, email| email == tdx_email }
render json: { errors: errors }, status: :unprocessable_entity and return
end

@room_ticket = RoomTicket.new(description: message, room_id: @room.id, submitted_by: current_user.uniqname, tdx_email: tdx_email )
Expand Down
89 changes: 67 additions & 22 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,85 @@ def show_room_percentage(room)

def tdx_emails(building)
emails = []
if AppPreference.find_by(name: 'tdx_facilities_email').value.present?
value = AppPreference.find_by(name: 'tdx_facilities_email')&.value&.split(':').map(&:strip)
facility_email = [value[0], value[1]]
end
if AppPreference.find_by(name: 'tdx_lsa_ts_email').value.present?
value = AppPreference.find_by(name: 'tdx_lsa_ts_email')&.value&.split(':').map(&:strip)
emails << [value[0], value[1]]
errors = []
lsa_ts_pref = AppPreference.find_by(name: 'tdx_lsa_ts_email')
lsa_ts_email, error = tdx_pref_to_email(
lsa_ts_pref, type: "LSA TS",
error_message: "No LSA TS Help desk email in the App Preferences - inform supervisor"
)
if error.present?
errors << error
else
emails << "No LSA TS Help desk email in the App Preferences - report an issue"
emails << lsa_ts_email
end

facilities_pref = AppPreference.find_by(name: 'tdx_facilities_email')
facility_email, error = tdx_pref_to_email(
facilities_pref, type: "LSA Facilities",
error_message: "No LSA Facilities Help desk email in the App Preferences - inform supervisor"
)
if error.present?
errors << error
end
error = nil
case building.nick_name&.downcase
when "dana"
if AppPreference.find_by(name: 'dana_building_facility_issues_email').value.present?
value = AppPreference.find_by(name: 'dana_building_facility_issues_email')&.value&.split(':').map(&:strip)
emails << [value[0], value[1]]
else
emails << facility_email
end
dana_pref = AppPreference.find_by(name: 'dana_building_facility_issues_email')
building_email, error = tdx_pref_to_email(
dana_pref, type: "Dana Building Facilities",
error_message: "No Dana Building Facilities Help desk email in the App Preferences - inform supervisor"
)
when "skb"
if AppPreference.find_by(name: 'skb_facility_issues_email').value.present?
value = AppPreference.find_by(name: 'skb_facility_issues_email')&.value&.split(':').map(&:strip)
emails << [value[0], value[1]]
skb_pref = AppPreference.find_by(name: 'skb_facility_issues_email')
building_email, error = tdx_pref_to_email(
skb_pref, type: "SKB Facilities",
error_message: "No SKB Facilities Help desk email in the App Preferences - inform supervisor"
)
when "pharm"
pharmacy_pref = AppPreference.find_by(name: 'pharmacy_building_facility_issues_email')
building_email, error = tdx_pref_to_email(
pharmacy_pref, type: "Pharmacy Building Facilities",
error_message: "No Pharmacy Building Facilities Help desk email in the App Preferences - inform supervisor"
)
else
building_email = facility_email
end
if error.present?
errors << error
elsif building_email.is_a?(Array) && building_email.length == 2
emails << building_email
end
return emails, errors
end

private

def tdx_pref_to_email(pref, type: "", error_message: nil)
if pref&.value.present?
value = pref.value.split(':').map(&:strip)

if value.length >= 2 && value[1].present?
if valid_email?(value[1])
[[value[0], value[1]], nil]
else
[[], type + ": Invalid email format in App Preferences - inform supervisor"]
end
else
emails << facility_email
[[], error_message.presence || "Invalid email format in App Preferences - inform supervisor"]
end
else
emails << facility_email
[[], error_message.presence || "No email in App Preferences - inform supervisor"]
end
return emails
end

def valid_email?(email)
email.match?(/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i)
end

def show_supervisor_phone
if AppPreference.find_by(name: 'supervisor_phone_number').present? && AppPreference.find_by(name: 'supervisor_phone_number').value.present?
"at " + AppPreference.find_by(name: 'supervisor_phone_number').value
supervisor_pref = AppPreference.find_by(name: 'supervisor_phone_number')
if supervisor_pref&.value.present?
"at " + supervisor_pref.value
else
""
end
Expand Down
16 changes: 14 additions & 2 deletions app/views/shared/_tdxtickets.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
<h2 class="modal-title fs-5" id="exampleModalLabel">Send an Issue Email</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<% email_options, errors = tdx_emails(@room.floor.building) %>
<div class="error-container">
<% if errors.present? %>
<div class="text-danger">
<ul>
<% errors.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
</div>
<% end %>
</div>

<div class="modal-body">
<% if room_recent_tickets(@room).count > 0 %>

Expand Down Expand Up @@ -49,7 +62,7 @@
<% end %>
<div>
<%= form.label :tdx_email, "Select the Email Address *" %>
<%= form.select(:tdx_email, options_for_select(tdx_emails(@room.floor.building))) %>
<%= form.select(:tdx_email, options_for_select(email_options)) %>
</div>
<div>
<div>Email Message *</div>
Expand All @@ -65,4 +78,3 @@
</div>
</div>
</div>

1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{:name => 'tdx_facilities_email', :description => 'An email address to create a TDX ticket with LSA Facilities', :pref_type => 'string', :value => "Facilities Issues (LSA classrooms): lsa-facilities@umich.edu"},
{:name => 'dana_building_facility_issues_email', :description => 'An email address to report Dana Building Facility Issues', :pref_type => 'string', :value => "Dana Building Facility Issues: seas-facilities@umich.edu"},
{:name => 'skb_facility_issues_email', :description => 'An email address to report SKB Building Facility Issues', :pref_type => 'string', :value => "SKB Facility Issues: ptitus@umich.edu"},
{:name => 'pharmacy_building_facility_issues_email', :description => 'An email address to report Pharmacy Building Facility Issues', :pref_type => 'string', :value => ""},
{:name => 'tdx_tickets_quantity_on_dashboard', :description => 'How many recent Room Issues should be displayed on the Dashboard?', :pref_type => 'integer', :value => 6}
]
existing_preferences = AppPreference.all.pluck(:name)
Expand Down
Loading