Skip to content

Commit

Permalink
Merge branch 'EN-8090-fix-slack-mention-on-association-account-creation'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Mar 6, 2025
2 parents fd785ae + 088fa25 commit fa60513
Show file tree
Hide file tree
Showing 22 changed files with 13 additions and 94 deletions.
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class User < ApplicationRecord
before_save :slack_id_no_empty
after_save :clean_up_passwords, if: :saved_change_to_encrypted_password?
after_save :sync_newsletter, if: :saved_change_to_email?
after_save :signal_association

has_many :followings, -> { where active: true }
has_many :subscriptions, through: :followings, source: :partner
Expand Down Expand Up @@ -405,7 +406,14 @@ def newsletter_subscription= newsletter_subscription

email_preference = EmailPreference.find_by(user: self, email_category_id: category_id) || email_preferences.build(email_category_id: category_id)
email_preference.subscribed = ActiveModel::Type::Boolean.new.cast(newsletter_subscription)
end

def signal_association
return unless address.present?
return unless saved_change_to_address_id? || saved_change_to_goal?
return unless goal_association?

SlackServices::SignalAssociationCreation.new(user: self).notify
end

def sync_newsletter
Expand Down
1 change: 0 additions & 1 deletion app/services/user_services/public_user_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def update(user:, platform: nil)

if user.update(params)
signal_blocked_user(user)
signal_association(user)

callback.on_success.try(:call, user)
else
Expand Down
9 changes: 0 additions & 9 deletions app/services/user_services/user_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def create(send_sms: false, sms_code: nil)
UserServices::SMSSender.new(user: user).send_welcome_sms(sms_code) if send_sms
MemberMailer.welcome(user).deliver_later if user.email.present?

signal_association(user)

callback.on_success.try(:call, user)
else
return callback.on_duplicate(user) if User.where(phone: params[:phone]).count>0
Expand All @@ -49,13 +47,6 @@ def signal_blocked_user user
SlackServices::SignalUserCreation.new(user: user, blocked_user_ids: blocked_user_ids).notify
end

def signal_association user
return unless user.saved_change_to_goal?
return unless user.goal_association?

SlackServices::SignalAssociationCreation.new(user: user).notify
end

private
attr_reader :params, :callback

Expand Down
6 changes: 0 additions & 6 deletions spec/acceptance/api/v1/contributions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report contribution' do
expect(response_status).to eq(201)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
}
}.to_json }

ENV['SLACK_WEBHOOK_URL'] = "https://url.to.slack.com"

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
let!(:join_request) { FactoryBot.create(:join_request, joinable: entourage, user: user, status: :accepted) }

Expand Down
6 changes: 0 additions & 6 deletions spec/acceptance/api/v1/entourages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report entourage' do
expect(response_status).to eq(201)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report neighborhood' do
expect(response_status).to eq(201)
Expand Down
6 changes: 0 additions & 6 deletions spec/acceptance/api/v1/neighborhoods_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report neighborhood' do
expect(response_status).to eq(201)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report outing' do
expect(response_status).to eq(201)
Expand Down
6 changes: 0 additions & 6 deletions spec/acceptance/api/v1/solicitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@
}
}.to_json }


ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context '201' do
example_request 'Report solicitation' do
expect(response_status).to eq(201)
Expand Down
12 changes: 0 additions & 12 deletions spec/acceptance/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
explanation "Users"
header "Content-Type", "application/json"

ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before(:each) {
ENV['SLACK_WEBHOOK_URL'] = 'https://url.to.slack.com'
stub_request(:post, "https://url.to.slack.com").to_return(status: 200)
}

after(:each) {
ENV['SLACK_WEBHOOK_URL'] = nil
}

post '/api/v1/login' do
route_summary "Login"
# route_description "no description"
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/api/v1/contributions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@

ENV['SLACK_SIGNAL_NEIGHBORHOOD_WEBHOOK'] = '{"url":"https://url.to.slack.com","channel":"channel","username":"signal-contribution"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalContribution).to receive(:notify)
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/api/v1/conversations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,6 @@

let!(:join_request) { FactoryBot.create(:join_request, joinable: conversation, user: user, status: :accepted) }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalConversation).to receive(:notify)
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/api/v1/entourages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,6 @@

ENV['SLACK_SIGNAL_GROUP_WEBHOOK'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }


context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalGroup).to receive(:notify)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,6 @@
let(:chat_message) { create :chat_message, messageable: neighborhood }
let!(:join_request) { FactoryBot.create(:join_request, joinable: neighborhood, user: user, status: "accepted") }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "correct messageable" do
before {
expect_any_instance_of(SlackServices::SignalNeighborhoodChatMessage).to receive(:notify)
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/api/v1/neighborhoods_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,6 @@
describe 'POST #report' do
let(:neighborhood) { create :neighborhood }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalNeighborhood).to receive(:notify)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,6 @@
let(:chat_message) { create :chat_message, messageable: outing }
let!(:join_request) { FactoryBot.create(:join_request, joinable: outing, user: user, status: "accepted") }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "correct messageable" do
before {
expect_any_instance_of(SlackServices::SignalOutingChatMessage).to receive(:notify)
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/api/v1/outings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,6 @@
describe 'POST #report' do
let(:outing) { create :outing }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalOuting).to receive(:notify)
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/api/v1/solicitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@

ENV['SLACK_SIGNAL_NEIGHBORHOOD_WEBHOOK'] = '{"url":"https://url.to.slack.com","channel":"channel","username":"signal-solicitation"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalSolicitation).to receive(:notify)
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1110,10 +1110,6 @@ def event
let(:reported_user) { create :public_user }
let(:result) { JSON.parse(response.body) }

ENV['SLACK_SIGNAL'] = '{"url":"https://url.to.slack.com","channel":"channel"}'

before { stub_request(:post, "https://url.to.slack.com").to_return(status: 200) }

context "valid params" do
before {
expect_any_instance_of(SlackServices::SignalUser).to receive(:notify)
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

stub_request(:any, /.*api.mailjet.com.*/).to_return(status: 200, body: { id: 1 }.to_json, headers: {})
stub_request(:any, /.*api.openai.*/).to_return(status: 200, body: "{}", headers: {})
stub_request(:any, "https://url.to.slack.com").to_return(status: 200)

# deactivate slack_trace notifications
SlackServices::StackTrace.any_instance.stub(:notify).and_return(nil)
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
end
end

ENV["DISABLE_CRYPT"]="TRUE"
ENV['ADMIN_HOST'] = 'https://this.is.local'
ENV["DISABLE_CRYPT"] = "TRUE"
ENV['ENTOURAGE_SECRET'] = 'test_entourage_secret'
ENV["SLACK_DEFAULT_INTERLOCUTOR"] = "laure"
ENV["MODERATOR_PHONE"] = "+33768037348"
ENV['SLACK_WEBHOOK_URL'] = "https://url.to.slack.com"
ENV["SLACK_SIGNAL"] = '{"url":"https://url.to.slack.com","channel":"channel","channel-associations":"channel-associations"}'
API_HOST = 'api.entourage.test'

0 comments on commit fa60513

Please sign in to comment.