diff options
-rw-r--r-- | app/helpers/user_helper.rb | 11 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/users/show.html.haml | 18 | ||||
-rw-r--r-- | features/abuse_report.feature | 7 | ||||
-rw-r--r-- | features/steps/abuse_reports.rb | 5 | ||||
-rw-r--r-- | spec/features/users_spec.rb | 38 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 1 |
7 files changed, 73 insertions, 9 deletions
diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 00000000000..058cff85135 --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,11 @@ +module UserHelper + + def abuse_report_button_title(user) + if user.abuse_report + "#{user.username} has already been reported for abuse." + else + "Report #{user.username} for abuse." + end + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 3879f3fd381..a3b149ff992 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -97,7 +97,9 @@ class User < ActiveRecord::Base # Namespace for personal projects has_one :namespace, -> { where type: nil }, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace" + # Profile + has_one :abuse_report, dependent: :destroy has_many :keys, dependent: :destroy has_many :emails, dependent: :destroy has_many :identities, dependent: :destroy, autosave: true diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 37d5dba0330..0661d8d06a2 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -19,14 +19,18 @@ = icon('user') Profile settings - elsif current_user - .pull-right + #report_abuse.pull-right %span.dropdown - %a.light.dropdown-toggle.btn.btn-sm{href: '#', "data-toggle" => "dropdown"} - = icon('exclamation-circle') - %ul.dropdown-menu.dropdown-menu-right - %li - = link_to new_abuse_report_path(user_id: @user.id) do - Report abuse + - if @user.abuse_report + %span.light.dropdown-toggle.btn.btn-sm.btn-close{title: abuse_report_button_title(@user)} + = icon('exclamation-circle') + - else + %a.light.dropdown-toggle.btn.btn-sm{href: '#', "data-toggle" => "dropdown"} + = icon('exclamation-circle') + %ul.dropdown-menu.dropdown-menu-right + %li + = link_to new_abuse_report_path(user_id: @user.id), title: abuse_report_button_title(@user) do + Report abuse .username @#{@user.username} diff --git a/features/abuse_report.feature b/features/abuse_report.feature index 3e1cb455b77..fc80f0aa399 100644 --- a/features/abuse_report.feature +++ b/features/abuse_report.feature @@ -8,3 +8,10 @@ Feature: Abuse reports And I click "Report abuse" button When I fill and submit abuse form Then I should see success message + + Scenario: Report abuse available only once + Given I visit "Mike" user page + And I click "Report abuse" button + When I fill and submit abuse form + And I visit "Mike" user page + Then I should not see the "Remove abuse" dropdown / button diff --git a/features/steps/abuse_reports.rb b/features/steps/abuse_reports.rb index 8f9ddb2899f..623807dac82 100644 --- a/features/steps/abuse_reports.rb +++ b/features/steps/abuse_reports.rb @@ -22,6 +22,11 @@ class Spinach::Features::AbuseReports < Spinach::FeatureSteps user_mike end + step 'I should not see the "Remove abuse" dropdown / button' do + expect(find(:css, '#report_abuse')).not_to have_selector(:css, 'ul.dropdown-menu') + expect(find(:css, '#report_abuse')).to have_selector(:css, '.btn-close') + end + def user_mike @user_mike ||= create(:user, name: 'Mike') end diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index efcb8a31abe..633616241f1 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' feature 'Users', feature: true do + let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') } + let(:user2) { create(:user, username: 'user2', name: 'User 2', email: 'user2@gitlab.com') } + scenario 'GET /users/sign_in creates a new user account' do visit new_user_session_path fill_in 'user_name', with: 'Name Surname' @@ -11,7 +14,6 @@ feature 'Users', feature: true do end scenario 'Successful user signin invalidates password reset token' do - user = create(:user) expect(user.reset_password_token).to be_nil visit new_user_password_path @@ -28,7 +30,6 @@ feature 'Users', feature: true do expect(user.reset_password_token).to be_nil end - let!(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') } scenario 'Should show one error if email is already taken' do visit new_user_session_path fill_in 'user_name', with: 'Another user name' @@ -48,4 +49,37 @@ feature 'Users', feature: true do page.find('#error_explanation').find('ul').all('li').count end + context 'With a logged-in user' do + before do + login_as(user) + end + + describe 'Abuse report button' do + context 'User has never been reported for abuse' do + it 'enables the "Report abuse" button / dropdown' do + visit user_path(user2) + + expect(page.find('#report_abuse').find('ul.dropdown-menu').all('li').count).to be(1) + expect(page.find('#report_abuse').all('.btn-close').count).to be(0) + end + end + + context 'User has already been reported for abuse' do + before do + @abuse_report = AbuseReport.new(user: user2, message: 'Foo bar') + @abuse_report.reporter = user + @abuse_report.save! + end + + it 'disables the "Report abuse" button' do + visit user_path(user2) + + expect(page.find('#report_abuse').all('ul.dropdown-menu').count).to be(0) + expect(page.find('#report_abuse').all('.btn-close').count).to be(1) + end + end + end + + end + end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 480950859a2..6342c3b8d13 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -73,6 +73,7 @@ describe User do describe 'associations' do it { is_expected.to have_one(:namespace) } + it { is_expected.to have_one(:abuse_report) } it { is_expected.to have_many(:snippets).class_name('Snippet').dependent(:destroy) } it { is_expected.to have_many(:project_members).dependent(:destroy) } it { is_expected.to have_many(:groups) } |