Skip to content

Conversation

@Abijeet
Copy link
Member

@Abijeet Abijeet commented Dec 7, 2017

Greetings,

@MorrisJobke - Please find the merge request that fixes #7175

I've done the following,

  1. Updated the query to fetch the users in users > everyone tab.
  2. Updated the query to fetch the users in users > admin tab.
  3. Tested to ensure that the disabled users are also being fetched.

Tested with SQLite.

Signed-off-by: Abijeet abijeetpatro@gmail.com

@codecov
Copy link

codecov bot commented Dec 7, 2017

Codecov Report

Merging #7419 into master will decrease coverage by 18.1%.
The diff coverage is 91.17%.

@@              Coverage Diff              @@
##             master    #7419       +/-   ##
=============================================
- Coverage     52.87%   34.77%   -18.11%     
- Complexity    23658    24885     +1227     
=============================================
  Files          1449     1602      +153     
  Lines         80454    94750    +14296     
  Branches          0     1368     +1368     
=============================================
- Hits          42541    32949     -9592     
- Misses        37913    61801    +23888
Impacted Files Coverage Δ Complexity Δ
lib/private/DB/Connection.php 65.41% <ø> (-3.01%) 45 <0> (ø)
...lder/ExpressionBuilder/SqliteExpressionBuilder.php 100% <100%> (ø) 2 <1> (+1) ⬆️
...B/QueryBuilder/FunctionBuilder/FunctionBuilder.php 71.42% <100%> (+9.89%) 7 <1> (+1) ⬆️
...eryBuilder/ExpressionBuilder/ExpressionBuilder.php 90.24% <50%> (-2.53%) 23 <0> (ø)
lib/private/User/Database.php 75.59% <92.85%> (+6.59%) 42 <1> (-3) ⬇️
lib/private/App/AppStore/Bundles/Bundle.php 0% <0%> (-100%) 2% <0%> (ø)
apps/dav/lib/CalDAV/Activity/Setting/Todo.php 0% <0%> (-100%) 8% <0%> (ø)
apps/user_ldap/lib/Settings/Section.php 0% <0%> (-100%) 5% <0%> (ø)
apps/federation/lib/Hooks.php 0% <0%> (-100%) 4% <0%> (ø)
lib/public/AppFramework/Http/StreamResponse.php 0% <0%> (-100%) 6% <0%> (ø)
... and 811 more

@Abijeet
Copy link
Member Author

Abijeet commented Dec 8, 2017

Not sure why the test case failed, please let me know if there is anything I've to do or change.

@MorrisJobke
Copy link
Member

Not sure why the test case failed, please let me know if there is anything I've to do or change.

Fixed in master: #7433

@blizzz
Copy link
Member

blizzz commented Dec 12, 2017

It works, however I'D appreciate "unit" tests in tests/lib/User/DatabaseTest.php to ensure this keeps working in the future. Basically testSearch() from the inherited "Backend" class can be extended to look for the email.

@Abijeet
Copy link
Member Author

Abijeet commented Dec 16, 2017

@blizzz - Thank you. I'll add the test cases some time today.

Fixes #7175.

- Updated the query to fetch the users in users > everyone tab.
- Updated the query to fetch the users in users > admin tab.
- Tested to ensure that the disabled users are also being fetched.
- Added test cases.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
@Abijeet
Copy link
Member Author

Abijeet commented Dec 16, 2017

@blizzz , @MorrisJobke -

Couple of things,

  1. I'm not sure if I've implemented the test cases properly. Please let me know if I've to change anything here.
  2. There was an extra space in the .htaccess that Netbeans trimmed off, let me know if I should undo that.

@Abijeet
Copy link
Member Author

Abijeet commented Dec 16, 2017

Also I noticed one more thing, searching with _ in LIKE isn't working.

So for example, if there is a user with uid as admin_user.

If you search for this user in the view with the following search term - admin_, you'll not get any value in the response. This is because escapeLikeParameter function adds a \ before the _ (Ref: https://github.com/nextcloud/server/blob/master/lib/private/DB/Connection.php#L410). Tested on SQLite.

Not sure if this is a known issue.

Header set Cache-Control "max-age=15778463"
</FilesMatch>

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

.htaccess Outdated
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
</IfModule>
Copy link
Member

Choose a reason for hiding this comment

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

That change should be undone. We usually have a new line at the end of files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, added the newline back. Will keep in mind for future.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
@blizzz
Copy link
Member

blizzz commented Dec 19, 2017

This is because escapeLikeParameter function adds a \ before the _ (Ref: https://github.com/nextcloud/server/blob/master/lib/private/DB/Connection.php#L410). Tested on SQLite.

This was added for security reasons, since % and _ act as wildcards in SQL. The \ is necessary to escape them so user input does not act like a wildcard. For sqlite to work it requires an additional ESCAPE '\' however. This is not the case?

@blizzz blizzz requested a review from icewind1991 December 19, 2017 16:14
add additional user searching tests

Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991
Copy link
Member

Took the opportunity to refactor the user searching code and fixed the _ issue

@blizzz please re-review

->from('users', 'u')
->leftJoin('u', 'preferences', 'p', $query->expr()->andX(
$query->expr()->eq('userid', 'uid')),
$query->expr()->eq('appid', new Literal('settings')),
Copy link
Member

Choose a reason for hiding this comment

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

Literal cannot be hidden from consumers?

Copy link
Member

Choose a reason for hiding this comment

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

All plain strings are used as column names

Copy link
Member

Choose a reason for hiding this comment

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

I mean whether everywhere where we use strings in queries they need to be instances of Literal or whether it can be abstracted away?

Copy link
Member

Choose a reason for hiding this comment

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

We need to use Literal to explicitly tell the query builder that the string is safe to use

Copy link
Member

Choose a reason for hiding this comment

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

ok

@blizzz
Copy link
Member

blizzz commented Jan 12, 2018

@icewind1991 just the other question, looks good otherwise and is working

Signed-off-by: Robin Appelman <robin@icewind.nl>
@blizzz
Copy link
Member

blizzz commented Jan 17, 2018

needs another reviewer

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

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

Tested and works 👍

@MorrisJobke MorrisJobke merged commit de56915 into nextcloud:master Mar 6, 2018
*
* @param mixed $field
* @return IQueryFunction
* @since 13.0.0
Copy link
Member

Choose a reason for hiding this comment

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

See #8696

@Abijeet
Copy link
Member Author

Abijeet commented Mar 10, 2018

Finally :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to search for email address in user management

4 participants