Commit 1dd80d22a58d6407951e89eedcdbf21d340f9261
1 parent
21f7c99c
Exists in
master
and in
4 other branches
Prevent confusion in naming user variable at admin area
Showing
6 changed files
with
66 additions
and
66 deletions
Show diff stats
app/controllers/admin/users_controller.rb
| 1 | 1 | class Admin::UsersController < Admin::ApplicationController |
| 2 | - before_filter :admin_user, only: [:show, :edit, :update, :destroy] | |
| 2 | + before_filter :user, only: [:show, :edit, :update, :destroy] | |
| 3 | 3 | |
| 4 | 4 | def index |
| 5 | - @admin_users = User.scoped | |
| 6 | - @admin_users = @admin_users.filter(params[:filter]) | |
| 7 | - @admin_users = @admin_users.search(params[:name]) if params[:name].present? | |
| 8 | - @admin_users = @admin_users.alphabetically.page(params[:page]) | |
| 5 | + @users = User.scoped | |
| 6 | + @users = @users.filter(params[:filter]) | |
| 7 | + @users = @users.search(params[:name]) if params[:name].present? | |
| 8 | + @users = @users.alphabetically.page(params[:page]) | |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def show |
| 12 | - @projects = admin_user.authorized_projects | |
| 12 | + @projects = user.authorized_projects | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def new |
| 16 | - @admin_user = User.new.with_defaults | |
| 16 | + @user = User.new.with_defaults | |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | def edit |
| 20 | - admin_user | |
| 20 | + user | |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | def block |
| 24 | - if admin_user.block | |
| 24 | + if user.block | |
| 25 | 25 | redirect_to :back, alert: "Successfully blocked" |
| 26 | 26 | else |
| 27 | 27 | redirect_to :back, alert: "Error occured. User was not blocked" |
| ... | ... | @@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 31 | def unblock |
| 32 | - if admin_user.activate | |
| 32 | + if user.activate | |
| 33 | 33 | redirect_to :back, alert: "Successfully unblocked" |
| 34 | 34 | else |
| 35 | 35 | redirect_to :back, alert: "Error occured. User was not unblocked" |
| ... | ... | @@ -44,17 +44,17 @@ class Admin::UsersController < Admin::ApplicationController |
| 44 | 44 | password_expires_at: Time.now |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - @admin_user = User.new(params[:user].merge(opts), as: :admin) | |
| 48 | - @admin_user.admin = (admin && admin.to_i > 0) | |
| 49 | - @admin_user.created_by_id = current_user.id | |
| 47 | + @user = User.new(params[:user].merge(opts), as: :admin) | |
| 48 | + @user.admin = (admin && admin.to_i > 0) | |
| 49 | + @user.created_by_id = current_user.id | |
| 50 | 50 | |
| 51 | 51 | respond_to do |format| |
| 52 | - if @admin_user.save | |
| 53 | - format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully created.' } | |
| 54 | - format.json { render json: @admin_user, status: :created, location: @admin_user } | |
| 52 | + if @user.save | |
| 53 | + format.html { redirect_to [:admin, @user], notice: 'User was successfully created.' } | |
| 54 | + format.json { render json: @user, status: :created, location: @user } | |
| 55 | 55 | else |
| 56 | 56 | format.html { render "new" } |
| 57 | - format.json { render json: @admin_user.errors, status: :unprocessable_entity } | |
| 57 | + format.json { render json: @user.errors, status: :unprocessable_entity } | |
| 58 | 58 | end |
| 59 | 59 | end |
| 60 | 60 | end |
| ... | ... | @@ -67,26 +67,26 @@ class Admin::UsersController < Admin::ApplicationController |
| 67 | 67 | params[:user].delete(:password_confirmation) |
| 68 | 68 | end |
| 69 | 69 | |
| 70 | - admin_user.admin = (admin && admin.to_i > 0) | |
| 70 | + user.admin = (admin && admin.to_i > 0) | |
| 71 | 71 | |
| 72 | 72 | respond_to do |format| |
| 73 | - if admin_user.update_attributes(params[:user], as: :admin) | |
| 74 | - format.html { redirect_to [:admin, admin_user], notice: 'User was successfully updated.' } | |
| 73 | + if user.update_attributes(params[:user], as: :admin) | |
| 74 | + format.html { redirect_to [:admin, user], notice: 'User was successfully updated.' } | |
| 75 | 75 | format.json { head :ok } |
| 76 | 76 | else |
| 77 | 77 | # restore username to keep form action url. |
| 78 | - admin_user.username = params[:id] | |
| 78 | + user.username = params[:id] | |
| 79 | 79 | format.html { render "edit" } |
| 80 | - format.json { render json: admin_user.errors, status: :unprocessable_entity } | |
| 80 | + format.json { render json: user.errors, status: :unprocessable_entity } | |
| 81 | 81 | end |
| 82 | 82 | end |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | def destroy |
| 86 | - if admin_user.personal_projects.count > 0 | |
| 86 | + if user.personal_projects.count > 0 | |
| 87 | 87 | redirect_to admin_users_path, alert: "User is a project owner and can't be removed." and return |
| 88 | 88 | end |
| 89 | - admin_user.destroy | |
| 89 | + user.destroy | |
| 90 | 90 | |
| 91 | 91 | respond_to do |format| |
| 92 | 92 | format.html { redirect_to admin_users_path } |
| ... | ... | @@ -96,7 +96,7 @@ class Admin::UsersController < Admin::ApplicationController |
| 96 | 96 | |
| 97 | 97 | protected |
| 98 | 98 | |
| 99 | - def admin_user | |
| 100 | - @admin_user ||= User.find_by_username!(params[:id]) | |
| 99 | + def user | |
| 100 | + @user ||= User.find_by_username!(params[:id]) | |
| 101 | 101 | end |
| 102 | 102 | end | ... | ... |
app/models/project_team.rb
| ... | ... | @@ -21,7 +21,7 @@ class ProjectTeam |
| 21 | 21 | end |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | - def find user_id | |
| 24 | + def find(user_id) | |
| 25 | 25 | user = project.users.find_by_id(user_id) |
| 26 | 26 | |
| 27 | 27 | if group |
| ... | ... | @@ -31,7 +31,7 @@ class ProjectTeam |
| 31 | 31 | user |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | - def get_tm user_id | |
| 34 | + def find_tm(user_id) | |
| 35 | 35 | project.users_projects.find_by_user_id(user_id) |
| 36 | 36 | end |
| 37 | 37 | ... | ... |
app/views/admin/users/_form.html.haml
| 1 | 1 | .user_new |
| 2 | - = form_for [:admin, @admin_user] do |f| | |
| 3 | - -if @admin_user.errors.any? | |
| 2 | + = form_for [:admin, @user] do |f| | |
| 3 | + -if @user.errors.any? | |
| 4 | 4 | #error_explanation |
| 5 | 5 | %ul.unstyled.alert.alert-error |
| 6 | - - @admin_user.errors.full_messages.each do |msg| | |
| 6 | + - @user.errors.full_messages.each do |msg| | |
| 7 | 7 | %li= msg |
| 8 | 8 | |
| 9 | 9 | %fieldset |
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | = f.text_field :email, required: true, autocomplete: "off" |
| 25 | 25 | %span.help-inline * required |
| 26 | 26 | |
| 27 | - - if @admin_user.new_record? | |
| 27 | + - if @user.new_record? | |
| 28 | 28 | %fieldset |
| 29 | 29 | %legend Password |
| 30 | 30 | .clearfix |
| ... | ... | @@ -65,14 +65,14 @@ |
| 65 | 65 | %strong.cred Administrator |
| 66 | 66 | .input= f.check_box :admin |
| 67 | 67 | .span4 |
| 68 | - - unless @admin_user.new_record? | |
| 68 | + - unless @user.new_record? | |
| 69 | 69 | .alert.alert-error |
| 70 | - - if @admin_user.blocked? | |
| 70 | + - if @user.blocked? | |
| 71 | 71 | %p This user is blocked and is not able to login to GitLab |
| 72 | - = link_to 'Unblock User', unblock_admin_user_path(@admin_user), method: :put, class: "btn btn-small" | |
| 72 | + = link_to 'Unblock User', unblock_admin_user_path(@user), method: :put, class: "btn btn-small" | |
| 73 | 73 | - else |
| 74 | 74 | %p Blocked users will be removed from all projects & will not be able to login to GitLab. |
| 75 | - = 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" | |
| 75 | + = 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" | |
| 76 | 76 | %fieldset |
| 77 | 77 | %legend Profile |
| 78 | 78 | .clearfix |
| ... | ... | @@ -86,9 +86,9 @@ |
| 86 | 86 | .input= f.text_field :twitter |
| 87 | 87 | |
| 88 | 88 | .actions |
| 89 | - - if @admin_user.new_record? | |
| 89 | + - if @user.new_record? | |
| 90 | 90 | = f.submit 'Create user', class: "btn btn-create" |
| 91 | 91 | = link_to 'Cancel', admin_users_path, class: "btn btn-cancel" |
| 92 | 92 | - else |
| 93 | 93 | = f.submit 'Save changes', class: "btn btn-save" |
| 94 | - = link_to 'Cancel', admin_user_path(@admin_user), class: "btn btn-cancel" | |
| 94 | + = link_to 'Cancel', admin_user_path(@user), class: "btn btn-cancel" | ... | ... |
app/views/admin/users/edit.html.haml
app/views/admin/users/index.html.haml
| ... | ... | @@ -33,9 +33,9 @@ |
| 33 | 33 | .span9 |
| 34 | 34 | .ui-box |
| 35 | 35 | %h5.title |
| 36 | - Users (#{@admin_users.total_count}) | |
| 36 | + Users (#{@users.total_count}) | |
| 37 | 37 | %ul.well-list |
| 38 | - - @admin_users.each do |user| | |
| 38 | + - @users.each do |user| | |
| 39 | 39 | %li |
| 40 | 40 | - if user.blocked? |
| 41 | 41 | %i.icon-lock.cred |
| ... | ... | @@ -58,4 +58,4 @@ |
| 58 | 58 | - else |
| 59 | 59 | = link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove" |
| 60 | 60 | = link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove" |
| 61 | - = paginate @admin_users, theme: "gitlab" | |
| 61 | + = paginate @users, theme: "gitlab" | ... | ... |
app/views/admin/users/show.html.haml
| 1 | 1 | %h3.page_title |
| 2 | 2 | User: |
| 3 | - = @admin_user.name | |
| 4 | - - if @admin_user.blocked? | |
| 3 | + = @user.name | |
| 4 | + - if @user.blocked? | |
| 5 | 5 | %span.cred (Blocked) |
| 6 | - - if @admin_user.admin | |
| 6 | + - if @user.admin | |
| 7 | 7 | %span.cred (Admin) |
| 8 | 8 | |
| 9 | 9 | .pull-right |
| 10 | - = link_to edit_admin_user_path(@admin_user), class: "btn grouped btn-small" do | |
| 10 | + = link_to edit_admin_user_path(@user), class: "btn grouped btn-small" do | |
| 11 | 11 | %i.icon-edit |
| 12 | 12 | Edit |
| 13 | - - unless @admin_user == current_user | |
| 14 | - - if @admin_user.blocked? | |
| 15 | - = link_to 'Unblock', unblock_admin_user_path(@admin_user), method: :put, class: "btn grouped btn-small success" | |
| 13 | + - unless @user == current_user | |
| 14 | + - if @user.blocked? | |
| 15 | + = link_to 'Unblock', unblock_admin_user_path(@user), method: :put, class: "btn grouped btn-small success" | |
| 16 | 16 | - else |
| 17 | - = 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" | |
| 18 | - = 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" | |
| 17 | + = 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" | |
| 18 | + = link_to 'Destroy', [:admin, @user], confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn grouped btn-small btn-remove" | |
| 19 | 19 | %hr |
| 20 | 20 | |
| 21 | 21 | .row |
| ... | ... | @@ -24,50 +24,50 @@ |
| 24 | 24 | %h5.title |
| 25 | 25 | Account: |
| 26 | 26 | .pull-right |
| 27 | - = image_tag gravatar_icon(@admin_user.email, 32), class: "avatar s32" | |
| 27 | + = image_tag gravatar_icon(@user.email, 32), class: "avatar s32" | |
| 28 | 28 | %ul.well-list |
| 29 | 29 | %li |
| 30 | 30 | %span.light Name: |
| 31 | - %strong= @admin_user.name | |
| 31 | + %strong= @user.name | |
| 32 | 32 | %li |
| 33 | 33 | %span.light Username: |
| 34 | 34 | %strong |
| 35 | - = @admin_user.username | |
| 35 | + = @user.username | |
| 36 | 36 | %li |
| 37 | 37 | %span.light Email: |
| 38 | 38 | %strong |
| 39 | - = mail_to @admin_user.email | |
| 39 | + = mail_to @user.email | |
| 40 | 40 | |
| 41 | 41 | %li |
| 42 | 42 | %span.light Member since: |
| 43 | 43 | %strong |
| 44 | - = @admin_user.created_at.stamp("Nov 12, 2031") | |
| 44 | + = @user.created_at.stamp("Nov 12, 2031") | |
| 45 | 45 | |
| 46 | 46 | %li |
| 47 | 47 | %span.light Last sign-in at: |
| 48 | 48 | %strong |
| 49 | - - if @admin_user.last_sign_in_at | |
| 50 | - = @admin_user.last_sign_in_at.stamp("Nov 12, 2031") | |
| 49 | + - if @user.last_sign_in_at | |
| 50 | + = @user.last_sign_in_at.stamp("Nov 12, 2031") | |
| 51 | 51 | - else |
| 52 | 52 | never |
| 53 | 53 | |
| 54 | - - if @admin_user.ldap_user? | |
| 54 | + - if @user.ldap_user? | |
| 55 | 55 | %li |
| 56 | 56 | %span.light LDAP uid: |
| 57 | 57 | %strong |
| 58 | - = @admin_user.extern_uid | |
| 58 | + = @user.extern_uid | |
| 59 | 59 | |
| 60 | - - if @admin_user.created_by | |
| 60 | + - if @user.created_by | |
| 61 | 61 | %li |
| 62 | 62 | %span.light Created by: |
| 63 | 63 | %strong |
| 64 | - = link_to @admin_user.created_by.name, [:admin, @admin_user.created_by] | |
| 64 | + = link_to @user.created_by.name, [:admin, @user.created_by] | |
| 65 | 65 | |
| 66 | - - if @admin_user.users_groups.present? | |
| 66 | + - if @user.users_groups.present? | |
| 67 | 67 | .ui-box |
| 68 | 68 | %h5.title Groups: |
| 69 | 69 | %ul.well-list |
| 70 | - - @admin_user.users_groups.each do |user_group| | |
| 70 | + - @user.users_groups.each do |user_group| | |
| 71 | 71 | - group = user_group.group |
| 72 | 72 | %li |
| 73 | 73 | %strong= link_to group.name, admin_group_path(group) |
| ... | ... | @@ -79,7 +79,7 @@ |
| 79 | 79 | %h5.title Projects (#{@projects.count}) |
| 80 | 80 | %ul.well-list |
| 81 | 81 | - @projects.sort_by(&:name_with_namespace).each do |project| |
| 82 | - - tm = project.team.get_tm(@admin_user.id) | |
| 82 | + - tm = project.team.find_tm(@user.id) | |
| 83 | 83 | %li |
| 84 | 84 | = link_to admin_project_path(project), class: dom_class(project) do |
| 85 | 85 | - if project.namespace |
| ... | ... | @@ -91,5 +91,5 @@ |
| 91 | 91 | - if tm |
| 92 | 92 | .pull-right |
| 93 | 93 | %span.light= tm.human_access |
| 94 | - = 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 | |
| 94 | + = 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 | |
| 95 | 95 | %i.icon-remove | ... | ... |