Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F324287
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 9:02 AM
Size
6 KB
Mime Type
text/x-diff
Expires
Wed, Nov 27, 9:02 AM (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
156130
Attached To
rWEBDNS WebDNS (edet4)
View Options
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
new file mode 100644
index 0000000..d6ac2c0
--- /dev/null
+++ b/app/controllers/admin/users_controller.rb
@@ -0,0 +1,32 @@
+module Admin
+ class UsersController < ApplicationController
+ before_action :authenticate_user!
+ before_action :admin_only!
+
+ # GET /users/orphans
+ def orphans
+ @users = User.orphans
+ 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/models/user.rb b/app/models/user.rb
index f2bc444..0fc6268 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,7 +1,9 @@
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :memberships
has_many :groups, through: :memberships
+
+ scope :orphans, -> { includes(:memberships).where(:memberships => { user_id: nil }) }
end
diff --git a/app/views/admin/users/orphans.html.erb b/app/views/admin/users/orphans.html.erb
new file mode 100644
index 0000000..c08cd7d
--- /dev/null
+++ b/app/views/admin/users/orphans.html.erb
@@ -0,0 +1,10 @@
+<div>
+ <p>
+ <%= 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' %>
+ <% end %>
+ </p>
+</div>
diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb
index 5f0b8b8..5aa2498 100644
--- a/app/views/shared/_nav.html.erb
+++ b/app/views/shared/_nav.html.erb
@@ -1,53 +1,54 @@
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">WebDNS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/domains">Domains</a></li>
<li><%= mail_to WebDNS.settings[:contact_mail], 'Contact' %></li>
<% if admin? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Admin<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="/admin/groups/">Groups</a></li>
<li><a href="/admin/jobs/">Jobs</a></li>
+ <li><a href="/admin/users/orphans/">Orphans</a></li>
</ul>
</li>
<% end %>
<% if user_signed_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<%= current_user.try(:email) %>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><%= link_to('Logout', destroy_user_session_path, method: :delete) %></li>
<li class="divider"></li>
<li class="dropdown-header">Profile</li>
<li><%= link_to('Change Password', edit_user_registration_path) %></li>
<li><a href="#">Edit</a></li>
</ul>
</li>
<% end %>
<form class="navbar-form navbar-left" role="search" action="/records/search" method="get">
<div class="form-group">
<input type="text" name="q" id="q" class="form-control" placeholder="Records" value="<%= params[:q] %>">
</div>
<button type="submit" class="btn btn-default">Search</button>
</form>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
diff --git a/config/routes.rb b/config/routes.rb
index 8b6db0a..94031d9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,48 +1,52 @@
Rails.application.routes.draw do
# Override devise user removal
devise_scope :users do
delete :users, to: redirect('/')
end
devise_for :users
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 } }
# 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
+ 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
Event Timeline
Log In to Comment