From 228da2dd28a91b3ab2729787e93e72940975a2bd Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 18 Jun 2015 17:56:15 +0200 Subject: Admin can see and remove user identities Signed-off-by: Dmitriy Zaporozhets --- CHANGELOG | 1 + app/controllers/admin/identities_controller.rb | 21 +++++++++++++++++++++ app/views/admin/identities/_identity.html.haml | 11 +++++++++++ app/views/admin/users/show.html.haml | 14 ++++++++++++++ config/routes.rb | 2 ++ 5 files changed, 49 insertions(+) create mode 100644 app/controllers/admin/identities_controller.rb create mode 100644 app/views/admin/identities/_identity.html.haml diff --git a/CHANGELOG b/CHANGELOG index 86de9314d80..a6c2f9ac0cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ v 7.13.0 (unreleased) - Rename "Design" profile settings page to "Preferences". - Allow users to customize their default Dashboard page. - Update ssl_ciphers in Nginx example to remove DHE settings. This will deny forward secrecy for Android 2.3.7, Java 6 and OpenSSL 0.9.8 + - Admin can remove user identities v 7.12.0 (unreleased) - Fix post-receive errors on a push when an external issue tracker is configured (Stan Hu) diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb new file mode 100644 index 00000000000..6107b1bcb40 --- /dev/null +++ b/app/controllers/admin/identities_controller.rb @@ -0,0 +1,21 @@ +class Admin::IdentitiesController < Admin::ApplicationController + before_action :user, only: [:destroy] + + def destroy + identity = user.identities.find(params[:id]) + + respond_to do |format| + if identity.destroy + format.html { redirect_to [:admin, user], notice: 'User identity was successfully removed.' } + else + format.html { redirect_to [:admin, user], alert: 'Failed to remove user identity.' } + end + end + end + + protected + + def user + @user ||= User.find_by!(username: params[:user_id]) + end +end diff --git a/app/views/admin/identities/_identity.html.haml b/app/views/admin/identities/_identity.html.haml new file mode 100644 index 00000000000..b94edefaa41 --- /dev/null +++ b/app/views/admin/identities/_identity.html.haml @@ -0,0 +1,11 @@ +%tr + %td + = identity.provider + %td + = identity.extern_uid + %td + = link_to [:admin, @user, identity], method: :delete, + class: 'btn btn-xs btn-danger', + data: { confirm: "Are you sure you want to remove this identity" } do + %i.fa.fa-trash + Delete diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index f7195ac3326..1546e069863 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -23,6 +23,8 @@ %a{"data-toggle" => "tab", href: "#projects"} Projects %li %a{"data-toggle" => "tab", href: "#ssh-keys"} SSH keys + %li + %a{"data-toggle" => "tab", href: "#identities"} Identities .tab-content #account.tab-pane.active @@ -230,3 +232,15 @@ %i.fa.fa-times #ssh-keys.tab-pane = render 'profiles/keys/key_table', admin: true + + #identities.tab-pane + - if @user.identities.present? + %table.table + %thead + %tr + %th Provider + %th Id + %th + = render @user.identities + - else + %h4 This user has no identities diff --git a/config/routes.rb b/config/routes.rb index d60bc796fdb..e9ff607aafe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,6 +149,8 @@ Gitlab::Application.routes.draw do namespace :admin do resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do resources :keys, only: [:show, :destroy] + resources :identities, only: [:destroy] + member do put :team_update put :block -- cgit v1.2.1 From 270b7ce810775d69887e76162a00e8dc97e5d959 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 19 Jun 2015 11:46:49 +0200 Subject: Add ability for admin to edit user identity Signed-off-by: Dmitriy Zaporozhets --- CHANGELOG | 2 +- app/controllers/admin/identities_controller.rb | 26 ++++++++++++++++++++++---- app/views/admin/identities/_form.html.haml | 19 +++++++++++++++++++ app/views/admin/identities/_identity.html.haml | 3 +++ app/views/admin/identities/edit.html.haml | 6 ++++++ config/routes.rb | 2 +- 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/identities/_form.html.haml create mode 100644 app/views/admin/identities/edit.html.haml diff --git a/CHANGELOG b/CHANGELOG index a6c2f9ac0cb..a0fb7ead800 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,7 @@ v 7.13.0 (unreleased) - Rename "Design" profile settings page to "Preferences". - Allow users to customize their default Dashboard page. - Update ssl_ciphers in Nginx example to remove DHE settings. This will deny forward secrecy for Android 2.3.7, Java 6 and OpenSSL 0.9.8 - - Admin can remove user identities + - Admin can edit and remove user identities v 7.12.0 (unreleased) - Fix post-receive errors on a push when an external issue tracker is configured (Stan Hu) diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 6107b1bcb40..795fecd78d6 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -1,11 +1,21 @@ class Admin::IdentitiesController < Admin::ApplicationController - before_action :user, only: [:destroy] + before_action :user + before_action :identity - def destroy - identity = user.identities.find(params[:id]) + def edit + end + + def update + if @identity.update_attributes(identity_params) + redirect_to admin_user_path(@user), notice: 'User identity was successfully updated.' + else + render :edit + end + end + def destroy respond_to do |format| - if identity.destroy + if @identity.destroy format.html { redirect_to [:admin, user], notice: 'User identity was successfully removed.' } else format.html { redirect_to [:admin, user], alert: 'Failed to remove user identity.' } @@ -18,4 +28,12 @@ class Admin::IdentitiesController < Admin::ApplicationController def user @user ||= User.find_by!(username: params[:user_id]) end + + def identity + @identity ||= user.identities.find(params[:id]) + end + + def identity_params + params[:identity].permit(:provider, :extern_uid) + end end diff --git a/app/views/admin/identities/_form.html.haml b/app/views/admin/identities/_form.html.haml new file mode 100644 index 00000000000..1c34706a124 --- /dev/null +++ b/app/views/admin/identities/_form.html.haml @@ -0,0 +1,19 @@ += form_for [:admin, @user, @identity], html: { class: 'form-horizontal fieldset-form' } do |f| + -if @identity.errors.any? + #error_explanation + .alert.alert-danger + - @identity.errors.full_messages.each do |msg| + %p= msg + + .form-group + = f.label :provider, class: 'control-label' + .col-sm-10 + = f.text_field :provider, required: true, autocomplete: "off", class: 'form-control', required: true + .form-group + = f.label :extern_uid, class: 'control-label' + .col-sm-10 + = f.text_field :extern_uid, required: true, autocomplete: "off", class: 'form-control', required: true + + .form-actions + = f.submit 'Save changes', class: "btn btn-save" + diff --git a/app/views/admin/identities/_identity.html.haml b/app/views/admin/identities/_identity.html.haml index b94edefaa41..0b7020b887d 100644 --- a/app/views/admin/identities/_identity.html.haml +++ b/app/views/admin/identities/_identity.html.haml @@ -4,6 +4,9 @@ %td = identity.extern_uid %td + = link_to edit_admin_user_identity_path(@user, identity), class: 'btn btn-xs btn-grouped' do + %i.fa.fa-edit + Edit = link_to [:admin, @user, identity], method: :delete, class: 'btn btn-xs btn-danger', data: { confirm: "Are you sure you want to remove this identity" } do diff --git a/app/views/admin/identities/edit.html.haml b/app/views/admin/identities/edit.html.haml new file mode 100644 index 00000000000..d49d79ce5c9 --- /dev/null +++ b/app/views/admin/identities/edit.html.haml @@ -0,0 +1,6 @@ +- page_title @user.name, "Users" +%h3.page-title + Edit identity for #{@user.name} +%hr + += render 'form' diff --git a/config/routes.rb b/config/routes.rb index e9ff607aafe..8428eff1ef5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,7 +149,7 @@ Gitlab::Application.routes.draw do namespace :admin do resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do resources :keys, only: [:show, :destroy] - resources :identities, only: [:destroy] + resources :identities, only: [:edit, :update, :destroy] member do put :team_update -- cgit v1.2.1 From d059c69db76a5a55841bb8b0914211ae0a4bfd4f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 19 Jun 2015 12:04:34 +0200 Subject: Move identities list to own controller action Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/identities_controller.rb | 12 ++++++++---- app/views/admin/identities/index.html.haml | 15 +++++++++++++++ app/views/admin/users/show.html.haml | 14 +------------- config/routes.rb | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 app/views/admin/identities/index.html.haml diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 795fecd78d6..17ace5a258b 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -1,13 +1,17 @@ class Admin::IdentitiesController < Admin::ApplicationController before_action :user - before_action :identity + before_action :identity, except: :index + + def index + @identities = @user.identities + end def edit end def update if @identity.update_attributes(identity_params) - redirect_to admin_user_path(@user), notice: 'User identity was successfully updated.' + redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully updated.' else render :edit end @@ -16,9 +20,9 @@ class Admin::IdentitiesController < Admin::ApplicationController def destroy respond_to do |format| if @identity.destroy - format.html { redirect_to [:admin, user], notice: 'User identity was successfully removed.' } + format.html { redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully removed.' } else - format.html { redirect_to [:admin, user], alert: 'Failed to remove user identity.' } + format.html { redirect_to admin_user_identities_path(@user), alert: 'Failed to remove user identity.' } end end end diff --git a/app/views/admin/identities/index.html.haml b/app/views/admin/identities/index.html.haml new file mode 100644 index 00000000000..bc8f1b9f0b2 --- /dev/null +++ b/app/views/admin/identities/index.html.haml @@ -0,0 +1,15 @@ +%h3.page-title + Identities for + = link_to @user.name, [:admin, @user] + +%hr +- if @identities.present? + %table.table + %thead + %tr + %th Provider + %th Id + %th + = render @identities +- else + %h4 This user has no identities diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 1546e069863..278102d5d4d 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -24,7 +24,7 @@ %li %a{"data-toggle" => "tab", href: "#ssh-keys"} SSH keys %li - %a{"data-toggle" => "tab", href: "#identities"} Identities + = link_to "Identities", admin_user_identities_path(@user) .tab-content #account.tab-pane.active @@ -232,15 +232,3 @@ %i.fa.fa-times #ssh-keys.tab-pane = render 'profiles/keys/key_table', admin: true - - #identities.tab-pane - - if @user.identities.present? - %table.table - %thead - %tr - %th Provider - %th Id - %th - = render @user.identities - - else - %h4 This user has no identities diff --git a/config/routes.rb b/config/routes.rb index 8428eff1ef5..00a95a23edc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,7 +149,7 @@ Gitlab::Application.routes.draw do namespace :admin do resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do resources :keys, only: [:show, :destroy] - resources :identities, only: [:edit, :update, :destroy] + resources :identities, only: [:index, :edit, :update, :destroy] member do put :team_update -- cgit v1.2.1 From aca6d36722df8139bb26e06fd39970b797aa6a1f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 19 Jun 2015 12:23:05 +0200 Subject: Add tests for admin managing user identities Signed-off-by: Dmitriy Zaporozhets --- features/admin/users.feature | 19 ++++++++++++++++++- features/steps/admin/users.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/features/admin/users.feature b/features/admin/users.feature index 1a8720dd77e..f17254911b7 100644 --- a/features/admin/users.feature +++ b/features/admin/users.feature @@ -28,7 +28,7 @@ Feature: Admin Users When I submit modified user Then I see user attributes changed -@javascript + @javascript Scenario: Remove users secondary email Given I visit admin users page And I view the user with secondary email @@ -45,3 +45,20 @@ Feature: Admin Users Then I should see key details And I click on remove key Then I should see the key removed + + Scenario: Show user identities + Given user "Pete" with twitter account + And I visit "Pete" identities page in admin + Then I should see twitter details + + Scenario: Update user identities + Given user "Pete" with twitter account + And I visit "Pete" identities page in admin + And I modify twitter identity + Then I should see twitter details updated + + Scenario: Remove user identities + Given user "Pete" with twitter account + And I visit "Pete" identities page in admin + And I remove twitter identity + Then I should not see twitter details diff --git a/features/steps/admin/users.rb b/features/steps/admin/users.rb index 34a3ed9f615..a9bb314b24f 100644 --- a/features/steps/admin/users.rb +++ b/features/steps/admin/users.rb @@ -114,4 +114,40 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps step 'I should see the key removed' do expect(page).not_to have_content 'ssh-rsa Key2' end + + step 'user "Pete" with twitter account' do + @user = create(:user, name: 'Pete') + @user.identities.create!(extern_uid: '123456', provider: 'twitter') + end + + step 'I visit "Pete" identities page in admin' do + visit admin_user_identities_path(@user) + end + + step 'I should see twitter details' do + expect(page).to have_content 'Identities for Pete' + expect(page).to have_content 'twitter' + end + + step 'I modify twitter identity' do + click_link 'Edit' + fill_in 'identity_extern_uid', with: '654321' + fill_in 'identity_provider', with: 'twitter_updated' + click_button 'Save changes' + end + + step 'I should see twitter details updated' do + expect(page).to have_content 'Identities for Pete' + expect(page).to have_content 'twitter_updated' + expect(page).to have_content '654321' + end + + step 'I remove twitter identity' do + click_link 'Delete' + end + + step 'I should not see twitter details' do + expect(page).to have_content 'Identities for Pete' + expect(page).to_not have_content 'twitter' + end end -- cgit v1.2.1 From 8f89a4884744cf633fcff218dcfc657a8ff922b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 16:52:06 +0200 Subject: Minor improvements to admin identities text Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/identities/_identity.html.haml | 4 +--- app/views/admin/identities/index.html.haml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/admin/identities/_identity.html.haml b/app/views/admin/identities/_identity.html.haml index 0b7020b887d..671c4fbc677 100644 --- a/app/views/admin/identities/_identity.html.haml +++ b/app/views/admin/identities/_identity.html.haml @@ -5,10 +5,8 @@ = identity.extern_uid %td = link_to edit_admin_user_identity_path(@user, identity), class: 'btn btn-xs btn-grouped' do - %i.fa.fa-edit Edit = link_to [:admin, @user, identity], method: :delete, class: 'btn btn-xs btn-danger', - data: { confirm: "Are you sure you want to remove this identity" } do - %i.fa.fa-trash + data: { confirm: "Are you sure you want to remove this identity?" } do Delete diff --git a/app/views/admin/identities/index.html.haml b/app/views/admin/identities/index.html.haml index bc8f1b9f0b2..76a0f6ca812 100644 --- a/app/views/admin/identities/index.html.haml +++ b/app/views/admin/identities/index.html.haml @@ -8,7 +8,7 @@ %thead %tr %th Provider - %th Id + %th Identifier %th = render @identities - else -- cgit v1.2.1 From b21390936a02764cc5aee8cfeef3d2f8419da4fc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 16:53:11 +0200 Subject: Make provider a select for identities form in admin area Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/identities/_form.html.haml | 6 +++--- lib/gitlab/o_auth/provider.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/gitlab/o_auth/provider.rb diff --git a/app/views/admin/identities/_form.html.haml b/app/views/admin/identities/_form.html.haml index 1c34706a124..f0f3c3ff221 100644 --- a/app/views/admin/identities/_form.html.haml +++ b/app/views/admin/identities/_form.html.haml @@ -8,11 +8,11 @@ .form-group = f.label :provider, class: 'control-label' .col-sm-10 - = f.text_field :provider, required: true, autocomplete: "off", class: 'form-control', required: true + = f.select :provider, Gitlab::OAuth::Provider.names, { allow_blank: false }, class: 'form-control' .form-group - = f.label :extern_uid, class: 'control-label' + = f.label :extern_uid, "Identifier", class: 'control-label' .col-sm-10 - = f.text_field :extern_uid, required: true, autocomplete: "off", class: 'form-control', required: true + = f.text_field :extern_uid, required: true, class: 'form-control', required: true .form-actions = f.submit 'Save changes', class: "btn btn-save" diff --git a/lib/gitlab/o_auth/provider.rb b/lib/gitlab/o_auth/provider.rb new file mode 100644 index 00000000000..f986499a27c --- /dev/null +++ b/lib/gitlab/o_auth/provider.rb @@ -0,0 +1,19 @@ +module Gitlab + module OAuth + class Provider + def self.names + providers = [] + + Gitlab.config.ldap.servers.values.each do |server| + providers << server['provider_name'] + end + + Gitlab.config.omniauth.providers.each do |provider| + providers << provider['name'] + end + + providers + end + end + end +end -- cgit v1.2.1 From cc04c5b82897564e4a78d7cd36bff853cc7efd83 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 17:12:20 +0200 Subject: Refactor admin user page Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/users_controller.rb | 11 +- app/views/admin/identities/index.html.haml | 6 +- app/views/admin/users/_head.html.haml | 23 ++ app/views/admin/users/groups.html.haml | 19 ++ app/views/admin/users/keys.html.haml | 3 + app/views/admin/users/projects.html.haml | 43 ++++ app/views/admin/users/show.html.haml | 372 +++++++++++------------------ config/routes.rb | 3 + 8 files changed, 245 insertions(+), 235 deletions(-) create mode 100644 app/views/admin/users/_head.html.haml create mode 100644 app/views/admin/users/groups.html.haml create mode 100644 app/views/admin/users/keys.html.haml create mode 100644 app/views/admin/users/projects.html.haml diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 06d6d61e907..a01eef74fb9 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,5 +1,5 @@ class Admin::UsersController < Admin::ApplicationController - before_action :user, only: [:show, :edit, :update, :destroy] + before_action :user, except: [:index, :new, :create] def index @users = User.order_name_asc.filter(params[:filter]) @@ -9,8 +9,17 @@ class Admin::UsersController < Admin::ApplicationController end def show + end + + def projects @personal_projects = user.personal_projects @joined_projects = user.projects.joined(@user) + end + + def groups + end + + def keys @keys = user.keys end diff --git a/app/views/admin/identities/index.html.haml b/app/views/admin/identities/index.html.haml index 76a0f6ca812..ae57e3adc4d 100644 --- a/app/views/admin/identities/index.html.haml +++ b/app/views/admin/identities/index.html.haml @@ -1,8 +1,6 @@ -%h3.page-title - Identities for - = link_to @user.name, [:admin, @user] +- page_title "Identities", @user.name, "Users" += render 'admin/users/head' -%hr - if @identities.present? %table.table %thead diff --git a/app/views/admin/users/_head.html.haml b/app/views/admin/users/_head.html.haml new file mode 100644 index 00000000000..c1ec1d48e17 --- /dev/null +++ b/app/views/admin/users/_head.html.haml @@ -0,0 +1,23 @@ +%h3.page-title + = @user.name + - if @user.blocked? + %span.cred (Blocked) + - if @user.admin + %span.cred (Admin) + + .pull-right + = link_to edit_admin_user_path(@user), class: "btn btn-grouped" do + %i.fa.fa-pencil-square-o + Edit + +%ul.nav.nav-tabs + = nav_link(path: 'users#show') do + = link_to "Account", admin_user_path(@user) + = nav_link(path: 'users#groups') do + = link_to "Groups", groups_admin_user_path(@user) + = nav_link(path: 'users#projects') do + = link_to "Projects", projects_admin_user_path(@user) + = nav_link(path: 'users#keys') do + = link_to "SSH keys", keys_admin_user_path(@user) + = nav_link(controller: :identities) do + = link_to "Identities", admin_user_identities_path(@user) diff --git a/app/views/admin/users/groups.html.haml b/app/views/admin/users/groups.html.haml new file mode 100644 index 00000000000..dbecb7bbfd6 --- /dev/null +++ b/app/views/admin/users/groups.html.haml @@ -0,0 +1,19 @@ +- page_title "Groups", @user.name, "Users" += render 'admin/users/head' + +- if @user.group_members.present? + .panel.panel-default + .panel-heading Groups: + %ul.well-list + - @user.group_members.each do |group_member| + - group = group_member.group + %li.group_member + %span{class: ("list-item-name" unless group_member.owner?)} + %strong= link_to group.name, admin_group_path(group) + .pull-right + %span.light= group_member.human_access + - unless group_member.owner? + = link_to group_group_member_path(group, group_member), data: { confirm: remove_user_from_group_message(group, group_member) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do + %i.fa.fa-times.fa-inverse +- else + .nothing-here-block This user has no groups. diff --git a/app/views/admin/users/keys.html.haml b/app/views/admin/users/keys.html.haml new file mode 100644 index 00000000000..07110717082 --- /dev/null +++ b/app/views/admin/users/keys.html.haml @@ -0,0 +1,3 @@ +- page_title "Keys", @user.name, "Users" += render 'admin/users/head' += render 'profiles/keys/key_table', admin: true diff --git a/app/views/admin/users/projects.html.haml b/app/views/admin/users/projects.html.haml new file mode 100644 index 00000000000..0d7a1a25a80 --- /dev/null +++ b/app/views/admin/users/projects.html.haml @@ -0,0 +1,43 @@ +- page_title "Projects", @user.name, "Users" += render 'admin/users/head' + +- if @user.groups.any? + .panel.panel-default + .panel-heading Group projects + %ul.well-list + - @user.groups.each do |group| + %li + %strong= group.name + – access to + #{pluralize(group.projects.count, 'project')} + +.row + .col-md-6 + - if @personal_projects.present? + = render 'users/projects', projects: @personal_projects + - else + .nothing-here-block This user has no personal projects. + + + .col-md-6 + .panel.panel-default + .panel-heading Joined projects (#{@joined_projects.count}) + %ul.well-list + - @joined_projects.sort_by(&:name_with_namespace).each do |project| + - member = project.team.find_member(@user.id) + %li.project_member + .list-item-name + = link_to admin_namespace_project_path(project.namespace, project), class: dom_class(project) do + = project.name_with_namespace + + - if member + .pull-right + - if member.owner? + %span.light Owner + - else + %span.light= member.human_access + + - if member.respond_to? :project + = link_to namespace_project_project_member_path(project.namespace, project, member), data: { confirm: remove_from_project_team_message(project, member) }, remote: true, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from project' do + %i.fa.fa-times + diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 278102d5d4d..69918193e8a 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -1,234 +1,146 @@ - page_title @user.name, "Users" -%h3.page-title - User: - = @user.name - - if @user.blocked? - %span.cred (Blocked) - - if @user.admin - %span.cred (Admin) - - .pull-right - = link_to edit_admin_user_path(@user), class: "btn btn-grouped" do - %i.fa.fa-pencil-square-o - Edit -%hr -%ul.nav.nav-tabs - %li.active - %a{"data-toggle" => "tab", href: "#account"} Account - %li - %a{"data-toggle" => "tab", href: "#profile"} Profile - %li - %a{"data-toggle" => "tab", href: "#groups"} Groups - %li - %a{"data-toggle" => "tab", href: "#projects"} Projects - %li - %a{"data-toggle" => "tab", href: "#ssh-keys"} SSH keys - %li - = link_to "Identities", admin_user_identities_path(@user) - -.tab-content - #account.tab-pane.active - .row - .col-md-6 - .panel.panel-default - .panel-heading - Account: - %ul.well-list - %li - %span.light Name: - %strong= @user.name - %li - %span.light Username: - %strong - = @user.username - %li - %span.light Email: - %strong - = mail_to @user.email - - @user.emails.each do |email| - %li - %span.light Secondary email: - %strong= email.email - = link_to remove_email_admin_user_path(@user, email), data: { confirm: "Are you sure you want to remove #{email.email}?" }, method: :delete, class: "btn-xs btn btn-remove pull-right", title: 'Remove secondary email', id: "remove_email_#{email.id}" do - %i.fa.fa-times - - %li - %span.light Can create groups: - %strong - = @user.can_create_group ? "Yes" : "No" - %li - %span.light Personal projects limit: - %strong - = @user.projects_limit - %li - %span.light Member since: - %strong - = @user.created_at.stamp("Nov 12, 2031") - - if @user.confirmed_at - %li - %span.light Confirmed at: - %strong - = @user.confirmed_at.stamp("Nov 12, 2031") += render 'admin/users/head', page_name: 'Account' + +.row + .col-md-6 + .panel.panel-default + .panel-heading + = @user.name + %ul.well-list + %li + = image_tag avatar_icon(@user.email, 60), class: "avatar s60" + %li + %span.light Profile page: + %strong + = link_to user_path(@user) do + = @user.username + = render 'users/profile', user: @user + + .panel.panel-default + .panel-heading + Account: + %ul.well-list + %li + %span.light Name: + %strong= @user.name + %li + %span.light Username: + %strong + = @user.username + %li + %span.light Email: + %strong + = mail_to @user.email + - @user.emails.each do |email| + %li + %span.light Secondary email: + %strong= email.email + = link_to remove_email_admin_user_path(@user, email), data: { confirm: "Are you sure you want to remove #{email.email}?" }, method: :delete, class: "btn-xs btn btn-remove pull-right", title: 'Remove secondary email', id: "remove_email_#{email.id}" do + %i.fa.fa-times + + %li + %span.light Can create groups: + %strong + = @user.can_create_group ? "Yes" : "No" + %li + %span.light Personal projects limit: + %strong + = @user.projects_limit + %li + %span.light Member since: + %strong + = @user.created_at.stamp("Nov 12, 2031") + - if @user.confirmed_at + %li + %span.light Confirmed at: + %strong + = @user.confirmed_at.stamp("Nov 12, 2031") + - else + %li + %span.light Confirmed: + %strong.cred + No + + %li + %span.light Current sign-in at: + %strong + - if @user.current_sign_in_at + = @user.current_sign_in_at.stamp("Nov 12, 2031") - else - %li - %span.light Confirmed: - %strong.cred - No - - %li - %span.light Current sign-in at: - %strong - - if @user.current_sign_in_at - = @user.current_sign_in_at.stamp("Nov 12, 2031") - - else - never - - %li - %span.light Last sign-in at: - %strong - - if @user.last_sign_in_at - = @user.last_sign_in_at.stamp("Nov 12, 2031") - - else - never - - %li - %span.light Sign-in count: - %strong - = @user.sign_in_count - - - if @user.ldap_user? - %li - %span.light LDAP uid: - %strong - = @user.ldap_identity.extern_uid - - - if @user.created_by - %li - %span.light Created by: - %strong - = link_to @user.created_by.name, [:admin, @user.created_by] - - .col-md-6 - - unless @user == current_user - - if @user.blocked? - .panel.panel-info - .panel-heading - This user is blocked - .panel-body - %p Blocking user has the following effects: - %ul - %li User will not be able to login - %li User will not be able to access git repositories - %li Personal projects will be left - %li Owned groups will be left - %br - = link_to 'Unblock user', unblock_admin_user_path(@user), method: :put, class: "btn btn-info", data: { confirm: 'Are you sure?' } - - else - .panel.panel-warning - .panel-heading - Block this user - .panel-body - %p Blocking user has the following effects: - %ul - %li User will not be able to login - %li User will not be able to access git repositories - %li User will be removed from joined projects and groups - %li Personal projects will be left - %li Owned groups will be left - %br - = link_to 'Block user', block_admin_user_path(@user), data: { confirm: 'USER WILL BE BLOCKED! Are you sure?' }, method: :put, class: "btn btn-warning" + never - .panel.panel-danger - .panel-heading - Remove user - .panel-body - - if @user.can_be_removed? - %p Deleting a user has the following effects: - %ul - %li All user content like authored issues, snippets, comments will be removed - - rp = @user.personal_projects.count - - unless rp.zero? - %li #{pluralize rp, 'personal project'} will be removed and cannot be restored - %br - = link_to 'Remove user', [:admin, @user], data: { confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?" }, method: :delete, class: "btn btn-remove" - - else - - if @user.solo_owned_groups.present? - %p - This user is currently an owner in these groups: - %strong #{@user.solo_owned_groups.map(&:name).join(', ')} - %p - You must transfer ownership or delete these groups before you can delete this user. - - #profile.tab-pane - .row - .col-md-6 - .panel.panel-default + %li + %span.light Last sign-in at: + %strong + - if @user.last_sign_in_at + = @user.last_sign_in_at.stamp("Nov 12, 2031") + - else + never + + %li + %span.light Sign-in count: + %strong + = @user.sign_in_count + + - if @user.ldap_user? + %li + %span.light LDAP uid: + %strong + = @user.ldap_identity.extern_uid + + - if @user.created_by + %li + %span.light Created by: + %strong + = link_to @user.created_by.name, [:admin, @user.created_by] + + .col-md-6 + - unless @user == current_user + - if @user.blocked? + .panel.panel-info .panel-heading - = @user.name - %ul.well-list - %li - = image_tag avatar_icon(@user.email, 60), class: "avatar s60" - %li - %span.light Profile page: - %strong - = link_to user_path(@user) do - = @user.username - .col-md-6 - = render 'users/profile', user: @user - - #groups.tab-pane - - if @user.group_members.present? - .panel.panel-default - .panel-heading Groups: - %ul.well-list - - @user.group_members.each do |group_member| - - group = group_member.group - %li.group_member - %span{class: ("list-item-name" unless group_member.owner?)} - %strong= link_to group.name, admin_group_path(group) - .pull-right - %span.light= group_member.human_access - - unless group_member.owner? - = link_to group_group_member_path(group, group_member), data: { confirm: remove_user_from_group_message(group, group_member) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do - %i.fa.fa-times.fa-inverse - - else - .nothing-here-block This user has no groups. - - #projects.tab-pane - - if @user.groups.any? - .panel.panel-default - .panel-heading Group projects - %ul.well-list - - @user.groups.each do |group| - %li - %strong= group.name - – access to - #{pluralize(group.projects.count, 'project')} - - .row - .col-md-6 - = render 'users/projects', projects: @personal_projects - - .col-md-6 - .panel.panel-default - .panel-heading Joined projects (#{@joined_projects.count}) - %ul.well-list - - @joined_projects.sort_by(&:name_with_namespace).each do |project| - - member = project.team.find_member(@user.id) - %li.project_member - .list-item-name - = link_to admin_namespace_project_path(project.namespace, project), class: dom_class(project) do - = project.name_with_namespace - - - if member - .pull-right - - if member.owner? - %span.light Owner - - else - %span.light= member.human_access - - - if member.respond_to? :project - = link_to namespace_project_project_member_path(project.namespace, project, member), data: { confirm: remove_from_project_team_message(project, member) }, remote: true, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from project' do - %i.fa.fa-times - #ssh-keys.tab-pane - = render 'profiles/keys/key_table', admin: true + This user is blocked + .panel-body + %p Blocking user has the following effects: + %ul + %li User will not be able to login + %li User will not be able to access git repositories + %li Personal projects will be left + %li Owned groups will be left + %br + = link_to 'Unblock user', unblock_admin_user_path(@user), method: :put, class: "btn btn-info", data: { confirm: 'Are you sure?' } + - else + .panel.panel-warning + .panel-heading + Block this user + .panel-body + %p Blocking user has the following effects: + %ul + %li User will not be able to login + %li User will not be able to access git repositories + %li User will be removed from joined projects and groups + %li Personal projects will be left + %li Owned groups will be left + %br + = link_to 'Block user', block_admin_user_path(@user), data: { confirm: 'USER WILL BE BLOCKED! Are you sure?' }, method: :put, class: "btn btn-warning" + + .panel.panel-danger + .panel-heading + Remove user + .panel-body + - if @user.can_be_removed? + %p Deleting a user has the following effects: + %ul + %li All user content like authored issues, snippets, comments will be removed + - rp = @user.personal_projects.count + - unless rp.zero? + %li #{pluralize rp, 'personal project'} will be removed and cannot be restored + %br + = link_to 'Remove user', [:admin, @user], data: { confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?" }, method: :delete, class: "btn btn-remove" + - else + - if @user.solo_owned_groups.present? + %p + This user is currently an owner in these groups: + %strong #{@user.solo_owned_groups.map(&:name).join(', ')} + %p + You must transfer ownership or delete these groups before you can delete this user. diff --git a/config/routes.rb b/config/routes.rb index 00a95a23edc..33f55dde476 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -152,6 +152,9 @@ Gitlab::Application.routes.draw do resources :identities, only: [:index, :edit, :update, :destroy] member do + get :projects + get :keys + get :groups put :team_update put :block put :unblock -- cgit v1.2.1 From 3fe3cbf222a036d4487b9630e2abfc58ec7515cf Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 17:52:22 +0200 Subject: Fix indendity test Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/users/_head.html.haml | 2 +- features/admin/users.feature | 1 + features/steps/admin/users.rb | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/views/admin/users/_head.html.haml b/app/views/admin/users/_head.html.haml index c1ec1d48e17..9d5e934c8ba 100644 --- a/app/views/admin/users/_head.html.haml +++ b/app/views/admin/users/_head.html.haml @@ -9,7 +9,7 @@ = link_to edit_admin_user_path(@user), class: "btn btn-grouped" do %i.fa.fa-pencil-square-o Edit - +%hr %ul.nav.nav-tabs = nav_link(path: 'users#show') do = link_to "Account", admin_user_path(@user) diff --git a/features/admin/users.feature b/features/admin/users.feature index f17254911b7..6755645778a 100644 --- a/features/admin/users.feature +++ b/features/admin/users.feature @@ -40,6 +40,7 @@ Feature: Admin Users Given user "Pete" with ssh keys And I visit admin users page And click on user "Pete" + And click on ssh keys tab Then I should see key list And I click on the key title Then I should see key details diff --git a/features/steps/admin/users.rb b/features/steps/admin/users.rb index a9bb314b24f..149603391b3 100644 --- a/features/steps/admin/users.rb +++ b/features/steps/admin/users.rb @@ -121,23 +121,27 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps end step 'I visit "Pete" identities page in admin' do + Gitlab::OAuth::Provider.stub!(names: %w(twitter twitter_updated)) visit admin_user_identities_path(@user) end step 'I should see twitter details' do - expect(page).to have_content 'Identities for Pete' + expect(page).to have_content 'Pete' expect(page).to have_content 'twitter' end step 'I modify twitter identity' do - click_link 'Edit' + within '.table' do + click_link 'Edit' + end + fill_in 'identity_extern_uid', with: '654321' - fill_in 'identity_provider', with: 'twitter_updated' + select 'twitter_updated', from: 'identity_provider' click_button 'Save changes' end step 'I should see twitter details updated' do - expect(page).to have_content 'Identities for Pete' + expect(page).to have_content 'Pete' expect(page).to have_content 'twitter_updated' expect(page).to have_content '654321' end @@ -147,7 +151,11 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps end step 'I should not see twitter details' do - expect(page).to have_content 'Identities for Pete' + expect(page).to have_content 'Pete' expect(page).to_not have_content 'twitter' end + + step 'click on ssh keys tab' do + click_link 'SSH keys' + end end -- cgit v1.2.1 From d7553d3630d0a60c1b8a100f7c5fbe3ba5745803 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 18:01:52 +0200 Subject: Address review comments Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/identities_controller.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 17ace5a258b..174043f3327 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -18,12 +18,10 @@ class Admin::IdentitiesController < Admin::ApplicationController end def destroy - respond_to do |format| - if @identity.destroy - format.html { redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully removed.' } - else - format.html { redirect_to admin_user_identities_path(@user), alert: 'Failed to remove user identity.' } - end + if @identity.destroy + redirect_to admin_user_identities_path(@user), notice: 'User identity was successfully removed.' + else + redirect_to admin_user_identities_path(@user), alert: 'Failed to remove user identity.' end end @@ -38,6 +36,6 @@ class Admin::IdentitiesController < Admin::ApplicationController end def identity_params - params[:identity].permit(:provider, :extern_uid) + params[:identity].require(:identity).permit(:provider, :extern_uid) end end -- cgit v1.2.1 From 7390b94db2e9273141cebfb99cfdbb03ad2d2f33 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Jun 2015 18:02:50 +0200 Subject: Fix code style issue Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/identities/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/identities/_form.html.haml b/app/views/admin/identities/_form.html.haml index f0f3c3ff221..b405aa6e8e3 100644 --- a/app/views/admin/identities/_form.html.haml +++ b/app/views/admin/identities/_form.html.haml @@ -1,5 +1,5 @@ = form_for [:admin, @user, @identity], html: { class: 'form-horizontal fieldset-form' } do |f| - -if @identity.errors.any? + - if @identity.errors.any? #error_explanation .alert.alert-danger - @identity.errors.full_messages.each do |msg| -- cgit v1.2.1 From 1beb0dbe56438ae513565b1bdc0db7c1d692a156 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 23 Jun 2015 10:26:50 +0200 Subject: Fix admin identities code Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/identities_controller.rb | 2 +- app/views/admin/users/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 174043f3327..d28614731f9 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -36,6 +36,6 @@ class Admin::IdentitiesController < Admin::ApplicationController end def identity_params - params[:identity].require(:identity).permit(:provider, :extern_uid) + params.require(:identity).permit(:provider, :extern_uid) end end diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 0b8260964fe..2662b3569ec 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -1,5 +1,5 @@ - page_title @user.name, "Users" -= render 'admin/users/head', page_name: 'Account' += render 'admin/users/head' .row .col-md-6 -- cgit v1.2.1 From 7780a886e7c90b2fbe281d3b8452151c20659543 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 23 Jun 2015 10:56:12 +0200 Subject: Set proper title when edit identity from admin area Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/identities/edit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/identities/edit.html.haml b/app/views/admin/identities/edit.html.haml index d49d79ce5c9..515d46b0f29 100644 --- a/app/views/admin/identities/edit.html.haml +++ b/app/views/admin/identities/edit.html.haml @@ -1,4 +1,4 @@ -- page_title @user.name, "Users" +- page_title "Edit", @identity.provider, "Identities", @user.name, "Users" %h3.page-title Edit identity for #{@user.name} %hr -- cgit v1.2.1 From 4acd1f5d6a1942d4348b5d94e278fdb25c29e532 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 23 Jun 2015 15:49:15 +0200 Subject: Fix tests for admin identities after migrate to rspec3 --- features/steps/admin/users.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/features/steps/admin/users.rb b/features/steps/admin/users.rb index 149603391b3..6c4b91586d6 100644 --- a/features/steps/admin/users.rb +++ b/features/steps/admin/users.rb @@ -121,7 +121,7 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps end step 'I visit "Pete" identities page in admin' do - Gitlab::OAuth::Provider.stub!(names: %w(twitter twitter_updated)) + allow(Gitlab::OAuth::Provider).to receive(:names).and_return(%w(twitter twitter_updated)) visit admin_user_identities_path(@user) end @@ -131,10 +131,7 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps end step 'I modify twitter identity' do - within '.table' do - click_link 'Edit' - end - + find('.table').find(:link, 'Edit').click fill_in 'identity_extern_uid', with: '654321' select 'twitter_updated', from: 'identity_provider' click_button 'Save changes' -- cgit v1.2.1