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

fix(users): user feedback messages improvements #1045

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

curzolapierre
Copy link
Member

@curzolapierre curzolapierre commented Feb 23, 2024

- [ ] Add a changelog entry in the section "To Be Released" of CHANGELOG.md

@curzolapierre curzolapierre self-assigned this Feb 23, 2024
@curzolapierre curzolapierre force-pushed the fix/cmd/user_feedback_improvement branch from 0514162 to c39cd9e Compare February 23, 2024 14:39
@@ -47,6 +47,17 @@ func UpdateUser(ctx context.Context, app, addonUUID, username string) error {
if !userExists {
return errors.New(ctx, fmt.Sprintf("User \"%s\" does not exist", username))
}
// Check if the user is protected
Copy link
Contributor

@ipfaze ipfaze Feb 23, 2024

Choose a reason for hiding this comment

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

issue(blocking): you can avoid a loop here by saving the user in the last for loop:

for _, user := range l {

And then do your check after:
if !userExists {

@curzolapierre curzolapierre force-pushed the fix/cmd/user_feedback_improvement branch from c39cd9e to 8187212 Compare February 23, 2024 14:48
@curzolapierre curzolapierre changed the title fix(users): reword DBMS to addon fix(users): user feedback messages improvements Feb 23, 2024
Comment on lines 40 to 53
var userExists bool
var userProtected bool
for _, user := range l {
if user.Name == username {
userExists = true

if user.Protected {
userProtected = true
}
break
}
}
if !userExists {
return errors.New(ctx, fmt.Sprintf("User \"%s\" does not exist", username))
}

if userProtected {
return errors.New(ctx, fmt.Sprintf("User \"%s\" is protected and cannot be updated", username))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

For better readability I suggest:

Suggested change
var userExists bool
var userProtected bool
for _, user := range l {
if user.Name == username {
userExists = true
if user.Protected {
userProtected = true
}
break
}
}
if !userExists {
return errors.New(ctx, fmt.Sprintf("User \"%s\" does not exist", username))
}
if userProtected {
return errors.New(ctx, fmt.Sprintf("User \"%s\" is protected and cannot be updated", username))
}
var user
for _, u := range l {
if u.Name == username {
user = u
break
}
}
if user == nil {
return errors.New(ctx, fmt.Sprintf("User \"%s\" does not exist", username))
}
if user.Protected {
return errors.New(ctx, fmt.Sprintf("User \"%s\" is protected", username))
}

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed a suggestion, WDYT?

Copy link
Contributor

@ipfaze ipfaze left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@curzolapierre curzolapierre merged commit 33e3ee7 into master Feb 23, 2024
6 checks passed
@curzolapierre curzolapierre deleted the fix/cmd/user_feedback_improvement branch February 23, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants