Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): add SetEnforceUniqueUsernames to restrict allowed values #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a pointer? Because I believe that Go's "escape analysis" will put this in the heap instead of stack.

This beauty thing Go does to avoid dangling pointer—since variable should only exists inside the function—always bug my brain. 🤯

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it doesn't have to be. Gonna change it later

}

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
Expand Down
3 changes: 2 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down