Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit 138feda

Browse files
Merge pull request #447 from OperationCode/password_change
Add slack invites
2 parents a2ad9a3 + 6cfebb6 commit 138feda

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

app/jobs/slack_jobs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SlackJobs < ApplicationJob
66
def slack_client
77
@slack_client ||= Slack::Client.new(
88
subdomain: ENV.fetch('SLACK_SUBDOMAIN'),
9-
token: ENV.fetch('SLACK_TOKEN')
9+
token: ENV.fetch('SLACK_LEGACY_ADMIN_TOKEN') # admin token required to invite
1010
)
1111
end
1212
end

app/jobs/slack_jobs/inviter_job.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ class SlackJobs
22
class InviterJob < SlackJobs
33
include Sidekiq::Worker
44

5-
def perform(_email)
6-
logger.debug 'Deprecated pathway, trying to determine what is placing this on queue.'
5+
def perform(email)
6+
# Invites user to general channel
7+
Raven.user_context email: email
8+
Raven.tags_context slack_invite: 'yes'
9+
slack_client.invite(
10+
email: email,
11+
channels: ['C03GSNF77'],
12+
extra_message: 'Welcome to Operation Code!\n'\
13+
'Once you log in, please take a moment to introduce yourself in the #general channel - a bit about who you are, where you\'re coming from, and where you\'re interested in going next.\n'\
14+
'Thank you for joining us!\n'\
15+
'-from the OC volunteer team\n'\
16+
)
717
end
818
end
919
end

app/lib/slack/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(subdomain:, token:)
2020
@domain = "#{subdomain}.slack.com"
2121
end
2222

23-
def invite(email:, channels: [])
23+
def invite(extra_message:, email:, channels: [])
2424
Rails.logger.info "Inviting user with email '#{email}'"
2525
body = send_api_request(
2626
to: INVITE_PATH,
@@ -29,6 +29,7 @@ def invite(email:, channels: [])
2929
channels: channels.join(','),
3030
token: @token,
3131
set_active: 'true',
32+
extra_message: extra_message,
3233
_attempts: 1
3334
}
3435
)

app/lib/slack/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def client
2020
def set_client
2121
Slack::Client.new(
2222
subdomain: OperationCode.fetch_secret_with(name: :slack_domain),
23-
token: OperationCode.fetch_secret_with(name: :slack_token)
23+
token: OperationCode.fetch_secret_with(name: :slack_legacy_admin_token)
2424
)
2525
end
2626
end

app/models/user.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def name
151151

152152
def welcome_user
153153
add_to_send_grid
154+
invite_to_slack
155+
end
156+
157+
def invite_to_slack
158+
SlackJobs::InviterJob.perform_async(self.email)
154159
end
155160

156161
def add_to_send_grid

test/models/user_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def teardown
1616
assert_equal [user.id], AddUserToSendGridJob.jobs.first['args']
1717
end
1818

19+
test 'welcoming a user adds them to SlackInvite' do
20+
user = create(:user, user_opts)
21+
user.welcome_user
22+
assert_equal 1, SlackJobs::InviterJob.jobs.length
23+
assert_equal [user.email], SlackJobs::InviterJob.jobs.first['args']
24+
end
25+
1926
test 'must have a valid email' do
2027
refute User.new(email: 'bogusemail', password: 'password', zip: '97201').valid?
2128
assert User.new(email: '[email protected]', password: 'password', zip: '97201').valid?

0 commit comments

Comments
 (0)