aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstephenbroyer <stephen.broyer@sonarsource.com>2013-10-10 11:55:44 +0200
committerstephenbroyer <stephen.broyer@sonarsource.com>2013-10-10 11:56:26 +0200
commit02b933aa218e500989a0ef5d200b2ed28e098411 (patch)
treeea6af99004865c589083470f2bbf59a0ded62517
parenteaac0cad4e8646b2a4ec2c4e1c1abaf2416561f8 (diff)
downloadsonarqube-02b933aa218e500989a0ef5d200b2ed28e098411.tar.gz
sonarqube-02b933aa218e500989a0ef5d200b2ed28e098411.zip
SONAR-4538 Use modal windows to create & edit in SonarQube
(create or reactivate user)
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb68
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb64
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb28
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb19
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/routes.rb1
5 files changed, 176 insertions, 4 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
index dde1806b3fa..2639c182385 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
@@ -51,6 +51,41 @@ class UsersController < ApplicationController
end
+ def create_modal
+ return unless request.post?
+ cookies.delete :auth_token
+ @errors = []
+ user = User.find_by_login(params[:user][:login])
+ if user && !user.active
+ if user.update_attributes(params[:user])
+ # case user: exist,inactive,no errors when update BUT TO REACTIVATE
+ @user = user
+ user.errors.full_messages.each{|msg| @errors<<msg}
+ render :partial => 'users/reactivate_modal_form', :status => 400
+ else
+ # case user: exist,inactive, WITH ERRORS when update
+ @user = user
+ @user.id = nil
+ user.errors.full_messages.each{|msg| @errors<<msg}
+ render :partial => 'users/create_modal_form', :status => 400
+ end
+ else
+ user=prepare_user
+ if user.save
+ # case user: don't exist, no errors when create
+ user.notify_creation_handlers
+ flash[:notice] = 'User is created.'
+ render :text => 'ok', :status => 200
+ else
+ # case user: don't exist, WITH ERRORS when create
+ # case user: exist and ACTIVE, whith or without errors when create
+ @user = user
+ user.errors.full_messages.each{|msg| @errors<<msg}
+ render :partial => 'users/create_modal_form', :status => 400
+ end
+ end
+ end
+
def signup
access_denied unless request.post? && Property.value('sonar.allowUsersToSignUp')=='true'
@@ -74,6 +109,26 @@ class UsersController < ApplicationController
end
end
+ def create_modal_form
+ init_users_list
+ if params[:id]
+ @user = User.find(params[:id])
+ else
+ @user = User.new
+ end
+ render :partial => 'users/create_modal_form'
+ end
+
+ def reactivate_modal_form
+ init_users_list
+ if params[:id]
+ @user = User.find(params[:id])
+ else
+ @user = User.new
+ end
+ render :partial => 'users/reactivate_modal_form'
+ end
+
def new
render :action => 'new', :layout => 'nonav'
end
@@ -129,6 +184,19 @@ class UsersController < ApplicationController
to_index(user.errors, nil)
end
+ def reactivate_modal
+ user = User.find_by_login(params[:user][:login])
+ if user
+ user.reactivate!(java_facade.getSettings().getString('sonar.defaultGroup'))
+ user.notify_creation_handlers
+ flash[:notice] = 'User was successfully reactivated.'
+ render :text => 'ok', :status => 200
+ else
+ flash[:error] = "A user with login #{params[:user][:login]} does not exist."
+ render :text => 'login unknown', :status => 200
+ end
+ end
+
def destroy
begin
user = User.find(params[:id])
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb
new file mode 100644
index 00000000000..60f117d50eb
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_create_modal_form.html.erb
@@ -0,0 +1,64 @@
+<%
+ action_name = 'create_modal'
+ title = 'Add new user'
+ submit_button_label = 'Create'
+ if @user.id
+ if @user.active
+ action_name = 'update_modal'
+ title = 'Edit user'
+ submit_button_label = 'Update'
+ if params[:action] == 'change_password'
+ action_name = 'update_password_modal'
+ title = 'Change password'
+ end
+ end
+ end
+%>
+<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= title %></h2>
+ </div>
+ <div class="modal-body">
+ <% if @errors
+ @errors.each do |error|
+ %>
+ <p class="error"><%= h error -%></p>
+ <% end
+ end
+ %>
+ <div class="modal-field"><label for="user[login]">Login<em class="mandatory">*</em></label>
+ <% if @user.id %>
+ <%= @user.login %>
+ <%= f.hidden_field :login %>
+ <% else %>
+ <%= f.text_field :login, :size => 30, :maxLength => 40 %>
+ <% end %>
+ </div>
+ <% if params[:action] != 'change_password' %>
+ <div class="modal-field">
+ <label for="user[]">Name<em class="mandatory">*</em></label>
+ <%= f.text_field :name, :size => 30, :maxLength => 200 %></div>
+
+ <div class="modal-field">
+ <label for="user[]">Email</label>
+ <%= f.text_field :email, :size => 30, :maxLength => 100 %></div>
+ <% end %>
+ <% if !@user.id || @errors %>
+ <div class="modal-field"><label for="user[password]">Password<em class="mandatory">*</em></label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+ <div class="modal-field"><label for="user[password_confirmation]">Confirm password<em class="mandatory">*</em></label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+ <% elsif params[:action] == 'change_password' %>
+ <div class="modal-field"><label for="user[password]">New password</label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+ <div class="modal-field"><label for="user[password_confirmation]">Confirm password</label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
+ <% end %>
+ </div>
+ <div class="modal-foot">
+ <%= submit_tag submit_button_label %>
+ <%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
+ </div>
+ </fieldset>
+ <script>
+ $j("#user_modal_form").modalForm();
+ </script>
+<% end %>
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb
new file mode 100644
index 00000000000..aa105217040
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_reactivate_modal_form.html.erb
@@ -0,0 +1,28 @@
+<% action_name = 'reactivate_modal'
+ title = 'Reactivate user?'
+ submit_button_label = 'Reactivate user'
+%>
+<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :id =>'user_modal_form', :method => @user.id.nil? ? :post : :put} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= title %></h2>
+ </div>
+ <div class="modal-body">
+ <%= f.hidden_field :login %>
+
+ <p class="error">
+ A user with login "<%= @user.login -%>" already exists in the database but is deactivated.<br/>
+ <br/>
+ Do you really want to reactivate this user?
+ </p>
+ </div>
+ <div class="modal-foot">
+ <%= submit_tag submit_button_label %>
+ <%= link_to 'Cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
+ </div>
+ </fieldset>
+
+ <script>
+ $j("#user_modal_form").modalForm();
+ </script>
+<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
index 7e431a6395f..946e98169bb 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/index.html.erb
@@ -1,7 +1,17 @@
+<div class="line-block">
+ <% if profiles_administrator? %>
+ <ul style="float: right" class="horizontal">
+ <li class="marginleft10 add">
+ <a href="<%=ApplicationController.root_context-%>/users/create_modal_form" class="open-modal link-action">Add new user</a>
+ </li>
+ </ul>
+ <% end %>
+ <h1 class="marginbottom10">Users</h1>
+</div>
+
<table width="100%">
<tr>
<td valign="top">
- <h1 class="marginbottom10">Users</h1>
<table class="data width100 sortable" id="users">
<thead>
<tr>
@@ -9,7 +19,7 @@
<th class="left sortfirstasc">Name</th>
<th class="left">Email</th>
<th class="left nosort">Groups</th>
- <th class="operations nosort" nowrap>Operations</th>
+ <th class="left nosort" nowrap>Operations</th>
</tr>
</thead>
<tbody >
@@ -21,7 +31,7 @@
<td class="left" valign="top">
<%= user.groups.sort.map(&:name).join(', ') %> (<%= link_to "select", {:action => 'select_group', :id => user.id}, {:id => "select-#{u user.login}", :class => 'link-action'} %>)
</td>
- <td class="operations" valign="top">
+ <td class="left" valign="top">
<%= link_to "Edit", { :id => user.id, :action => 'edit'}, {:id => "edit-#{u user.login}", :class => 'link-action'} %>
&nbsp;
<%= link_to "Change password", { :id => user.id, :action => 'change_password'}, {:id => "change-password-#{u user.login}", :class => 'link-action'} %>
@@ -57,7 +67,8 @@
end
end
%>
- <% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :method => @user.id.nil?? :post : :put } do |f| %>
+
+ <% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :method => @user.id.nil?? :post : :put } do |f| %>
<table class="admintable" width="100%">
<tr>
<td class="left" valign="top"><h1><%= title %></h1></td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
index 4f89c36487c..8164614f56e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/routes.rb
@@ -1,6 +1,7 @@
ActionController::Routing::Routes.draw do |map|
map.connect 'users/select_group', :controller => 'users', :action => 'select_group'
map.connect 'users/set_groups', :controller => 'users', :action => 'set_groups'
+ map.connect 'users/create_modal_form', :controller => 'users', :action => 'create_modal_form'
map.resources :users
map.namespace :api do |api|