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
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'net/http'

class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session

Expand All @@ -14,4 +16,12 @@ def authenticate_admin!
redirect_to request.referrer || root_path, notice: "Admins Only! :|"
end
end

def send_slack_notification msg
uri = URI('https://slack.com/api/chat.postMessage')
params = { :token => Rails.application.secrets.slack_token, :channel => Rails.application.secrets.slack_channel, :text => msg, :pretty => 1 }
uri.query = URI.encode_www_form(params)

Net::HTTP.get_response(uri)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a slack ruby client you can consider using, instead of making the calls directly.

end
end
2 changes: 2 additions & 0 deletions app/controllers/charitable_organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def create

if draft.save
redirect_to draft, notice: 'Your new Charitable Organization is pending approval.'
send_slack_notification "New CharitableOrganization: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
@charitable_organization = CharitableOrganization.new(charitable_organization_update_params)
render :new
Expand Down Expand Up @@ -63,6 +64,7 @@ def update

if draft.save
redirect_to draft, notice: 'Your Charitable Organization update is pending approval.'
send_slack_notification "CharitableOrganization Updated: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
render :edit
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def create
if draft.save
path = location_draft_path(organization: @organization, legacy_table_name: @legacy_table_name, id: draft.id)
redirect_to path, notice: 'Your new location is pending approval.'
send_slack_notification "New Location: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
@location = location_class.new(location_update_params)
render :new
Expand Down Expand Up @@ -56,6 +57,7 @@ def update
if draft.save
path = location_draft_path(organization: @organization, legacy_table_name: @legacy_table_name, id: draft.id)
redirect_to path, notice: "#{location_class.legacy_table_display_name} update is pending approval."
send_slack_notification "Location updated: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
render :edit
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/needs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def create

if draft.save
redirect_to draft, notice: 'Your new need is pending approval.'
send_slack_notification "New need added: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
@need = Need.new(need_update_params)
render :new
Expand Down Expand Up @@ -63,6 +64,7 @@ def update

if draft.save
redirect_to draft, notice: 'Your need update is pending approval.'
send_slack_notification "Need updated: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
render :edit
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/shelters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create

if draft.save
redirect_to draft, notice: 'Your new shelter is pending approval.'
send_slack_notification "New shelter added: https://irma-api.herokuapp.com/drafts/#{draft.id}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some Slack formatting would add a nice touch here. Maybe include draft.record.shelter to include the text from the Shelter field like:

send_slack_notification "New shelter added in <https://irma-api.herokuapp.com/drafts/#{draft.id}|#{draft.record.shelter}>"

You could also make it a call to action, ie "Admins, please review new shelter in https://irma-api.herokuapp.com/drafts/#{draft.id}|#{draft.record.shelter}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use draft_url(draft), that should generate a URL that works in all environments, not just production.

else
@shelter = Shelter.new(shelter_update_params)
render :new
Expand All @@ -51,6 +52,7 @@ def update

if draft.save
redirect_to draft, notice: 'Your shelter update is pending approval.'
send_slack_notification "Shelter updated: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
render :edit
end
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/mucked_homes_helper.rb

This file was deleted.

8 changes: 7 additions & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

development:
secret_key_base: d22cd95910c4425ab8adfd2aa968b845775c6ffff23f9cdb337bc6f210199ca97736ed261d06bf69242f6483a8e6c474ab88f02dabb9865f9911ff215da31695

slack_token: "xoxp-235986621104-238493557106-238649524195-b886dacfa83620d7c79b483114198cf9"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a real token? It might be better as an environment variable like SECRET_KEY_BASE below. That would make sense for all the environments. Someone with Heroku access to the app would need to set this up before deploying.

The secret should be rolled as well.

slack_channel: "#shelters_notif"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be good as a environment variable too, even if it isn't a secret per se. That'd make it easy to test in development.


test:
secret_key_base: 44caab1bd8c8d8cf74981bfc824b9c0a1786d7bc3a2d6b09f493f69b3fdd0c76b19d1e587545be50f8f4ae3fd66506b8b113a00a98ae7f8e7b00bf4b21690aeb
slack_token: "xoxp-235986621104-238493557106-238649524195-b886dacfa83620d7c79b483114198cf9"
slack_channel: "#shelters_notif"

# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
Expand All @@ -30,3 +34,5 @@ test:

production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
slack_token: "xoxp-235986621104-238493557106-238649524195-b886dacfa83620d7c79b483114198cf9"
slack_channel: "#shelters_notif"