-
Notifications
You must be signed in to change notification settings - Fork 11
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
Refactor to separate app code logic from core groups/memb logic + keep groups always in sync for centr_groups feature #138
Conversation
lib/Controller/PageController.php
Outdated
if (is_null($groupInfo)) { | ||
// TODO makes no sense, l10n does not exist 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.
Should I add l10n?
lib/Controller/PageController.php
Outdated
@@ -92,19 +85,21 @@ public function index() { | |||
/** | |||
* Search in all groups the current user is member of | |||
* | |||
* @param string $customGroupId custom group id | |||
* TODO: Get explanation what this was supposed to do |
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 have no idea what is this function about
lib/CustomGroupsBackend.php
Outdated
@@ -47,42 +46,13 @@ public function __construct( | |||
} | |||
|
|||
/** | |||
* Checks if backend implements actions. | |||
* Expose to the core only group details |
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 backend exposes to core only groupDetails
lib/CustomGroupsBackend.php
Outdated
* @param string $gid gid of the group | ||
* @return boolean true if user is in group, false otherwise | ||
*/ | ||
public function inGroup($uid, $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.
all memberships in this backend are gone to core - only groups are kept for consistency.
throw new NotFound("Group not found \"$groupId\""); | ||
} | ||
$group->delete(); | ||
$this->helper->deleteGroup($uri); |
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.
Moved the delete group logic to Helper (which does the sync to core also)
|
||
$event = new GenericEvent(null, ['groupName' => $this->groupInfo['display_name'], 'user' => $userId]); | ||
$this->dispatcher->dispatch('\OCA\CustomGroups::addUserToGroup', $event); | ||
$this->helper->addUser($this->groupInfo['uri'], $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.
Moved the add user to group logic to Helper (which does the sync to core also)
if (!$this->helper->isUserAdmin($this->groupInfo['group_id'])) { | ||
return 403; | ||
} | ||
$result = $this->helper->updateGroup($this->groupInfo['uri'], $displayName); |
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.
Moved the group update logic to Helper (which does the sync to core also)
lib/Dav/GroupsCollection.php
Outdated
|
||
// add current user as admin | ||
$this->groupsHandler->addToGroup($this->helper->getUserId(), $groupId, true); | ||
$this->helper->createGroup($name, $displayName); |
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.
Moved the group create logic to Helper (which does the sync to core also)
lib/Dav/MembershipNode.php
Outdated
$event = new GenericEvent(null, ['userId' => $userId, 'groupName' => $this->groupInfo['display_name']]); | ||
$this->dispatcher->dispatch('\OCA\CustomGroups::leaveFromGroup', $event); | ||
} | ||
$this->helper->removeUser($this->groupInfo['uri'], $this->memberInfo['user_id']); |
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.
Moved the add group user logic to Helper (which does the sync to core also)
Keep note that I also keep custom groups and memberships table - this is to not affect negatively stability of the app with big rewrite (with core mem/groups being new), and additionaly for consistency so if something goes really wrong, some cronjob sync will adjust it back (source of truth is custom groups app). |
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.
👍 for code-style. I don`t have enough knowledge in this part of core to do a full review. So only a nitpick:
If possible and in the scope of this task try to decompose the Helper class (ideally remove it) and fit the methods somewhere else in the architecture (maybe in smaller specialized classes) . Or if a helper method is just used once move it to a private method of the using class.
In my experience helper classes tend to accumulate all kinds of cruft, especially in bigger projects and finally transform to dumps for methods when people are in a hurry or don`t understand the architecture.
https://rrees.me/2009/02/09/the-helper-anti-pattern/
https://en.wikipedia.org/wiki/God_object
Mind pointing to the changes you did after moving the code ? Another alternative is to have the first PR commit only move the code and the second commit make the change so we can clearly see it. When moving code + changing it is difficult to see what's changed. Will this code also work with previous 10.0 versions ? |
@PVince81 Good idea! Will do :> Yes. it will work only with central_groups branch. However, without this change custom groups will also work, but users will see their memberships and new groups on login or when sync cron runs. So yes, this PR in case of custom groups is required, since it is OC user creating groups, not LDAP admin. |
Codecov Report
@@ Coverage Diff @@
## master #138 +/- ##
===========================================
+ Coverage 83.61% 84.92% +1.3%
- Complexity 300 306 +6
===========================================
Files 21 22 +1
Lines 952 975 +23
===========================================
+ Hits 796 828 +32
+ Misses 156 147 -9
Continue to review full report at Codecov.
|
@PVince81 @IljaN @tomneedham @butonic Just tested this app both with unit testss (>90% coverage) and manualy for stable10 core with 1st commit. This refactor should make this app cleaner, @IljaN thanks for earlier comments, they were very helpful - now there is a class CustomGroupsManager. |
Yes, after change in first commit, this app will work with both central groups and with earlier versions. This is due to the fact I really separated this app from core.. the only difference with central_groups is that instead core hitting this app for groups (through GroupInterface), it will not touch it and use central groups table. On other hand, app will sync all its changes with core (except admin of custom groups, since core does not care and this is only UX feature) @PVince81 @DeepDiver1975 |
@@ -37,7 +37,7 @@ Sharing with a Custom Group is as easy and quick as always. Just click on the sh | |||
</types> | |||
<use-migrations>true</use-migrations> | |||
<dependencies> | |||
<owncloud min-version="10.0.3" max-version="10.1" /> | |||
<owncloud min-version="10.1" max-version="10.1" /> |
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.
@PVince81 ok, with second commit I needed to increase the requirement, since createGroupFromBackend is needed for syncing with core. Everything else works as previously.
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.
First commit however passed all checks with stable core
central group tables wont be done |
The goal of following changes were to:
Refactor:
Always sync with centr_groups:
App keeps its groups/memberbers in sync with core with any action in the UX (add group/user remove group/user)
Central groups in core will result in separate core groups/membership logic so that core never hits the app code (and thus core is more stable)
Manual checks passed with stable10 in core
Manual checks passed with centr_groups in core
Adjusted unit tests