Page MenuHomeGRNET

No OneTemporary

File Metadata

Created
Mon, Nov 25, 7:29 AM
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 6442315..d95747d 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -1,39 +1,44 @@
module Admin
class UsersController < ApplicationController
before_action :authenticate_user!
before_action :admin_only!
+ # GET /users
+ def index
+ @users = User.all
+ end
+
# 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/groups/index.html.erb b/app/views/admin/groups/index.html.erb
index 8641bd8..84889d7 100644
--- a/app/views/admin/groups/index.html.erb
+++ b/app/views/admin/groups/index.html.erb
@@ -1,26 +1,28 @@
-<table class="table table-striped">
+<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Domains</th>
<th>Users</th>
- <th colspan="2">Controls</th>
+ <th>Controls</th>
</tr>
</thead>
<tbody>
<% @groups.each do |group| %>
<tr>
<td><%= link_to group.name, group %></td>
<td><%= @domain_count[group.id] || 0 %></td>
<td><%= @membership_count[group.id] || 0 %></td>
- <td><%= link_to_edit edit_admin_group_path(group) %></td>
- <td><%= link_to_destroy admin_group_path(group), method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ <td>
+ <%= link_to_edit edit_admin_group_path(group) %>
+ <%= link_to_destroy admin_group_path(group), method: :delete, data: { confirm: 'Are you sure?' } %>
+ </td>
</tr>
<% end %>
</tbody>
</table>
<p>
<%= link_to 'New Group &raquo;'.html_safe, new_admin_group_path, class: 'btn btn-lg btn-primary' %>
</p>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb
new file mode 100644
index 0000000..60156a0
--- /dev/null
+++ b/app/views/admin/users/index.html.erb
@@ -0,0 +1,23 @@
+<div>
+ <%= 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| %>
+ <table id=user-list" class="table table-striped table-bordered">
+ <thead>
+ <tr>
+ <th>Username</th>
+ <th>Groups</th>
+ <th>Controls</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @users.each do |u| %>
+ <tr>
+ <td><%= u.email %></td>
+ <td><%= f.collection_select "orphan-#{u.id}", Group.all, :id, :name, hide_label: true, prompt: 'Group' %></td>
+ <td><%= link_to 'Delete', admin_user_path(u), method: :delete, data: { confirm: "Are sure you want to delete #{u.email}?"} %></td>
+ <% end %>
+ </tr>
+ <tbody>
+ </table>
+ <%= f.submit 'Apply', class: 'btn btn-primary' %>
+ <% end %>
+</div>
diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb
index 222af44..b3aea61 100644
--- a/app/views/shared/_nav.html.erb
+++ b/app/views/shared/_nav.html.erb
@@ -1,64 +1,65 @@
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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>
<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>
<ul class="nav navbar-nav navbar-right">
<% 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/users/">Users</a></li>
<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">
<% if current_user.can_change_password? %>
<li><%= link_to('Change Password', edit_user_registration_path) %></li>
<% end %>
<% if current_user.notifications? %>
<li><%= link_to('Mute notifcications', mute_user_domains_path(current_user), method: :put,
title: 'Mute all domain notifications') %></li>
<% else %>
<li><%= link_to('Unmute notifications', unmute_user_domains_path(current_user), method: :put,
title: 'Unmute all domain notifications') %></li>
<% end %>
<li><%= link_to('API Token', token_user_path(current_user)) %></li>
<li><%= link_to('Logout', destroy_user_session_path, method: :delete) %></li>
</ul>
</li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
diff --git a/config/routes.rb b/config/routes.rb
index b85202c..6123d20 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,88 +1,89 @@
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 :users, only: [] do
get :token, to: 'users#token', on: :member
post :generate_token, to: 'users#generate_token', on: :member
resources :domains, only: [] do
put :mute, to: 'users#mute'
put :unmute, to: 'users#unmute'
put :mute, to: 'users#mute_all', on: :collection
put :unmute, to: 'users#unmute_all', on: :collection
end
end
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
delete :full_destroy, to: 'domains#full_destroy', 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 :users, except: [:show]
resources :groups, except: [:show]
resources :jobs, only: [:index, :destroy] do
put :done, to: 'jobs#update', on: :member,
defaults: { job: { status: 1 } }
put :pending, to: 'jobs#update', on: :member,
defaults: { job: { status: 0 } }
get '/type/:category', to: 'jobs#index', on: :collection,
constraints: proc { |req| ['completed', 'pending'].include?(req.params[:category]) }
end
resources :users, only: [:destroy] do
get :orphans, to: 'users#orphans', on: :collection
put :update_groups, to: 'users#update_groups', on: :collection
end
end
# API
scope '/api' do
get :ping, to: 'api#ping'
get :whoami, to: 'api#whoami'
get '/domain/:domain/list', to: 'api#list', constraints: { domain: /[^\/]+/}
post '/domain/:domain/bulk', to: 'api#bulk', constraints: { domain: /[^\/]+/}
get :domains, to: 'api#domains'
end if WebDNS.settings[:api]
# Private
put 'private/replace_ds', to: 'private#replace_ds'
put 'private/trigger_event', to: 'private#trigger_event'
get 'private/zones', to: 'private#zones'
get 'help/api', to: 'help#api'
end

Event Timeline