diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-28 16:10:28 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-28 16:10:28 +0200 |
commit | ad3462332b60a7974a0e1d3cb778b3fecf733415 (patch) | |
tree | becd653df889904ab6679522aa0421e3cc989b1a | |
parent | 0c7da9d534ae91a37cbea4ba80e21d77aa3b973c (diff) | |
parent | 05a44dcb8b70663e376acfb2b5874bae454bfecf (diff) | |
download | gitlab-ce-ad3462332b60a7974a0e1d3cb778b3fecf733415.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/controllers/admin/users_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/registrations_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/blob_helper.rb | 10 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/services/delete_user_service.rb | 10 | ||||
-rw-r--r-- | app/views/admin/users/index.html.haml | 9 | ||||
-rw-r--r-- | app/views/admin/users/show.html.haml | 24 | ||||
-rw-r--r-- | app/views/profiles/accounts/show.html.haml | 26 | ||||
-rw-r--r-- | app/views/projects/blame/show.html.haml | 2 | ||||
-rw-r--r-- | lib/api/users.rb | 2 | ||||
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 18 |
15 files changed, 112 insertions, 42 deletions
diff --git a/CHANGELOG b/CHANGELOG index 1cdb669d5b7..8fbf85df338 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ v 7.12.0 (unreleased) - Disable "New Issue" and "New Merge Request" buttons when features are disabled in project settings (Stan Hu) - Remove Rack Attack monkey patches and bump to version 4.3.0 (Stan Hu) - Fix clone URL losing selection after a single click in Safari and Chrome (Stan Hu) + - Fix git blame syntax highlighting when different commits break up lines (Stan Hu) - Allow to configure location of the `.gitlab_shell_secret` file. (Jakub Jirutka) - Disabled expansion of top/bottom blobs for new file diffs - Update Asciidoctor gem to version 1.5.2. (Jakub Jirutka) @@ -27,6 +28,7 @@ v 7.12.0 (unreleased) - Group project contributions by both name and email. - Clarify navigation labels for Project Settings and Group Settings. - Move user avatar and logout button to sidebar + - You can not remove user if he/she is an only owner of group v 7.11.4 - Fix missing bullets when creating lists @@ -277,4 +277,4 @@ end gem "newrelic_rpm" gem 'octokit', '3.7.0' -gem "rugments" +gem "rugments", "~> 1.0.0.beta7" diff --git a/Gemfile.lock b/Gemfile.lock index 80e4a44c1da..7dbc3b4ffa9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -531,7 +531,7 @@ GEM rubyntlm (0.5.0) rubypants (0.2.0) rugged (0.22.2) - rugments (1.0.0.beta6) + rugments (1.0.0.beta7) safe_yaml (0.9.7) sanitize (2.1.0) nokogiri (>= 1.4.4) @@ -781,7 +781,7 @@ DEPENDENCIES rqrcode-rails3 rspec-rails (= 2.99) rubocop (= 0.28.0) - rugments + rugments (~> 1.0.0.beta7) sanitize (~> 2.0) sass-rails (~> 4.0.2) sdoc diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index d36e359934c..06d6d61e907 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -86,11 +86,7 @@ class Admin::UsersController < Admin::ApplicationController end def destroy - # 1. Remove groups where user is the only owner - user.solo_owned_groups.map(&:destroy) - - # 2. Remove user with all authored content including personal projects - user.destroy + DeleteUserService.new.execute(user) respond_to do |format| format.html { redirect_to admin_users_path } diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 830751a989f..6ccc7934f2f 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -6,7 +6,7 @@ class RegistrationsController < Devise::RegistrationsController end def destroy - current_user.destroy + DeleteUserService.new.execute(current_user) respond_to do |format| format.html { redirect_to new_user_session_path, notice: "Account successfully removed." } diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 9fe5f82f02f..50df3801703 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,6 +1,6 @@ module BlobHelper - def highlight(blob_name, blob_content, nowrap = false) - formatter = Rugments::Formatters::HTML.new( + def highlight(blob_name, blob_content, nowrap: false, continue: false) + @formatter ||= Rugments::Formatters::HTML.new( nowrap: nowrap, cssclass: 'code highlight', lineanchors: true, @@ -8,11 +8,11 @@ module BlobHelper ) begin - lexer = Rugments::Lexer.guess(filename: blob_name, source: blob_content) - result = formatter.format(lexer.lex(blob_content)).html_safe + @lexer ||= Rugments::Lexer.guess(filename: blob_name, source: blob_content).new + result = @formatter.format(@lexer.lex(blob_content, continue: continue)).html_safe rescue lexer = Rugments::Lexers::PlainText - result = formatter.format(lexer.lex(blob_content)).html_safe + result = @formatter.format(lexer.lex(blob_content)).html_safe end result diff --git a/app/models/user.rb b/app/models/user.rb index 50ca4bc5acc..c1bb51e86fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -689,4 +689,8 @@ class User < ActiveRecord::Base true end + + def can_be_removed? + !solo_owned_groups.present? + end end diff --git a/app/services/delete_user_service.rb b/app/services/delete_user_service.rb new file mode 100644 index 00000000000..d259b4efca6 --- /dev/null +++ b/app/services/delete_user_service.rb @@ -0,0 +1,10 @@ +class DeleteUserService + def execute(user) + if user.solo_owned_groups.present? + user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user' + user + else + user.destroy + end + end +end diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index fe648470233..45dee86b017 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -79,11 +79,12 @@ %i.fa.fa-envelope = mail_to user.email, user.email, class: 'light' - = link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-sm" + = link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-xs" - unless user == current_user - if user.blocked? - = link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-sm success" + = link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-xs btn-success" - else - = link_to 'Block', block_admin_user_path(user), data: {confirm: 'USER WILL BE BLOCKED! Are you sure?'}, method: :put, class: "btn btn-sm btn-remove" - = link_to 'Destroy', [:admin, user], data: { confirm: "USER #{user.name} WILL BE REMOVED! All tickets linked to this user will also be removed! Maybe block the user instead? Are you sure?" }, method: :delete, class: "btn btn-sm btn-remove" + = link_to 'Block', block_admin_user_path(user), data: {confirm: 'USER WILL BE BLOCKED! Are you sure?'}, method: :put, class: "btn btn-xs btn-warning" + - if user.can_be_removed? + = link_to 'Destroy', [:admin, user], data: { confirm: "USER #{user.name} WILL BE REMOVED! All tickets linked to this user will also be removed! Maybe block the user instead? Are you sure?" }, method: :delete, class: "btn btn-xs btn-remove" = paginate @users, theme: "gitlab" diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 7fc85206109..f7195ac3326 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -140,18 +140,22 @@ .panel-heading Remove user .panel-body - %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 + - 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? - %li - Next groups with all content will be removed: + %p + This user is currently an owner in these groups: %strong #{@user.solo_owned_groups.map(&:name).join(', ')} - %br - = link_to 'Remove user', [:admin, @user], data: { confirm: "USER #{@user.name} WILL BE REMOVED! Are you sure?" }, method: :delete, class: "btn btn-remove" + %p + You must transfer ownership or delete these groups before you can delete this user. #profile.tab-pane .row diff --git a/app/views/profiles/accounts/show.html.haml b/app/views/profiles/accounts/show.html.haml index 06bad7dd84a..4d1d50dcbab 100644 --- a/app/views/profiles/accounts/show.html.haml +++ b/app/views/profiles/accounts/show.html.haml @@ -91,15 +91,19 @@ %legend Remove account %div - %p Deleting an account has the following effects: - %ul - %li All user content like authored issues, snippets, comments will be removed - - rp = current_user.personal_projects.count - - unless rp.zero? - %li #{pluralize rp, 'personal project'} will be removed and cannot be restored - - if current_user.solo_owned_groups.present? - %li - The following groups will be abandoned. You should transfer or remove them: - %strong #{current_user.solo_owned_groups.map(&:name).join(', ')} - = link_to 'Delete account', user_registration_path, data: { confirm: "REMOVE #{current_user.name}? Are you sure?" }, method: :delete, class: "btn btn-remove" + - if @user.can_be_removed? + %p Deleting an account has the following effects: + %ul + %li All user content like authored issues, snippets, comments will be removed + - rp = current_user.personal_projects.count + - unless rp.zero? + %li #{pluralize rp, 'personal project'} will be removed and cannot be restored + = link_to 'Delete account', user_registration_path, data: { confirm: "REMOVE #{current_user.name}? Are you sure?" }, method: :delete, class: "btn btn-remove" + - else + - if @user.solo_owned_groups.present? + %p + Your account 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 yur account. diff --git a/app/views/projects/blame/show.html.haml b/app/views/projects/blame/show.html.haml index 462f5b7afb0..8019c7f4569 100644 --- a/app/views/projects/blame/show.html.haml +++ b/app/views/projects/blame/show.html.haml @@ -32,5 +32,5 @@ %code :erb <% lines.each do |line| %> - <%= highlight(@blob.name, line, true).html_safe %> + <%= highlight(@blob.name, line, nowrap: true, continue: true).html_safe %> <% end %> diff --git a/lib/api/users.rb b/lib/api/users.rb index 032a5d76e43..7d4c68c7412 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -194,7 +194,7 @@ module API user = User.find_by(id: params[:id]) if user - user.destroy + DeleteUserService.new.execute(user) else not_found!('User') end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb new file mode 100644 index 00000000000..e49e4e6d5d8 --- /dev/null +++ b/spec/helpers/blob_helper_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe BlobHelper do + describe 'highlight' do + let(:blob_name) { 'test.lisp' } + let(:no_context_content) { ":type \"assem\"))" } + let(:blob_content) { "(make-pathname :defaults name\n#{no_context_content}" } + let(:split_content) { blob_content.split("\n") } + + it 'should return plaintext for unknown lexer context' do + result = highlight(blob_name, no_context_content, nowrap: true, continue: false) + expect(result).to eq('<span id="LC1" class="line">:type "assem"))</span>') + end + + it 'should highlight single block' do + expected = %Q[<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span> +<span id="LC2" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>] + + expect(highlight(blob_name, blob_content, nowrap: true, continue: false)).to eq(expected) + end + + it 'should highlight continued blocks' do + # Both lines have LC1 as ID since formatter doesn't support continue at the moment + expected = [ + '<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>', + '<span id="LC1" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>' + ] + + result = split_content.map{ |content| highlight(blob_name, content, nowrap: true, continue: true) } + expect(result).to eq(expected) + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e1205c18a85..49c7b7d99ce 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -572,7 +572,6 @@ describe User do end describe "#contributed_projects_ids" do - subject { create(:user) } let!(:project1) { create(:project) } let!(:project2) { create(:project, forked_from_project: project3) } @@ -598,4 +597,21 @@ describe User do expect(subject.contributed_projects_ids).not_to include(project2.id) end end + + describe :can_be_removed? do + subject { create(:user) } + + context 'no owned groups' do + it { expect(subject.can_be_removed?).to be_truthy } + end + + context 'has owned groups' do + before do + group = create(:group) + group.add_owner(subject) + end + + it { expect(subject.can_be_removed?).to be_falsey } + end + end end |