From ab6b68942cdaeea251535860c5b2af9ecc84236e Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 7 Oct 2020 15:21:21 +0200 Subject: [PATCH] Follow up - db3f553140ef506f8d31815ec08651187a3a6e4f - Office365 and Google channel: - Enhancement: Refresh Google and Office365 page every 30 seconds to display possible errors. - Refactoring: Removed unused method `ExternalCredentials::Office365.user_aliases`. - Fixes: Technical incompatibility between Google and Office365 causes Google view to break. - Fixes: Broken duplicate Email detection. --- .../app/controllers/_channel/google.coffee | 14 +++--- .../app/controllers/_channel/office365.coffee | 14 +++--- lib/external_credential/office365.rb | 46 ++++--------------- 3 files changed, 22 insertions(+), 52 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_channel/google.coffee b/app/assets/javascripts/app/controllers/_channel/google.coffee index 0d47a828c..31b69afe5 100644 --- a/app/assets/javascripts/app/controllers/_channel/google.coffee +++ b/app/assets/javascripts/app/controllers/_channel/google.coffee @@ -10,7 +10,7 @@ class App.ChannelGoogle extends App.ControllerTabs { name: 'Accounts', target: 'c-account', - controller: ChannelGoogleAccountOverview, + controller: ChannelAccountOverview, }, { name: 'Filter', @@ -32,7 +32,7 @@ class App.ChannelGoogle extends App.ControllerTabs @render() -class ChannelGoogleAccountOverview extends App.ControllerSubContent +class ChannelAccountOverview extends App.ControllerSubContent requiredPermission: 'admin.channel_google' events: 'click .js-new': 'new' @@ -50,7 +50,7 @@ class ChannelGoogleAccountOverview extends App.ControllerSubContent constructor: -> super - #@interval(@load, 60000) + @interval(@load, 30000) @load() load: (reset_channel_id = false) => @@ -189,7 +189,7 @@ class ChannelGoogleAccountOverview extends App.ControllerSubContent e.preventDefault() channel_id = $(e.target).closest('.action').data('id') item = App.Channel.find(channel_id) - new App.ChannelInboundEdit( + new ChannelInboundEdit( container: @el.closest('.content') item: item callback: @load @@ -220,7 +220,7 @@ class ChannelGoogleAccountOverview extends App.ControllerSubContent e.preventDefault() id = $(e.target).closest('.action').data('id') item = App.Channel.find(id) - new App.ChannelGroupEdit( + new ChannelGroupEdit( container: @el.closest('.content') item: item callback: @load @@ -261,7 +261,7 @@ class ChannelGoogleAccountOverview extends App.ControllerSubContent callback: @load ) -class App.ChannelInboundEdit extends App.ControllerModal +class ChannelInboundEdit extends App.ControllerModal buttonClose: true buttonCancel: true buttonSubmit: true @@ -321,7 +321,7 @@ class App.ChannelInboundEdit extends App.ControllerModal timeout: 6000 ) -class App.ChannelGroupEdit extends App.ControllerModal +class ChannelGroupEdit extends App.ControllerModal buttonClose: true buttonCancel: true buttonSubmit: true diff --git a/app/assets/javascripts/app/controllers/_channel/office365.coffee b/app/assets/javascripts/app/controllers/_channel/office365.coffee index 7fbb4b29a..6525c63fe 100644 --- a/app/assets/javascripts/app/controllers/_channel/office365.coffee +++ b/app/assets/javascripts/app/controllers/_channel/office365.coffee @@ -10,7 +10,7 @@ class App.ChannelOffice365 extends App.ControllerTabs { name: 'Accounts', target: 'c-account', - controller: ChannelOffice365AccountOverview, + controller: ChannelAccountOverview, }, { name: 'Filter', @@ -32,7 +32,7 @@ class App.ChannelOffice365 extends App.ControllerTabs @render() -class ChannelOffice365AccountOverview extends App.ControllerSubContent +class ChannelAccountOverview extends App.ControllerSubContent requiredPermission: 'admin.channel_office365' events: 'click .js-new': 'new' @@ -50,7 +50,7 @@ class ChannelOffice365AccountOverview extends App.ControllerSubContent constructor: -> super - #@interval(@load, 60000) + @interval(@load, 30000) @load() load: (reset_channel_id = false) => @@ -180,7 +180,7 @@ class ChannelOffice365AccountOverview extends App.ControllerSubContent e.preventDefault() channel_id = $(e.target).closest('.action').data('id') item = App.Channel.find(channel_id) - new App.ChannelInboundEdit( + new ChannelInboundEdit( container: @el.closest('.content') item: item callback: @load @@ -211,7 +211,7 @@ class ChannelOffice365AccountOverview extends App.ControllerSubContent e.preventDefault() id = $(e.target).closest('.action').data('id') item = App.Channel.find(id) - new App.ChannelGroupEdit( + new ChannelGroupEdit( container: @el.closest('.content') item: item callback: @load @@ -252,7 +252,7 @@ class ChannelOffice365AccountOverview extends App.ControllerSubContent callback: @load ) -class App.ChannelInboundEdit extends App.ControllerModal +class ChannelInboundEdit extends App.ControllerModal buttonClose: true buttonCancel: true buttonSubmit: true @@ -312,7 +312,7 @@ class App.ChannelInboundEdit extends App.ControllerModal timeout: 6000 ) -class App.ChannelGroupEdit extends App.ControllerModal +class ChannelGroupEdit extends App.ControllerModal buttonClose: true buttonCancel: true buttonSubmit: true diff --git a/lib/external_credential/office365.rb b/lib/external_credential/office365.rb index 6b86533fc..35583689e 100644 --- a/lib/external_credential/office365.rb +++ b/lib/external_credential/office365.rb @@ -107,16 +107,17 @@ class ExternalCredential::Office365 return migrate_channel end - email_addresses = user_aliases(response) - email_addresses.unshift({ - realname: "#{Setting.get('product_name')} Support", - email: user_data[:preferred_username], - }) + email_addresses = [ + { + realname: "#{Setting.get('product_name')} Support", + email: user_data[:preferred_username], + }, + ] email_addresses.each do |email| - next if !EmailAddress.exists?(email: email[:preferred_username]) + next if !EmailAddress.exists?(email: email[:email]) - raise Exceptions::UnprocessableEntity, "Duplicate email address or email alias #{email[:preferred_username]} found!" + raise Exceptions::UnprocessableEntity, "Duplicate email address or email alias #{email[:email]} found!" end # create channel @@ -226,37 +227,6 @@ class ExternalCredential::Office365 ).symbolize_keys end - def self.user_aliases(_token) - # uri = URI.parse('https://www.office365apis.com/gmail/v1/users/me/settings/sendAs') - # http = Net::HTTP.new(uri.host, uri.port) - # http.use_ssl = true - # response = http.get(uri.request_uri, { 'Authorization' => "#{token[:token_type]} #{token[:access_token]}" }) - # if response.code != 200 && response.body.blank? - # Rails.logger.error "Request failed! (code: #{response.code})" - # raise "Request failed! (code: #{response.code})" - # end - - # result = JSON.parse(response.body) - # if result['error'] && response.code != 200 - # Rails.logger.error "Request failed! ERROR: #{result['error']['message']}" - # raise "Request failed! ERROR: #{result['error']['message']}" - # end - - # aliases = [] - # result['sendAs'].each do |row| - # next if row['isPrimary'] - # next if !row['verificationStatus'] - # next if row['verificationStatus'] != 'accepted' - - # aliases.push({ - # realname: row['displayName'], - # email: row['sendAsEmail'], - # }) - # end - - [] - end - def self.user_info(id_token) split = id_token.split('.')[1] return if split.blank?