Skip to content

Commit

Permalink
refactor: Cleans Questionnaire for MyMLH V3 (#338)
Browse files Browse the repository at this point in the history
* refactor: Removes "Convert to Admin" on Questionnaire

* refactor: Updates MyMLH branding + V3

* fix: Removes tests for convert_to_admin

* refactor: Removes remaining "convert_to_admin" calls

Co-authored-by: Peter Kos <pkos91@icloud.com>
  • Loading branch information
cbaudouinjr and peterkos authored Sep 17, 2020
1 parent 1599fe1 commit 31b418d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/controllers/manage/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Manage::ApplicationController < ApplicationController
before_action :logged_in
before_action :require_admin_or_limited_admin
before_action :limit_write_access_to_admins, only: ["edit", "update", "new", "create", "destroy", "convert_to_admin", "deliver", "merge", "perform_merge", "toggle_bus_captain", "duplicate", "update_acc_status", "send_update_email", "live_preview"]
before_action :limit_write_access_to_admins, only: ["edit", "update", "new", "create", "destroy", "deliver", "merge", "perform_merge", "toggle_bus_captain", "duplicate", "update_acc_status", "send_update_email", "live_preview"]
skip_before_action :verify_authenticity_token, if: :json_request?

def logged_in
Expand Down
9 changes: 1 addition & 8 deletions app/controllers/manage/questionnaires_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Manage::QuestionnairesController < Manage::ApplicationController
include QuestionnairesControllable

before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :convert_to_admin, :update_acc_status]
before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :update_acc_status]

respond_to :html, :json

Expand Down Expand Up @@ -95,13 +95,6 @@ def check_in
redirect_to index_redirect_path
end

def convert_to_admin
user = @questionnaire.user
@questionnaire.destroy
user.update_attributes(role: :admin)
redirect_to edit_manage_user_path(user)
end

def destroy
@questionnaire.destroy
respond_with(:manage, @questionnaire)
Expand Down
12 changes: 7 additions & 5 deletions app/views/manage/questionnaires/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@
.card-body
- if @questionnaire&.user&.provider == 'mlh'
%h6.card-subtitle.mb-2
%span.badge.badge-info Provided by My MLH
%span.badge.badge-info Provided by MyMLH
= f.simple_fields_for :user, @questionnaire.user do |u|
= u.input :first_name, input_html: { "data-validate" => "presence" }, label: "First Name", autofocus: true
= u.input :last_name, input_html: { "data-validate" => "presence" }, label: "Last Name"
= f.input :email, input_html: { "data-validate" => "presence email", value: @questionnaire.user.try(:email) }, required: true, hint: 'Can be an existing user (without a questionnaire) or a new user. If this is a new user, they will receive a randomly-generated password that they must request a password reset for.'
= f.input :phone, input_html: { "data-validate" => "presence" }
= f.input :date_of_birth, start_year: Date.today.year - 18, end_year: Date.today.year - 90, order: [:month, :day, :year], input_html: { "data-validate" => "presence" }

= f.input :school_id, as: :school_selection, input_html: { "data-validate" => "presence" }
= f.input :level_of_study, input_html: { "data-validate" => "presence" }
= f.input :major, input_html: { "data-validate" => "presence" }
= f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }
= f.input :gender, input_html: { "data-validate" => "presence" }
= f.input :dietary_restrictions, label: "Dietary restrictions"
= f.input :special_needs, label: "Special needs"

.col-xl-6
.card.mb-4
.card-header Special notices
.card-body
= f.input :shirt_size, as: :select, collection: Questionnaire::POSSIBLE_SHIRT_SIZES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }
= f.input :dietary_restrictions, label: "Dietary restrictions"
= f.input :special_needs, label: "Special needs"
.card.mb-4
.card-header Resume
.card-body
Expand Down
6 changes: 0 additions & 6 deletions app/views/manage/questionnaires/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
.btn-group{role: "group"}
- if current_user.admin?
= link_to 'Edit', edit_manage_questionnaire_path(@questionnaire), class: 'btn btn-sm btn-outline-secondary'
- if current_user.admin?
.btn-group{role: "group"}
%button.btn.btn-sm.btn-outline-secondary.dropdown-toggle#title-actions{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", type: "button"}
.fa.fa-cog
.dropdown-menu.dropdown-menu-right{"aria-labelledby" => "title-actions"}
= link_to 'Convert to Admin', convert_to_admin_manage_questionnaire_path(@questionnaire), method: :patch, data: { confirm: "Are you sure? The questionnaire for \"#{@questionnaire.user.full_name}\" will be permanently erased, and \"#{@questionnaire.email}\" will become an admin. This action is irreversible." }, class: 'dropdown-item'

= render 'overview'

Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
resources :questionnaires do
post :datatable, on: :collection
patch :check_in, on: :member
patch :convert_to_admin, on: :member
patch :update_acc_status, on: :member
patch :bulk_apply, on: :collection
end
Expand Down
1 change: 0 additions & 1 deletion docs/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Example for questionnaire management endpoints:
Prefix Verb URI Pattern Controller#Action
datatable_manage_questionnaires POST /manage/questionnaires/datatable(.:format) manage/questionnaires#datatable
check_in_manage_questionnaire PATCH /manage/questionnaires/:id/check_in(.:format) manage/questionnaires#check_in
convert_to_admin_manage_questionnaire PATCH /manage/questionnaires/:id/convert_to_admin(.:format) manage/questionnaires#convert_to_admin
update_acc_status_manage_questionnaire PATCH /manage/questionnaires/:id/update_acc_status(.:format) manage/questionnaires#update_acc_status
bulk_apply_manage_questionnaires PATCH /manage/questionnaires/bulk_apply(.:format) manage/questionnaires#bulk_apply
manage_questionnaires GET /manage/questionnaires(.:format) manage/questionnaires#index
Expand Down
25 changes: 0 additions & 25 deletions test/controllers/manage/questionnaires_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to new_user_session_path
end

should "not allow convert questionnaire's user to an admin" do
patch :convert_to_admin, params: { id: @questionnaire }
assert_response :redirect
assert_redirected_to new_user_session_path
end

should "not allow access to manage_questionnaires#destroy" do
patch :destroy, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -123,12 +117,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to root_path
end

should "not allow convert questionnaire's user to an admin" do
patch :convert_to_admin, params: { id: @questionnaire }
assert_response :redirect
assert_redirected_to root_path
end

should "not allow access to manage_questionnaires#destroy" do
patch :destroy, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -194,12 +182,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to manage_questionnaires_path
end

should "not allow convert questionnaire's user to an admin" do
patch :convert_to_admin, params: { id: @questionnaire }
assert_response :redirect
assert_redirected_to manage_questionnaires_path
end

should "not allow access to manage_questionnaires#destroy" do
patch :destroy, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -299,13 +281,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to manage_questionnaire_path(assigns(:questionnaire))
end

should "convert questionnaire's user to an admin" do
patch :convert_to_admin, params: { id: @questionnaire }
assert assigns(:questionnaire).user.admin?
assert_nil assigns(:questionnaire).user.reload.questionnaire
assert_redirected_to edit_manage_user_path(assigns(:questionnaire).user)
end

should "destroy questionnaire" do
assert_difference("Questionnaire.count", -1) do
delete :destroy, params: { id: @questionnaire }
Expand Down

0 comments on commit 31b418d

Please sign in to comment.