summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-03-28 22:33:51 +0100
committerGravatar √Čtienne Deparis 2020-03-28 22:33:51 +0100
commitea13f3004f0f06e75552961d37ca9fcb24d20d6a (patch)
tree9e285619795517179f93ad458d711c293648c89c
parentf27fa9239e89bfe96fe140b419eedfb12fdd003a (diff)
downloadstatus-ea13f3004f0f06e75552961d37ca9fcb24d20d6a.tar.gz
status-ea13f3004f0f06e75552961d37ca9fcb24d20d6a.tar.xz
status-ea13f3004f0f06e75552961d37ca9fcb24d20d6a.zip
feat: Allow registration from mattermost
With the email attached to the mattermost useraccount
-rw-r--r--lib/mattermost_helper.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/mattermost_helper.rb b/lib/mattermost_helper.rb
index 5c16663..5868a3b 100644
--- a/lib/mattermost_helper.rb
+++ b/lib/mattermost_helper.rb
@@ -51,8 +51,7 @@ module MattermostHelper # rubocop:disable Metrics/ModuleLength
rescue JSON::ParserError
warn "Wrong data received: #{data.inspect}"
end
- { 'mattermost_uid' => data.dig('id'),
- 'handle' => data.dig('username') }
+ data
end
def mattermost_user_id
@@ -64,7 +63,9 @@ module MattermostHelper # rubocop:disable Metrics/ModuleLength
end
data = mattermost_fetch_user_data(req)
return nil unless data
- update_status(data, @current_status['email'])
+ update_status({ 'mattermost_uid' => data.dig('id'),
+ 'handle' => data.dig('username') },
+ @current_status['email'])
data['mattermost_uid']
end
@@ -100,11 +101,32 @@ module MattermostHelper # rubocop:disable Metrics/ModuleLength
mattermost_run_curl(curl_cmd)
end
- def find_status_for_mattermost(username)
- row = fetch_status('handle' => username)
- return nil unless row
+ def create_or_update_status_for_mattermost(username)
+ data = mattermost_fetch_user_data('/users/username/' + username)
+ return nil unless data
+ email = data.dig('email')
+ return nil unless email
+ row = fetch_status('email' => email)
+ unless row
+ generate_and_send_new_token(email)
+ row = fetch_status('email' => email)
+ end
@details = row['details']
@current_status = row
+ update_status({ 'mattermost_uid' => data.dig('id'),
+ 'handle' => username },
+ email)
+ @current_status
+ end
+
+ def find_status_for_mattermost(username)
+ row = fetch_status('handle' => username)
+ if row
+ @details = row['details']
+ @current_status = row
+ return @current_status
+ end
+ create_or_update_status_for_mattermost(username)
end
def parse_mattermost_text(text)