]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update sharing when users are removed, added to groups, and removed from groups
authorMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 25 Apr 2012 22:18:19 +0000 (18:18 -0400)
committerMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 25 Apr 2012 22:18:58 +0000 (18:18 -0400)
apps/files_sharing/appinfo/app.php
apps/files_sharing/lib_share.php

index 117b65d754fc4fb97acba49199663ed16a5c9a95..645f4f5e4f23de8fb3bf3f5f9928c7c8ba2eb0e7 100644 (file)
@@ -7,6 +7,9 @@ OC_APP::registerAdmin('files_sharing', 'settings');
 OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem");
 OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem");
 OC_Hook::connect("OC_Filesystem", "post_write", "OC_Share", "updateItem");
+OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_Share', 'removeUser');
+OC_Hook::connect('OC_User', 'post_addToGroup', 'OC_Share', 'addToGroupShare');
+OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFromGroupShare');
 $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
 if ($dir != '/Shared' || OC_Appconfig::getValue('files_sharing', 'resharing', 'yes') == 'yes') {
        OC_Util::addScript("files_sharing", "share");
index 673984f393b6fe28f20f7983c6f6ec9f21c899fb..84def87963a1c2def5dc996b3d00af5935f4f4fa 100644 (file)
@@ -436,6 +436,34 @@ class OC_Share {
                }
        }
 
+       public static function removeUser($arguments) {
+               $query = OC_DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_owner = ? OR uid_shared_with '.self::getUsersAndGroups($arguments['uid']));
+               $query->execute(array($arguments['uid']));
+       }
+
+       public static function addToGroupShare($arguments) {
+               $length = -strlen($arguments['gid']) - 1;
+               $query = OC_DB::prepare('SELECT uid_owner, source, permissions FROM *PREFIX*sharing WHERE SUBSTR(uid_shared_with, '.$length.') = ?');
+               $gid = '@'.$arguments['gid'];
+               $result = $query->execute(array($gid))->fetchAll();
+               if (count($result) > 0) {
+                       $query = OC_DB::prepare('INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)');
+                       $sharedFolder = '/'.$arguments['uid'].'/files/Shared/';
+                       $lastSource = '';
+                       for ($i = 0; i < count($result); $i++) {
+                               if ($result[$i]['source'] != $lastSource) {
+                                       $query->execute(array($result[$i]['uid_owner'], $arguments['uid'].'@'.$arguments['gid'], $result[$i]['source'], $sharedFolder.basename($result[$i]['source']), $result[$i]['permissions']));
+                                       $lastSource = $result[$i]['source'];
+                               }
+                       }
+               }
+       }
+
+       public static function removeFromGroupShare($arguments) {
+               $query = OC_DB::prepare('DELETE FROM *PREFIX*sharing WHERE uid_shared_with = ?');
+               $query->execute(array($arguments['uid'].'@'.$arguments['gid']));
+       }
+
 }
 
 ?>