Skip to content

Commit 71601dd

Browse files
authored
Merge pull request #96 from dblock/lifecycle
Added Team#bot_user_id, activated_user_id and activated_user_access_token.
2 parents d3a24dd + 07e2bee commit 71601dd

File tree

15 files changed

+94
-21
lines changed

15 files changed

+94
-21
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-02-25 14:24:34 -0500 using RuboCop version 0.58.2.
3+
# on 2019-03-23 14:16:02 -0400 using RuboCop version 0.58.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
### Changelog
22

3-
#### 0.9.1 (Next)
3+
#### 0.10.0 (Next)
44

5+
* [#96](https://github.com/slack-ruby/slack-ruby-bot-server/pull/96): Added `Team#bot_user_id`, `activated_user_id` and `activated_user_access_token` - [@dblock](https://github.com/dblock).
56
* Your contribution here.
67

78
* [#95](https://github.com/slack-ruby/slack-ruby-bot-server/pull/95): Expose the optional `state` parameter that is returned from the Add to Slack button - [@aok-solutions](https://github.com/aok-solutions).

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ when 'mongoid' then
55
gem 'kaminari-mongoid'
66
gem 'mongoid'
77
gem 'mongoid-scroll'
8+
gem 'mongoid-shell'
89
when 'activerecord' then
910
gem 'activerecord', '~> 5.0.0'
1011
gem 'otr-activerecord', '~> 1.2.1'
@@ -26,7 +27,6 @@ group :development, :test do
2627
gem 'fabrication'
2728
gem 'faker'
2829
gem 'hyperclient'
29-
gem 'mongoid-shell'
3030
gem 'rack-server-pages'
3131
gem 'rack-test'
3232
gem 'rake'

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,11 @@ end
170170

171171
### Access Tokens
172172

173-
By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores a `bot_access_token` that grants a certain amount of privileges to the bot user as described in [Slack OAuth Docs](https://api.slack.com/docs/oauth). You may not want a bot user at all, or may require different auth scopes, such as `users.profile:read` to access user profile information via `Slack::Web::Client#users_profile_get`. To obtain the non-bot access token make the following changes.
173+
By default the implementation of [Team](lib/slack-ruby-bot-server/models/team) stores a `bot_access_token` as `token` that grants a certain amount of privileges to the bot user as described in [Slack OAuth Docs](https://api.slack.com/docs/oauth) along with `activated_user_access_token` that represents the token of the installing user. You may not want a bot user at all, or may require different auth scopes, such as `users.profile:read` to access user profile information via `Slack::Web::Client#users_profile_get`. To change required scopes make the following changes.
174174

175175
1) Configure your app to require additional scopes in Slack API under _OAuth_, _Permissions_
176-
2) Add `access_token` and, optionally, `scope` to your `Team` model
177-
3) Change the _Add to Slack_ buttons to require the additional scope, eg. `https://slack.com/oauth/authorize?scope=bot,users.profile:read&client_id=...`
178-
4) Store the access token returned from `Slack::Web::Client#oauth_access` and scope when creating a team in your `Teams` API endpoint.
176+
2) Change the _Add to Slack_ buttons to require the additional scope, eg. `https://slack.com/oauth/authorize?scope=bot,users.profile:read&client_id=...`
177+
3) The access token with the requested scopes will be stored as `activated_user_access_token`.
179178

180179
You can see a sample implementation in [slack-sup#3a497b](https://github.com/dblock/slack-sup/commit/3a497b436d25d3a7738562655cda64b180ae0096).
181180

UPGRADING.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
Upgrading Slack-Ruby-Bot-Server
22
===============================
33

4+
### Upgrading to >= 0.10.0
5+
6+
#### New Team Fields
7+
8+
The following fields have been added to `Team`.
9+
10+
* `bot_user_id`: the bot `user_id` during installation
11+
* `activated_user_id`: the installing Slack user `user_id`
12+
* `activated_user_access_token`: the installing Slack user `access_token`
13+
14+
No action is required for Mongoid.
15+
16+
If you're using ActiveRecord, create a migration similar to [sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb](sample_apps/sample_app_activerecord/db/migrate/20190323181453_add_activated_fields.rb) to add these fields.
17+
18+
```ruby
19+
class AddActivatedFields < ActiveRecord::Migration[5.0]
20+
def change
21+
add_column :teams, :bot_user_id, :string
22+
add_column :teams, :activated_user_id, :string
23+
add_column :teams, :activated_user_access_token, :string
24+
end
25+
end
26+
```
27+
28+
See [#96](https://github.com/slack-ruby/slack-ruby-bot-server/pull/96) for more information.
29+
430
### Upgrading to >= 0.9.0
531

6-
### Removed Ping Worker
32+
#### Removed Ping Worker
733

834
The ping worker that was added in 0.7.0 has been removed in favor of a lower level implementation in slack-ruby-client. Remove any references to `ping` options.
935

1036
See [slack-ruby-client#226](https://github.com/slack-ruby/slack-ruby-client/pull/226) and [#93](https://github.com/slack-ruby/slack-ruby-bot-server/pull/93) for more information.
1137

1238
### Upgrading to >= 0.8.0
1339

14-
### Different Asynchronous I/O Library
40+
#### Different Asynchronous I/O Library
1541

1642
The library now uses [async-websocket](https://github.com/socketry/async-websocket) instead of [celluloid-io](https://github.com/celluloid/celluloid-io). If your application is built on Celluloid you may need to make changes and use `Async::Reactor.run` and the likes.
1743

lib/slack-ruby-bot-server/api/endpoints/teams_endpoint.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,28 @@ class TeamsEndpoint < Grape::API
4747
)
4848

4949
token = rc['bot']['bot_access_token']
50+
bot_user_id = rc['bot']['bot_user_id']
51+
user_id = rc['user_id']
52+
access_token = rc['access_token']
5053
team = Team.where(token: token).first
5154
team ||= Team.where(team_id: rc['team_id']).first
52-
if team && !team.active?
55+
56+
if team
57+
team.update_attributes!(
58+
activated_user_id: user_id,
59+
activated_user_access_token: access_token,
60+
bot_user_id: bot_user_id
61+
)
62+
raise "Team #{team.name} is already registered." if team.active?
5363
team.activate!(token)
54-
elsif team
55-
raise "Team #{team.name} is already registered."
5664
else
5765
team = Team.create!(
5866
token: token,
5967
team_id: rc['team_id'],
60-
name: rc['team_name']
68+
name: rc['team_name'],
69+
activated_user_id: user_id,
70+
activated_user_access_token: access_token,
71+
bot_user_id: bot_user_id
6172
)
6273
end
6374

lib/slack-ruby-bot-server/config/database_adapters/activerecord.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ def self.check!
1212

1313
def self.init!
1414
return if ActiveRecord::Base.connection.tables.include?('teams')
15+
1516
ActiveRecord::Base.connection.create_table :teams do |t|
1617
t.string :team_id
1718
t.string :name
1819
t.string :domain
1920
t.string :token
21+
t.string :bot_user_id
22+
t.string :activated_user_id
23+
t.string :activated_user_access_token
2024
t.boolean :active, default: true
2125
t.timestamps
2226
end

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Team
99
field :domain, type: String
1010
field :token, type: String
1111
field :active, type: Boolean, default: true
12+
field :bot_user_id, type: String
13+
field :activated_user_id, type: String
14+
field :activated_user_access_token, type: String
1215

1316
include Methods
1417

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SlackRubyBotServer
2-
VERSION = '0.9.1'.freeze
2+
VERSION = '0.10.0'.freeze
33
end

0 commit comments

Comments
 (0)