Skip to content

Commit

Permalink
Merge pull request #121 from gate-sso/issue-#82
Browse files Browse the repository at this point in the history
Issue #82 - Include inactive user as a checkbox on UI
  • Loading branch information
ajeygore authored Aug 27, 2018
2 parents 619cb49 + d18a148 commit 2809511
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
14 changes: 12 additions & 2 deletions app/assets/javascripts/group.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# You can use CoffeeScript in this file: http://coffeescript.org/

group_ready = ->
$('#assign_admin_include_inactive_user').prop('checked', false);
$('#assign_admin_user_id').selectize
maxItems: 1
valueField: 'id'
Expand All @@ -15,9 +16,13 @@ group_ready = ->
if !query.length
return callback()

# Clear the cache, because user list may change
this.clearOptions()
include_inactive = $('#assign_admin_include_inactive_user').is(':checked')

# Use remote as source
$.ajax
url: '/users/search?q=' + encodeURIComponent(query)
url: '/users/search?q=' + encodeURIComponent(query) + '&include_inactive=' + include_inactive
type: 'GET'
error: ->
callback()
Expand All @@ -30,6 +35,7 @@ group_ready = ->
$('#assign_admin_user_id').on 'change', ->
set_allow_submit($(this).val(), $(this))

$('#add_user_include_inactive_user').prop('checked', false);
$('#add_user_user_id').selectize
maxItems: 1
valueField: 'id'
Expand All @@ -42,9 +48,13 @@ group_ready = ->
if !query.length
return callback()

# Clear the cache, because user list may change
this.clearOptions()
include_inactive = $('#add_user_include_inactive_user').is(':checked')

# Use remote as source
$.ajax
url: '/users/search?q=' + encodeURIComponent(query)
url: '/users/search?q=' + encodeURIComponent(query) + '&include_inactive=' + include_inactive
type: 'GET'
error: ->
callback()
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def update
def search
@users = User.
where("name LIKE :q OR email LIKE :q", q: "%#{params[:q]}%").
where(active: true).
order("name ASC").
limit(20)
unless params[:include_inactive] == 'true'
@users = @users.where(active: true)
end
data = @users.map{ |user| {
id: user.id,
name: user.name,
Expand Down
20 changes: 17 additions & 3 deletions app/views/groups/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
= text_field_tag "user_id", "", id: "assign_admin_user_id", class: "form-control"
.col
= submit_tag "Assign admin", class: "form-control btn btn-md btn-primary", disabled: true
.row
.col
= check_box_tag "assign_admin_include_inactive_user", "true", false
= " Include Inactive User"
.col
a name="group_members"
br
.card
Expand All @@ -39,10 +44,13 @@
th Email address
th
tbody
- @group.users.sort_by{ |user| user.email}.select{|user| user.active}.each do |user|
- @group.users.sort_by{ |user| user.email}.each do |user|
tr
td
= link_to "#{user.name}", user_path(user)
- if user.active?
= link_to "#{user.name}", user_path(user)
- else
= link_to "#{user.name} (inactive)", user_path(user)
td
= "#{user.email}"
td
Expand All @@ -61,7 +69,13 @@
= text_field_tag "user_id", "", id: "add_user_user_id", class: "form-control"
.col
= submit_tag "Add User", class: "form-control btn-md btn-primary", disabled: true

.row
.col
.col
.col
= check_box_tag "add_user_include_inactive_user", "true", false
= " Include Inactive User"
.col
br
.card
.card-body
Expand Down
11 changes: 10 additions & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@
end

describe 'Search for Users' do
it "should return active users according to supplied search string" do
it "should return only active users by default according to query" do
sign_in user
users = create_list(:user, 3)
users.last.update(active: false)
get :search, { q: users.first.name }
returned_ids = JSON.parse(response.body).collect{|c| c['id']}
expect(returned_ids).to eq([users.first.id])
end

it "should return users according to query, if we supplied include_inactive params" do
sign_in user
users = create_list(:user, 3)
users.last.update(active: false)
get :search, { q: users.last.name, include_inactive: 'true' }
returned_ids = JSON.parse(response.body).collect{|c| c['id']}
expect(returned_ids).to eq([users.last.id])
end
end

describe "GET #regenerate_token" do
Expand Down

0 comments on commit 2809511

Please sign in to comment.