Commit cba7f20d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Allow users to send abuse reports

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ce47dd4b
...@@ -34,6 +34,7 @@ v 7.14.0 (unreleased) ...@@ -34,6 +34,7 @@ v 7.14.0 (unreleased)
- Add support for CI skipped status - Add support for CI skipped status
- Fetch code from forks to refs/merge-requests/:id/head when merge request created - Fetch code from forks to refs/merge-requests/:id/head when merge request created
- Remove satellites - Remove satellites
- Allow users to send abuse reports
v 7.13.2 v 7.13.2
- Fix randomly failed spec - Fix randomly failed spec
......
class AbuseReportsController < ApplicationController
def new
@abuse_report = AbuseReport.new
@abuse_report.user_id = params[:user_id]
end
def create
@abuse_report = AbuseReport.new(report_params)
@abuse_report.reporter = current_user
if @abuse_report.save
redirect_to root_path, notice: 'Thank you for report. GitLab administrator will be able to see it'
else
render :new
end
end
private
def report_params
params.require(:abuse_report).permit(:user_id, :message)
end
end
class AbuseReport < ActiveRecord::Base
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 }
end
- page_title "Report abuse"
%h3.page-title Report abuse
%p Please use this form if user makes spam or inappropriate content
%hr
= form_for @abuse_report, html: { class: 'form-horizontal'} do |f|
= f.hidden_field :user_id
- if @abuse_report.errors.any?
.alert.alert-danger
- @abuse_report.errors.full_messages.each do |msg|
%p= msg
.form-group
= f.label :user_id, class: 'control-label'
.col-sm-10
= users_select_tag("abuse_reports[user_id]", placeholder: 'Select user to report abuse',
class: 'custom-form-control js-select2', selected: @abuse_report.user_id, scope: :all)
.form-group
= f.label :message, class: 'control-label'
.col-sm-10
= f.text_area :message, class: "form-control", rows: 2, required: true
.help-block
Explain the problem with this account.
%br
If user sends spam please provide a link to spam issue or comment
.form-actions
= f.submit "Send report", class: "btn btn-create"
:coffeescript
new UsersSelect()
...@@ -18,6 +18,16 @@ ...@@ -18,6 +18,16 @@
= link_to profile_path, class: 'btn btn-sm' do = link_to profile_path, class: 'btn btn-sm' do
%i.fa.fa-pencil-square-o %i.fa.fa-pencil-square-o
Edit Profile settings Edit Profile settings
- elsif current_user
.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
.username .username
@#{@user.username} @#{@user.username}
.description .description
......
...@@ -65,6 +65,9 @@ Gitlab::Application.routes.draw do ...@@ -65,6 +65,9 @@ Gitlab::Application.routes.draw do
end end
end end
# Spam reports
resources :abuse_reports, only: [:new, :create]
# #
# Import # Import
# #
......
class CreateAbuseReports < ActiveRecord::Migration
def change
create_table :abuse_reports do |t|
t.integer :reporter_id
t.integer :user_id
t.text :message
t.timestamps
end
end
end
...@@ -11,11 +11,19 @@ ...@@ -11,11 +11,19 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150717130904) do ActiveRecord::Schema.define(version: 20150806104937) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "abuse_reports", force: true do |t|
t.integer "reporter_id"
t.integer "user_id"
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "application_settings", force: true do |t| create_table "application_settings", force: true do |t|
t.integer "default_projects_limit" t.integer "default_projects_limit"
t.boolean "signup_enabled" t.boolean "signup_enabled"
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :abuse_report do
reporter factory: :user
user
message 'User sends spam'
end
end
require 'rails_helper'
RSpec.describe AbuseReport, type: :model do
subject { create(:abuse_report) }
it { expect(subject).to be_valid }
end
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