Skip to content
Snippets Groups Projects
Commit 1dd80d22 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Prevent confusion in naming user variable at admin area

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