Skip to content

Commit

Permalink
add locations deleted to weekly admin email
Browse files Browse the repository at this point in the history
  • Loading branch information
scottwainstock committed Mar 17, 2018
1 parent 63a1fc0 commit 286dfe8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ GuardClause:
PerlBackrefs:
Enabled: false
CyclomaticComplexity:
Max: 15
Max: 16
PerceivedComplexity:
Max: 15
Max: 16
AbcSize:
Enabled: false
Metrics/BlockLength:
Expand Down
2 changes: 2 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Location < ApplicationRecord
LocationPictureXref.where(location_id: record.id).destroy_all
MachineScoreXref.where("location_machine_xref_id in (select id from location_machine_xrefs where location_id = #{record.id})").destroy_all
LocationMachineXref.where(location_id: record.id).destroy_all

UserSubmission.create(region_id: region.id, location: self, submission_type: UserSubmission::DELETE_LOCATION_TYPE, submission: "Deleted #{name} (#{id})")
end

def should_skip_geocode
Expand Down
1 change: 1 addition & 0 deletions app/models/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def generate_weekly_admin_email_body
#{user_submissions.select { |us| !us.created_at.nil? && us.created_at.between?(start_of_week, end_of_week) && us.submission_type == UserSubmission::SUGGEST_LOCATION_TYPE }.count} Location(s) submitted to you this week
#{locations.select { |l| !l.created_at.nil? && l.created_at.between?(start_of_week, end_of_week) }.count} Location(s) added by you this week
#{user_submissions.select { |us| !us.created_at.nil? && us.created_at.between?(start_of_week, end_of_week) && us.submission_type == UserSubmission::DELETE_LOCATION_TYPE }.count} Location(s) deleted this week
#{user_submissions.select { |us| !us.created_at.nil? && us.created_at.between?(start_of_week, end_of_week) && us.submission_type == UserSubmission::NEW_CONDITION_TYPE }.count} machine comment(s) by users this week
#{location_machine_xrefs.select { |lmx| !lmx.created_at.nil? && lmx.created_at.between?(start_of_week, end_of_week) }.count} machine(s) added by users this week
#{user_submissions.select { |us| !us.created_at.nil? && us.created_at.between?(start_of_week, end_of_week) && us.submission_type == UserSubmission::REMOVE_MACHINE_TYPE }.count} machine(s) removed by users this week
Expand Down
1 change: 1 addition & 0 deletions app/models/user_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UserSubmission < ApplicationRecord
LOCATION_METADATA_TYPE = 'location_metadata'.freeze
NEW_SCORE_TYPE = 'new_msx'.freeze
CONFIRM_LOCATION_TYPE = 'confirm_location'.freeze
DELETE_LOCATION_TYPE = 'delete_location'.freeze

def user_email
user ? user.email : ''
Expand Down
5 changes: 5 additions & 0 deletions spec/models/region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
FactoryBot.create(:user_submission, region: @region, submission_type: 'remove_machine')
FactoryBot.create(:user_submission, region: @region, submission_type: 'remove_machine')

FactoryBot.create(:user_submission, region: @region, submission_type: 'delete_location')
FactoryBot.create(:user_submission, region: @region, submission_type: 'delete_location')
FactoryBot.create(:user_submission, region: @region, submission_type: 'delete_location')

FactoryBot.create(:location_machine_xref, location: location_added_today, machine: FactoryBot.create(:machine), created_at: Date.today - 2.week)
FactoryBot.create(:location_machine_xref, location: location_added_today, machine: FactoryBot.create(:machine), created_at: Date.today - 2.week)

Expand Down Expand Up @@ -134,6 +138,7 @@
2 Location(s) submitted to you this week
2 Location(s) added by you this week
3 Location(s) deleted this week
2 machine comment(s) by users this week
1 machine(s) added by users this week
2 machine(s) removed by users this week
Expand Down

0 comments on commit 286dfe8

Please sign in to comment.