File tree Expand file tree Collapse file tree 5 files changed +34
-1
lines changed
lib/slack-ruby-bot-server Expand file tree Collapse file tree 5 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11# This configuration was generated by
22# `rubocop --auto-gen-config`
3- # on 2020-06-16 16:54:39 -0400 using RuboCop version 0.81.0.
3+ # on 2020-07-17 08:36:05 -0400 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
Original file line number Diff line number Diff line change 22
33#### 0.12.3 (Next)
44
5+ * [ #123 ] ( https://github.com/slack-ruby/slack-ruby-bot-server/pull/123 ) : Reactivate a team that was disabled from Slack - [ @dblock ] ( https://github.com/dblock ) .
56* Your contribution here.
67
78#### 0.12.2 (2020/7/26)
Original file line number Diff line number Diff line change @@ -54,11 +54,14 @@ class TeamsEndpoint < Grape::API
5454 team ||= Team . where ( team_id : rc [ 'team_id' ] ) . first
5555
5656 if team
57+ team . ping_if_active!
58+
5759 team . update_attributes! (
5860 activated_user_id : user_id ,
5961 activated_user_access_token : access_token ,
6062 bot_user_id : bot_user_id
6163 )
64+
6265 raise "Team #{ team . name } is already registered." if team . active?
6366
6467 team . activate! ( token )
Original file line number Diff line number Diff line change @@ -38,5 +38,17 @@ def ping!
3838 presence : client . users_getPresence ( user : auth [ 'user_id' ] )
3939 }
4040 end
41+
42+ def ping_if_active!
43+ return unless active?
44+
45+ ping!
46+ rescue Slack ::Web ::Api ::Errors ::SlackError => e
47+ logger . warn "Active team #{ self } ping, #{ e . message } ."
48+ case e . message
49+ when 'account_inactive' , 'invalid_auth'
50+ deactivate!
51+ end
52+ end
4153 end
4254end
Original file line number Diff line number Diff line change 106106 expect ( team . bot_user_id ) . to eq 'bot_user_id'
107107 end . to_not change ( Team , :count )
108108 end
109+ it 'reactivates a team deactivated on slack' do
110+ expect ( SlackRubyBotServer ::Service . instance ) . to receive ( :start! )
111+ existing_team = Fabricate ( :team , token : 'token' )
112+ expect do
113+ expect_any_instance_of ( Team ) . to receive ( :ping! ) { raise Slack ::Web ::Api ::Errors ::SlackError , 'invalid_auth' }
114+ team = client . teams . _post ( code : 'code' )
115+ expect ( team . team_id ) . to eq existing_team . team_id
116+ expect ( team . name ) . to eq existing_team . name
117+ expect ( team . active ) . to be true
118+ team = Team . find ( team . id )
119+ expect ( team . token ) . to eq 'token'
120+ expect ( team . active ) . to be true
121+ expect ( team . bot_user_id ) . to eq 'bot_user_id'
122+ expect ( team . activated_user_id ) . to eq 'user_id'
123+ end . to_not change ( Team , :count )
124+ end
109125 it 'returns a useful error when team already exists' do
126+ expect_any_instance_of ( Team ) . to receive ( :ping_if_active! )
110127 existing_team = Fabricate ( :team , token : 'token' )
111128 expect { client . teams . _post ( code : 'code' ) } . to raise_error Faraday ::ClientError do |e |
112129 json = JSON . parse ( e . response [ :body ] )
You can’t perform that action at this time.
0 commit comments