-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make LoginName optional for admin edit user API #28834
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
base: main
Are you sure you want to change the base?
Conversation
- Modify TestAPIEditUser to load bean using LowerName instead of LoginName - Add case in TestAPIEditUser to check LoginName is updated when passed
|
@KN4CK3R I didn't get you, LoginSource is not used in this API |
type EditUserOption struct {
// required: true
SourceID int64 `json:"source_id"` There it is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you made both optional but I meant that if one was set, the other must be set too.
routers/api/v1/admin/user.go
Outdated
if len(form.LoginName) != 0 { | ||
ctx.ContextUser.LoginName = form.LoginName | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoginName
gets set from parseAuthSource
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, should there be a validation for it? or should we simply return from parseAuthSource
if (sourceID == 0 || len(form.LoginName) == 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the lines 232-234 and add the check to the (faulty) if sourceID == 0
in parseAuthSource
. Don't make it too beautiful because that part will be replaced with #28733 anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did add the check in parseAuthSource
, but we can't remove 232-234 otherwise users will only be able to update LoginName when sourceId != 0
(See failing test when 232-234 is removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, the sourceId != 0
is just wrong. 0
is the valid id of the default database login. With the admin api it's currently not possible to set a user login source to "use database".
Lines 276 to 284 in 5574968
func GetSourceByID(ctx context.Context, id int64) (*Source, error) { | |
source := new(Source) | |
if id == 0 { | |
source.Cfg = registeredConfigs[NoType]() | |
// Set this source to active | |
// FIXME: allow disabling of db based password authentication in future | |
source.IsActive = true | |
return source, nil | |
} |
I think that check is there because if you don't provide a value in the request, it defaults to 0. Therefore you can't distinguish between "not set" and "set to 0". Other fields in the EditUserOption
form use pointers which can be tested for nil
to have a "is set" check. As LoginName
is optional too now, both fields should be pointers too. You may need to change other tests then too and util.ToPointer
will be your friend. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this helped.
The fix for this case became messy, so I'll convert this to a draft for now, I'll pick it up once #28733 is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you take a look at it now, please?
8aed0f6
to
9e3009e
Compare
Fixes #18935
Related #28733
required
doc comment for EditUserOption.LoginNameEditUser
to only update LoginName when providedTestAPIEditUser
to load bean using LowerName instead of LoginNameTestAPIEditUser
to check LoginName is updated when passed