From 31b418dfc050a82a3b654417aa7df4eb8934c1a4 Mon Sep 17 00:00:00 2001 From: "Chris Baudouin, Jr" Date: Thu, 17 Sep 2020 13:13:19 -0400 Subject: [PATCH] refactor: Cleans Questionnaire for MyMLH V3 (#338) * 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 --- .../manage/application_controller.rb | 2 +- .../manage/questionnaires_controller.rb | 9 +------ .../manage/questionnaires/_form.html.haml | 12 +++++---- .../manage/questionnaires/show.html.haml | 6 ----- config/routes.rb | 1 - docs/api-overview.md | 1 - .../manage/questionnaires_controller_test.rb | 25 ------------------- 7 files changed, 9 insertions(+), 47 deletions(-) diff --git a/app/controllers/manage/application_controller.rb b/app/controllers/manage/application_controller.rb index cced5e844..d2cbc8e72 100644 --- a/app/controllers/manage/application_controller.rb +++ b/app/controllers/manage/application_controller.rb @@ -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 diff --git a/app/controllers/manage/questionnaires_controller.rb b/app/controllers/manage/questionnaires_controller.rb index ca14c9d85..4edb31cc0 100644 --- a/app/controllers/manage/questionnaires_controller.rb +++ b/app/controllers/manage/questionnaires_controller.rb @@ -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 @@ -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) diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index 189d88215..b52c22783 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -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 diff --git a/app/views/manage/questionnaires/show.html.haml b/app/views/manage/questionnaires/show.html.haml index 54d910fa9..64960e699 100644 --- a/app/views/manage/questionnaires/show.html.haml +++ b/app/views/manage/questionnaires/show.html.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 872cbfc23..44d89e523 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/docs/api-overview.md b/docs/api-overview.md index da4e24b63..ac81471f9 100644 --- a/docs/api-overview.md +++ b/docs/api-overview.md @@ -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 diff --git a/test/controllers/manage/questionnaires_controller_test.rb b/test/controllers/manage/questionnaires_controller_test.rb index 969937faa..210c0dbc2 100644 --- a/test/controllers/manage/questionnaires_controller_test.rb +++ b/test/controllers/manage/questionnaires_controller_test.rb @@ -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 @@ -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 @@ -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 @@ -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 }