Class: SlackIntegration
Constant Summary
collapse
- ALL_FEATURES =
%i[commands notifications].freeze
- SCOPE_COMMANDS =
'commands'
- SCOPE_CHAT_WRITE =
'chat:write'
- SCOPE_CHAT_WRITE_PUBLIC =
'chat:write.public'
- ORGANIZATION_ALIAS =
'gitlab-organization'
- SCOPES =
[SCOPE_COMMANDS, SCOPE_CHAT_WRITE, SCOPE_CHAT_WRITE_PUBLIC].freeze
- DATABASE_ATTRIBUTES =
%w[
team_id team_name user_id bot_user_id encrypted_bot_access_token encrypted_bot_access_token_iv
].freeze
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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
#sharding_organization
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.organization_alias(organization_id) ⇒ Object
60
61
62
63
64
|
# File 'app/models/slack_integration.rb', line 60
def self.organization_alias(organization_id)
raise ArgumentError, 'organization_id must be an Integer' unless organization_id.is_a?(Integer)
[SlackIntegration::ORGANIZATION_ALIAS, organization_id].join('-')
end
|
Instance Method Details
#all_features_supported? ⇒ Boolean
83
84
85
|
# File 'app/models/slack_integration.rb', line 83
def all_features_supported?
ALL_FEATURES.all? { |feature| feature_available?(feature) } end
|
#authorized_scope_names ⇒ Object
99
100
101
|
# File 'app/models/slack_integration.rb', line 99
def authorized_scope_names
slack_api_scopes.pluck(:name)
end
|
#authorized_scope_names=(names) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/models/slack_integration.rb', line 87
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, organization_id: integration.organization_id_from_parent
)
self.slack_api_scopes = scopes
end
|
#feature_available?(feature_name) ⇒ Boolean
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/models/slack_integration.rb', line 66
def feature_available?(feature_name)
case feature_name
when :commands
true
when :notifications
scoped_to?(SCOPE_CHAT_WRITE, SCOPE_CHAT_WRITE_PUBLIC)
else
false
end
end
|
#to_database_hash ⇒ Object
103
104
105
|
# File 'app/models/slack_integration.rb', line 103
def to_database_hash
attributes_for_database.slice(*DATABASE_ATTRIBUTES)
end
|
#upgrade_needed? ⇒ Boolean
79
80
81
|
# File 'app/models/slack_integration.rb', line 79
def upgrade_needed?
!all_features_supported?
end
|