Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
16 changes: 16 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ 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)
flash[:notice] = "User is blocked"
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

Expand Down
12 changes: 7 additions & 5 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<th>E-mail</th>
<th>Admin</th>
<th>Coach</th>
<th>Delete</th>
<th>Delete | Block</th>
</tr>
</thead>
<tbody>
Expand All @@ -29,11 +29,13 @@
</td>
<td>
<% 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" %>
<% elsif user.coach && user.is_blocked %>
<%= button_to "Delete", admin_user_path(user), method: "delete" %>
<%= button_to "Unblock", unblock_admin_user_path(user), method: "put", class: "unblock-button" %>
<% elsif user.coach %>
<%= button_to "Blacklist", blacklist_admin_user_path(user), method: "put" %>
<%= button_to "Delete", admin_user_path(user), method: "delete" %>
<%= button_to "Block", block_admin_user_path(user), method: "put" %>
<% end %>
</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
root to: "events#index"
resources :users do
member do
put :blacklist
put :block
put :unblock
end
end
resources :events do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200827174101_rename_blacklisted_to_is_blocked.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameBlacklistedToIsBlocked < ActiveRecord::Migration[5.2]
def change
rename_column :users, :blacklisted, :is_blocked
end
end
38 changes: 19 additions & 19 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions test/controllers/admin/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require 'test_helper'

class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end

end
17 changes: 15 additions & 2 deletions test/system/admin_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class AdminUsersTest < ApplicationSystemTestCase
setup do
create(:user, email: "[email protected]", password: "admin", admin: true)
@user = create(:user, email: "[email protected]", password: "test", admin: false)
@user = create(:user, email: "[email protected]", password: "test", admin: false, is_blocked: false)
create(:coach, user: @user)

visit admin_users_path

Expand All @@ -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 [email protected]_blocked?
assert_button "Block"
end
end