From dc105e7a047e5ca8c75723f1743c2fbd054dd3cf Mon Sep 17 00:00:00 2001 From: jnelle <602579@fom-net.de> Date: Sun, 5 Nov 2023 17:15:47 +0100 Subject: [PATCH 1/2] refactor(app): add SetEnforceUniqueUsernames to restrict allowed values Signed-off-by: jnelle <602579@fom-net.de> * Since I couldn't find the allowed values in the GO SDK docs, I decided to add this, because it restricts the allowed values and shows the developer which values are allowed --- app.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app.go b/app.go index 1291d64..6c3620f 100644 --- a/app.go +++ b/app.go @@ -54,6 +54,36 @@ type AppSettings struct { AsyncModerationConfig *AsyncModerationConfiguration `json:"async_moderation_config,omitempty"` } +type EnforceUniqueUsernames int64 + +const ( + No EnforceUniqueUsernames = iota + App + Team +) + +// check allowed values for enforce_unique_usernames here +// https://getstream.io/chat/docs/rest/#settings-updateapp +func (s EnforceUniqueUsernames) String() *string { + var result string + switch s { + case No: + result = "no" + case App: + result = "app" + case Team: + result = "team" + default: + result = "app" + } + return &result +} + +func (a *AppSettings) SetEnforceUniqueUsernames(e EnforceUniqueUsernames) *AppSettings { + a.EnforceUniqueUsernames = e.String() + return a +} + func (a *AppSettings) SetDisableAuth(b bool) *AppSettings { a.DisableAuth = &b return a From 6559498f70e94b6e8c76f7a52dbe1df3cd17f179 Mon Sep 17 00:00:00 2001 From: jnelle <602579@fom-net.de> Date: Sun, 5 Nov 2023 17:35:24 +0100 Subject: [PATCH 2/2] tests: adjust TestClient_UpdateAppSettings for SetEnforceUniqueUsernames Signed-off-by: jnelle <602579@fom-net.de> --- app_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index df5071d..8ea60ee 100644 --- a/app_test.go +++ b/app_test.go @@ -21,7 +21,8 @@ func TestClient_UpdateAppSettings(t *testing.T) { settings := NewAppSettings(). SetDisableAuth(true). - SetDisablePermissions(true) + SetDisablePermissions(true). + SetEnforceUniqueUsernames(No) _, err := c.UpdateAppSettings(ctx, settings) require.NoError(t, err)