Commit 5f95a5e0 authored by Rémy Coutable's avatar Rémy Coutable Committed by rymai

Disable the "Report abuse" button if a user has already been reported

parent 10c036fc
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
......@@ -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
......
......@@ -19,13 +19,17 @@
= icon('user')
Profile settings
- elsif current_user
.pull-right
#report_abuse.pull-right
%span.dropdown
- 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) do
= link_to new_abuse_report_path(user_id: @user.id), title: abuse_report_button_title(@user) do
Report abuse
.username
......
......@@ -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
......@@ -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
......
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
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment