diff --git a/app/assets/javascripts/app/people/activity.html.erb b/app/assets/javascripts/app/people/activity.html.erb
index 9c5276bc2..65715a571 100644
--- a/app/assets/javascripts/app/people/activity.html.erb
+++ b/app/assets/javascripts/app/people/activity.html.erb
@@ -73,6 +73,36 @@
+
+ {{report_user_form.error}}
+
+
+
+
+
+
+
+
+
diff --git a/app/assets/javascripts/app/people/activity.js b/app/assets/javascripts/app/people/activity.js
index 502f111b0..8c52f9c72 100644
--- a/app/assets/javascripts/app/people/activity.js
+++ b/app/assets/javascripts/app/people/activity.js
@@ -3,6 +3,9 @@ angular.module('app').controller('PeopleShow', function ($scope, $routeParams, $
$location.url("/teams/bountysource").replace();
}
+ // shortcut
+ var person_id = $routeParams.id;
+
$api.person_get($routeParams.id).then(function(person) {
$pageTitle.set(person.display_name, 'Profile');
@@ -12,10 +15,68 @@ angular.module('app').controller('PeopleShow', function ($scope, $routeParams, $
return person;
});
- $scope.events = Timeline.query({ per_page: 30, person_id: $routeParams.id });
+ $scope.events = Timeline.query({ per_page: 30, person_id: person_id });
$api.person_teams($routeParams.id).then(function(teams) {
$scope.teams = teams;
return teams;
});
+
+ var report_user_form = $scope.report_user_form = {
+
+ state: "hidden",
+
+ // where all the form data is stored
+ data: {},
+
+ // report reasons
+ reasons: ['spam', 'abuse', 'fraud', 'other'],
+
+ // if not logged in, send to login, else show form
+ show: function() {
+ if ($scope.current_person) {
+ report_user_form.previous_data = angular.copy(report_user_form.data);
+ report_user_form.state = "shown";
+ } else {
+ $api.set_post_auth_url($location.url());
+ $location.url("/signin");
+ }
+ },
+
+ // disappear the form
+ hide: function() {
+ report_user_form.state = "hidden";
+ },
+
+ // disappear the form and restore previous data
+ cancel: function() {
+ report_user_form.data = report_user_form.previous_data;
+ report_user_form.error = null;
+ report_user_form.hide();
+ },
+
+ // submit report
+ submit: function() {
+ report_user_form.error = null;
+ var data = { person_id: person_id, reason: report_user_form.data.report_reason, note: report_user_form.data.note};
+ $api.person_report(person_id, data).then(report_user_form.report_callback);
+ },
+
+ report_callback: function(response) {
+ if (response && response.error) {
+ report_user_form.error = response.error;
+ } else {
+ report_user_form.state = "submitted";
+ }
+ },
+
+ };
+
+ $scope.selectReportReason = function(reason){
+ $scope.report_user_form.data.report_reason = reason;
+ };
+
+ $scope.report_user_form.data = {};
+ $scope.report_user_form.data.report_reason = report_user_form.reasons[0];
+
});
diff --git a/app/assets/javascripts/common/services/api.js.erb b/app/assets/javascripts/common/services/api.js.erb
index ab953c567..8db8acd07 100644
--- a/app/assets/javascripts/common/services/api.js.erb
+++ b/app/assets/javascripts/common/services/api.js.erb
@@ -856,6 +856,10 @@ angular.module('services').config(function($httpProvider) {
return this.call("/people/"+person_id+"/teams");
};
+ this.person_report = function(person_id, data) {
+ return this.call("/people/"+person_id+"/report", "POST", {report: data} );
+ };
+
this.followed_trackers = function() {
return this.call('/trackers/followed');
};
diff --git a/app/controllers/api/v1/people_controller.rb b/app/controllers/api/v1/people_controller.rb
index 8521eba4b..4c97f1778 100644
--- a/app/controllers/api/v1/people_controller.rb
+++ b/app/controllers/api/v1/people_controller.rb
@@ -1,5 +1,5 @@
class Api::V1::PeopleController < ApplicationController
- before_action :require_auth, except: [:recent, :profile, :activity, :login, :create, :reset_password, :request_password_reset, :interesting, :count, :teams, :email_registered]
+ before_action :require_auth, except: [:recent, :profile, :activity, :login, :create, :reset_password, :request_password_reset, :interesting, :count, :teams, :email_registered, :report]
before_action :require_profile, only: [:profile, :activity, :teams]
# show all of the authenticated user's info
@@ -339,6 +339,14 @@ def set_languages
head :ok
end
+ # report account
+ def report
+ report = Hash.new
+ params[:report].each { |k, v| report[k.to_sym] = v }
+ @person.send_email(:report_account, report: report)
+ head :ok
+ end
+
protected
def person_params
diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb
index a209f639f..7634d01af 100644
--- a/app/mailers/mailer.rb
+++ b/app/mailers/mailer.rb
@@ -738,4 +738,14 @@ def cash_out_payment_sent(options)
mail(to: @person.email, subject: 'Your cash out has been processed')
end
+ def report_account(options)
+ @person = options[:person]
+ @report = options[:report]
+
+ mail(to: self.default_params[:from], cc: @person.email, subject: "Account activity report") do |format|
+ format.text
+ format.html
+ end
+ end
+
end
diff --git a/app/views/mailer/report_account.html.erb b/app/views/mailer/report_account.html.erb
new file mode 100644
index 000000000..fbcf8bd52
--- /dev/null
+++ b/app/views/mailer/report_account.html.erb
@@ -0,0 +1,15 @@
+