-
Notifications
You must be signed in to change notification settings - Fork 339
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
Adding a "create user" to the api #370
Conversation
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.
some comments for you. thanks!
traffic_ops/app/lib/API/User.pm
Outdated
return $self->alert("full-name is required."); | ||
} | ||
|
||
if ( !defined($params->{email}) ) { |
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.
email is a unique column. do you want to check to make sure this email is not already in use? kind of like you did for username?
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.
nevermind, i guess email uniqueness is checked in the is_valid() function
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.
Indeed
+----------------------+--------+------------------------------------------------+ | ||
|``uid`` | int | | | ||
+----------------------+--------+------------------------------------------------+ | ||
| ``tenantId`` | int | Owning tenant ID | |
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 add tenant to this response?
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.
Ori plans to do so in a separate PR or on the merge with pr 434
traffic_ops/app/lib/API/User.pm
Outdated
my $tenant_id = exists($params->{tenantId}) ? $params->{tenantId} : $self->current_user_tenant(); | ||
|
||
my $values = { | ||
address_line1 => defined_or_default($params->{addressLine1}, ""), |
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 don't think you need to do all these defined_or_default()
it's fine if they leave out addressLine1 which will just set address_line1 to undef.
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.
done
traffic_ops/app/lib/API/User.pm
Outdated
country => defined_or_default($params->{country}, ""), | ||
email => $params->{email}, | ||
full_name => $params->{fullName}, | ||
new_user => defined_or_default($params->{newUser}, 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.
just set this to
new_user => \0, # false
it's confusing, i know but "new_user" is used for users that were created via a registrationSent.
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.
Done. "0" an not "\0" as setting it to "\0" failed.
Will need to look further into it to understand why
traffic_ops/app/lib/API/User.pm
Outdated
$response->{stateOrProvince} = $rs->state_or_province; | ||
$response->{uid} = $rs->uid; | ||
$response->{username} = $rs->username; | ||
$response->{tenantId} = $rs->tenant_id; |
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 return the tenant name as well?
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.
Ori plans to add it in a separate PR
Indeed
…On Apr 7, 2017 6:16 AM, "Jeremy Mitchell" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In traffic_ops/app/lib/API/User.pm
<#370 (comment)>
:
> + my $name = $params->{username};
+ if ( !defined($name) ) {
+ return $self->alert("Username is required.");
+ }
+
+ my $existing = $self->db->resultset('TmUser')->search( { username => $name } )->single();
+ if ($existing) {
+ return $self->alert("A user with username \"$name\" already exists.");
+ }
+
+
+ if ( !defined($params->{fullName}) ) {
+ return $self->alert("full-name is required.");
+ }
+
+ if ( !defined($params->{email}) ) {
nevermind, i guess email uniqueness is checked in the is_valid() function
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#370 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AXGkYLXxSpb8U3fcfR6JyCEygD0RjcT5ks5rtaqDgaJpZM4MehR1>
.
|
you might want to run your code thru the perl formatter. I see some formatting errors. Here's more info about that: https://github.com/apache/incubator-trafficcontrol/blob/master/CONTRIBUTING.md#code-formatting |
traffic_ops/app/lib/API/User.pm
Outdated
|
||
my $name = $params->{username}; | ||
if ( !defined($name) ) { | ||
return $self->alert("Username is required."); |
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.
you check for username, fullName and email in the is_valid method. so you don't have to do that here.
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'll remove the checks for full-name and email.
As "username" value is use for searching the DB later on, I prefer to validate it.
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 don't understand. fullname, email and username are validated here:
https://github.com/apache/incubator-trafficcontrol/blob/master/traffic_ops/app/lib/API/User.pm#L463
also, you should probably add role to line 463
my $tenant_name = defined ($tenant_id) ? $schema->resultset('Tenant')->find( { id => $tenant_id } )->get_column('name') : "null"; | ||
|
||
# Verify the user | ||
ok my $user = $schema->resultset('TmUser')->find( { username => $login_user } ), 'Does the portal user exist?'; |
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 update this message? not sure what portal user has to do with this.
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.
Done
->json_is( "/response/username" => $addedUserName ) | ||
->json_is( "/response/email" => $addedUserEmail) | ||
->json_is( "/response/tenantId" => $tenant_id) #tenant Id not set - getting the tenant id from the user | ||
, 'Failed adding user?'; |
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.
this test message doesn't seem right either. Maybe "Successfully added user?" would be better.
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.
Done
@nir-sopher - can you fix this PR? "This branch cannot be rebased safely" - i'd like to get it merged if possible |
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.
some comments for you. please address these comments as well as rebase and we can get this merged. thanks.
traffic_ops/app/lib/API/User.pm
Outdated
|
||
my $name = $params->{username}; | ||
if ( !defined($name) ) { | ||
return $self->alert("Username is required."); |
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 don't understand. fullname, email and username are validated here:
https://github.com/apache/incubator-trafficcontrol/blob/master/traffic_ops/app/lib/API/User.pm#L463
also, you should probably add role to line 463
traffic_ops/app/lib/API/User.pm
Outdated
return $self->alert("confirm-local-password is required."); | ||
} | ||
|
||
if ($params->{localPassword} ne $params->{confirmLocalPassword}){ |
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.
this is not necessary, it is validated in the is_valid method
traffic_ops/app/lib/API/User.pm
Outdated
return $self->alert("local-password and confirmed-local-password mismatch."); | ||
} | ||
|
||
if ( !defined($params->{role}) ) { |
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.
if you add 'role' to line 463, you can take this out as well....
…response the value is bool like everywhere else
Rebase was done a PR review changes were made, except for a test for "username" in the beginning of the create function. The test is done as the value is in use by the function logic. |
The change of the "role" broke the UT and was reverted. |
… some errors in existing logic when checking uniqueness of email and username and did some formatting
removed some irrelevant props, leveraged the is_valid() method, fixed…
yes, there is a UT failure: t/user.t (Wstat: 256 Tests: 21 Failed: 1) but i'm pretty sure this was fixed in master so i'll pull this in and if it's still broken, i can fix it. it only changes the behavior of user-update in the sense that role is now checked which in my opinion is a very valid check. you should not be able to update a user and leave out a required field - role. |
No description provided.