-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Central group table] Add membership manager to central group table #29154
Conversation
I will also start writing unit tests to test queries I am using, so dont focus on them to much at that point. If we decide on that approach, lets merge it with #29107. This should not affect any other class and existing functionalities. It will when all TODOs will be implemented. |
lib/private/Group/Group.php
Outdated
private $backendGroup; | ||
|
||
/** | ||
* // TODO: use BackendGroup 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.
All the TODOs in the code are places which should be implemented after merging this PR
d31f4d3
to
506df6b
Compare
lib/private/Group/GroupMapper.php
Outdated
return $this->findEntity($qb->getSQL(), $qb->getParameters()); | ||
try { | ||
/** @var BackendGroup $backendGroup */ | ||
$backendGroup = $this->findEntity($qb->getSQL(), $qb->getParameters()); |
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.
Add some additional checks which are not in original version. It should return null and not throw exception
lib/private/Group/Manager.php
Outdated
@@ -143,10 +144,21 @@ protected function clearCaches() { | |||
|
|||
/** | |||
* @param string $gid | |||
* @return boolean | |||
*/ | |||
public function isCached($gid) { |
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 method is required to build optimized queries
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.
public? I don't see any reason to make this function public. This should be private.
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.
True, will write a UserCacheManager and GroupCacheManager Włoch will be used Both in Group/User Manager and Mapper
lib/private/Server.php
Outdated
}); | ||
$this->registerService('GroupMapper', function(Server $c) { | ||
return new GroupMapper($c->getDatabaseConnection()); | ||
}); | ||
$this->registerService('MembershipManager', function(Server $c) { | ||
return new MembershipManager($c->getDatabaseConnection(), $c->getConfig(), |
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.
All changes in this file are obligatory so it actually all works.
* @throws \BadFunctionCallException | ||
* @since 7.0.0 | ||
*/ | ||
public function mapRowToEntity($row) { |
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.
Make it public so MembershipManager can also create the Account entities (otherwise it will only be possible inside AccountMapper)
Added @throws in phpdoc to make it clear that this function should only be used by classes which operate over oc_accounts table.
lib/private/MembershipManager.php
Outdated
use Doctrine\DBAL\Exception\UniqueConstraintViolationException; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
|
||
class MembershipManager extends Access { |
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.
Please have a look on all the public functions of that class. To define them, I used Group, User, GroupManager, UserManager and SubAdmin finding requirements, and placed TODOs in all the places
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.
As said in #29107 (comment) , probably a bad idea to extend from Access
lib/private/MembershipManager.php
Outdated
// Adjust the query depending on availability of accountId and $backendGroupId | ||
// to have optimized access | ||
$alias = $this->getTableAlias(); | ||
if ($this->userManager->isCached($userId) && $this->groupManager->isCached($gid)) { |
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 use isCached mathods of Managers to build optimized queries - it means, fetch info from cache if available, otherwise perform JOIN.
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.
From my point of view, this reveals a design flaw. Why something related to the DB access has to check a class from the business logic? Why it needs to check if it's cached when noone should be interested in that?.
I think we should recheck the approach. What about the group manager handles also the membership? Could it simplify this?
506df6b
to
2ff6785
Compare
I'll need to do a second review |
I need to have second take on it, it was just poc, trying to figure out how this should be structured, and it is far from proper. Thanks for valuable feedback @jvillafanez, I also take into account your architecture vision. |
0ad5420
to
d694f08
Compare
71987fb
to
a63e8f3
Compare
a63e8f3
to
2569541
Compare
c5561a4
to
08ec5c9
Compare
@DeepDiver1975 @PVince81 I have tested it with #29282 integration into group manager, group, subadmin, user and user manager. This PR is ready |
Any input here? |
const MEMBERSHIP_TYPE_GROUP_ADMIN = 1; | ||
|
||
/** @var IConfig */ | ||
protected $config; |
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 this class isn't expected to be extended, this should be private.
@ownclouders rebase |
Hey! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost! |
lib/private/MembershipManager.php
Outdated
private $db; | ||
|
||
|
||
public function __construct(IDBConnection $db, IConfig $config) { |
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.
PHPDoc missing
lib/private/MembershipManager.php
Outdated
* the user has specific membership type | ||
* | ||
* @param string|int $userId | ||
* @param bool $isInternalUserId |
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.
what is internal?
lib/private/MembershipManager.php
Outdated
} | ||
|
||
/* | ||
* Return backend group entities for given user id $userId (internal or gid) of which |
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.
gid?
* | ||
* @return BackendGroup[] | ||
*/ | ||
public function getUserBackendGroups($userId) { |
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.
do we really need this function? From my understanding everything should internally work on accountIds
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.
It is just optimization, in case account id is only available by fetching the use from user manager.
lib/private/Server.php
Outdated
/** | ||
* @return \OC\User\AccountTermMapper | ||
*/ | ||
public function getAccountTermMapper() { |
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.
why? public getters in class Server shall only return OCP interfaces
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.
Hmm, so what with AccountMapper?
Automated rebase was successful! |
e64b67b
to
f90e106
Compare
3eb25b5
to
b9b7342
Compare
87cabc9
to
fd86b44
Compare
4f3e235
to
0c46853
Compare
@DeepDiver1975 addressed your doubts and fixed |
tests/lib/MembershipManagerTest.php
Outdated
use OC\User\AccountTermMapper; | ||
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use Test\TestCase; |
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.
unused
tests/lib/MembershipManagerTest.php
Outdated
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use Test\TestCase; | ||
use OCP\AppFramework\Db\DoesNotExistException; |
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.
unused
tests/lib/MembershipManagerTest.php
Outdated
private static function clearDB() { | ||
\OC::$server->getDatabaseConnection()->executeQuery('DELETE FROM `*PREFIX*memberships`'); | ||
\OC::$server->getDatabaseConnection()->executeQuery('DELETE FROM `*PREFIX*backend_groups`'); | ||
\OC::$server->getDatabaseConnection()->executeQuery('DELETE FROM `*PREFIX*accounts`'); |
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.
really kill all?
lib/private/Server.php
Outdated
@@ -89,6 +89,7 @@ | |||
use OCP\AppFramework\QueryException; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OC\Group\GroupMapper; | |||
use OC\MembershipManager; |
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.
unused
lib/private/Server.php
Outdated
$c->getMemCacheFactory(), | ||
$appManager, | ||
$c->getTempManager() | ||
new EnvironmentHelper(), |
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.
remove whitspace changes
lib/private/User/AccountMapper.php
Outdated
@@ -239,4 +239,4 @@ public function callForAllUsers($callback, $search, $onlySeen) { | |||
$stmt->closeCursor(); | |||
} | |||
|
|||
} | |||
} |
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.
remove whitespace changes
lib/private/MembershipManager.php
Outdated
* | ||
* @return bool | ||
*/ | ||
public function addGroupUser($accountId, $backendGroupId) { |
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.
addGroupMemberSqlQuery throws UniqueConstraintViolationException - see PHPDoc
this method should do also throw it
lib/private/MembershipManager.php
Outdated
* | ||
* @return bool | ||
*/ | ||
public function addGroupAdmin($accountId, $backendGroupId) { |
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.
same as with addGroupUser
lib/private/MembershipManager.php
Outdated
* return result for all groups. | ||
* | ||
* @param string|int|null $groupId | ||
* @param bool $isInternalGroupId |
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.
isInternalGroupId unknown
isBackendGroupId missing in PHPDoc
0c46853
to
8c14e9c
Compare
@DeepDiver1975 adjusted to comments |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is first approach to handle central group table feature. It utilizes new class Membership manager, which inherits from Access class. More implementation details will go inside the code.
NOTE: Mind that this PR target is
centr_groups
branch, from this PR #29107@patrickjahns