Skip to content

Commit 767e82c

Browse files
authored
Merge pull request #101 from dblock/remove-slack-api-token-migration
Removed migration code from legacy SLACK_API_TOKEN.
2 parents 988b3d1 + 9816280 commit 767e82c

File tree

5 files changed

+7
-58
lines changed

5 files changed

+7
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### 0.10.1 (Next)
44

5+
* [#101](https://github.com/slack-ruby/slack-ruby-bot-server/pull/101): Removed legacy migrations, including `SLACK_API_TOKEN`, team `name`, `team_id` and `active` - [@dblock](https://github.com/dblock).
56
* [#98](https://github.com/slack-ruby/slack-ruby-bot-server/pull/98): Removed `unicorn` from gem dependencies - [@dblock](https://github.com/dblock).
67
* [#90](https://github.com/slack-ruby/slack-ruby-bot-server/pull/90): Update ActiveRecord sample app to support ENV variables in `postgresql.yml` - [@ashkan18](https://github.com/ashkan18).
78
* Your contribution here.

UPGRADING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Upgrading Slack-Ruby-Bot-Server
33

44
### Upgrading to >= 0.10.1
55

6+
#### Removed Legacy Migrations
7+
8+
Several legacy migrations have been removed, including the code to automatically create a team from a legacy `SLACK_API_TOKEN`, setting `Team#active`, `name` and `team_id`.
9+
10+
See [#101](https://github.com/slack-ruby/slack-ruby-bot-server/pull/101) for more information.
11+
612
#### Unicorn Dependency
713

814
The dependency on `unicorn` has been removed from gemspec. Use `unicorn` or `puma` or another application server as you see fit by explicitly adding a dependency in your Gemfile.

lib/slack-ruby-bot-server/app.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ class App
33
def prepare!
44
check_database!
55
init_database!
6-
mark_teams_active!
7-
migrate_from_single_team!
8-
update_team_name_and_id!
96
purge_inactive_teams!
107
configure_global_aliases!
118
end
@@ -31,30 +28,6 @@ def init_database!
3128
SlackRubyBotServer::DatabaseAdapter.init!
3229
end
3330

34-
def mark_teams_active!
35-
Team.where(active: nil).update_all(active: true)
36-
end
37-
38-
def update_team_name_and_id!
39-
Team.active.where(team_id: nil).each do |team|
40-
begin
41-
auth = team.ping![:auth]
42-
team.update_attributes!(team_id: auth['team_id'], name: auth['team'])
43-
rescue StandardError => e
44-
logger.warn "Error pinging team #{team.id}: #{e.message}."
45-
team.set(active: false)
46-
end
47-
end
48-
end
49-
50-
def migrate_from_single_team!
51-
return unless ENV.key?('SLACK_API_TOKEN')
52-
logger.info 'Migrating from env SLACK_API_TOKEN ...'
53-
team = Team.find_or_create_from_env!
54-
logger.info "Automatically migrated team: #{team}."
55-
logger.warn "You should unset ENV['SLACK_API_TOKEN']."
56-
end
57-
5831
def purge_inactive_teams!
5932
Team.purge!
6033
end

lib/slack-ruby-bot-server/models/team/methods.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,5 @@ def ping!
3838
presence: client.users_getPresence(user: auth['user_id'])
3939
}
4040
end
41-
42-
def self.find_or_create_from_env!
43-
token = ENV['SLACK_API_TOKEN']
44-
return unless token
45-
team = Team.where(token: token).first
46-
team ||= Team.new(token: token)
47-
info = Slack::Web::Client.new(token: token).team_info
48-
team.team_id = info['team']['id']
49-
team.name = info['team']['name']
50-
team.domain = info['team']['domain']
51-
team.save!
52-
team
53-
end
5441
end
5542
end

spec/models/team_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
require 'spec_helper'
22

33
describe Team do
4-
context '#find_or_create_from_env!' do
5-
before do
6-
ENV['SLACK_API_TOKEN'] = 'token'
7-
end
8-
context 'team', vcr: { cassette_name: 'team_info' } do
9-
it 'creates a team' do
10-
expect { Team.find_or_create_from_env! }.to change(Team, :count).by(1)
11-
team = Team.first
12-
expect(team.team_id).to eq 'T04KB5WQH'
13-
expect(team.name).to eq 'dblock'
14-
expect(team.domain).to eq 'dblockdotorg'
15-
expect(team.token).to eq 'token'
16-
end
17-
end
18-
after do
19-
ENV.delete 'SLACK_API_TOKEN'
20-
end
21-
end
224
context '#purge!' do
235
let!(:active_team) { Fabricate(:team) }
246
let!(:inactive_team) { Fabricate(:team, active: false) }

0 commit comments

Comments
 (0)