5353use OCP \Mail \IMailer ;
5454use OCP \Share \Exceptions \ShareNotFound ;
5555use OCP \Share \IAttributes ;
56+ use OCP \Share \IManager ;
5657use OCP \Share \IShare ;
5758use OCP \Share \IShareProvider ;
5859use function str_starts_with ;
@@ -94,15 +95,17 @@ class DefaultShareProvider implements IShareProvider {
9495 private $ config ;
9596
9697 public function __construct (
97- IDBConnection $ connection ,
98- IUserManager $ userManager ,
99- IGroupManager $ groupManager ,
100- IRootFolder $ rootFolder ,
101- IMailer $ mailer ,
102- Defaults $ defaults ,
103- IFactory $ l10nFactory ,
104- IURLGenerator $ urlGenerator ,
105- IConfig $ config ) {
98+ IDBConnection $ connection ,
99+ IUserManager $ userManager ,
100+ IGroupManager $ groupManager ,
101+ IRootFolder $ rootFolder ,
102+ IMailer $ mailer ,
103+ Defaults $ defaults ,
104+ IFactory $ l10nFactory ,
105+ IURLGenerator $ urlGenerator ,
106+ IConfig $ config ,
107+ private IManager $ shareManager ,
108+ ) {
106109 $ this ->dbConn = $ connection ;
107110 $ this ->userManager = $ userManager ;
108111 $ this ->groupManager = $ groupManager ;
@@ -1302,6 +1305,7 @@ public function groupDeleted($gid) {
13021305 *
13031306 * @param string $uid
13041307 * @param string $gid
1308+ * @return void
13051309 */
13061310 public function userDeletedFromGroup ($ uid , $ gid ) {
13071311 /*
@@ -1313,7 +1317,7 @@ public function userDeletedFromGroup($uid, $gid) {
13131317 ->where ($ qb ->expr ()->eq ('share_type ' , $ qb ->createNamedParameter (IShare::TYPE_GROUP )))
13141318 ->andWhere ($ qb ->expr ()->eq ('share_with ' , $ qb ->createNamedParameter ($ gid )));
13151319
1316- $ cursor = $ qb ->execute ();
1320+ $ cursor = $ qb ->executeQuery ();
13171321 $ ids = [];
13181322 while ($ row = $ cursor ->fetch ()) {
13191323 $ ids [] = (int )$ row ['id ' ];
@@ -1330,7 +1334,45 @@ public function userDeletedFromGroup($uid, $gid) {
13301334 ->where ($ qb ->expr ()->eq ('share_type ' , $ qb ->createNamedParameter (IShare::TYPE_USERGROUP )))
13311335 ->andWhere ($ qb ->expr ()->eq ('share_with ' , $ qb ->createNamedParameter ($ uid )))
13321336 ->andWhere ($ qb ->expr ()->in ('parent ' , $ qb ->createNamedParameter ($ chunk , IQueryBuilder::PARAM_INT_ARRAY )));
1333- $ qb ->execute ();
1337+ $ qb ->executeStatement ();
1338+ }
1339+ }
1340+
1341+ if ($ this ->shareManager ->shareWithGroupMembersOnly ()) {
1342+ $ user = $ this ->userManager ->get ($ uid );
1343+ if ($ user === null ) {
1344+ return ;
1345+ }
1346+ $ userGroups = $ this ->groupManager ->getUserGroupIds ($ user );
1347+
1348+ // Delete user shares received by the user from users in the group.
1349+ $ userReceivedShares = $ this ->shareManager ->getSharedWith ($ uid , IShare::TYPE_USER , null , -1 );
1350+ foreach ($ userReceivedShares as $ share ) {
1351+ $ owner = $ this ->userManager ->get ($ share ->getSharedBy ());
1352+ if ($ owner === null ) {
1353+ continue ;
1354+ }
1355+ $ ownerGroups = $ this ->groupManager ->getUserGroupIds ($ owner );
1356+ $ mutualGroups = array_intersect ($ userGroups , $ ownerGroups );
1357+
1358+ if (count ($ mutualGroups ) === 0 ) {
1359+ $ this ->shareManager ->deleteShare ($ share );
1360+ }
1361+ }
1362+
1363+ // Delete user shares from the user to users in the group.
1364+ $ userEmittedShares = $ this ->shareManager ->getSharesBy ($ uid , IShare::TYPE_USER , null , true , -1 );
1365+ foreach ($ userEmittedShares as $ share ) {
1366+ $ recipient = $ this ->userManager ->get ($ share ->getSharedWith ());
1367+ if ($ recipient === null ) {
1368+ continue ;
1369+ }
1370+ $ recipientGroups = $ this ->groupManager ->getUserGroupIds ($ recipient );
1371+ $ mutualGroups = array_intersect ($ userGroups , $ recipientGroups );
1372+
1373+ if (count ($ mutualGroups ) === 0 ) {
1374+ $ this ->shareManager ->deleteShare ($ share );
1375+ }
13341376 }
13351377 }
13361378 }
0 commit comments