Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unblock button #299

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
!/tmp/.keep
.DS_Store
capybara-*
.vscode/

# Ignore Byebug command history file.
.byebug_history
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
17 changes: 14 additions & 3 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the changes to the coach applications only for future events? Otherwise we will be changing history.

@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

Expand Down
25 changes: 15 additions & 10 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thinking <3

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
Expand Down
14 changes: 8 additions & 6 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>Block | Delete</th>
</tr>
</thead>
<tbody>
Expand All @@ -27,13 +27,15 @@
<% end %>
</td>
<td>
<td class="actions">
<% 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 %>
</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
40 changes: 20 additions & 20 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 @@ -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"
Expand All @@ -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