Skip to content

Commit

Permalink
Merge branch 'main' into 187216522-international-schools
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushC authored Mar 14, 2024
2 parents 772f2df + 5135d22 commit 65f2484
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 49 deletions.
14 changes: 7 additions & 7 deletions app/controllers/email_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def edit
end

def update
template = EmailTemplate.find(params[:id])
template.update(template_params)
if template.save
flash[:success] = "Updated #{template.title} template successfully."
@email_template = EmailTemplate.find(params[:id])
@email_template.update(template_params)
if @email_template.save
flash[:success] = "Updated #{@email_template.title} template successfully."
redirect_to email_templates_path
else
flash[:alert] = "Failed to save #{template.title} template: " + template.errors.full_messages.join(", ")
redirect_to edit_email_template_path(params[:id])
flash.now[:alert] = "Failed to save #{@email_template.title} template: #{@email_template.errors.full_messages.join(", ")}"
render "edit"
end
end

Expand All @@ -36,7 +36,7 @@ def create
flash[:success] = "Created #{@email_template.title} successfully."
redirect_to email_templates_path
else
flash[:alert] = "Failed to submit information: " + @email_template.errors.full_messages.join(", ")
flash.now[:alert] = "Failed to submit information: #{@email_template.errors.full_messages.join(", ")}"
render "new"
end
end
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ def validate
redirect_to root_path
end

# TODO: Handle the more info / intermediate status route.
def deny
@teacher.denied!
if !params[:skip_email].present?
# TODO: Update dropdown to select the email template.
puts params[:denial_reason]
TeacherMailer.deny_email(@teacher, params[:denial_reason]).deliver_now
end
redirect_to root_path
Expand Down
1 change: 0 additions & 1 deletion app/views/email_templates/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%# This part of the page is the email template form %>
<%= form_with(model: email_template, local: true) do |form| %>
<div class="form">
<label for="email_template_title"><h3>Title</h3></label>
Expand Down
28 changes: 5 additions & 23 deletions app/views/main/_deny_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
<%= hidden_field_tag :action_type, '', class: "form-control action-type" %>
<%= label_tag 'action_reason', 'Reason', class: 'control-label' %>
<%= text_field_tag :action_reason_placeholder, '', class: "form-control action-reason", id: "action_reason" %>
<!-- <div class="form-group">
<label for="reason-select">Reason for Denial (Select)</label>
<select id="reason-select" name="reason-select" class="form-control">
<option value="">Select a reason</option>
<option value="Incomplete Application">Incomplete Application</option>
<option value="Insufficient Experience">Insufficient Experience</option>
<option value="Unfavorable References">Unfavorable References</option>
</select>
</div> -->
<div class="form-check">
<%= check_box_tag :skip_email, 'skip_email', false, class: 'form-check-input' %>
<%= label_tag 'skip_email', 'Skip email notification?', class: 'form-check-label' %>
Expand All @@ -37,39 +28,30 @@
<script type="text/javascript">
let modal = $('.js-denialModal');
modal.on('shown.bs.modal', function (event) {
let button = $(event.relatedTarget); // Button that triggered the modal
let button = $(event.relatedTarget);
let teacherId = button.data('teacher-id');
let teacherName = button.data('teacher-name');
let actionType = button.data('modal-type'); // Action type, e.g., "deny", "request_info"
let actionType = button.data('modal-type');
let newAction, newTitle, inputName;

// Determine the action and title based on the button clicked
switch(actionType) {
case "deny":
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
inputName = 'denial_reason'; // The dynamic part for the input's name attribute
break;
case "request_info":
newAction = `/teachers/${teacherId}/request_info`;
newTitle = 'Request Info from ' + teacherName;
inputName = 'request_reason'; // Change accordingly
inputName = 'request_reason';
break;
case "deny":
default:
newAction = `/teachers/${teacherId}/deny`;
newTitle = 'Deny ' + teacherName;
inputName = 'denial_reason'; // Fallback option
inputName = 'denial_reason';
}

// Update the form's action and the modal's title
modal.find('.form-horizontal').attr('action', newAction);
modal.find('.modal-title').text(newTitle);

// Dynamically change the name attribute of the input field
modal.find('#action_reason').attr('name', inputName);
});

// Reset the input field when the modal is closed
modal.on('hidden.bs.modal', function () {
modal.find('#action_reason').val('').attr('name', 'action_reason_placeholder');
modal.find('.modal-title').text('');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class AddPersonalEmailToTeachers < ActiveRecord::Migration[6.1]
def change
add_column :teachers, :personal_email, :string
# add_index :teachers, :personal_email, unique: true
add_index :teachers, [:email, :personal_email], unique: true
end
end
3 changes: 0 additions & 3 deletions db/migrate/20240218005604_add_to_field_to_email_template.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class AddToFieldToEmailTemplate < ActiveRecord::Migration[6.1]
def change
add_column :email_templates, :to, :string
#below is the default prepopulated 'to' field value,
to_field = "{{teacher_email}}, {{teacher_personal_email}}"
EmailTemplate.update_all(to: to_field)
end
end

This file was deleted.

4 changes: 1 addition & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
require_relative "seed_data"

SeedData.emails.each do |email_attrs|
# Based on what Professor Ball mentioned, 'title' is the unique identifier for each EmailTemplate
unique_identifier = { title: email_attrs[:title] }
email_template = EmailTemplate.find_or_initialize_by(unique_identifier)
email_template = EmailTemplate.find_or_initialize_by({ title: email_attrs[:title] })
email_template.update(email_attrs)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/teachers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@

context "flash a message after resend_welcome_email" do
it "succeeds when teacher is validated, sets success" do
ApplicationController.any_instance.stub(:current_user).and_return(Teacher.find_by(first_name: "Validated"))
validated_teacher = Teacher.find_by(first_name: "Validated")
ApplicationController.any_instance.stub(:current_user).and_return(validated_teacher)
request.env["HTTP_REFERER"] = edit_teacher_path(validated_teacher.id)
post :resend_welcome_email, params: { id: validated_teacher.id }
expect(flash[:success]).to eq("Welcome email resent successfully!")
expect(response).to redirect_to(edit_teacher_path(validated_teacher.id))
end

it "fails when teacher is not validated, sets alert" do
ApplicationController.any_instance.stub(:current_user).and_return(Teacher.find_by(first_name: "Short"))
nonvalidated_teacher = Teacher.find_by(first_name: "Short")
ApplicationController.any_instance.stub(:current_user).and_return(nonvalidated_teacher)
request.env["HTTP_REFERER"] = teacher_path(nonvalidated_teacher.id)
post :resend_welcome_email, params: { id: nonvalidated_teacher.id }
expect(flash[:alert]).to eq("Error resending welcome email. Please ensure that your account has been validated by an administrator.")
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/teachers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ barney:
more_info: ''
application_status: Denied
school: berkeley
education_level: -1
education_level: -1

0 comments on commit 65f2484

Please sign in to comment.