Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/assets/javascripts/app/people/activity.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,36 @@
<div ng-show="current_person.id == person.id" class="text-center">
<a href="/settings" class="btn btn-default btn-long border-gunmetal">Edit Your Profile</a>
</div>

<div ng-show="current_person.id != person.id" class="text-center" ng-switch="report_user_form.state">
<div class="alert alert-danger" ng-if="report_user_form.error">
{{report_user_form.error}}
</div>
<div ng-switch-when="hidden">
<button ng-click="report_user_form.show()" class="mt-3 btn btn-long btn-danger">Report This Account</button>
</div>
<form ng-switch-when="shown" class="form-horizontal ng-pristine ng-valid" ng-submit="report_user_form.submit()">
<label class="col-xs-12 control-label">Reason</label>
<!--select class="col-xs-12 mt-3" ng-model="report_user_form.data.report_reason" ng-options="item for item in report_user_form.reasons">
</select-->
<div class="btn-group mt-3">
<span ng-repeat="reason in report_user_form.reasons" ng-click="selectReportReason(reason)" class="btn btn-sm btn-light-blue btn-outline" ng-class="{active: reason == report_user_form.data.report_reason}">
{{ reason }}
</span>
</div>
<label class="col-xs-12 control-label">Comment</label>
<div class="col-xs-12 mt-3">
<textarea class="form-control ng-pristine ng-valid" ng-model="report_user_form.data.note" placeholder="Provide some additional information." rows="4"></textarea>
</div>
<div>
<button type="submit" class="mt-3 btn btn-light-blue">Submit</button>
<button ng-click="report_user_form.cancel()" class="mt-3 btn btn-danger">Cancel</button>
</div>
</form>
<div ng-switch-when="submitted">
<button class="mt-3 btn btn-long btn-default disabled">Reported</button>
</div>
</div>
</div>
</div>
</div>
Expand Down
63 changes: 62 additions & 1 deletion app/assets/javascripts/app/people/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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];

});
4 changes: 4 additions & 0 deletions app/assets/javascripts/common/services/api.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/api/v1/people_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/mailers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions app/views/mailer/report_account.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>
Activity report of the account: <a href="<%= Api::Application.config.www_url %>/users/<%=@report[:person_id]%>"><%=@report[:person_id]%></a>
</p>

<p>
From: <a href="<%=@person.frontend_url%>"/>
</p
>
<p>
<b>Reason:</b> <%=@report[:reason]%>
</p>

<p>
<b>Comment:</b> <%=@report[:note]%>
</p>
8 changes: 8 additions & 0 deletions app/views/mailer/report_account.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Activity report of the account: <%= Api::Application.config.www_url %>/users/<%=@report[:person_id]%>

From: <%=@person.frontend_url%>

Reason: <%=@report[:reason]%>

Comment: <%=@report[:note]%>

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
get 'people/:profile_id/teams', action: :teams
get 'people/:profile_id/activity', action: :activity
get 'projects', action: :projects
post 'people/:profile_id/report', action: :report

get :my_languages, action: :languages
post :my_languages, action: :set_languages
Expand Down