Skip to content

Commit 130ef06

Browse files
authored
Merge pull request #749 from code0-tech/748-add-urls-to-application-settings
Add urls to application settings
2 parents 76c8e69 + d3edc06 commit 130ef06

File tree

12 files changed

+136
-7
lines changed

12 files changed

+136
-7
lines changed

app/graphql/types/application_settings_type.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ class ApplicationSettingsType < Types::BaseObject
1717
null: false,
1818
description: 'Shows if admin status can be queried by non-administrators'
1919

20+
field :terms_and_conditions_url, String,
21+
null: true,
22+
description: 'URL to the terms and conditions page'
23+
24+
field :privacy_url, String,
25+
null: true,
26+
description: 'URL to the privacy policy page'
27+
28+
field :legal_notice_url, String,
29+
null: true,
30+
description: 'URL to the legal notice page'
31+
2032
field :identity_providers, Types::IdentityProviderType.connection_type,
2133
null: false,
2234
description: 'List of configured identity providers'

app/graphql/types/application_type.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ class ApplicationType < Types::BaseObject
1010
field :settings, Types::ApplicationSettingsType, null: true,
1111
description: 'Global application settings'
1212

13+
field :privacy_url, String,
14+
null: true,
15+
description: 'URL to the privacy policy page'
16+
17+
field :terms_and_conditions_url, String,
18+
null: true,
19+
description: 'URL to the terms and conditions page'
20+
21+
field :legal_notice_url, String,
22+
null: true,
23+
description: 'URL to the legal notice page'
24+
1325
expose_abilities %i[
1426
create_organization
1527
create_runtime
@@ -26,5 +38,17 @@ def metadata
2638
def settings
2739
ApplicationSetting.current
2840
end
41+
42+
def privacy_url
43+
ApplicationSetting.current.privacy_url
44+
end
45+
46+
def terms_and_conditions_url
47+
ApplicationSetting.current.terms_and_conditions_url
48+
end
49+
50+
def legal_notice_url
51+
ApplicationSetting.current.legal_notice_url
52+
end
2953
end
3054
end

app/models/application_setting.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ class ApplicationSetting < ApplicationRecord
1212
organization_creation_restricted: 2,
1313
identity_providers: 3,
1414
admin_status_visible: 4,
15+
terms_and_conditions_url: 5,
16+
privacy_url: 6,
17+
legal_notice_url: 7,
1518
}.with_indifferent_access
1619

1720
BOOLEAN_OPTIONS = %i[user_registration_enabled organization_creation_restricted admin_status_visible].freeze
21+
URL_OPTIONS = %i[terms_and_conditions_url privacy_url legal_notice_url].freeze
1822

1923
enum :setting, SETTINGS
2024

@@ -31,7 +35,17 @@ class ApplicationSetting < ApplicationRecord
3135
validates :value, inclusion: { in: [false, true] }, if: :"#{option}?"
3236
end
3337

38+
URL_OPTIONS.each do |option|
39+
validates :value,
40+
length: { maximum: 2048 },
41+
format: URI::DEFAULT_PARSER.make_regexp(%w[http https]),
42+
allow_nil: true,
43+
if: :"#{option}?"
44+
end
45+
3446
def validate_value
47+
return if URL_OPTIONS.map(&:to_s).include?(setting) && value.nil?
48+
3549
errors.add(:value, :blank) if value.nil?
3650
end
3751

db/fixtures/01_application_settings.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@
1919
s.setting = :admin_status_visible
2020
s.value = true
2121
end
22+
23+
ApplicationSetting.seed_once :setting do |s|
24+
s.setting = :terms_and_conditions_url
25+
s.value = nil
26+
end
27+
28+
ApplicationSetting.seed_once :setting do |s|
29+
s.setting = :privacy_url
30+
s.value = nil
31+
end
32+
33+
ApplicationSetting.seed_once :setting do |s|
34+
s.setting = :legal_notice_url
35+
s.value = nil
36+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AllowNullValueInApplicationSettings < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
change_column_null :application_settings, :value, true
6+
end
7+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
787d8a891ddc9e2e8292c54595ed167491cc7a58b493c946edc0684b9977094b

db/structure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ALTER SEQUENCE active_storage_variant_records_id_seq OWNED BY active_storage_var
5959
CREATE TABLE application_settings (
6060
id bigint NOT NULL,
6161
setting integer NOT NULL,
62-
value jsonb NOT NULL,
62+
value jsonb,
6363
created_at timestamp with time zone NOT NULL,
6464
updated_at timestamp with time zone NOT NULL
6565
);

docs/graphql/object/application.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Represents the application instance
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11+
| `legalNoticeUrl` | [`String`](../scalar/string.md) | URL to the legal notice page |
1112
| `metadata` | [`Metadata!`](../object/metadata.md) | Metadata about the application |
13+
| `privacyUrl` | [`String`](../scalar/string.md) | URL to the privacy policy page |
1214
| `settings` | [`ApplicationSettings`](../object/applicationsettings.md) | Global application settings |
15+
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | URL to the terms and conditions page |
1316
| `userAbilities` | [`ApplicationUserAbilities!`](../object/applicationuserabilities.md) | Abilities for the current user on this Application |
1417

docs/graphql/object/applicationsettings.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Represents the application settings
1010
|------|------|-------------|
1111
| `adminStatusVisible` | [`Boolean!`](../scalar/boolean.md) | Shows if admin status can be queried by non-administrators |
1212
| `identityProviders` | [`IdentityProviderConnection!`](../object/identityproviderconnection.md) | List of configured identity providers |
13+
| `legalNoticeUrl` | [`String`](../scalar/string.md) | URL to the legal notice page |
1314
| `organizationCreationRestricted` | [`Boolean!`](../scalar/boolean.md) | Shows if organization creation is restricted to administrators |
15+
| `privacyUrl` | [`String`](../scalar/string.md) | URL to the privacy policy page |
16+
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | URL to the terms and conditions page |
1417
| `userRegistrationEnabled` | [`Boolean!`](../scalar/boolean.md) | Shows if user registration is enabled |
1518

spec/graphql/types/application_settings_type_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
organizationCreationRestricted
1010
identityProviders
1111
adminStatusVisible
12+
termsAndConditionsUrl
13+
privacyUrl
14+
legalNoticeUrl
1215
]
1316
end
1417

0 commit comments

Comments
 (0)