diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index d6ac2c0..6442315 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,32 +1,39 @@ module Admin class UsersController < ApplicationController before_action :authenticate_user! before_action :admin_only! # GET /users/orphans def orphans @users = User.orphans end + # DELETE /users/:id + def destroy + @user = User.find(params[:id]) + @user.destroy + redirect_to orphans_admin_users_path, notice: "#{@user.email} was deleted." + end + def update_groups additions = 0 params.each_pair { |k, group_id| next if !k.start_with?('orphan-') _, id = k.split('-', 2) user = User.orphans.find_by_id(id) next if !user group = Group.find_by_id(group_id) next if !group user.groups << group additions += 1 } redirect_to :back, notice: "#{additions} users were assigned to groups" end end end diff --git a/app/views/admin/users/orphans.html.erb b/app/views/admin/users/orphans.html.erb index c08cd7d..793bcd9 100644 --- a/app/views/admin/users/orphans.html.erb +++ b/app/views/admin/users/orphans.html.erb @@ -1,10 +1,16 @@

<%= bootstrap_form_tag(url: update_groups_admin_users_path, method: 'PUT', layout: :horizontal, label_col: 'col-sm-2', control_col: 'col-sm-4') do |f| %> - <% @users.each do |u| %> - <%= f.collection_select "orphan-#{u.id}", Group.all, :id, :name, label: u.email, prompt: 'Assign to group' %> - <% end %> - <%= f.submit 'Add', class: 'btn btn-primary' %> + + <% @users.each do |u| %> + + + + + <% end %> + +
<%= u.email %><%= f.collection_select "orphan-#{u.id}", Group.all, :id, :name, hide_label: true, prompt: 'Group' %><%= link_to 'Delete', admin_user_path(u), method: :delete, data: { confirm: "Are sure you want to delete #{u.email}?"} %>
+ <%= f.submit 'Apply', class: 'btn btn-primary' %> <% end %>

diff --git a/config/routes.rb b/config/routes.rb index 4297194..5334499 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,57 +1,57 @@ Rails.application.routes.draw do # Override devise user removal devise_scope :users do delete :users, to: redirect('/') end devise_for :users get '/auth/saml', to: 'auth#saml' root to: redirect('/domains') resources :groups, only: [:show] do get :search_member, to: 'groups#search_member', on: :member post :members, to: 'groups#create_member', as: :create_member, on: :member delete 'member/:user_id', to: 'groups#destroy_member', as: :destroy_member, on: :member end resources :domains do get :edit_dnssec, to: 'domains#edit_dnssec', on: :member resources :records, except: [:index, :show] do # Reuse records#update instead of introducing new controller actions # # rubocop:disable Style/AlignHash put :disable, to: 'records#update', on: :member, defaults: { record: { disabled: true } } put :enable, to: 'records#update', on: :member, defaults: { record: { disabled: false } } put :editable, to: 'records#editable', on: :collection post :valid, to: 'records#valid', on: :collection post :bulk, to: 'records#bulk', on: :collection # rubocop:enable Style/AlignHash end end get '/records/search', to: 'records#search' # Admin namespace :admin do root to: redirect('/admin/groups') resources :groups, except: [:show] resources :jobs, only: [:index, :destroy] - resources :users, only: [] do + resources :users, only: [:destroy] do get :orphans, to: 'users#orphans', on: :collection put :update_groups, to: 'users#update_groups', on: :collection end end # Private put 'private/replace_ds', to: 'private#replace_ds' put 'private/trigger_event', to: 'private#trigger_event' end