Skip to content

Commit feff6a0

Browse files
authored
Merge Config and Settings type (#231)
1 parent e6a084d commit feff6a0

File tree

3 files changed

+50
-65
lines changed

3 files changed

+50
-65
lines changed

app.go

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,47 @@ import (
77
)
88

99
type AppSettings struct {
10-
DisableAuth *bool `json:"disable_auth_checks,omitempty"`
11-
DisablePermissions *bool `json:"disable_permissions_checks,omitempty"`
12-
APNConfig *APNConfig `json:"apn_config,omitempty"`
13-
FirebaseConfig *FirebaseConfigRequest `json:"firebase_config,omitempty"`
14-
XiaomiConfig *XiaomiConfigRequest `json:"xiaomi_config,omitempty"`
15-
HuaweiConfig *HuaweiConfigRequest `json:"huawei_config,omitempty"`
16-
PushConfig *PushConfigRequest `json:"push_config,omitempty"`
17-
WebhookURL *string `json:"webhook_url,omitempty"`
18-
MultiTenantEnabled *bool `json:"multi_tenant_enabled,omitempty"`
19-
AsyncURLEnrichEnabled *bool `json:"async_url_enrich_enabled,omitempty"`
20-
AutoTranslationEnabled *bool `json:"auto_translation_enabled,omitempty"`
21-
Grants map[string][]string `json:"grants,omitempty"`
22-
MigratePermissionsToV2 *bool `json:"migrate_permissions_to_v2,omitempty"`
23-
PermissionVersion *string `json:"permission_version,omitempty"`
24-
FileUploadConfig *FileUploadConfig `json:"file_upload_config,omitempty"`
25-
ImageUploadConfig *FileUploadConfig `json:"image_upload_config,omitempty"`
26-
ImageModerationLabels []string `json:"image_moderation_labels,omitempty"`
27-
ImageModerationEnabled *bool `json:"image_moderation_enabled,omitempty"`
28-
RemindersInterval int `json:"reminders_interval,omitempty"`
29-
BeforeMessageSendHookURL *string `json:"before_message_send_hook_url,omitempty"`
30-
CustomActionHandlerURL *string `json:"custom_action_handler_url,omitempty"`
31-
UserSearchDisallowedRoles []string `json:"user_search_disallowed_roles,omitempty"`
32-
EnforceUniqueUsernames *string `json:"enforce_unique_usernames,omitempty"`
33-
SqsURL *string `json:"sqs_url,omitempty"`
34-
SqsKey *string `json:"sqs_key,omitempty"`
35-
SqsSecret *string `json:"sqs_secret,omitempty"`
36-
WebhookEvents []string `json:"webhook_events,omitempty"`
37-
ChannelHideMembersOnly *bool `json:"channel_hide_members_only,omitempty"`
10+
Name string `json:"name"`
11+
OrganizationName string `json:"organization"`
12+
Suspended bool `json:"suspended"`
13+
SuspendedExplanation string `json:"suspended_explanation"`
14+
ConfigNameMap map[string]*ChannelConfig `json:"channel_configs"`
15+
RevokeTokensIssuedBefore *time.Time `json:"revoke_tokens_issued_before"`
16+
17+
DisableAuth *bool `json:"disable_auth_checks,omitempty"`
18+
DisablePermissions *bool `json:"disable_permissions_checks,omitempty"`
19+
20+
PushNotifications PushNotificationFields `json:"push_notifications"`
21+
PushConfig *PushConfigRequest `json:"push_config,omitempty"`
22+
APNConfig *APNConfig `json:"apn_config,omitempty"`
23+
FirebaseConfig *FirebaseConfigRequest `json:"firebase_config,omitempty"`
24+
XiaomiConfig *XiaomiConfigRequest `json:"xiaomi_config,omitempty"`
25+
HuaweiConfig *HuaweiConfigRequest `json:"huawei_config,omitempty"`
26+
WebhookURL *string `json:"webhook_url,omitempty"`
27+
WebhookEvents []string `json:"webhook_events,omitempty"`
28+
SqsURL *string `json:"sqs_url,omitempty"`
29+
SqsKey *string `json:"sqs_key,omitempty"`
30+
SqsSecret *string `json:"sqs_secret,omitempty"`
31+
BeforeMessageSendHookURL *string `json:"before_message_send_hook_url,omitempty"`
32+
CustomActionHandlerURL *string `json:"custom_action_handler_url,omitempty"`
33+
34+
FileUploadConfig *FileUploadConfig `json:"file_upload_config,omitempty"`
35+
ImageUploadConfig *FileUploadConfig `json:"image_upload_config,omitempty"`
36+
ImageModerationLabels []string `json:"image_moderation_labels,omitempty"`
37+
ImageModerationEnabled *bool `json:"image_moderation_enabled,omitempty"`
38+
39+
PermissionVersion *string `json:"permission_version,omitempty"`
40+
MigratePermissionsToV2 *bool `json:"migrate_permissions_to_v2,omitempty"`
41+
Policies map[string][]Policy `json:"policies"`
42+
Grants map[string][]string `json:"grants,omitempty"`
43+
44+
MultiTenantEnabled *bool `json:"multi_tenant_enabled,omitempty"`
45+
AsyncURLEnrichEnabled *bool `json:"async_url_enrich_enabled,omitempty"`
46+
AutoTranslationEnabled *bool `json:"auto_translation_enabled,omitempty"`
47+
RemindersInterval int `json:"reminders_interval,omitempty"`
48+
UserSearchDisallowedRoles []string `json:"user_search_disallowed_roles,omitempty"`
49+
EnforceUniqueUsernames *string `json:"enforce_unique_usernames,omitempty"`
50+
ChannelHideMembersOnly *bool `json:"channel_hide_members_only,omitempty"`
3851
}
3952

4053
func (a *AppSettings) SetDisableAuth(b bool) *AppSettings {
@@ -152,42 +165,13 @@ type Policy struct {
152165
UpdatedAt time.Time `json:"updated_at"`
153166
}
154167

155-
type AppConfig struct {
156-
Name string `json:"name"`
157-
OrganizationName string `json:"organization"`
158-
WebhookURL string `json:"webhook_url"`
159-
SuspendedExplanation string `json:"suspended_explanation"`
160-
PushNotifications PushNotificationFields `json:"push_notifications"`
161-
ConfigNameMap map[string]*ChannelConfig `json:"channel_configs"`
162-
Policies map[string][]Policy `json:"policies"`
163-
Suspended bool `json:"suspended"`
164-
DisableAuth bool `json:"disable_auth_checks"`
165-
DisablePermissions bool `json:"disable_permissions_checks"`
166-
MultiTenantEnabled bool `json:"multi_tenant_enabled"`
167-
RevokeTokensIssuedBefore *time.Time `json:"revoke_tokens_issued_before"`
168-
RemindersInterval int `json:"reminders_interval"`
169-
AsyncURLEnrichEnabled bool `json:"async_url_enrich_enabled"`
170-
Grants map[string][]string `json:"grants"`
171-
PermissionVersion string `json:"permission_version"`
172-
ImageModerationLabels []string `json:"image_moderation_labels"`
173-
ImageModerationEnabled *bool `json:"image_moderation_enabled"`
174-
BeforeMessageSendHookURL string `json:"before_message_send_hook_url"`
175-
CustomActionHandlerURL string `json:"custom_action_handler_url"`
176-
UserSearchDisallowedRoles []string `json:"user_search_disallowed_roles"`
177-
EnforceUniqueUsernames string `json:"enforce_unique_usernames"`
178-
SqsURL string `json:"sqs_url"`
179-
SqsKey string `json:"sqs_key"`
180-
SqsSecret string `json:"sqs_secret"`
181-
WebhookEvents []string `json:"webhook_events"`
182-
}
183-
184168
type AppResponse struct {
185-
App *AppConfig `json:"app"`
169+
App *AppSettings `json:"app"`
186170
Response
187171
}
188172

189-
// GetAppConfig returns app settings.
190-
func (c *Client) GetAppConfig(ctx context.Context) (*AppResponse, error) {
173+
// GetAppSettings returns app settings.
174+
func (c *Client) GetAppSettings(ctx context.Context) (*AppResponse, error) {
191175
var resp AppResponse
192176

193177
err := c.makeRequest(ctx, http.MethodGet, "app", nil, nil, &resp)

app_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestClient_GetApp(t *testing.T) {
1212
c := initClient(t)
1313
ctx := context.Background()
14-
_, err := c.GetAppConfig(ctx)
14+
_, err := c.GetAppSettings(ctx)
1515
require.NoError(t, err)
1616
}
1717

@@ -48,8 +48,9 @@ func TestClient_UpdateAppSettingsClearing(t *testing.T) {
4848
_, err = c.UpdateAppSettings(ctx, settings)
4949
require.NoError(t, err)
5050

51-
s, err := c.GetAppConfig(ctx)
52-
require.Equal(t, *settings.SqsURL, s.App.SqsURL)
51+
s, err := c.GetAppSettings(ctx)
52+
require.NoError(t, err)
53+
require.Equal(t, *settings.SqsURL, *s.App.SqsURL)
5354
}
5455

5556
func TestClient_CheckSqs(t *testing.T) {

client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func TestClient_SwapHttpClient(t *testing.T) {
4040
tr.Proxy = http.ProxyURL(proxyURL)
4141
cl := &http.Client{Transport: tr}
4242
c.SetClient(cl)
43-
_, err := c.GetAppConfig(ctx)
43+
_, err := c.GetAppSettings(ctx)
4444
require.Error(t, err)
4545

4646
cl = &http.Client{}
4747
c.SetClient(cl)
48-
_, err = c.GetAppConfig(ctx)
48+
_, err = c.GetAppSettings(ctx)
4949
require.NoError(t, err)
5050
}
5151

0 commit comments

Comments
 (0)