summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-10-01 13:17:18 +0000
committerDouwe Maan <douwe@gitlab.com>2015-10-01 13:17:18 +0000
commit96c2e22549917a32bae03c3c1e850a3225049239 (patch)
tree869c8d9fb86beb3306a9cad7fa1fdc0345dd934c
parent114853063b3a1747acfe96fa8c8159f4779e291c (diff)
parentea72d53ec083676ee1171e97c0869132f360d0c9 (diff)
downloadgitlab-ce-96c2e22549917a32bae03c3c1e850a3225049239.tar.gz
Merge branch 'disable-report-button-if-already-reported' into 'master'
Disable the "Report abuse" button if a user has already been reported Hello, I've implemented the feature request #2330. Here is what it looks like: ![report-abuse-button-disabled](https://gitlab.com/rymai/gitlab-ce/uploads/420d51906eac1c40c50701a0a340474f/report-abuse-button-disabled.png) I hope that's an acceptable solution. cc @DouweM See merge request !1456
-rw-r--r--app/models/abuse_report.rb4
-rw-r--r--app/models/user.rb1
-rw-r--r--app/views/users/show.html.haml13
-rw-r--r--features/abuse_report.feature7
-rw-r--r--features/steps/abuse_reports.rb4
-rw-r--r--spec/features/users_spec.rb4
-rw-r--r--spec/models/abuse_report_spec.rb12
-rw-r--r--spec/models/user_spec.rb1
8 files changed, 35 insertions, 11 deletions
diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb
index 07c87a7fe87..89b3116b9f2 100644
--- a/app/models/abuse_report.rb
+++ b/app/models/abuse_report.rb
@@ -11,11 +11,11 @@
#
class AbuseReport < ActiveRecord::Base
- belongs_to :reporter, class_name: "User"
+ belongs_to :reporter, class_name: 'User'
belongs_to :user
validates :reporter, presence: true
validates :user, presence: true
validates :message, presence: true
- validates :user_id, uniqueness: { scope: :reporter_id }
+ validates :user_id, uniqueness: true
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 3879f3fd381..9ea7cabff15 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -129,6 +129,7 @@ class User < ActiveRecord::Base
has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue"
has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest"
has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: :destroy
+ has_one :abuse_report, dependent: :destroy
#
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index 37d5dba0330..11beb3e3239 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -19,14 +19,13 @@
= icon('user')
Profile settings
- elsif current_user
- .pull-right
- %span.dropdown
- %a.light.dropdown-toggle.btn.btn-sm{href: '#', "data-toggle" => "dropdown"}
+ .report_abuse.pull-right
+ - if @user.abuse_report
+ %span#report_abuse_btn.light.btn.btn-sm.btn-close{title: 'Already reported for abuse', data: {toggle: 'tooltip', placement: 'right', container: 'body'}}
+ = icon('exclamation-circle')
+ - else
+ %a.light.btn.btn-sm{href: new_abuse_report_path(user_id: @user.id), title: 'Report abuse', data: {toggle: 'tooltip', placement: 'right', container: 'body'}}
= icon('exclamation-circle')
- %ul.dropdown-menu.dropdown-menu-right
- %li
- = link_to new_abuse_report_path(user_id: @user.id) do
- Report abuse
.username
@#{@user.username}
diff --git a/features/abuse_report.feature b/features/abuse_report.feature
index 3e1cb455b77..212972a762a 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 see a red "Report abuse" button
diff --git a/features/steps/abuse_reports.rb b/features/steps/abuse_reports.rb
index 8f9ddb2899f..56652ff6f05 100644
--- a/features/steps/abuse_reports.rb
+++ b/features/steps/abuse_reports.rb
@@ -22,6 +22,10 @@ class Spinach::Features::AbuseReports < Spinach::FeatureSteps
user_mike
end
+ step 'I should see a red "Report abuse" button' do
+ expect(find(:css, '.report_abuse')).to have_selector(:css, 'span.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..c1248162031 100644
--- a/spec/features/users_spec.rb
+++ b/spec/features/users_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
feature 'Users', feature: true do
+ let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@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 +13,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 +29,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'
diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb
index 635a6e2518c..d45319b25d4 100644
--- a/spec/models/abuse_report_spec.rb
+++ b/spec/models/abuse_report_spec.rb
@@ -16,4 +16,16 @@ RSpec.describe AbuseReport, type: :model do
subject { create(:abuse_report) }
it { expect(subject).to be_valid }
+
+ describe 'associations' do
+ it { is_expected.to belong_to(:reporter).class_name('User') }
+ it { is_expected.to belong_to(:user) }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of(:reporter) }
+ it { is_expected.to validate_presence_of(:user) }
+ it { is_expected.to validate_presence_of(:message) }
+ it { is_expected.to validate_uniqueness_of(:user_id) }
+ end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 480950859a2..b7b525bfca2 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -85,6 +85,7 @@ describe User do
it { is_expected.to have_many(:merge_requests).dependent(:destroy) }
it { is_expected.to have_many(:assigned_merge_requests).dependent(:destroy) }
it { is_expected.to have_many(:identities).dependent(:destroy) }
+ it { is_expected.to have_one(:abuse_report) }
end
describe 'validations' do