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

Jg0101 can remove user from room with admin #45

Open
wants to merge 5 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
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
crass (1.0.4)
database_cleaner (1.6.2)
devise (4.4.2)
bcrypt (~> 3.0)
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
loofah (2.2.1)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
Expand Down Expand Up @@ -142,8 +142,8 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.2.1)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class @RemoveUser
handler_events: ->
handle_on_remove_user_click()

handle_on_remove_user_click = ->
$('.remove_user').on 'ajax:success', (data) ->
id = data.currentTarget.attributes['id'].nodeValue
$('#row-' + id).remove();

$(document).on 'turbolinks:load', ->
new RemoveUser().handler_events()
4 changes: 4 additions & 0 deletions app/assets/stylesheets/styles/rooms.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.remove_user{
float: right;
}

.page-header{
.title{
display: inline-block;
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def index
@session_votes =
(SessionVote.where(owner_id: current_user.id) + [current_user.session_vote].compact).uniq
end

def remove_user
user = User.where(id: params[:user_id]).first
session_vote = SessionVote.where(id: params[:session_vote_id]).first
session_vote.users.delete(User.find(user.id))
end

def show
set_current_session_vote_id(@session_vote.id)
Expand Down Expand Up @@ -66,7 +72,7 @@ def join
.chain{ redirect_to(room_path(@invite.session_vote)) }
.on_dam{ redirect_to room_path }
end

private
def vote_params
params.require(:vote).permit(:card_id, :id, :step_id, :task_id, :step_position)
Expand Down
5 changes: 3 additions & 2 deletions app/views/rooms/room_owner_session.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.name.capitalize %></td>
<tr id="row-<%= user.id %>">
<td><%= user.name.capitalize %> <%= link_to "remove", remove_user_rooms_path(session_vote_id: @session_vote, user_id: user),
method: :delete, class: 'btn btn-danger remove_user', id: user.id, remote: true %></td>
<td>
<% count_steps.times do |index| %>
<span class='steps step-result-0<%= index %> label label-default' id='user-card-id-<%= user.id %>'>? </span>
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Rails.application.routes.draw do
devise_for :users
resources :tasks
resources :session_vote
devise_scope :user do
root to: "devise/sessions#new"
end

resources :rooms, only: [:index, :show, :new, :create] do

collection do
post 'vote'
delete 'remove_user'
end

collection do
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/rooms/remove_user_action_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'


describe RoomsController, '#remove_user', type: [:controller, :room] do
let!(:user) { create(:user) }
let!(:removable_user) { create(:user) }
let!(:session_vote) { create(:session_vote, owner: user, users: [removable_user, user]) }

it "removes the correct user from session_vote.users array" do
sign_in user
delete :remove_user, params: {session_vote_id: session_vote.id, user_id: removable_user.id}
expect(SessionVote.where(id: session_vote.id).first.users).to eq [user]
end
end