Commit 1dd80d22 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Prevent confusion in naming user variable at admin area

parent 21f7c99c
class Admin::UsersController < Admin::ApplicationController class Admin::UsersController < Admin::ApplicationController
before_filter :admin_user, only: [:show, :edit, :update, :destroy] before_filter :user, only: [:show, :edit, :update, :destroy]
def index def index
@admin_users = User.scoped @users = User.scoped
@admin_users = @admin_users.filter(params[:filter]) @users = @users.filter(params[:filter])
@admin_users = @admin_users.search(params[:name]) if params[:name].present? @users = @users.search(params[:name]) if params[:name].present?
@admin_users = @admin_users.alphabetically.page(params[:page]) @users = @users.alphabetically.page(params[:page])
end end
def show def show
@projects = admin_user.authorized_projects @projects = user.authorized_projects
end end
def new def new
@admin_user = User.new.with_defaults @user = User.new.with_defaults
end end
def edit def edit
admin_user user
end end
def block def block
if admin_user.block if user.block
redirect_to :back, alert: "Successfully blocked" redirect_to :back, alert: "Successfully blocked"
else else
redirect_to :back, alert: "Error occured. User was not blocked" redirect_to :back, alert: "Error occured. User was not blocked"
...@@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController
end end
def unblock def unblock
if admin_user.activate if user.activate
redirect_to :back, alert: "Successfully unblocked" redirect_to :back, alert: "Successfully unblocked"
else else
redirect_to :back, alert: "Error occured. User was not unblocked" redirect_to :back, alert: "Error occured. User was not unblocked"
...@@ -44,17 +44,17 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -44,17 +44,17 @@ class Admin::UsersController < Admin::ApplicationController
password_expires_at: Time.now password_expires_at: Time.now
} }
@admin_user = User.new(params[:user].merge(opts), as: :admin) @user = User.new(params[:user].merge(opts), as: :admin)
@admin_user.admin = (admin && admin.to_i > 0) @user.admin = (admin && admin.to_i > 0)
@admin_user.created_by_id = current_user.id @user.created_by_id = current_user.id
respond_to do |format| respond_to do |format|
if @admin_user.save if @user.save
format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully created.' } format.html { redirect_to [:admin, @user], notice: 'User was successfully created.' }
format.json { render json: @admin_user, status: :created, location: @admin_user } format.json { render json: @user, status: :created, location: @user }
else else
format.html { render "new" } format.html { render "new" }
format.json { render json: @admin_user.errors, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity }
end end
end end
end end
...@@ -67,26 +67,26 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -67,26 +67,26 @@ class Admin::UsersController < Admin::ApplicationController
params[:user].delete(:password_confirmation) params[:user].delete(:password_confirmation)
end end
admin_user.admin = (admin && admin.to_i > 0) user.admin = (admin && admin.to_i > 0)
respond_to do |format| respond_to do |format|
if admin_user.update_attributes(params[:user], as: :admin) if user.update_attributes(params[:user], as: :admin)
format.html { redirect_to [:admin, admin_user], notice: 'User was successfully updated.' } format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' }
format.json { head :ok } format.json { head :ok }
else else
# restore username to keep form action url. # restore username to keep form action url.
admin_user.username = params[:id] user.username = params[:id]
format.html { render "edit" } format.html { render "edit" }
format.json { render json: admin_user.errors, status: :unprocessable_entity } format.json { render json: user.errors, status: :unprocessable_entity }
end end
end end
end end
def destroy def destroy
if admin_user.personal_projects.count > 0 if user.personal_projects.count > 0
redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return
end end
admin_user.destroy user.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to admin_users_path } format.html { redirect_to admin_users_path }
...@@ -96,7 +96,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -96,7 +96,7 @@ class Admin::UsersController < Admin::ApplicationController
protected protected
def admin_user def user
@admin_user ||= User.find_by_username!(params[:id]) @user ||= User.find_by_username!(params[:id])
end end
end end
...@@ -21,7 +21,7 @@ class ProjectTeam ...@@ -21,7 +21,7 @@ class ProjectTeam
end end
end end
def find user_id def find(user_id)
user = project.users.find_by_id(user_id) user = project.users.find_by_id(user_id)
if group if group
...@@ -31,7 +31,7 @@ class ProjectTeam ...@@ -31,7 +31,7 @@ class ProjectTeam
user user
end end
def get_tm user_id def find_tm(user_id)
project.users_projects.find_by_user_id(user_id) project.users_projects.find_by_user_id(user_id)
end end
......
.user_new .user_new
= form_for [:admin, @admin_user] do |f| = form_for [:admin, @user] do |f|
-if @admin_user.errors.any? -if @user.errors.any?
#error_explanation #error_explanation
%ul.unstyled.alert.alert-error %ul.unstyled.alert.alert-error
- @admin_user.errors.full_messages.each do |msg| - @user.errors.full_messages.each do |msg|
%li= msg %li= msg
%fieldset %fieldset
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
= f.text_field :email, required: true, autocomplete: "off" = f.text_field :email, required: true, autocomplete: "off"
%span.help-inline * required %span.help-inline * required
- if @admin_user.new_record? - if @user.new_record?
%fieldset %fieldset
%legend Password %legend Password
.clearfix .clearfix
...@@ -65,14 +65,14 @@ ...@@ -65,14 +65,14 @@
%strong.cred Administrator %strong.cred Administrator
.input= f.check_box :admin .input= f.check_box :admin
.span4 .span4
- unless @admin_user.new_record? - unless @user.new_record?
.alert.alert-error .alert.alert-error
- if @admin_user.blocked? - if @user.blocked?
%p This user is blocked and is not able to login to GitLab %p This user is blocked and is not able to login to GitLab
= link_to 'Unblock User', unblock_admin_user_path(@admin_user), method: :put, class: "btn btn-small" = link_to 'Unblock User', unblock_admin_user_path(@user), method: :put, class: "btn btn-small"
- else - else
%p Blocked users will be removed from all projects &amp; will not be able to login to GitLab. %p Blocked users will be removed from all projects &amp; will not be able to login to GitLab.
= link_to 'Block User', block_admin_user_path(@admin_user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove" = link_to 'Block User', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
%fieldset %fieldset
%legend Profile %legend Profile
.clearfix .clearfix
...@@ -86,9 +86,9 @@ ...@@ -86,9 +86,9 @@
.input= f.text_field :twitter .input= f.text_field :twitter
.actions .actions
- if @admin_user.new_record? - if @user.new_record?
= f.submit 'Create user', class: "btn btn-create" = f.submit 'Create user', class: "btn btn-create"
= link_to 'Cancel', admin_users_path, class: "btn btn-cancel" = link_to 'Cancel', admin_users_path, class: "btn btn-cancel"
- else - else
= f.submit 'Save changes', class: "btn btn-save" = f.submit 'Save changes', class: "btn btn-save"
= link_to 'Cancel', admin_user_path(@admin_user), class: "btn btn-cancel" = link_to 'Cancel', admin_user_path(@user), class: "btn btn-cancel"
%h3.page_title %h3.page_title
#{@admin_user.name} &rarr; #{@user.name} &rarr;
%i.icon-edit %i.icon-edit
Edit user Edit user
%hr %hr
......
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
.span9 .span9
.ui-box .ui-box
%h5.title %h5.title
Users (#{@admin_users.total_count}) Users (#{@users.total_count})
%ul.well-list %ul.well-list
- @admin_users.each do |user| - @users.each do |user|
%li %li
- if user.blocked? - if user.blocked?
%i.icon-lock.cred %i.icon-lock.cred
...@@ -58,4 +58,4 @@ ...@@ -58,4 +58,4 @@
- else - else
= link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove" = link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
= link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove" = link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove"
= paginate @admin_users, theme: "gitlab" = paginate @users, theme: "gitlab"
%h3.page_title %h3.page_title
User: User:
= @admin_user.name = @user.name
- if @admin_user.blocked? - if @user.blocked?
%span.cred (Blocked) %span.cred (Blocked)
- if @admin_user.admin - if @user.admin
%span.cred (Admin) %span.cred (Admin)
.pull-right .pull-right
= link_to edit_admin_user_path(@admin_user), class: "btn grouped btn-small" do = link_to edit_admin_user_path(@user), class: "btn grouped btn-small" do
%i.icon-edit %i.icon-edit
Edit Edit
- unless @admin_user == current_user - unless @user == current_user
- if @admin_user.blocked? - if @user.blocked?
= link_to 'Unblock', unblock_admin_user_path(@admin_user), method: :put, class: "btn grouped btn-small success" = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped btn-small success"
- else - else
= link_to 'Block', block_admin_user_path(@admin_user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-small btn-remove" = link_to 'Block', block_admin_user_path(@user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn grouped btn-small btn-remove"
= link_to 'Destroy', [:admin, @admin_user], confirm: "USER #{@admin_user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn grouped btn-small btn-remove" = link_to 'Destroy', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn grouped btn-small btn-remove"
%hr %hr
.row .row
...@@ -24,50 +24,50 @@ ...@@ -24,50 +24,50 @@
%h5.title %h5.title
Account: Account:
.pull-right .pull-right
= image_tag gravatar_icon(@admin_user.email, 32), class: "avatar s32" = image_tag gravatar_icon(@user.email, 32), class: "avatar s32"
%ul.well-list %ul.well-list
%li %li
%span.light Name: %span.light Name:
%strong= @admin_user.name %strong= @user.name
%li %li
%span.light Username: %span.light Username:
%strong %strong
= @admin_user.username = @user.username
%li %li
%span.light Email: %span.light Email:
%strong %strong
= mail_to @admin_user.email = mail_to @user.email
%li %li
%span.light Member since: %span.light Member since:
%strong %strong
= @admin_user.created_at.stamp("Nov 12, 2031") = @user.created_at.stamp("Nov 12, 2031")
%li %li
%span.light Last sign-in at: %span.light Last sign-in at:
%strong %strong
- if @admin_user.last_sign_in_at - if @user.last_sign_in_at
= @admin_user.last_sign_in_at.stamp("Nov 12, 2031") = @user.last_sign_in_at.stamp("Nov 12, 2031")
- else - else
never never
- if @admin_user.ldap_user? - if @user.ldap_user?
%li %li
%span.light LDAP uid: %span.light LDAP uid:
%strong %strong
= @admin_user.extern_uid = @user.extern_uid
- if @admin_user.created_by - if @user.created_by
%li %li
%span.light Created by: %span.light Created by:
%strong %strong
= link_to @admin_user.created_by.name, [:admin, @admin_user.created_by] = link_to @user.created_by.name, [:admin, @user.created_by]
- if @admin_user.users_groups.present? - if @user.users_groups.present?
.ui-box .ui-box
%h5.title Groups: %h5.title Groups:
%ul.well-list %ul.well-list
- @admin_user.users_groups.each do |user_group| - @user.users_groups.each do |user_group|
- group = user_group.group - group = user_group.group
%li %li
%strong= link_to group.name, admin_group_path(group) %strong= link_to group.name, admin_group_path(group)
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
%h5.title Projects (#{@projects.count}) %h5.title Projects (#{@projects.count})
%ul.well-list %ul.well-list
- @projects.sort_by(&:name_with_namespace).each do |project| - @projects.sort_by(&:name_with_namespace).each do |project|
- tm = project.team.get_tm(@admin_user.id) - tm = project.team.find_tm(@user.id)
%li %li
= link_to admin_project_path(project), class: dom_class(project) do = link_to admin_project_path(project), class: dom_class(project) do
- if project.namespace - if project.namespace
...@@ -91,5 +91,5 @@ ...@@ -91,5 +91,5 @@
- if tm - if tm
.pull-right .pull-right
%span.light= tm.human_access %span.light= tm.human_access
= link_to admin_project_member_path(project, tm.user), confirm: remove_from_project_team_message(project, @admin_user), method: :delete, class: "btn btn-small btn-remove" do = link_to admin_project_member_path(project, tm.user), confirm: remove_from_project_team_message(project, @user), method: :delete, class: "btn btn-small btn-remove" do
%i.icon-remove %i.icon-remove
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment