diff --git a/.gitignore b/.gitignore index c33bf252..ecdaea19 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ !/tmp/.keep .DS_Store capybara-* +.vscode/ # Ignore Byebug command history file. .byebug_history diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b238693d..34869462 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -194,6 +194,22 @@ input[type=submit].button_link { padding: 0; } +input[type=submit].unblock-button { + padding: 14px 25px; + border: none; + text-align: center; + vertical-align: middle; + background-color: #b63838; + font-size: 16px; + text-align: center; + color: #fff; +} + +input[type=submit].unblock-button:hover { + background-color: #cd5c5c; + cursor: pointer; +} + .note { font-size: 11px; font-style: italic; diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index d34daf28..411118ab 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -27,9 +27,20 @@ def destroy redirect_to admin_users_path end - def blacklist - @user.update_attributes(blacklisted: true) - flash[:notice] = "User was blacklisted" + def block + @user.update_attributes(is_blocked: true) + @coach = Coach.where(user_id: @user.id).first + @coach_applications = CoachApplication.where(coach_id: @coach.id) + @coach_applications.each do |coach_application| + coach_application.update(state: 'rejected') + end + flash[:notice] = "User is blocked and rejected from the Events they applied for" + redirect_to admin_users_path + end + + def unblock + @user.update_attributes(is_blocked: false) + flash[:notice] = "User is unblocked" redirect_to admin_users_path end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index d20ef876..a4415928 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,17 +11,22 @@ def new_admin def create @user = authenticate(params) - sign_in(@user) do |status| - if status.success? - redirect_back_or url_after_create - else - flash.now.alert = status.failure_message - if params["user_type"] == "coach" - render template: "sessions/new_coach", status: :unauthorized - elsif params["user_type"] == "admin" - render template: "sessions/new_admin", status: :unauthorized + if @user.present? && @user.is_blocked + flash[:error] = "You have been blocked! Contact an Admin for details." + redirect_to coaches_sign_in_path + else + sign_in(@user) do |status| + if status.success? + redirect_back_or url_after_create else - render template: "clearance/sessions/new", status: :unauthorized + flash.now.alert = status.failure_message + if params["user_type"] == "coach" + render template: "sessions/new_coach", status: :unauthorized + elsif params["user_type"] == "admin" + render template: "sessions/new_admin", status: :unauthorized + else + render template: "clearance/sessions/new", status: :unauthorized + end end end end diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index e2c29803..1fbe4bea 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -5,7 +5,7 @@ E-mail Admin Coach - Delete + Block | Delete @@ -27,13 +27,15 @@ ✅ <% end %> - + <% if user != current_user && !user.coach %> - <%= button_to "Delete user", admin_user_path(user), method: "delete" %> - <% elsif user.coach && user.blacklisted %> - Blacklisted + <%= button_to "Delete", admin_user_path(user), method: "delete", data: { confirm: "Are you sure you want to delete this user?" } %> + <% elsif user.coach && user.is_blocked %> + <%= button_to "Unblock", unblock_admin_user_path(user), method: "put", class: "unblock-button" %> + <%= button_to "Delete", admin_user_path(user), method: "delete", data: { confirm: "Are you sure you want to delete this user?" } %> <% elsif user.coach %> - <%= button_to "Blacklist", blacklist_admin_user_path(user), method: "put" %> + <%= button_to "Block", block_admin_user_path(user), method: "put" %> + <%= button_to "Delete", admin_user_path(user), method: "delete", data: { confirm: "Are you sure you want to delete this user?" } %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 084e2cd4..5cd3d00f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,7 +37,8 @@ root to: "events#index" resources :users do member do - put :blacklist + put :block + put :unblock end end resources :events do diff --git a/db/migrate/20200827174101_rename_blacklisted_to_is_blocked.rb b/db/migrate/20200827174101_rename_blacklisted_to_is_blocked.rb new file mode 100644 index 00000000..0341341b --- /dev/null +++ b/db/migrate/20200827174101_rename_blacklisted_to_is_blocked.rb @@ -0,0 +1,5 @@ +class RenameBlacklistedToIsBlocked < ActiveRecord::Migration[5.2] + def change + rename_column :users, :blacklisted, :is_blocked + end +end diff --git a/db/schema.rb b/db/schema.rb index ce065c54..b205d04f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_02_24_192634) do +ActiveRecord::Schema.define(version: 2020_08_27_174101) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -52,7 +52,7 @@ t.integer "state", default: 0, null: false t.boolean "lightningtalk_approved", default: false t.datetime "contacted_at" - t.boolean "first_time_coaching", default: false + t.boolean "first_time_coaching" t.boolean "coach_the_coaches", default: false t.string "sponsor" t.index ["coach_id"], name: "index_coach_applications_on_coach_id" @@ -71,30 +71,30 @@ t.index ["user_id"], name: "index_coaches_on_user_id" end - create_table "event_group_attendees", force: :cascade do |t| - t.bigint "application_id" - t.bigint "event_group_id" + create_table "event_groups", force: :cascade do |t| + t.bigint "event_id" + t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["application_id"], name: "index_event_group_attendees_on_application_id" - t.index ["event_group_id"], name: "index_event_group_attendees_on_event_group_id" + t.index ["event_id"], name: "index_event_groups_on_event_id" end - create_table "event_group_coaches", force: :cascade do |t| - t.bigint "coach_application_id" + create_table "event_groups_applications", force: :cascade do |t| + t.bigint "application_id" t.bigint "event_group_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["coach_application_id"], name: "index_event_group_coaches_on_coach_application_id" - t.index ["event_group_id"], name: "index_event_group_coaches_on_event_group_id" + t.index ["application_id"], name: "index_event_groups_applications_on_application_id" + t.index ["event_group_id"], name: "index_event_groups_applications_on_event_group_id" end - create_table "event_groups", force: :cascade do |t| - t.bigint "event_id" - t.string "name" + create_table "event_groups_coach_applications", force: :cascade do |t| + t.bigint "coach_application_id" + t.bigint "event_group_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["event_id"], name: "index_event_groups_on_event_id" + t.index ["coach_application_id"], name: "index_event_groups_coach_applications_on_coach_application_id" + t.index ["event_group_id"], name: "index_event_groups_coach_applications_on_event_group_id" end create_table "events", id: :serial, force: :cascade do |t| @@ -142,16 +142,16 @@ t.string "confirmation_token", limit: 128 t.string "remember_token", limit: 128, null: false t.boolean "admin", default: false, null: false - t.boolean "blacklisted", default: false + t.boolean "is_blocked", default: false t.index ["email"], name: "index_users_on_email" t.index ["remember_token"], name: "index_users_on_remember_token" end add_foreign_key "coach_applications", "coaches" add_foreign_key "coach_applications", "events" - add_foreign_key "event_group_attendees", "applications" - add_foreign_key "event_group_attendees", "event_groups" - add_foreign_key "event_group_coaches", "coach_applications" - add_foreign_key "event_group_coaches", "event_groups" add_foreign_key "event_groups", "events" + add_foreign_key "event_groups_applications", "applications" + add_foreign_key "event_groups_applications", "event_groups" + add_foreign_key "event_groups_coach_applications", "coach_applications" + add_foreign_key "event_groups_coach_applications", "event_groups" end diff --git a/test/controllers/admin/users_controller_test.rb b/test/controllers/admin/users_controller_test.rb index f5657a4a..ea0e17f2 100644 --- a/test/controllers/admin/users_controller_test.rb +++ b/test/controllers/admin/users_controller_test.rb @@ -1,7 +1,5 @@ require 'test_helper' class Admin::UsersControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end + end diff --git a/test/system/admin_users_test.rb b/test/system/admin_users_test.rb index 98782c38..ababf472 100644 --- a/test/system/admin_users_test.rb +++ b/test/system/admin_users_test.rb @@ -3,7 +3,8 @@ class AdminUsersTest < ApplicationSystemTestCase setup do create(:user, email: "admin@user.de", password: "admin", admin: true) - @user = create(:user, email: "test@user.de", password: "test", admin: false) + @user = create(:user, email: "test@user.de", password: "test", admin: false, is_blocked: false) + create(:coach, user: @user) visit admin_users_path @@ -24,8 +25,20 @@ class AdminUsersTest < ApplicationSystemTestCase end test "Deleting user" do - click_on "Delete user" + click_on "Delete" assert_equal User.count, 1 end + + test "Block coach" do + click_on "Block" + + assert @user.reload.is_blocked? + assert_button "Unblock" + + click_on "Unblock" + + assert !@user.reload.is_blocked? + assert_button "Block" + end end