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

Adding a "create user" to the api #370

Closed
wants to merge 14 commits into from
Closed

Adding a "create user" to the api #370

wants to merge 14 commits into from

Conversation

nir-sopher
Copy link
Contributor

No description provided.

Copy link
Member

@mitchell852 mitchell852 left a 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!

return $self->alert("full-name is required.");
}

if ( !defined($params->{email}) ) {
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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 |
Copy link
Member

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?

Copy link
Contributor Author

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

my $tenant_id = exists($params->{tenantId}) ? $params->{tenantId} : $self->current_user_tenant();

my $values = {
address_line1 => defined_or_default($params->{addressLine1}, ""),
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

country => defined_or_default($params->{country}, ""),
email => $params->{email},
full_name => $params->{fullName},
new_user => defined_or_default($params->{newUser}, 0),
Copy link
Member

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.

Copy link
Contributor Author

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

$response->{stateOrProvince} = $rs->state_or_province;
$response->{uid} = $rs->uid;
$response->{username} = $rs->username;
$response->{tenantId} = $rs->tenant_id;
Copy link
Member

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?

Copy link
Contributor Author

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

@nir-sopher
Copy link
Contributor Author

nir-sopher commented Apr 7, 2017 via email

@mitchell852
Copy link
Member

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

http://trafficcontrol.apache.org/docs/latest/development/traffic_ops.html#perl-formatting-conventions


my $name = $params->{username};
if ( !defined($name) ) {
return $self->alert("Username is required.");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?';
Copy link
Member

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.

Copy link
Contributor Author

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?';
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@mitchell852
Copy link
Member

@nir-sopher - can you fix this PR? "This branch cannot be rebased safely" - i'd like to get it merged if possible

Copy link
Member

@mitchell852 mitchell852 left a 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.


my $name = $params->{username};
if ( !defined($name) ) {
return $self->alert("Username is required.");
Copy link
Member

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

return $self->alert("confirm-local-password is required.");
}

if ($params->{localPassword} ne $params->{confirmLocalPassword}){
Copy link
Member

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

return $self->alert("local-password and confirmed-local-password mismatch.");
}

if ( !defined($params->{role}) ) {
Copy link
Member

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....

@nir-sopher
Copy link
Contributor Author

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.

@nir-sopher
Copy link
Contributor Author

The change of the "role" broke the UT and was reverted.
It changes current behavior of user-update.
I prefer not to make such changes in this PR

mitchell852 and others added 2 commits June 2, 2017 14:47
… 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…
@mitchell852
Copy link
Member

yes, there is a UT failure:

t/user.t (Wstat: 256 Tests: 21 Failed: 1)
Failed test: 5
Non-zero exit status: 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.

@asfgit asfgit closed this in 5913c53 Jun 5, 2017
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.

None yet

2 participants