Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1090715
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
Wed, Oct 15, 10:53 AM
Size
7 KB
Mime Type
text/x-diff
Expires
Fri, Oct 17, 10:53 AM (1 d, 16 h)
Engine
blob
Format
Raw Data
Handle
280601
Attached To
rARCHIVING archiving
View Options
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 227d4a1..5752c2c 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -1,46 +1,71 @@
class Admin::UsersController < Admin::BaseController
# GET /admin/users
def index
@baculized_host_names = Hash.new { |h, k| h[k] = [] }
@non_baculized_host_names = Hash.new { |h, k| h[k] = [] }
@unverified_host_names = Hash.new { |h, k| h[k] = [] }
@users = User.all.includes(:hosts)
@users = @users.admin if params[:type] == 'admin'
@users = @users.vima if params[:type] == 'vima'
@users.each do |user|
user.hosts.each do |host|
if host.deployed? || host.updated? || host.dispatched? || host.for_removal?
@baculized_host_names[user.id] << host.name
else
@non_baculized_host_names[user.id] << host.name
@unverified_host_names[user.id] << host.name if !host.verified?
end
end
end
end
+ # GET /admin/users/new
+ def new
+ @user = User.new
+ end
+
+ # POST /admin/users
+ def create
+ @user = User.new(fetch_params)
+
+ @user.user_type = :admin
+ if @user.add_password(@user.password)
+ flash[:success] = 'User created'
+ redirect_to admin_users_path
+ else
+ flash[:error] = 'User was not created'
+ render 'new'
+ end
+ end
+
# PATCH /admin/users/1/ban
def ban
@user = User.find(params[:id])
if @user.ban
flash[:success] = 'User banned'
else
flash[:error] = 'User NOT banned'
end
redirect_to admin_users_path
end
# PATCH /admin/users/1/unban
def unban
@user = User.find(params[:id])
if @user.unban
flash[:success] = 'User enabled'
else
flash[:error] = 'User NOT enabled'
end
redirect_to admin_users_path
end
+
+ private
+
+ def fetch_params
+ params.require(:user).permit(:username, :email, :password, :retype_password)
+ end
end
diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb
new file mode 100644
index 0000000..df81432
--- /dev/null
+++ b/app/views/admin/users/_form.html.erb
@@ -0,0 +1,15 @@
+<%= bootstrap_form_for(@user, url: admin_users_path, method: :post, layout: :horizontal,
+ label_col: 'col-xs-3', control_col: 'col-xs-8') do |f| %>
+ <%= f.text_field :username, required: true %>
+ <%= f.password_field :password, required: true %>
+ <%= f.password_field :retype_password, required: true %>
+ <%= f.email_field :email, required: true %>
+
+ <div class="form-group">
+ <div class="col-xs-offset-8 col-xs-3">
+ <%= f.submit class: 'btn btn-success' %>
+ </div>
+ </div>
+<% end %>
+
+<%= link_to 'Cancel', admin_users_path, class: 'btn btn-danger', role: 'button' %>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb
index 5d1520f..d0fa88c 100644
--- a/app/views/admin/users/index.html.erb
+++ b/app/views/admin/users/index.html.erb
@@ -1,23 +1,34 @@
+<div class="row right">
+ <%= link_to new_admin_user_path, class: "btn btn-default", role: "button" do %>
+ <label class="glyphicon glyphicon-plus text-primary"></label>
+ New Admin
+ <% end %>
+</div>
+
<h1>Users</h1>
-<div class="table-responsive">
- <table class="table table-striped table-bordered table-condensed">
- <thead>
- <tr>
- <th>id</th>
- <th>username</th>
- <th>email</th>
- <th>user type</th>
- <th>created at</th>
- <th>clients</th>
- <th>unverified hosts</th>
- <th>pending hosts</th>
- <th>actions</th>
- </tr>
- </thead>
+<div class="row">
+ <div class="col-xs-12">
+ <div class="table-responsive">
+ <table class="table table-striped table-bordered table-condensed">
+ <thead>
+ <tr>
+ <th>id</th>
+ <th>username</th>
+ <th>email</th>
+ <th>user type</th>
+ <th>created at</th>
+ <th>clients</th>
+ <th>unverified hosts</th>
+ <th>pending hosts</th>
+ <th>actions</th>
+ </tr>
+ </thead>
- <tbody>
- <%= render partial: 'user', collection: @users %>
- </tbody>
- </table>
+ <tbody>
+ <%= render partial: 'user', collection: @users %>
+ </tbody>
+ </table>
+ </div>
+ </div>
</div>
diff --git a/app/views/admin/users/new.html.erb b/app/views/admin/users/new.html.erb
new file mode 100644
index 0000000..010faa0
--- /dev/null
+++ b/app/views/admin/users/new.html.erb
@@ -0,0 +1,11 @@
+<div class="row">
+ <div class="col-xs-4">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <h3>New Admin</h3>
+
+ <%= render partial: 'form' %>
+ </div>
+ </div>
+ </div>
+</div>
diff --git a/config/routes.rb b/config/routes.rb
index 5f840c9..eedbac6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,81 +1,81 @@
Rails.application.routes.draw do
root 'application#index'
post 'grnet' => 'application#grnet'
match 'vima', to: 'application#vima', :via => [:get, :post]
get 'logout' => 'application#logout'
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :users
get :restore
post :run_restore
end
collection do
post :index
end
end
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
post :disable
delete :revoke
end
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
post :backup_now
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
match '/', to: 'base#index', via: [:get, :post]
get '/login' => 'base#login', as: :login
resources :settings, only: [:index, :new, :create, :edit, :update] do
member do
delete :reset
end
end
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :configuration
post :disable
delete :revoke
end
end
resources :hosts, only: [:show] do
collection do
get :unverified
end
member do
post :verify
end
end
- resources :users, only: [:index] do
+ resources :users, only: [:index, :new, :create] do
member do
patch :ban
patch :unban
end
end
end
end
diff --git a/spec/routing/admin/users_routing_spec.rb b/spec/routing/admin/users_routing_spec.rb
index ee6f272..ea0505b 100644
--- a/spec/routing/admin/users_routing_spec.rb
+++ b/spec/routing/admin/users_routing_spec.rb
@@ -1,17 +1,27 @@
require 'spec_helper'
describe Admin::UsersController do
it 'routes GET /admin/users' do
expect(get('/admin/users')).to route_to(controller: 'admin/users', action: 'index')
end
+ it 'routes GET /admin/users/new' do
+ expect(get('/admin/users/new')).
+ to route_to(controller: 'admin/users', action: 'new')
+ end
+
+ it 'routes POST /admin/users' do
+ expect(post('/admin/users')).
+ to route_to(controller: 'admin/users', action: 'create')
+ end
+
it 'routes PATCH /admin/users/1/ban' do
expect(patch('/admin/users/1/ban')).
to route_to(controller: 'admin/users', action: 'ban', id: '1')
end
it 'routes PATCH /admin/users/1/unban' do
expect(patch('/admin/users/1/unban')).
to route_to(controller: 'admin/users', action: 'unban', id: '1')
end
end
Event Timeline
Log In to Comment