From 3a497b436d25d3a7738562655cda64b180ae0096 Mon Sep 17 00:00:00 2001 From: dblock Date: Sun, 20 Aug 2017 14:30:56 -0400 Subject: [PATCH] Ask for users.profile:read. --- .rubocop_todo.yml | 14 +++++++------- public/index.html.erb | 2 +- slack-sup/api/endpoints/teams_endpoint.rb | 8 ++++++-- slack-sup/models/team.rb | 3 +++ spec/integration/teams_spec.rb | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 524636b..4ce53c8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-08-19 19:16:02 -0400 using RuboCop version 0.49.1. +# on 2017-08-20 14:29:34 -0400 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -19,11 +19,11 @@ Lint/EndAlignment: Exclude: - 'slack-sup/models/team.rb' -# Offense count: 13 +# Offense count: 14 Metrics/AbcSize: Max: 40 -# Offense count: 49 +# Offense count: 52 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 162 @@ -31,19 +31,19 @@ Metrics/BlockLength: # Offense count: 1 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 125 + Max: 126 # Offense count: 5 Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 215 +# Offense count: 244 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 256 -# Offense count: 10 +# Offense count: 11 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 31 @@ -52,7 +52,7 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 11 -# Offense count: 31 +# Offense count: 40 Style/Documentation: Enabled: false diff --git a/public/index.html.erb b/public/index.html.erb index c97ad99..58af6a5 100644 --- a/public/index.html.erb +++ b/public/index.html.erb @@ -65,7 +65,7 @@
- Add S'Up to Slack + Add S'Up to Slack

Try free for two weeks, no credit card required, $39.99/yr subscription after that. diff --git a/slack-sup/api/endpoints/teams_endpoint.rb b/slack-sup/api/endpoints/teams_endpoint.rb index 95d4085..8d9e220 100644 --- a/slack-sup/api/endpoints/teams_endpoint.rb +++ b/slack-sup/api/endpoints/teams_endpoint.rb @@ -44,16 +44,20 @@ class TeamsEndpoint < Grape::API code: params[:code] ) + access_token = rc['access_token'] + team = Team.where(access_token: access_token).first + token = rc['bot']['bot_access_token'] - team = Team.where(token: token).first + team ||= Team.where(token: token).first team ||= Team.where(team_id: rc['team_id']).first if team && !team.active? - team.activate!(token) + team.update_attributes!(active: true, token: token, access_token: access_token) elsif team raise "Team #{team.name} is already registered." else team = Team.create!( token: token, + access_token: access_token, team_id: rc['team_id'], name: rc['team_name'] ) diff --git a/slack-sup/models/team.rb b/slack-sup/models/team.rb index 915afce..d60ea22 100644 --- a/slack-sup/models/team.rb +++ b/slack-sup/models/team.rb @@ -1,4 +1,7 @@ class Team + # non-bot access token + field :access_token, type: String + # enable API for this team field :api, type: Boolean, default: false diff --git a/spec/integration/teams_spec.rb b/spec/integration/teams_spec.rb index f527100..cadb70f 100644 --- a/spec/integration/teams_spec.rb +++ b/spec/integration/teams_spec.rb @@ -30,7 +30,7 @@ expect(title).to eq("S'Up for Slack Teams") end it 'includes a link to add to slack with the client id' do - expect(find("a[href='https://slack.com/oauth/authorize?scope=bot&client_id=#{ENV['SLACK_CLIENT_ID']}']")) + expect(find("a[href='https://slack.com/oauth/authorize?scope=bot,users.profile:read&client_id=#{ENV['SLACK_CLIENT_ID']}']")) end end end