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

Fixed disabled users query #9261

Closed
wants to merge 6 commits into from
Closed

Conversation

skjnldsv
Copy link
Member

@skjnldsv skjnldsv commented Apr 21, 2018

Fix #8009
Fix #8008
I feel like it's safer to return a different entry instead of directly subtracting the disabled users to the total user count. People might want to get the full data anyway.

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@codecov
Copy link

codecov bot commented Apr 21, 2018

Codecov Report

Merging #9261 into master will increase coverage by 6.12%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master    #9261      +/-   ##
============================================
+ Coverage     51.95%   58.07%   +6.12%     
============================================
  Files          1607       67    -1540     
  Lines         95393     7943   -87450     
  Branches       1394     1394              
============================================
- Hits          49559     4613   -44946     
+ Misses        45834     3330   -42504
Impacted Files Coverage Δ Complexity Δ
apps/files_external/lib/Lib/IdentifierTrait.php
apps/files_sharing/lib/ExpireSharesJob.php
lib/private/Federation/CloudIdManager.php
...haring/lib/Controller/ExternalSharesController.php
...iles_sharing/lib/Activity/Settings/PublicLinks.php
.../files_sharing/lib/Controller/RemoteController.php
apps/user_ldap/appinfo/routes.php
apps/user_ldap/lib/Command/Search.php
apps/federation/templates/settings-admin.php
lib/private/Files/Storage/Wrapper/Jail.php
... and 1523 more

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv skjnldsv force-pushed the disabled-users-by-group-fix branch from f57d65f to c7aabd2 Compare April 21, 2018 13:38
@skjnldsv skjnldsv self-assigned this Apr 21, 2018
@skjnldsv skjnldsv added bug 3. to review Waiting for reviews backport-request papercut Annoying recurring issue with possibly simple fix. feature: users and groups labels Apr 21, 2018
@skjnldsv skjnldsv added this to the Nextcloud 14 milestone Apr 21, 2018
@skjnldsv
Copy link
Member Author

Tests ok, ready to review :)

* @return int
* @since 14.0.0
*/
public function countDisabledUsersOfGroups(array $groups) {
Copy link
Member

Choose a reason for hiding this comment

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

Also give a hint for the return type here? : int ;)

* @return int
* @since 14.0.0
*/
public function countDisabledUsersOfGroups(array $groups);
Copy link
Member

Choose a reason for hiding this comment

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

Same here - type hint for the return type would be nice.

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv skjnldsv force-pushed the disabled-users-by-group-fix branch from c7aabd2 to d81ac13 Compare April 23, 2018 08:38
$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$queryBuilder->select($queryBuilder->createFunction('COUNT(Distinct uid)'))
->from('preferences', 'p')
->innerJoin('p', 'group_user', 'g', 'p.userid = g.uid')
Copy link
Member

Choose a reason for hiding this comment

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

This hard codes the user manager to our group backend ❌

->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
->andWhere($queryBuilder->expr()->in('gid', $queryBuilder->createNamedParameter(implode(',', $groups))));
Copy link
Member

Choose a reason for hiding this comment

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

no need to implode, $queryBuilder->createNamedParameter($groups, IQueryBuilder::PARAM_STR_ARRAY) has you covered

*/
public function countDisabledUsers();
public function countDisabledUsersOfGroups(array $groups):int;
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a space before the int? That's how we use it in all other places in our code.

*
* @return int
* @since 11.0.0
* @since 12.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.

Why isthmus updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

it was an error, implemented in 12 in the private fct but in 11 in the public interface :)
I guess a copy/paste error

@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Apr 23, 2018
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@@ -39,6 +39,7 @@
self::ADD_TO_GROUP => 'addToGroup',
self::REMOVE_FROM_GOUP => 'removeFromGroup',
self::COUNT_USERS => 'countUsersInGroup',
self::COUNT_DISABLED => 'countDisabledInGroup',
Copy link
Member

Choose a reason for hiding this comment

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

Not defined 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we discussed it with @rullzer and @nickvergessen.
Unfortunately

const CREATE_GROUP = 0x00000001;
const DELETE_GROUP = 0x00000010;
const ADD_TO_GROUP = 0x00000100;
const REMOVE_FROM_GOUP = 0x00001000; // oops
const REMOVE_FROM_GROUP = 0x00001000;
//OBSOLETE const GET_DISPLAYNAME = 0x00010000;
const COUNT_USERS = 0x00100000;
const GROUP_DETAILS = 0x01000000;
/**
* @since 13.0.0
*/
const IS_ADMIN = 0x10000000;
is full :(

Copy link
Member

Choose a reason for hiding this comment

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

We should go the interface way 😉 see #8935

Copy link
Member

Choose a reason for hiding this comment

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

that was also the conclusion in IRC ;)

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv
Copy link
Member Author

Let's close this in favor of a new one

@skjnldsv skjnldsv closed this Apr 23, 2018
@MorrisJobke MorrisJobke deleted the disabled-users-by-group-fix branch April 23, 2018 12:15
@MorrisJobke MorrisJobke removed this from the Nextcloud 14 milestone Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress bug feature: users and groups papercut Annoying recurring issue with possibly simple fix.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants