Last active
February 2, 2025 04:26
-
-
Save mkaschenko/bbe586c28a14138b11ea5e96e409cbb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This module runs a full profile sync for a specific user, depending on which | |
| # integrations are enabled. It supports all existing transcript and assignment | |
| # integrations. | |
| module UserProfileSyncs | |
| def self.sync(company, user) | |
| integrations = IntegrationsDispatcher.history_integrations + | |
| IntegrationsDispatcher.assignment_integrations | |
| integrations = IntegrationsDispatcher.select_enabled(integrations, company, user) | |
| integrations = IntegrationsDispatcher.dispatch(integrations, company, user) | |
| IntegrationsDispatcher.humanize(integrations) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| # This module accumulates knowledge about: | |
| # - types of integrations, | |
| # - ways to check if integrations are enabled, | |
| # - ways to dispatch integrations. | |
| module IntegrationsDispatcher | |
| module IntegrationTypes | |
| HISTORY = 'history' | |
| ASSIGNMENT = 'assignment' | |
| end | |
| def self.history_integrations | |
| [{ name: Constants::Providers::ABSORB, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_company?), | |
| dispatch: method(:dispatch_history_integration) }, | |
| { name: Constants::Providers::CIRCUS_STREET, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_company?), | |
| dispatch: method(:dispatch_history_integration_for_circus_street) }, | |
| { name: Constants::Providers::CORNERSTONE, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_user?), | |
| dispatch: method(:dispatch_history_integration) }, | |
| { name: Constants::Providers::SABA, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_company?), | |
| dispatch: method(:dispatch_history_integration) }, | |
| { name: Constants::Providers::SUCCESSFACTORS, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_user?), | |
| dispatch: method(:dispatch_history_integration) }, | |
| { name: Constants::Providers::SUMTOTAL, | |
| type: IntegrationTypes::HISTORY, | |
| enabled: method(:enabled_history_integration_for_company?), | |
| dispatch: method(:dispatch_history_integration) }] | |
| end | |
| def self.assignment_integrations | |
| [{ name: Constants::Providers::SUCCESSFACTORS, | |
| type: IntegrationTypes::ASSIGNMENT, | |
| enabled: method(:enabled_assignment_integration?), | |
| dispatch: method(:dispatch_assignment_integration) }] | |
| end | |
| def self.select_enabled(integrations, company, user) | |
| integrations.select do |integration| | |
| integration.fetch(:enabled).call(integration, company, user) | |
| end | |
| end | |
| def self.dispatch(integrations, company, user) | |
| integrations.each do |integration| | |
| integration.fetch(:dispatch).call(integration, company, user) | |
| end | |
| end | |
| def self.humanize(integrations) | |
| integrations.map { |integration| integration.slice(:name, :type) } | |
| end | |
| ### | |
| ### Here are different ways to check if integrations are enabled | |
| ### | |
| def self.enabled_history_integration_for_company?(integration, company, _user) | |
| company.integration_enabled_for_verified_learning?(integration.fetch(:name)) | |
| end | |
| def self.enabled_history_integration_for_user?(integration, _company, user) | |
| # TODO: Should we also evaluate this condition here? | |
| # https://github.com/pathgather/pathgather/blob/master/app/workers/recurring_learning_history_import_worker.rb#L33-L34 | |
| user.integration_enabled_for_verified_learning?(integration.fetch(:name)) | |
| end | |
| def self.enabled_assignment_integration?(integration, company, _user) | |
| # TODO: Should we also evaluate this condition here? | |
| # https://github.com/pathgather/pathgather/blob/master/app/workers/recurring_successfactors_assignments_import_worker.rb#L14-L15 | |
| company.integration_enabled_for_assignments?(integration.fetch(:name)) | |
| end | |
| ### | |
| ### Here are different ways to dispatch integrations | |
| ### | |
| def self.dispatch_history_integration(integration, company, user) | |
| LearningHistoryImportWorker.perform_async( | |
| company.schema_name, integration.fetch(:name), user.id | |
| ) | |
| end | |
| # https://github.com/Pathgather/pathgather/pull/989#discussion_r194556635 | |
| def self.dispatch_history_integration_for_circus_street(integration, company, _user) | |
| LearningHistoryImportWorker.perform_async( | |
| company.schema_name, integration.fetch(:name) | |
| ) | |
| end | |
| # TODO: There is only one assignment integration at the moment, for Successfactors. | |
| # Because of that, work with it as the general one. If more integrations come, | |
| # names 'dispatch_assignment_*' should be reconsider. | |
| def self.dispatch_assignment_integration(_integration, company, user) | |
| SuccessfactorsAssignmentsImportWorker.perform_async(company.schema_name, user.id) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment