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

[Central group table] Add membership manager to central group table #29154

Merged
merged 1 commit into from
Dec 1, 2017

Conversation

mrow4a
Copy link
Contributor

@mrow4a mrow4a commented Oct 5, 2017

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

@mrow4a
Copy link
Contributor Author

mrow4a commented Oct 5, 2017

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.

private $backendGroup;

/**
* // TODO: use BackendGroup 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.

All the TODOs in the code are places which should be implemented after merging this PR

@mrow4a mrow4a self-assigned this Oct 5, 2017
return $this->findEntity($qb->getSQL(), $qb->getParameters());
try {
/** @var BackendGroup $backendGroup */
$backendGroup = $this->findEntity($qb->getSQL(), $qb->getParameters());
Copy link
Contributor Author

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

@@ -143,10 +144,21 @@ protected function clearCaches() {

/**
* @param string $gid
* @return boolean
*/
public function isCached($gid) {
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

});
$this->registerService('GroupMapper', function(Server $c) {
return new GroupMapper($c->getDatabaseConnection());
});
$this->registerService('MembershipManager', function(Server $c) {
return new MembershipManager($c->getDatabaseConnection(), $c->getConfig(),
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;

class MembershipManager extends Access {
Copy link
Contributor Author

@mrow4a mrow4a Oct 5, 2017

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

Copy link
Member

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

// 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)) {
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 use isCached mathods of Managers to build optimized queries - it means, fetch info from cache if available, otherwise perform JOIN.

Copy link
Member

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?

@mrow4a
Copy link
Contributor Author

mrow4a commented Oct 9, 2017

@jvillafanez

@mrow4a mrow4a requested a review from jvillafanez October 9, 2017 13:09
@jvillafanez
Copy link
Member

I'll need to do a second review

@mrow4a
Copy link
Contributor Author

mrow4a commented Oct 11, 2017

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.

@mrow4a mrow4a force-pushed the centr_groups branch 2 times, most recently from 0ad5420 to d694f08 Compare October 16, 2017 09:44
@mrow4a mrow4a force-pushed the centr_group_org branch 3 times, most recently from 71987fb to a63e8f3 Compare October 18, 2017 11:01
@mrow4a mrow4a force-pushed the centr_group_org branch 2 times, most recently from c5561a4 to 08ec5c9 Compare November 7, 2017 19:29
@mrow4a
Copy link
Contributor Author

mrow4a commented Nov 7, 2017

@DeepDiver1975 @PVince81 I have tested it with #29282 integration into group manager, group, subadmin, user and user manager. This PR is ready

@mrow4a
Copy link
Contributor Author

mrow4a commented Nov 14, 2017

Any input here?

const MEMBERSHIP_TYPE_GROUP_ADMIN = 1;

/** @var IConfig */
protected $config;
Copy link
Member

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.

@DeepDiver1975
Copy link
Member

@ownclouders rebase

@ownclouders
Copy link
Contributor

Hey! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost!

private $db;


public function __construct(IDBConnection $db, IConfig $config) {
Copy link
Member

Choose a reason for hiding this comment

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

PHPDoc missing

* the user has specific membership type
*
* @param string|int $userId
* @param bool $isInternalUserId
Copy link
Member

Choose a reason for hiding this comment

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

what is internal?

}

/*
* Return backend group entities for given user id $userId (internal or gid) of which
Copy link
Member

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

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

Copy link
Contributor Author

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.

/**
* @return \OC\User\AccountTermMapper
*/
public function getAccountTermMapper() {
Copy link
Member

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

Copy link
Contributor Author

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?

@ownclouders
Copy link
Contributor

Automated rebase was successful!

@mrow4a mrow4a force-pushed the centr_groups branch 2 times, most recently from e64b67b to f90e106 Compare November 27, 2017 13:12
@mrow4a mrow4a force-pushed the centr_group_org branch 2 times, most recently from 3eb25b5 to b9b7342 Compare November 27, 2017 13:33
@mrow4a mrow4a force-pushed the centr_groups branch 2 times, most recently from 87cabc9 to fd86b44 Compare November 28, 2017 12:09
@mrow4a mrow4a force-pushed the centr_group_org branch 2 times, most recently from 4f3e235 to 0c46853 Compare November 28, 2017 13:02
@mrow4a
Copy link
Contributor Author

mrow4a commented Nov 28, 2017

@DeepDiver1975 addressed your doubts and fixed

use OC\User\AccountTermMapper;
use OCP\IConfig;
use OCP\IDBConnection;
use Test\TestCase;
Copy link
Member

Choose a reason for hiding this comment

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

unused

use OCP\IConfig;
use OCP\IDBConnection;
use Test\TestCase;
use OCP\AppFramework\Db\DoesNotExistException;
Copy link
Member

Choose a reason for hiding this comment

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

unused

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

Choose a reason for hiding this comment

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

really kill all?

@@ -89,6 +89,7 @@
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Utility\ITimeFactory;
use OC\Group\GroupMapper;
use OC\MembershipManager;
Copy link
Member

Choose a reason for hiding this comment

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

unused

$c->getMemCacheFactory(),
$appManager,
$c->getTempManager()
new EnvironmentHelper(),
Copy link
Member

Choose a reason for hiding this comment

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

remove whitspace changes

@@ -239,4 +239,4 @@ public function callForAllUsers($callback, $search, $onlySeen) {
$stmt->closeCursor();
}

}
}
Copy link
Member

Choose a reason for hiding this comment

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

remove whitespace changes

*
* @return bool
*/
public function addGroupUser($accountId, $backendGroupId) {
Copy link
Member

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

*
* @return bool
*/
public function addGroupAdmin($accountId, $backendGroupId) {
Copy link
Member

Choose a reason for hiding this comment

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

same as with addGroupUser

* return result for all groups.
*
* @param string|int|null $groupId
* @param bool $isInternalGroupId
Copy link
Member

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

@mrow4a
Copy link
Contributor Author

mrow4a commented Nov 30, 2017

@DeepDiver1975 adjusted to comments

@DeepDiver1975 DeepDiver1975 added this to the development milestone Dec 1, 2017
@DeepDiver1975 DeepDiver1975 merged commit 5ad907c into centr_groups Dec 1, 2017
@DeepDiver1975 DeepDiver1975 deleted the centr_group_org branch December 1, 2017 11:39
@lock
Copy link

lock bot commented Aug 1, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants