diff --git a/app/assets/javascripts/app/people/activity.html.erb b/app/assets/javascripts/app/people/activity.html.erb index 9c5276bc2..802c2ce72 100644 --- a/app/assets/javascripts/app/people/activity.html.erb +++ b/app/assets/javascripts/app/people/activity.html.erb @@ -73,6 +73,39 @@
+ ++ Reported profile: + <%= @reported_person.display_name %> +
+ ++ Profile URL: + <%= link_to @reported_profile_url, @reported_profile_url %> +
+ ++ Reporter: + <%= @reporter.display_name %> +
+ ++ Reporter email: + <%= mail_to @reporter.email %> +
+ ++ Reason: + <%= @reason %> +
+ ++ Comment: +
+ ++ <%= simple_format(@comment.presence || "No comment provided.") %> +
diff --git a/app/views/mailer/profile_reported.text.erb b/app/views/mailer/profile_reported.text.erb new file mode 100644 index 000000000..a7bcbb4fd --- /dev/null +++ b/app/views/mailer/profile_reported.text.erb @@ -0,0 +1,12 @@ +Profile reported + +Reported profile: <%= @reported_person.display_name %> +Profile URL: <%= @reported_profile_url %> + +Reporter: <%= @reporter.display_name %> +Reporter email: <%= @reporter.email %> + +Reason: <%= @reason %> + +Comment: +<%= @comment.presence || "No comment provided." %> diff --git a/config/routes.rb b/config/routes.rb index 780d7ee9a..8028ea4a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -271,6 +271,7 @@ scope controller: :people do get 'users/:profile_id', action: :profile get 'users/:profile_id/activity', action: :activity + post 'people/:profile_id/report', action: :report get 'people/count', action: :count get 'people/:profile_id/teams', action: :teams get 'people/:profile_id/activity', action: :activity diff --git a/spec/controllers/api/v1/people_controller_spec.rb b/spec/controllers/api/v1/people_controller_spec.rb index bb54dac27..626bbcfa0 100644 --- a/spec/controllers/api/v1/people_controller_spec.rb +++ b/spec/controllers/api/v1/people_controller_spec.rb @@ -102,4 +102,52 @@ expect(person.languages).to include language2 end end + + describe "report" do + let(:reporter) { create(:person, email: "reporter@example.com", display_name: "Reporter") } + let(:reported_person) { create(:person, email: "reported@example.com", display_name: "Reported") } + let(:params) { { access_token: reporter.create_access_token, profile_id: reported_person.to_param } } + + it "emails support with the selected reason and comment" do + expect { + post :report, params: params.merge(reason: "spam", comment: "Suspicious links") + }.to change(ActionMailer::Base.deliveries, :count).by(1) + + assert_response :ok + + email = ActionMailer::Base.deliveries.last + expect(email.to).to eq(["support@bountysource.com"]) + expect(email.from).to eq([reporter.email]) + expect(email.reply_to).to eq([reporter.email]) + expect(email.subject).to eq("Profile reported: #{reported_person.display_name}") + expect(email.encoded).to include("spam") + expect(email.encoded).to include("Suspicious links") + expect(email.encoded).to include(reported_person.to_param) + end + + it "requires authentication" do + post :report, params: params.except(:access_token).merge(reason: "spam") + assert_response :unauthorized + end + + it "rejects invalid reasons" do + expect { + post :report, params: params.merge(reason: "not-a-reason") + }.not_to change(ActionMailer::Base.deliveries, :count) + + assert_response :unprocessable_entity + end + + it "does not allow self reports" do + expect { + post :report, params: { + access_token: reporter.create_access_token, + profile_id: reporter.to_param, + reason: "spam" + } + }.not_to change(ActionMailer::Base.deliveries, :count) + + assert_response :unprocessable_entity + end + end end diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index c305dae87..03ca4618d 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -96,4 +96,26 @@ expect(email.subject).to eq("#{fundraiser.person.display_name} backed your fundraiser #{fundraiser.title}") end end + + describe "#profile_reported" do + let(:reported_person) { create(:person, display_name: "Reported Person") } + let(:email) do + Mailer.profile_reported( + reporter: person, + reported_person: reported_person, + reason: "fraud", + comment: "Looks suspicious" + ) + end + + it "renders a support email from the reporter" do + expect(email.to).to eq(["support@bountysource.com"]) + expect(email.from).to eq([person.email]) + expect(email.reply_to).to eq([person.email]) + expect(email.subject).to eq("Profile reported: #{reported_person.display_name}") + expect(email.encoded).to include("fraud") + expect(email.encoded).to include("Looks suspicious") + expect(email.encoded).to include(reported_person.to_param) + end + end end