Skip to content

Fixes #7175 - Allow to search for email address in user management - #7419

Merged
MorrisJobke merged 4 commits into
nextcloud:masterfrom
Abijeet:feature-7175
Mar 6, 2018
Merged

Fixes #7175 - Allow to search for email address in user management #7419
MorrisJobke merged 4 commits into
nextcloud:masterfrom
Abijeet:feature-7175

Conversation

@Abijeet

Copy link
Copy Markdown
Member

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

codecovBot commented Dec 7, 2017

Copy link
Copy Markdown

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 FilesCoverage ΔComplexity Δ
lib/private/DB/Connection.php65.41% <ø> (-3.01%)45 <0> (ø)
...lder/ExpressionBuilder/SqliteExpressionBuilder.php100% <100%> (ø)2 <1> (+1)⬆️
...B/QueryBuilder/FunctionBuilder/FunctionBuilder.php71.42% <100%> (+9.89%)7 <1> (+1)⬆️
...eryBuilder/ExpressionBuilder/ExpressionBuilder.php90.24% <50%> (-2.53%)23 <0> (ø)
lib/private/User/Database.php75.59% <92.85%> (+6.59%)42 <1> (-3)⬇️
lib/private/App/AppStore/Bundles/Bundle.php0% <0%> (-100%)2% <0%> (ø)
apps/dav/lib/CalDAV/Activity/Setting/Todo.php0% <0%> (-100%)8% <0%> (ø)
apps/user_ldap/lib/Settings/Section.php0% <0%> (-100%)5% <0%> (ø)
apps/federation/lib/Hooks.php0% <0%> (-100%)4% <0%> (ø)
lib/public/AppFramework/Http/StreamResponse.php0% <0%> (-100%)6% <0%> (ø)
... and 811 more

@Abijeet

Copy link
Copy Markdown
MemberAuthor

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

@MorrisJobke

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

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
Copy Markdown
MemberAuthor

@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
Copy Markdown
MemberAuthor

@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
Copy Markdown
MemberAuthor

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.

Comment thread.htaccess
Header set Cache-Control "max-age=15778463"
</FilesMatch>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine.

Comment thread.htaccess Outdated
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
</IfModule> No newline at end of file

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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

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?

add additional user searching tests
Signed-off-by: Robin Appelman <robin@icewind.nl>
@icewind1991

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

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

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

Copy link
Copy Markdown
Member

needs another reviewer

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

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:masterMar 6, 2018
@MorrisJobkeMorrisJobke mentioned this pull request Mar 6, 2018
*
* @param mixed $field
* @return IQueryFunction
* @since 13.0.0

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

Finally :)

Sign up for freeto 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

@Abijeet@MorrisJobke@blizzz@icewind1991