Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 867f27f

Browse files
authored
Merge pull request #1 from dblock/oauth-version
Only start OAuth v1 teams with a bot token.
2 parents 1b28455 + 4f81318 commit 867f27f

File tree

11 files changed

+57
-12
lines changed

11 files changed

+57
-12
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 2020-11-14 17:59:41 -0500 using RuboCop version 0.81.0.
3+
# on 2020-11-27 15:32:33 -0500 using RuboCop version 0.81.0.
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.1.2 (Next)
3+
#### 0.2.0 (Next)
44

5+
* [#1](https://github.com/slack-ruby/slack-ruby-bot-server-rtm/pull/1): Only start OAuth v1 teams with a bot token - [@dblock](https://github.com/dblock).
56
* Your contribution here.
67

78
#### 0.1.1 (2020/11/15)

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ Slack Ruby Bot Server RealTime (RTM) Extension
44
[![Gem Version](https://badge.fury.io/rb/slack-ruby-bot-server-rtm.svg)](https://badge.fury.io/rb/slack-ruby-bot-server-rtm)
55
[![Build Status](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-rtm.svg?branch=main)](https://travis-ci.org/slack-ruby/slack-ruby-bot-server-rtm)
66

7-
An extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that makes it easy to implement Slack RTM bots.
7+
# Table of Contents
8+
9+
- [Introduction](#introduction)
10+
- [Samples](#samples)
11+
- [Usage](#usage)
12+
- [Gemfile](#gemfile)
13+
- [Configure](#configure)
14+
- [Server Class](#server-class)
15+
- [Copyright & License](#copyright--license)
16+
17+
### Introduction
18+
19+
This library is an extension to [slack-ruby-bot-server](https://github.com/slack-ruby/slack-ruby-bot-server) that makes it easy to implement Slack RTM bots.
820

921
### Samples
1022

lib/slack-ruby-bot-server-rtm/lifecycle.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
end
66

77
SlackRubyBotServer::Config.service_class.instance.on :starting do |team, _error, options|
8+
next if team.respond_to?(:oauth_version) && team.oauth_version != 'v1'
9+
810
SlackRubyBotServer::Config.service_class.instance.logger.info "Starting real-time team #{team}."
911
options = { team: team }
1012
server = SlackRubyBotServer::RealTime::Config.server_class.new(options)
@@ -26,6 +28,6 @@
2628
end
2729

2830
SlackRubyBotServer::Config.service_class.instance.on :deactivated do |team, _error, _options|
29-
SlackRubyBotServer::Config.service_class.instance.logger.info "De-activating real-time team #{team}."
31+
SlackRubyBotServer::Config.service_class.instance.logger.info "De-activated real-time team #{team}."
3032
team.server = nil
3133
end

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ def self.start_server!(team, server, wait = 1)
2323
rescue StandardError => e
2424
SlackRubyBotServer::Config.service_class.instance.send(:run_callbacks, :error, team, e)
2525
case e.message
26-
when 'account_inactive', 'invalid_auth' then
27-
SlackRubyBotServer::Config.service_class.instance.logger.error "#{team.name}: #{e.message}, team will be deactivated."
28-
SlackRubyBotServer::Config.service_class.instance.deactivate! team
26+
when 'account_inactive', 'invalid_auth'
27+
if team.respond_to?(:oauth_version) && team.oauth_version != 'v1'
28+
SlackRubyBotServer::Config.service_class.instance.logger.info "#{team.name}: #{e.message}, team OAuth scope has been upgraded."
29+
else
30+
SlackRubyBotServer::Config.service_class.instance.logger.error "#{team.name}: #{e.message}, team will be deactivated."
31+
SlackRubyBotServer::Config.service_class.instance.deactivate! team
32+
end
2933
else
3034
wait = e.retry_after if e.is_a?(Slack::Web::Api::Errors::TooManyRequestsError)
3135
SlackRubyBotServer::Config.service_class.instance.logger.error "#{team.name}: #{e.message}, restarting in #{wait} second(s)."

lib/slack-ruby-bot-server-rtm/version.rb

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

33
module SlackRubyBotServer
44
module RealTime
5-
VERSION = '0.1.2'
5+
VERSION = '0.2.0'
66
end
77
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddOauthFields < ActiveRecord::Migration[5.0]
4+
def change
5+
add_column :teams, :oauth_scope, :string
6+
add_column :teams, :oauth_version, :string, default: 'v1', null: false
7+
end
8+
end

sample_apps/sample_app_activerecord/db/schema.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
# It's strongly recommended that you check this file into your version control system.
1414

15-
ActiveRecord::Schema.define(version: 20_190_323_181_453) do
15+
ActiveRecord::Schema.define(version: 20_201_125_164_500) do
1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension 'plpgsql'
1818

@@ -22,10 +22,12 @@
2222
t.boolean 'active', default: true
2323
t.string 'domain'
2424
t.string 'token'
25-
t.datetime 'created_at', null: false
26-
t.datetime 'updated_at', null: false
25+
t.datetime 'created_at', null: false
26+
t.datetime 'updated_at', null: false
2727
t.string 'bot_user_id'
2828
t.string 'activated_user_id'
2929
t.string 'activated_user_access_token'
30+
t.string 'oauth_scope'
31+
t.string 'oauth_version', default: 'v1', null: false
3032
end
3133
end

spec/database_adapters/activerecord/schema.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
t.string :bot_user_id
1414
t.string :activated_user_id
1515
t.string :activated_user_access_token
16+
t.string :oauth_scope
17+
t.string :oauth_version, default: 'v1', null: false
1618
t.boolean :active, default: true
1719
t.timestamps
1820
end

spec/slack-ruby-bot-server-rtm/lifecycle_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require 'spec_helper'
44

55
describe SlackRubyBotServer::Config do
6-
let(:team) { Fabricate(:team) }
76
context 'with defaults' do
7+
let(:team) { Fabricate(:team) }
88
let(:server) { SlackRubyBotServer::RealTime::Server.new(team: team) }
99
let(:services) { SlackRubyBotServer::Service.instance.instance_variable_get(:@services) }
1010
before do
@@ -39,6 +39,7 @@
3939
end
4040
end
4141
context 'overriding server_class' do
42+
let(:team) { Fabricate(:team) }
4243
let(:server_class) do
4344
Class.new(SlackRubyBotServer::RealTime::Server) do
4445
attr_reader :called
@@ -65,4 +66,16 @@ def initialize(options = {})
6566
SlackRubyBotServer::Service.instance.stop!(team)
6667
end
6768
end
69+
context 'v2 oauth scope' do
70+
let(:team) { Fabricate(:team, oauth_version: 'v2') }
71+
let(:server) { SlackRubyBotServer::RealTime::Server.new(team: team) }
72+
let(:services) { SlackRubyBotServer::Service.instance.instance_variable_get(:@services) }
73+
before do
74+
allow(SlackRubyBotServer::RealTime::Server).to receive(:new).with(team: team).and_return(server)
75+
end
76+
it 'does not support real-time and is ignored' do
77+
expect(server).to_not receive(:start_async)
78+
SlackRubyBotServer::Service.instance.start!(team)
79+
end
80+
end
6881
end

0 commit comments

Comments
 (0)