Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/graphql/mutations/application_settings/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Update < BaseMutation
argument :privacy_url, String,
required: false,
description: 'Set the URL to the privacy policy page.'
argument :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int,
required: false,
description: 'Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat'
argument :terms_and_conditions_url, String,
required: false,
description: 'Set the URL to the terms and conditions page.'
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types/application_settings_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ class ApplicationSettingsType < Types::BaseObject
field :identity_providers, Types::IdentityProviderType.connection_type,
null: false,
description: 'List of configured identity providers'

field :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int,
null: false,
description: 'The maximum amount of minutes a runtime is shown as connected after the last heartbeat'
end
end
3 changes: 2 additions & 1 deletion app/graphql/types/runtime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class RuntimeType < Types::BaseObject
def status
last_heartbeat = object.last_heartbeat

if last_heartbeat && last_heartbeat >= 10.minutes.ago
max_heartbeat_interval = ApplicationSetting.current[:runtime_max_heartbeat_interval_minutes]
if last_heartbeat && last_heartbeat >= max_heartbeat_interval.minutes.ago
:connected
else
:disconnected
Expand Down
6 changes: 6 additions & 0 deletions app/models/application_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class MissingApplicationSettings < StandardError
terms_and_conditions_url: 5,
privacy_url: 6,
legal_notice_url: 7,
runtime_max_heartbeat_interval_minutes: 8,
}.with_indifferent_access

BOOLEAN_OPTIONS = %i[user_registration_enabled organization_creation_restricted admin_status_visible].freeze
URL_OPTIONS = %i[terms_and_conditions_url privacy_url legal_notice_url].freeze
NUMBER_OPTIONS = %i[runtime_max_heartbeat_interval_minutes].freeze

enum :setting, SETTINGS

Expand All @@ -46,6 +48,10 @@ class MissingApplicationSettings < StandardError
if: :"#{option}?"
end

NUMBER_OPTIONS.each do |option|
validates :value, numericality: true, if: :"#{option}?"
end

def validate_value
return if URL_OPTIONS.map(&:to_s).include?(setting) && value.nil?

Expand Down
5 changes: 5 additions & 0 deletions db/fixtures/01_application_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
s.setting = :legal_notice_url
s.value = nil
end

ApplicationSetting.seed_once :setting do |s|
s.setting = :runtime_max_heartbeat_interval_minutes
s.value = 10
end
1 change: 1 addition & 0 deletions docs/graphql/mutation/applicationsettingsupdate.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Update application settings.
| `legalNoticeUrl` | [`String`](../scalar/string.md) | Set the URL to the legal notice page. |
| `organizationCreationRestricted` | [`Boolean`](../scalar/boolean.md) | Set if organization creation is restricted to administrators. |
| `privacyUrl` | [`String`](../scalar/string.md) | Set the URL to the privacy policy page. |
| `runtimeMaxHeartbeatIntervalMinutes` | [`Int`](../scalar/int.md) | Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat |
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | Set the URL to the terms and conditions page. |
| `userRegistrationEnabled` | [`Boolean`](../scalar/boolean.md) | Set if user registration is enabled. |

Expand Down
1 change: 1 addition & 0 deletions docs/graphql/object/applicationsettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Represents the application settings
| `legalNoticeUrl` | [`String`](../scalar/string.md) | URL to the legal notice page |
| `organizationCreationRestricted` | [`Boolean!`](../scalar/boolean.md) | Shows if organization creation is restricted to administrators |
| `privacyUrl` | [`String`](../scalar/string.md) | URL to the privacy policy page |
| `runtimeMaxHeartbeatIntervalMinutes` | [`Int!`](../scalar/int.md) | The maximum amount of minutes a runtime is shown as connected after the last heartbeat |
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | URL to the terms and conditions page |
| `userRegistrationEnabled` | [`Boolean!`](../scalar/boolean.md) | Shows if user registration is enabled |
1 change: 1 addition & 0 deletions spec/graphql/types/application_settings_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
termsAndConditionsUrl
privacyUrl
legalNoticeUrl
runtimeMaxHeartbeatIntervalMinutes
]
end

Expand Down