From b8c237ca58abd1915e3f6f88e840f91d54185696 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Sun, 2 Jun 2024 19:41:40 +0530 Subject: [PATCH] feat: add scope to cache key --- .../v1/accounts/microsoft/authorizations_controller.rb | 4 ++-- app/controllers/oauth_callback_controller.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/accounts/microsoft/authorizations_controller.rb b/app/controllers/api/v1/accounts/microsoft/authorizations_controller.rb index bee47b213..df563094a 100644 --- a/app/controllers/api/v1/accounts/microsoft/authorizations_controller.rb +++ b/app/controllers/api/v1/accounts/microsoft/authorizations_controller.rb @@ -12,8 +12,8 @@ class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts } ) if redirect_url - email = email.downcase - ::Redis::Alfred.setex(email, Current.account.id, 5.minutes) + cache_key = "microsoft::#{email.downcase}" + ::Redis::Alfred.setex(cache_key, Current.account.id, 5.minutes) render json: { success: true, url: redirect_url } else render json: { success: false }, status: :unprocessable_entity diff --git a/app/controllers/oauth_callback_controller.rb b/app/controllers/oauth_callback_controller.rb index fe5782f93..309160f1f 100644 --- a/app/controllers/oauth_callback_controller.rb +++ b/app/controllers/oauth_callback_controller.rb @@ -6,7 +6,7 @@ class OauthCallbackController < ApplicationController ) handle_response - ::Redis::Alfred.delete(users_data['email'].downcase) + ::Redis::Alfred.delete(cache_key) rescue StandardError => e ChatwootExceptionTracker.new(e).capture_exception redirect_to '/' @@ -60,6 +60,10 @@ class OauthCallbackController < ApplicationController raise NotImplementedError end + def cache_key + "#{provider_name}::#{users_data['email'].downcase}" + end + def create_channel_with_inbox ActiveRecord::Base.transaction do channel_email = Channel::Email.create!(email: users_data['email'], account: account) @@ -78,7 +82,7 @@ class OauthCallbackController < ApplicationController end def account_id - ::Redis::Alfred.get(users_data['email'].downcase) + ::Redis::Alfred.get(cache_key) end def account