diff --git a/app/controllers/saml_controller.rb b/app/controllers/saml_controller.rb index 89aa366..7a14d6a 100644 --- a/app/controllers/saml_controller.rb +++ b/app/controllers/saml_controller.rb @@ -129,21 +129,20 @@ class SAMLController < ApplicationController def try_assign_to_slack_workspace return unless current_identity.slack_id.present? - # Check if user is already in workspace - if SlackService.user_in_workspace?(user_id: current_identity.slack_id) + case SlackService.user_workspace_status(user_id: current_identity.slack_id) + when :in_workspace current_identity.update(is_in_workspace: true) unless current_identity.is_in_workspace - return + when :not_in_workspace + scenario = current_identity.onboarding_scenario_instance + return unless scenario.slack_channels.any? + + AssignSlackWorkspaceJob.perform_later( + slack_id: current_identity.slack_id, + user_type: :multi_channel_guest, + channel_ids: scenario.slack_channels, + identity_id: current_identity.id + ) end - - scenario = current_identity.onboarding_scenario_instance - return unless scenario.slack_channels.any? - - AssignSlackWorkspaceJob.perform_later( - slack_id: current_identity.slack_id, - user_type: :multi_channel_guest, - channel_ids: scenario.slack_channels, - identity_id: current_identity.id - ) end def check_enterprise_features! diff --git a/app/services/slack_service.rb b/app/services/slack_service.rb index 6352671..51670e0 100644 --- a/app/services/slack_service.rb +++ b/app/services/slack_service.rb @@ -52,18 +52,18 @@ module SlackService false end - def user_in_workspace?(user_id:) + def user_workspace_status(user_id:) response = client.users_info(user: user_id) user = response.dig("user") - return false unless user - return false if user["deleted"] + return :unknown unless user + return :deactivated if user["deleted"] teams = user["teams"] || [] - teams.include?(team_id) + teams.include?(team_id) ? :in_workspace : :not_in_workspace rescue => e - Rails.logger.warn "Could not check if user #{user_id} is in workspace: #{e.message}" - false + Rails.logger.warn "Could not check workspace status for user #{user_id}: #{e.message}" + :unknown end end end