Class: SlackIntegration

Inherits:
ApplicationRecord show all
Includes:
EachBatch
Defined in:
app/models/slack_integration.rb

Constant Summary collapse

ALL_FEATURES =
%i[commands notifications].freeze
SCOPE_COMMANDS =
'commands'
SCOPE_CHAT_WRITE =
'chat:write'
SCOPE_CHAT_WRITE_PUBLIC =
'chat:write.public'
SCOPES =

These scopes are requested when installing the app, additional scopes will need reauthorization. api.slack.com/authentication/oauth-v2#asking

[SCOPE_COMMANDS, SCOPE_CHAT_WRITE, SCOPE_CHAT_WRITE_PUBLIC].freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance 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

Instance Method Details

#all_features_supported?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/slack_integration.rb', line 67

def all_features_supported?
  ALL_FEATURES.all? { |feature| feature_available?(feature) } # rubocop: disable Gitlab/FeatureAvailableUsage
end

#authorized_scope_namesObject



78
79
80
# File 'app/models/slack_integration.rb', line 78

def authorized_scope_names
  slack_api_scopes.pluck(:name)
end

#authorized_scope_names=(names) ⇒ Object



71
72
73
74
75
76
# File 'app/models/slack_integration.rb', line 71

def authorized_scope_names=(names)
  names = Array.wrap(names).flat_map { |name| name.split(',') }.map(&:strip)

  scopes = ::Integrations::SlackWorkspace::ApiScope.find_or_initialize_by_names(names)
  self.slack_api_scopes = scopes
end

#feature_available?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/slack_integration.rb', line 50

def feature_available?(feature_name)
  case feature_name
  when :commands
    # The slash commands feature requires 'commands' scope.
    # All records will support this scope, as this was the original feature.
    true
  when :notifications
    scoped_to?(SCOPE_CHAT_WRITE, SCOPE_CHAT_WRITE_PUBLIC)
  else
    false
  end
end

#update_active_status_of_integrationObject



46
47
48
# File 'app/models/slack_integration.rb', line 46

def update_active_status_of_integration
  integration.update_active_status
end

#upgrade_needed?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/slack_integration.rb', line 63

def upgrade_needed?
  !all_features_supported?
end