Class: Integrations::SlackWorkspace::IntegrationApiScope

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/integrations/slack_workspace/integration_api_scope.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.update_scopes(integration_ids, scopes) ⇒ Object

Efficient scope propagation



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/integrations/slack_workspace/integration_api_scope.rb', line 12

def self.update_scopes(integration_ids, scopes)
  return if integration_ids.empty?

  scope_ids = scopes.pluck(:id)

  attrs = scope_ids.flat_map do |scope_id|
    integration_ids.map { |si_id| { slack_integration_id: si_id, slack_api_scope_id: scope_id } }
  end

  # We don't know which ones to preserve - so just delete them all in a single query
  transaction do
    where(slack_integration_id: integration_ids).delete_all
    insert_all(attrs) unless attrs.empty?
  end
end