summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-16 13:43:01 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-12-17 10:32:06 +0100
commitc9610e0a052526adb3138dccf6114d710979a0b7 (patch)
tree2c9c722e8a989e38b36e9e9c9eef12cc9b0e2e76
parente663725961de66ac838d0a5a85978656938e74f4 (diff)
downloadgitlab-ce-zj-mattermost-session.tar.gz
Fix rubocop failureszj-mattermost-session
-rw-r--r--config/initializers/1_settings.rb4
-rw-r--r--lib/mattermost/session.rb36
2 files changed, 23 insertions, 17 deletions
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb
index 45404e579ae..ddea325c6ca 100644
--- a/config/initializers/1_settings.rb
+++ b/config/initializers/1_settings.rb
@@ -265,8 +265,8 @@ Settings.lfs['storage_path'] = File.expand_path(Settings.lfs['storage_path'] ||
# Mattermost
#
Settings['mattermost'] ||= Settingslogic.new({})
-Settings.mattermost['enabled'] = false if Settings.mattermost['enabled'].nil?
-Settings.mattermost['host'] = nil unless Settings.mattermost.enabled
+Settings.mattermost['enabled'] = false if Settings.mattermost['enabled'].nil?
+Settings.mattermost['host'] = nil unless Settings.mattermost.enabled
#
# Gravatar
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index a3715bed482..fb8d7d97f8a 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -54,7 +54,15 @@ module Mattermost
end
def params
- Rack::Utils.parse_query(@oauth_uri.query).symbolize_keys
+ Rack::Utils.parse_query(oauth_uri.query).symbolize_keys
+ end
+
+ def get(path, options = {})
+ self.class.get(path, options.merge(headers: @headers))
+ end
+
+ def post(path, options = {})
+ self.class.post(path, options.merge(headers: @headers))
end
private
@@ -63,11 +71,12 @@ module Mattermost
return unless oauth_uri
return unless token_uri
- self.token = request_token
+ @token = request_token
@headers = {
- "Authorization": "Bearer #{self.token}"
+ Authorization: "Bearer #{@token}"
}
- self.token
+
+ @token
end
def destroy
@@ -75,35 +84,32 @@ module Mattermost
end
def oauth_uri
+ return @oauth_uri if defined?(@oauth_uri)
+
+ @oauth_uri = nil
+
response = get("/api/v3/oauth/gitlab/login", follow_redirects: false)
return unless 300 <= response.code && response.code < 400
redirect_uri = response.headers['location']
return unless redirect_uri
- @oauth_uri ||= URI.parse(redirect_uri)
+ @oauth_uri = URI.parse(redirect_uri)
end
def token_uri
@token_uri ||=
- if @oauth_uri
+ if oauth_uri
authorization.authorize.redirect_uri if pre_auth.authorizable?
end
end
def request_token
- response = get(@token_uri, follow_redirects: false)
+ response = get(token_uri, follow_redirects: false)
+
if 200 <= response.code && response.code < 400
response.headers['token']
end
end
-
- def get(path, options = {})
- self.class.get(path, options.merge(headers: @headers))
- end
-
- def post(path, options = {})
- self.class.post(path, options.merge(headers: @headers))
- end
end
end