@@ -30,119 +30,119 @@ |
||
| 30 | 30 | * Storage placeholder to represent a missing precondition, storage unavailable |
| 31 | 31 | */ |
| 32 | 32 | class FailedCache implements ICache { |
| 33 | - /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | - private $visible; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * FailedCache constructor. |
|
| 38 | - * |
|
| 39 | - * @param bool $visible |
|
| 40 | - */ |
|
| 41 | - public function __construct($visible = true) { |
|
| 42 | - $this->visible = $visible; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - public function getNumericStorageId() { |
|
| 47 | - return -1; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function get($file) { |
|
| 51 | - if ($file === '') { |
|
| 52 | - return new CacheEntry([ |
|
| 53 | - 'fileid' => -1, |
|
| 54 | - 'size' => 0, |
|
| 55 | - 'mimetype' => 'httpd/unix-directory', |
|
| 56 | - 'mimepart' => 'httpd', |
|
| 57 | - 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | - 'mtime' => time() |
|
| 59 | - ]); |
|
| 60 | - } else { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getFolderContents($folder) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getFolderContentsById($fileId) { |
|
| 70 | - return []; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function put($file, array $data) { |
|
| 74 | - return; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function insert($file, array $data) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function update($id, array $data) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getId($file) { |
|
| 86 | - return -1; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function getParentId($file) { |
|
| 90 | - return -1; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function inCache($file) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function remove($file) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function move($source, $target) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function clear() { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function getStatus($file) { |
|
| 114 | - return ICache::NOT_FOUND; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function search($pattern) { |
|
| 118 | - return []; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function searchByMime($mimetype) { |
|
| 122 | - return []; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function searchByTag($tag, $userId) { |
|
| 126 | - return []; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function searchQuery(ISearchQuery $query) { |
|
| 130 | - return []; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function getAll() { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getIncomplete() { |
|
| 138 | - return []; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function getPathById($id) { |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function normalize($path) { |
|
| 146 | - return $path; |
|
| 147 | - } |
|
| 33 | + /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | + private $visible; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * FailedCache constructor. |
|
| 38 | + * |
|
| 39 | + * @param bool $visible |
|
| 40 | + */ |
|
| 41 | + public function __construct($visible = true) { |
|
| 42 | + $this->visible = $visible; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + public function getNumericStorageId() { |
|
| 47 | + return -1; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function get($file) { |
|
| 51 | + if ($file === '') { |
|
| 52 | + return new CacheEntry([ |
|
| 53 | + 'fileid' => -1, |
|
| 54 | + 'size' => 0, |
|
| 55 | + 'mimetype' => 'httpd/unix-directory', |
|
| 56 | + 'mimepart' => 'httpd', |
|
| 57 | + 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | + 'mtime' => time() |
|
| 59 | + ]); |
|
| 60 | + } else { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getFolderContents($folder) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getFolderContentsById($fileId) { |
|
| 70 | + return []; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function put($file, array $data) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function insert($file, array $data) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function update($id, array $data) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getId($file) { |
|
| 86 | + return -1; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function getParentId($file) { |
|
| 90 | + return -1; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function inCache($file) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function remove($file) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function move($source, $target) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function clear() { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function getStatus($file) { |
|
| 114 | + return ICache::NOT_FOUND; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function search($pattern) { |
|
| 118 | + return []; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function searchByMime($mimetype) { |
|
| 122 | + return []; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function searchByTag($tag, $userId) { |
|
| 126 | + return []; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function searchQuery(ISearchQuery $query) { |
|
| 130 | + return []; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function getAll() { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getIncomplete() { |
|
| 138 | + return []; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function getPathById($id) { |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function normalize($path) { |
|
| 146 | + return $path; |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -27,101 +27,101 @@ |
||
| 27 | 27 | use OCP\Files\Search\ISearchQuery; |
| 28 | 28 | |
| 29 | 29 | class NullCache implements ICache { |
| 30 | - public function getNumericStorageId() { |
|
| 31 | - return -1; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function get($file) { |
|
| 35 | - return $file !== '' ? null : |
|
| 36 | - new CacheEntry([ |
|
| 37 | - 'fileid' => -1, |
|
| 38 | - 'parent' => -1, |
|
| 39 | - 'name' => '', |
|
| 40 | - 'path' => '', |
|
| 41 | - 'size' => '0', |
|
| 42 | - 'mtime' => time(), |
|
| 43 | - 'storage_mtime' => time(), |
|
| 44 | - 'etag' => '', |
|
| 45 | - 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
| 46 | - 'mimepart' => 'httpd', |
|
| 47 | - 'permissions' => Constants::PERMISSION_READ |
|
| 48 | - ]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getFolderContents($folder) { |
|
| 52 | - return []; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function getFolderContentsById($fileId) { |
|
| 56 | - return []; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function put($file, array $data) { |
|
| 60 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function insert($file, array $data) { |
|
| 64 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function update($id, array $data) { |
|
| 68 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function getId($file) { |
|
| 72 | - return -1; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getParentId($file) { |
|
| 76 | - return -1; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function inCache($file) { |
|
| 80 | - return $file === ''; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function remove($file) { |
|
| 84 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function move($source, $target) { |
|
| 88 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 92 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function getStatus($file) { |
|
| 96 | - return ICache::COMPLETE; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function search($pattern) { |
|
| 100 | - return []; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function searchByMime($mimetype) { |
|
| 104 | - return []; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function searchQuery(ISearchQuery $query) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function searchByTag($tag, $userId) { |
|
| 112 | - return []; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function getIncomplete() { |
|
| 116 | - return []; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getPathById($id) { |
|
| 120 | - return ''; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function normalize($path) { |
|
| 124 | - return $path; |
|
| 125 | - } |
|
| 30 | + public function getNumericStorageId() { |
|
| 31 | + return -1; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function get($file) { |
|
| 35 | + return $file !== '' ? null : |
|
| 36 | + new CacheEntry([ |
|
| 37 | + 'fileid' => -1, |
|
| 38 | + 'parent' => -1, |
|
| 39 | + 'name' => '', |
|
| 40 | + 'path' => '', |
|
| 41 | + 'size' => '0', |
|
| 42 | + 'mtime' => time(), |
|
| 43 | + 'storage_mtime' => time(), |
|
| 44 | + 'etag' => '', |
|
| 45 | + 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
| 46 | + 'mimepart' => 'httpd', |
|
| 47 | + 'permissions' => Constants::PERMISSION_READ |
|
| 48 | + ]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getFolderContents($folder) { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function getFolderContentsById($fileId) { |
|
| 56 | + return []; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function put($file, array $data) { |
|
| 60 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function insert($file, array $data) { |
|
| 64 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function update($id, array $data) { |
|
| 68 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function getId($file) { |
|
| 72 | + return -1; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getParentId($file) { |
|
| 76 | + return -1; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function inCache($file) { |
|
| 80 | + return $file === ''; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function remove($file) { |
|
| 84 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function move($source, $target) { |
|
| 88 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 92 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function getStatus($file) { |
|
| 96 | + return ICache::COMPLETE; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function search($pattern) { |
|
| 100 | + return []; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function searchByMime($mimetype) { |
|
| 104 | + return []; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function searchQuery(ISearchQuery $query) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function searchByTag($tag, $userId) { |
|
| 112 | + return []; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function getIncomplete() { |
|
| 116 | + return []; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getPathById($id) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function normalize($path) { |
|
| 124 | + return $path; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php /** @var $l OC_L10N */ ?> |
| 2 | 2 | <?php |
| 3 | 3 | script('core', [ |
| 4 | - 'jquery-showpassword', |
|
| 4 | + 'jquery-showpassword', |
|
| 5 | 5 | ]); |
| 6 | 6 | script('user_ldap', [ |
| 7 | - 'renewPassword', |
|
| 7 | + 'renewPassword', |
|
| 8 | 8 | ]); |
| 9 | 9 | style('user_ldap', 'renewPassword'); |
| 10 | 10 | \OC_Util::addVendorScript('strengthify/jquery.strengthify'); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | <div class="warning title"> |
| 19 | 19 | <?php p($l->t('Please renew your password.')); ?><br> |
| 20 | 20 | </div> |
| 21 | - <?php foreach($_['messages'] as $message): ?> |
|
| 21 | + <?php foreach ($_['messages'] as $message): ?> |
|
| 22 | 22 | <div class="warning"> |
| 23 | 23 | <?php p($message); ?><br> |
| 24 | 24 | </div> |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | <?php endif; ?> |
| 32 | 32 | <div id="message" class="hidden"> |
| 33 | 33 | <img class="float-spinner" alt="" |
| 34 | - src="<?php p(image_path('core', 'loading-dark.gif'));?>"> |
|
| 34 | + src="<?php p(image_path('core', 'loading-dark.gif')); ?>"> |
|
| 35 | 35 | <span id="messageText"></span> |
| 36 | 36 | <!-- the following div ensures that the spinner is always inside the #message div --> |
| 37 | 37 | <div style="clear: both;"></div> |
| 38 | 38 | </div> |
| 39 | 39 | <p class="grouptop"> |
| 40 | 40 | <input type="password" id="oldPassword" name="oldPassword" |
| 41 | - placeholder="<?php echo $l->t('Current password');?>" |
|
| 41 | + placeholder="<?php echo $l->t('Current password'); ?>" |
|
| 42 | 42 | autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
| 43 | 43 | <label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label> |
| 44 | 44 | </p> |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | <input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label> |
| 48 | 48 | <label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label> |
| 49 | 49 | <input type="password" id="newPassword" name="newPassword" |
| 50 | - placeholder="<?php echo $l->t('New password');?>" |
|
| 50 | + placeholder="<?php echo $l->t('New password'); ?>" |
|
| 51 | 51 | data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
| 52 | 52 | </p> |
| 53 | 53 | |
@@ -80,22 +80,22 @@ discard block |
||
| 80 | 80 | //pass in app.php we do add here, except something else is passed e.g. |
| 81 | 81 | //in tests. |
| 82 | 82 | |
| 83 | - if(isset($arguments['helper'])) { |
|
| 83 | + if (isset($arguments['helper'])) { |
|
| 84 | 84 | $this->ldapHelper = $arguments['helper']; |
| 85 | 85 | } else { |
| 86 | 86 | $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if(isset($arguments['ocConfig'])) { |
|
| 89 | + if (isset($arguments['ocConfig'])) { |
|
| 90 | 90 | $this->ocConfig = $arguments['ocConfig']; |
| 91 | 91 | } else { |
| 92 | 92 | $this->ocConfig = \OC::$server->getConfig(); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if(isset($arguments['userBackend'])) { |
|
| 95 | + if (isset($arguments['userBackend'])) { |
|
| 96 | 96 | $this->userBackend = $arguments['userBackend']; |
| 97 | 97 | } else { |
| 98 | - $this->userBackend = new User_Proxy( |
|
| 98 | + $this->userBackend = new User_Proxy( |
|
| 99 | 99 | $this->ldapHelper->getServerConfigurationPrefixes(true), |
| 100 | 100 | new LDAP(), |
| 101 | 101 | $this->ocConfig, |
@@ -103,19 +103,19 @@ discard block |
||
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if(isset($arguments['db'])) { |
|
| 106 | + if (isset($arguments['db'])) { |
|
| 107 | 107 | $this->db = $arguments['db']; |
| 108 | 108 | } else { |
| 109 | 109 | $this->db = \OC::$server->getDatabaseConnection(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if(isset($arguments['mapping'])) { |
|
| 112 | + if (isset($arguments['mapping'])) { |
|
| 113 | 113 | $this->mapping = $arguments['mapping']; |
| 114 | 114 | } else { |
| 115 | 115 | $this->mapping = new UserMapping($this->db); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if(isset($arguments['deletedUsersIndex'])) { |
|
| 118 | + if (isset($arguments['deletedUsersIndex'])) { |
|
| 119 | 119 | $this->dui = $arguments['deletedUsersIndex']; |
| 120 | 120 | } else { |
| 121 | 121 | $this->dui = new DeletedUsersIndex( |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | public function run($argument) { |
| 131 | 131 | $this->setArguments($argument); |
| 132 | 132 | |
| 133 | - if(!$this->isCleanUpAllowed()) { |
|
| 133 | + if (!$this->isCleanUpAllowed()) { |
|
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | $users = $this->mapping->getList($this->getOffset(), $this->limit); |
| 137 | - if(!is_array($users)) { |
|
| 137 | + if (!is_array($users)) { |
|
| 138 | 138 | //something wrong? Let's start from the beginning next time and |
| 139 | 139 | //abort |
| 140 | 140 | $this->setOffset(true); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function isCleanUpAllowed() { |
| 162 | 162 | try { |
| 163 | - if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 163 | + if ($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 164 | 164 | return false; |
| 165 | 165 | } |
| 166 | 166 | } catch (\Exception $e) { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @return bool |
| 178 | 178 | */ |
| 179 | 179 | private function isCleanUpEnabled() { |
| 180 | - return (bool)$this->ocConfig->getSystemValue( |
|
| 180 | + return (bool) $this->ocConfig->getSystemValue( |
|
| 181 | 181 | 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * @param array $users result from getMappedUsers() |
| 187 | 187 | */ |
| 188 | 188 | private function checkUsers(array $users) { |
| 189 | - foreach($users as $user) { |
|
| 189 | + foreach ($users as $user) { |
|
| 190 | 190 | $this->checkUser($user); |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param string[] $user |
| 197 | 197 | */ |
| 198 | 198 | private function checkUser(array $user) { |
| 199 | - if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 199 | + if ($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 200 | 200 | //still available, all good |
| 201 | 201 | |
| 202 | 202 | return; |
@@ -218,8 +218,7 @@ discard block |
||
| 218 | 218 | * @param bool $reset whether the offset should be set to 0 |
| 219 | 219 | */ |
| 220 | 220 | public function setOffset($reset = false) { |
| 221 | - $newOffset = $reset ? 0 : |
|
| 222 | - $this->getOffset() + $this->limit; |
|
| 221 | + $newOffset = $reset ? 0 : $this->getOffset() + $this->limit; |
|
| 223 | 222 | $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
| 224 | 223 | } |
| 225 | 224 | |
@@ -40,197 +40,197 @@ |
||
| 40 | 40 | * @package OCA\User_LDAP\Jobs; |
| 41 | 41 | */ |
| 42 | 42 | class CleanUp extends TimedJob { |
| 43 | - /** @var int $limit amount of users that should be checked per run */ |
|
| 44 | - protected $limit = 50; |
|
| 45 | - |
|
| 46 | - /** @var int $defaultIntervalMin default interval in minutes */ |
|
| 47 | - protected $defaultIntervalMin = 51; |
|
| 48 | - |
|
| 49 | - /** @var User_LDAP|User_Proxy $userBackend */ |
|
| 50 | - protected $userBackend; |
|
| 51 | - |
|
| 52 | - /** @var \OCP\IConfig $ocConfig */ |
|
| 53 | - protected $ocConfig; |
|
| 54 | - |
|
| 55 | - /** @var \OCP\IDBConnection $db */ |
|
| 56 | - protected $db; |
|
| 57 | - |
|
| 58 | - /** @var Helper $ldapHelper */ |
|
| 59 | - protected $ldapHelper; |
|
| 60 | - |
|
| 61 | - /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
| 62 | - protected $mapping; |
|
| 63 | - |
|
| 64 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
| 65 | - protected $dui; |
|
| 66 | - |
|
| 67 | - public function __construct() { |
|
| 68 | - $minutes = \OC::$server->getConfig()->getSystemValue( |
|
| 69 | - 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 70 | - $this->setInterval(intval($minutes) * 60); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * assigns the instances passed to run() to the class properties |
|
| 75 | - * @param array $arguments |
|
| 76 | - */ |
|
| 77 | - public function setArguments($arguments) { |
|
| 78 | - //Dependency Injection is not possible, because the constructor will |
|
| 79 | - //only get values that are serialized to JSON. I.e. whatever we would |
|
| 80 | - //pass in app.php we do add here, except something else is passed e.g. |
|
| 81 | - //in tests. |
|
| 82 | - |
|
| 83 | - if(isset($arguments['helper'])) { |
|
| 84 | - $this->ldapHelper = $arguments['helper']; |
|
| 85 | - } else { |
|
| 86 | - $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if(isset($arguments['ocConfig'])) { |
|
| 90 | - $this->ocConfig = $arguments['ocConfig']; |
|
| 91 | - } else { |
|
| 92 | - $this->ocConfig = \OC::$server->getConfig(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if(isset($arguments['userBackend'])) { |
|
| 96 | - $this->userBackend = $arguments['userBackend']; |
|
| 97 | - } else { |
|
| 98 | - $this->userBackend = new User_Proxy( |
|
| 99 | - $this->ldapHelper->getServerConfigurationPrefixes(true), |
|
| 100 | - new LDAP(), |
|
| 101 | - $this->ocConfig, |
|
| 102 | - \OC::$server->getNotificationManager(), |
|
| 103 | - \OC::$server->getUserSession(), |
|
| 104 | - \OC::$server->query('LDAPUserPluginManager') |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if(isset($arguments['db'])) { |
|
| 109 | - $this->db = $arguments['db']; |
|
| 110 | - } else { |
|
| 111 | - $this->db = \OC::$server->getDatabaseConnection(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if(isset($arguments['mapping'])) { |
|
| 115 | - $this->mapping = $arguments['mapping']; |
|
| 116 | - } else { |
|
| 117 | - $this->mapping = new UserMapping($this->db); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if(isset($arguments['deletedUsersIndex'])) { |
|
| 121 | - $this->dui = $arguments['deletedUsersIndex']; |
|
| 122 | - } else { |
|
| 123 | - $this->dui = new DeletedUsersIndex( |
|
| 124 | - $this->ocConfig, $this->db, $this->mapping); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * makes the background job do its work |
|
| 130 | - * @param array $argument |
|
| 131 | - */ |
|
| 132 | - public function run($argument) { |
|
| 133 | - $this->setArguments($argument); |
|
| 134 | - |
|
| 135 | - if(!$this->isCleanUpAllowed()) { |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - $users = $this->mapping->getList($this->getOffset(), $this->limit); |
|
| 139 | - if(!is_array($users)) { |
|
| 140 | - //something wrong? Let's start from the beginning next time and |
|
| 141 | - //abort |
|
| 142 | - $this->setOffset(true); |
|
| 143 | - return; |
|
| 144 | - } |
|
| 145 | - $resetOffset = $this->isOffsetResetNecessary(count($users)); |
|
| 146 | - $this->checkUsers($users); |
|
| 147 | - $this->setOffset($resetOffset); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * checks whether next run should start at 0 again |
|
| 152 | - * @param int $resultCount |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public function isOffsetResetNecessary($resultCount) { |
|
| 156 | - return ($resultCount < $this->limit) ? true : false; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * checks whether cleaning up LDAP users is allowed |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public function isCleanUpAllowed() { |
|
| 164 | - try { |
|
| 165 | - if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - } catch (\Exception $e) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $enabled = $this->isCleanUpEnabled(); |
|
| 173 | - |
|
| 174 | - return $enabled; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * checks whether clean up is enabled by configuration |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 181 | - private function isCleanUpEnabled() { |
|
| 182 | - return (bool)$this->ocConfig->getSystemValue( |
|
| 183 | - 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * checks users whether they are still existing |
|
| 188 | - * @param array $users result from getMappedUsers() |
|
| 189 | - */ |
|
| 190 | - private function checkUsers(array $users) { |
|
| 191 | - foreach($users as $user) { |
|
| 192 | - $this->checkUser($user); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * checks whether a user is still existing in LDAP |
|
| 198 | - * @param string[] $user |
|
| 199 | - */ |
|
| 200 | - private function checkUser(array $user) { |
|
| 201 | - if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 202 | - //still available, all good |
|
| 203 | - |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $this->dui->markUser($user['name']); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * gets the offset to fetch users from the mappings table |
|
| 212 | - * @return int |
|
| 213 | - */ |
|
| 214 | - private function getOffset() { |
|
| 215 | - return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0)); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * sets the new offset for the next run |
|
| 220 | - * @param bool $reset whether the offset should be set to 0 |
|
| 221 | - */ |
|
| 222 | - public function setOffset($reset = false) { |
|
| 223 | - $newOffset = $reset ? 0 : |
|
| 224 | - $this->getOffset() + $this->limit; |
|
| 225 | - $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * returns the chunk size (limit in DB speak) |
|
| 230 | - * @return int |
|
| 231 | - */ |
|
| 232 | - public function getChunkSize() { |
|
| 233 | - return $this->limit; |
|
| 234 | - } |
|
| 43 | + /** @var int $limit amount of users that should be checked per run */ |
|
| 44 | + protected $limit = 50; |
|
| 45 | + |
|
| 46 | + /** @var int $defaultIntervalMin default interval in minutes */ |
|
| 47 | + protected $defaultIntervalMin = 51; |
|
| 48 | + |
|
| 49 | + /** @var User_LDAP|User_Proxy $userBackend */ |
|
| 50 | + protected $userBackend; |
|
| 51 | + |
|
| 52 | + /** @var \OCP\IConfig $ocConfig */ |
|
| 53 | + protected $ocConfig; |
|
| 54 | + |
|
| 55 | + /** @var \OCP\IDBConnection $db */ |
|
| 56 | + protected $db; |
|
| 57 | + |
|
| 58 | + /** @var Helper $ldapHelper */ |
|
| 59 | + protected $ldapHelper; |
|
| 60 | + |
|
| 61 | + /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
| 62 | + protected $mapping; |
|
| 63 | + |
|
| 64 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
| 65 | + protected $dui; |
|
| 66 | + |
|
| 67 | + public function __construct() { |
|
| 68 | + $minutes = \OC::$server->getConfig()->getSystemValue( |
|
| 69 | + 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 70 | + $this->setInterval(intval($minutes) * 60); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * assigns the instances passed to run() to the class properties |
|
| 75 | + * @param array $arguments |
|
| 76 | + */ |
|
| 77 | + public function setArguments($arguments) { |
|
| 78 | + //Dependency Injection is not possible, because the constructor will |
|
| 79 | + //only get values that are serialized to JSON. I.e. whatever we would |
|
| 80 | + //pass in app.php we do add here, except something else is passed e.g. |
|
| 81 | + //in tests. |
|
| 82 | + |
|
| 83 | + if(isset($arguments['helper'])) { |
|
| 84 | + $this->ldapHelper = $arguments['helper']; |
|
| 85 | + } else { |
|
| 86 | + $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if(isset($arguments['ocConfig'])) { |
|
| 90 | + $this->ocConfig = $arguments['ocConfig']; |
|
| 91 | + } else { |
|
| 92 | + $this->ocConfig = \OC::$server->getConfig(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if(isset($arguments['userBackend'])) { |
|
| 96 | + $this->userBackend = $arguments['userBackend']; |
|
| 97 | + } else { |
|
| 98 | + $this->userBackend = new User_Proxy( |
|
| 99 | + $this->ldapHelper->getServerConfigurationPrefixes(true), |
|
| 100 | + new LDAP(), |
|
| 101 | + $this->ocConfig, |
|
| 102 | + \OC::$server->getNotificationManager(), |
|
| 103 | + \OC::$server->getUserSession(), |
|
| 104 | + \OC::$server->query('LDAPUserPluginManager') |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if(isset($arguments['db'])) { |
|
| 109 | + $this->db = $arguments['db']; |
|
| 110 | + } else { |
|
| 111 | + $this->db = \OC::$server->getDatabaseConnection(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if(isset($arguments['mapping'])) { |
|
| 115 | + $this->mapping = $arguments['mapping']; |
|
| 116 | + } else { |
|
| 117 | + $this->mapping = new UserMapping($this->db); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if(isset($arguments['deletedUsersIndex'])) { |
|
| 121 | + $this->dui = $arguments['deletedUsersIndex']; |
|
| 122 | + } else { |
|
| 123 | + $this->dui = new DeletedUsersIndex( |
|
| 124 | + $this->ocConfig, $this->db, $this->mapping); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * makes the background job do its work |
|
| 130 | + * @param array $argument |
|
| 131 | + */ |
|
| 132 | + public function run($argument) { |
|
| 133 | + $this->setArguments($argument); |
|
| 134 | + |
|
| 135 | + if(!$this->isCleanUpAllowed()) { |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + $users = $this->mapping->getList($this->getOffset(), $this->limit); |
|
| 139 | + if(!is_array($users)) { |
|
| 140 | + //something wrong? Let's start from the beginning next time and |
|
| 141 | + //abort |
|
| 142 | + $this->setOffset(true); |
|
| 143 | + return; |
|
| 144 | + } |
|
| 145 | + $resetOffset = $this->isOffsetResetNecessary(count($users)); |
|
| 146 | + $this->checkUsers($users); |
|
| 147 | + $this->setOffset($resetOffset); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * checks whether next run should start at 0 again |
|
| 152 | + * @param int $resultCount |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public function isOffsetResetNecessary($resultCount) { |
|
| 156 | + return ($resultCount < $this->limit) ? true : false; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * checks whether cleaning up LDAP users is allowed |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public function isCleanUpAllowed() { |
|
| 164 | + try { |
|
| 165 | + if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + } catch (\Exception $e) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $enabled = $this->isCleanUpEnabled(); |
|
| 173 | + |
|
| 174 | + return $enabled; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * checks whether clean up is enabled by configuration |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | + private function isCleanUpEnabled() { |
|
| 182 | + return (bool)$this->ocConfig->getSystemValue( |
|
| 183 | + 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * checks users whether they are still existing |
|
| 188 | + * @param array $users result from getMappedUsers() |
|
| 189 | + */ |
|
| 190 | + private function checkUsers(array $users) { |
|
| 191 | + foreach($users as $user) { |
|
| 192 | + $this->checkUser($user); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * checks whether a user is still existing in LDAP |
|
| 198 | + * @param string[] $user |
|
| 199 | + */ |
|
| 200 | + private function checkUser(array $user) { |
|
| 201 | + if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 202 | + //still available, all good |
|
| 203 | + |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $this->dui->markUser($user['name']); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * gets the offset to fetch users from the mappings table |
|
| 212 | + * @return int |
|
| 213 | + */ |
|
| 214 | + private function getOffset() { |
|
| 215 | + return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0)); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * sets the new offset for the next run |
|
| 220 | + * @param bool $reset whether the offset should be set to 0 |
|
| 221 | + */ |
|
| 222 | + public function setOffset($reset = false) { |
|
| 223 | + $newOffset = $reset ? 0 : |
|
| 224 | + $this->getOffset() + $this->limit; |
|
| 225 | + $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * returns the chunk size (limit in DB speak) |
|
| 230 | + * @return int |
|
| 231 | + */ |
|
| 232 | + public function getChunkSize() { |
|
| 233 | + return $this->limit; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | use OCP\AppFramework\IAppContainer; |
| 28 | 28 | |
| 29 | 29 | class Application extends App { |
| 30 | - public function __construct () { |
|
| 30 | + public function __construct() { |
|
| 31 | 31 | parent::__construct('user_ldap'); |
| 32 | 32 | $container = $this->getContainer(); |
| 33 | 33 | |
@@ -28,26 +28,26 @@ |
||
| 28 | 28 | use OCP\AppFramework\IAppContainer; |
| 29 | 29 | |
| 30 | 30 | class Application extends App { |
| 31 | - public function __construct () { |
|
| 32 | - parent::__construct('user_ldap'); |
|
| 33 | - $container = $this->getContainer(); |
|
| 31 | + public function __construct () { |
|
| 32 | + parent::__construct('user_ldap'); |
|
| 33 | + $container = $this->getContainer(); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Controller |
|
| 37 | - */ |
|
| 38 | - $container->registerService('RenewPasswordController', function(IAppContainer $c) { |
|
| 39 | - /** @var \OC\Server $server */ |
|
| 40 | - $server = $c->query('ServerContainer'); |
|
| 35 | + /** |
|
| 36 | + * Controller |
|
| 37 | + */ |
|
| 38 | + $container->registerService('RenewPasswordController', function(IAppContainer $c) { |
|
| 39 | + /** @var \OC\Server $server */ |
|
| 40 | + $server = $c->query('ServerContainer'); |
|
| 41 | 41 | |
| 42 | - return new RenewPasswordController( |
|
| 43 | - $c->getAppName(), |
|
| 44 | - $server->getRequest(), |
|
| 45 | - $c->query('UserManager'), |
|
| 46 | - $server->getConfig(), |
|
| 47 | - $c->query('OCP\IL10N'), |
|
| 48 | - $c->query('Session'), |
|
| 49 | - $server->getURLGenerator() |
|
| 50 | - ); |
|
| 51 | - }); |
|
| 52 | - } |
|
| 42 | + return new RenewPasswordController( |
|
| 43 | + $c->getAppName(), |
|
| 44 | + $server->getRequest(), |
|
| 45 | + $c->query('UserManager'), |
|
| 46 | + $server->getConfig(), |
|
| 47 | + $c->query('OCP\IL10N'), |
|
| 48 | + $c->query('Session'), |
|
| 49 | + $server->getURLGenerator() |
|
| 50 | + ); |
|
| 51 | + }); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -31,82 +31,82 @@ |
||
| 31 | 31 | |
| 32 | 32 | class ImageManager { |
| 33 | 33 | |
| 34 | - /** @var IConfig */ |
|
| 35 | - private $config; |
|
| 36 | - /** @var IAppData */ |
|
| 37 | - private $appData; |
|
| 34 | + /** @var IConfig */ |
|
| 35 | + private $config; |
|
| 36 | + /** @var IAppData */ |
|
| 37 | + private $appData; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * ImageManager constructor. |
|
| 41 | - * |
|
| 42 | - * @param IConfig $config |
|
| 43 | - * @param IAppData $appData |
|
| 44 | - */ |
|
| 45 | - public function __construct(IConfig $config, |
|
| 46 | - IAppData $appData |
|
| 47 | - ) { |
|
| 48 | - $this->config = $config; |
|
| 49 | - $this->appData = $appData; |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * ImageManager constructor. |
|
| 41 | + * |
|
| 42 | + * @param IConfig $config |
|
| 43 | + * @param IAppData $appData |
|
| 44 | + */ |
|
| 45 | + public function __construct(IConfig $config, |
|
| 46 | + IAppData $appData |
|
| 47 | + ) { |
|
| 48 | + $this->config = $config; |
|
| 49 | + $this->appData = $appData; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get folder for current theming files |
|
| 54 | - * |
|
| 55 | - * @return \OCP\Files\SimpleFS\ISimpleFolder |
|
| 56 | - * @throws NotPermittedException |
|
| 57 | - * @throws \RuntimeException |
|
| 58 | - */ |
|
| 59 | - public function getCacheFolder() { |
|
| 60 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 61 | - try { |
|
| 62 | - $folder = $this->appData->getFolder($cacheBusterValue); |
|
| 63 | - } catch (NotFoundException $e) { |
|
| 64 | - $folder = $this->appData->newFolder($cacheBusterValue); |
|
| 65 | - $this->cleanup(); |
|
| 66 | - } |
|
| 67 | - return $folder; |
|
| 68 | - } |
|
| 52 | + /** |
|
| 53 | + * Get folder for current theming files |
|
| 54 | + * |
|
| 55 | + * @return \OCP\Files\SimpleFS\ISimpleFolder |
|
| 56 | + * @throws NotPermittedException |
|
| 57 | + * @throws \RuntimeException |
|
| 58 | + */ |
|
| 59 | + public function getCacheFolder() { |
|
| 60 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 61 | + try { |
|
| 62 | + $folder = $this->appData->getFolder($cacheBusterValue); |
|
| 63 | + } catch (NotFoundException $e) { |
|
| 64 | + $folder = $this->appData->newFolder($cacheBusterValue); |
|
| 65 | + $this->cleanup(); |
|
| 66 | + } |
|
| 67 | + return $folder; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Get a file from AppData |
|
| 72 | - * |
|
| 73 | - * @param string $filename |
|
| 74 | - * @throws NotFoundException |
|
| 75 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
| 76 | - */ |
|
| 77 | - public function getCachedImage($filename) { |
|
| 78 | - $currentFolder = $this->getCacheFolder(); |
|
| 79 | - return $currentFolder->getFile($filename); |
|
| 80 | - } |
|
| 70 | + /** |
|
| 71 | + * Get a file from AppData |
|
| 72 | + * |
|
| 73 | + * @param string $filename |
|
| 74 | + * @throws NotFoundException |
|
| 75 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
| 76 | + */ |
|
| 77 | + public function getCachedImage($filename) { |
|
| 78 | + $currentFolder = $this->getCacheFolder(); |
|
| 79 | + return $currentFolder->getFile($filename); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Store a file for theming in AppData |
|
| 84 | - * |
|
| 85 | - * @param string $filename |
|
| 86 | - * @param string $data |
|
| 87 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
| 88 | - */ |
|
| 89 | - public function setCachedImage($filename, $data) { |
|
| 90 | - $currentFolder = $this->getCacheFolder(); |
|
| 91 | - if ($currentFolder->fileExists($filename)) { |
|
| 92 | - $file = $currentFolder->getFile($filename); |
|
| 93 | - } else { |
|
| 94 | - $file = $currentFolder->newFile($filename); |
|
| 95 | - } |
|
| 96 | - $file->putContent($data); |
|
| 97 | - return $file; |
|
| 98 | - } |
|
| 82 | + /** |
|
| 83 | + * Store a file for theming in AppData |
|
| 84 | + * |
|
| 85 | + * @param string $filename |
|
| 86 | + * @param string $data |
|
| 87 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
| 88 | + */ |
|
| 89 | + public function setCachedImage($filename, $data) { |
|
| 90 | + $currentFolder = $this->getCacheFolder(); |
|
| 91 | + if ($currentFolder->fileExists($filename)) { |
|
| 92 | + $file = $currentFolder->getFile($filename); |
|
| 93 | + } else { |
|
| 94 | + $file = $currentFolder->newFile($filename); |
|
| 95 | + } |
|
| 96 | + $file->putContent($data); |
|
| 97 | + return $file; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * remove cached files that are not required any longer |
|
| 102 | - */ |
|
| 103 | - public function cleanup() { |
|
| 104 | - $currentFolder = $this->getCacheFolder(); |
|
| 105 | - $folders = $this->appData->getDirectoryListing(); |
|
| 106 | - foreach ($folders as $folder) { |
|
| 107 | - if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
| 108 | - $folder->delete(); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 100 | + /** |
|
| 101 | + * remove cached files that are not required any longer |
|
| 102 | + */ |
|
| 103 | + public function cleanup() { |
|
| 104 | + $currentFolder = $this->getCacheFolder(); |
|
| 105 | + $folders = $this->appData->getDirectoryListing(); |
|
| 106 | + foreach ($folders as $folder) { |
|
| 107 | + if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
| 108 | + $folder->delete(); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -34,44 +34,44 @@ |
||
| 34 | 34 | |
| 35 | 35 | class ThemingImages implements IRepairStep { |
| 36 | 36 | |
| 37 | - private $appData; |
|
| 38 | - private $rootFolder; |
|
| 37 | + private $appData; |
|
| 38 | + private $rootFolder; |
|
| 39 | 39 | |
| 40 | - public function __construct(IAppData $appData, IRootFolder $rootFolder) { |
|
| 41 | - $this->appData = $appData; |
|
| 42 | - $this->rootFolder = $rootFolder; |
|
| 43 | - } |
|
| 40 | + public function __construct(IAppData $appData, IRootFolder $rootFolder) { |
|
| 41 | + $this->appData = $appData; |
|
| 42 | + $this->rootFolder = $rootFolder; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /* |
|
| 45 | + /* |
|
| 46 | 46 | * @inheritdoc |
| 47 | 47 | */ |
| 48 | - public function getName() { |
|
| 49 | - return 'Move theming files to AppData storage'; |
|
| 50 | - } |
|
| 48 | + public function getName() { |
|
| 49 | + return 'Move theming files to AppData storage'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @inheritdoc |
|
| 54 | - */ |
|
| 55 | - public function run(IOutput $output) { |
|
| 56 | - $folder = $this->appData->newFolder("images"); |
|
| 57 | - /** @var File $file */ |
|
| 58 | - $file = null; |
|
| 59 | - try { |
|
| 60 | - $file = $this->rootFolder->get('themedinstancelogo'); |
|
| 61 | - $logo = $folder->newFile('logo'); |
|
| 62 | - $logo->putContent($file->getContent()); |
|
| 63 | - $file->delete(); |
|
| 64 | - } catch (NotFoundException $e) { |
|
| 65 | - $output->info('No theming logo image to migrate'); |
|
| 66 | - } |
|
| 52 | + /** |
|
| 53 | + * @inheritdoc |
|
| 54 | + */ |
|
| 55 | + public function run(IOutput $output) { |
|
| 56 | + $folder = $this->appData->newFolder("images"); |
|
| 57 | + /** @var File $file */ |
|
| 58 | + $file = null; |
|
| 59 | + try { |
|
| 60 | + $file = $this->rootFolder->get('themedinstancelogo'); |
|
| 61 | + $logo = $folder->newFile('logo'); |
|
| 62 | + $logo->putContent($file->getContent()); |
|
| 63 | + $file->delete(); |
|
| 64 | + } catch (NotFoundException $e) { |
|
| 65 | + $output->info('No theming logo image to migrate'); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - try { |
|
| 69 | - $file = $this->rootFolder->get('themedbackgroundlogo'); |
|
| 70 | - $background = $folder->newFile('background'); |
|
| 71 | - $background->putContent($file->getContent()); |
|
| 72 | - $file->delete(); |
|
| 73 | - } catch (NotFoundException $e) { |
|
| 74 | - $output->info('No theming background image to migrate'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 68 | + try { |
|
| 69 | + $file = $this->rootFolder->get('themedbackgroundlogo'); |
|
| 70 | + $background = $folder->newFile('background'); |
|
| 71 | + $background->putContent($file->getContent()); |
|
| 72 | + $file->delete(); |
|
| 73 | + } catch (NotFoundException $e) { |
|
| 74 | + $output->info('No theming background image to migrate'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | $updatedEntries = $builder->execute(); |
| 73 | 73 | if ($updatedEntries > 0) { |
| 74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 74 | + $out->info('Fixed file share permissions for '.$updatedEntries.' shares'); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ($deletedEntries) { |
| 110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 110 | + $out->info('Removed '.$deletedEntries.' shares where the parent did not exist'); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
@@ -33,90 +33,90 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class RepairInvalidShares implements IRepairStep { |
| 35 | 35 | |
| 36 | - const CHUNK_SIZE = 200; |
|
| 37 | - |
|
| 38 | - /** @var \OCP\IConfig */ |
|
| 39 | - protected $config; |
|
| 40 | - |
|
| 41 | - /** @var \OCP\IDBConnection */ |
|
| 42 | - protected $connection; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param \OCP\IConfig $config |
|
| 46 | - * @param \OCP\IDBConnection $connection |
|
| 47 | - */ |
|
| 48 | - public function __construct($config, $connection) { |
|
| 49 | - $this->connection = $connection; |
|
| 50 | - $this->config = $config; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function getName() { |
|
| 54 | - return 'Repair invalid shares'; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Adjust file share permissions |
|
| 59 | - * @suppress SqlInjectionChecker |
|
| 60 | - */ |
|
| 61 | - private function adjustFileSharePermissions(IOutput $out) { |
|
| 62 | - $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
| 63 | - $builder = $this->connection->getQueryBuilder(); |
|
| 64 | - |
|
| 65 | - $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
| 66 | - $builder |
|
| 67 | - ->update('share') |
|
| 68 | - ->set('permissions', $permsFunc) |
|
| 69 | - ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
| 70 | - ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
| 71 | - |
|
| 72 | - $updatedEntries = $builder->execute(); |
|
| 73 | - if ($updatedEntries > 0) { |
|
| 74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Remove shares where the parent share does not exist anymore |
|
| 80 | - */ |
|
| 81 | - private function removeSharesNonExistingParent(IOutput $out) { |
|
| 82 | - $deletedEntries = 0; |
|
| 83 | - |
|
| 84 | - $query = $this->connection->getQueryBuilder(); |
|
| 85 | - $query->select('s1.parent') |
|
| 86 | - ->from('share', 's1') |
|
| 87 | - ->where($query->expr()->isNotNull('s1.parent')) |
|
| 88 | - ->andWhere($query->expr()->isNull('s2.id')) |
|
| 89 | - ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
| 90 | - ->groupBy('s1.parent') |
|
| 91 | - ->setMaxResults(self::CHUNK_SIZE); |
|
| 92 | - |
|
| 93 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
| 94 | - $deleteQuery->delete('share') |
|
| 95 | - ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
| 96 | - |
|
| 97 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
| 98 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
| 99 | - $deletedInLastChunk = 0; |
|
| 100 | - $result = $query->execute(); |
|
| 101 | - while ($row = $result->fetch()) { |
|
| 102 | - $deletedInLastChunk++; |
|
| 103 | - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
| 104 | - ->execute(); |
|
| 105 | - } |
|
| 106 | - $result->closeCursor(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($deletedEntries) { |
|
| 110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function run(IOutput $out) { |
|
| 115 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 116 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
| 117 | - $this->adjustFileSharePermissions($out); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $this->removeSharesNonExistingParent($out); |
|
| 121 | - } |
|
| 36 | + const CHUNK_SIZE = 200; |
|
| 37 | + |
|
| 38 | + /** @var \OCP\IConfig */ |
|
| 39 | + protected $config; |
|
| 40 | + |
|
| 41 | + /** @var \OCP\IDBConnection */ |
|
| 42 | + protected $connection; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param \OCP\IConfig $config |
|
| 46 | + * @param \OCP\IDBConnection $connection |
|
| 47 | + */ |
|
| 48 | + public function __construct($config, $connection) { |
|
| 49 | + $this->connection = $connection; |
|
| 50 | + $this->config = $config; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function getName() { |
|
| 54 | + return 'Repair invalid shares'; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Adjust file share permissions |
|
| 59 | + * @suppress SqlInjectionChecker |
|
| 60 | + */ |
|
| 61 | + private function adjustFileSharePermissions(IOutput $out) { |
|
| 62 | + $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
| 63 | + $builder = $this->connection->getQueryBuilder(); |
|
| 64 | + |
|
| 65 | + $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
| 66 | + $builder |
|
| 67 | + ->update('share') |
|
| 68 | + ->set('permissions', $permsFunc) |
|
| 69 | + ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
| 70 | + ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
| 71 | + |
|
| 72 | + $updatedEntries = $builder->execute(); |
|
| 73 | + if ($updatedEntries > 0) { |
|
| 74 | + $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Remove shares where the parent share does not exist anymore |
|
| 80 | + */ |
|
| 81 | + private function removeSharesNonExistingParent(IOutput $out) { |
|
| 82 | + $deletedEntries = 0; |
|
| 83 | + |
|
| 84 | + $query = $this->connection->getQueryBuilder(); |
|
| 85 | + $query->select('s1.parent') |
|
| 86 | + ->from('share', 's1') |
|
| 87 | + ->where($query->expr()->isNotNull('s1.parent')) |
|
| 88 | + ->andWhere($query->expr()->isNull('s2.id')) |
|
| 89 | + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
| 90 | + ->groupBy('s1.parent') |
|
| 91 | + ->setMaxResults(self::CHUNK_SIZE); |
|
| 92 | + |
|
| 93 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
| 94 | + $deleteQuery->delete('share') |
|
| 95 | + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
| 96 | + |
|
| 97 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
| 98 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
| 99 | + $deletedInLastChunk = 0; |
|
| 100 | + $result = $query->execute(); |
|
| 101 | + while ($row = $result->fetch()) { |
|
| 102 | + $deletedInLastChunk++; |
|
| 103 | + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
| 104 | + ->execute(); |
|
| 105 | + } |
|
| 106 | + $result->closeCursor(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($deletedEntries) { |
|
| 110 | + $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function run(IOutput $out) { |
|
| 115 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 116 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
| 117 | + $this->adjustFileSharePermissions($out); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $this->removeSharesNonExistingParent($out); |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -194,6 +194,9 @@ |
||
| 194 | 194 | parent::propPatch($propPatch); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | + /** |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 197 | 200 | public function getContactsGroups() { |
| 198 | 201 | return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
| 199 | 202 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function getACL() { |
| 102 | - $acl = [ |
|
| 102 | + $acl = [ |
|
| 103 | 103 | [ |
| 104 | 104 | 'privilege' => '{DAV:}read', |
| 105 | 105 | 'principal' => $this->getOwner(), |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | 'protected' => true, |
| 112 | 112 | ]; |
| 113 | 113 | if ($this->getOwner() !== parent::getOwner()) { |
| 114 | - $acl[] = [ |
|
| 114 | + $acl[] = [ |
|
| 115 | 115 | 'privilege' => '{DAV:}read', |
| 116 | 116 | 'principal' => parent::getOwner(), |
| 117 | 117 | 'protected' => true, |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | public function delete() { |
| 172 | 172 | if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
| 173 | - $principal = 'principal:' . parent::getOwner(); |
|
| 173 | + $principal = 'principal:'.parent::getOwner(); |
|
| 174 | 174 | $shares = $this->carddavBackend->getShares($this->getResourceId()); |
| 175 | 175 | $shares = array_filter($shares, function($share) use ($principal){ |
| 176 | 176 | return $share['href'] === $principal; |
@@ -38,179 +38,179 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * AddressBook constructor. |
|
| 43 | - * |
|
| 44 | - * @param BackendInterface $carddavBackend |
|
| 45 | - * @param array $addressBookInfo |
|
| 46 | - * @param IL10N $l10n |
|
| 47 | - */ |
|
| 48 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 49 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
| 50 | - |
|
| 51 | - if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 52 | - $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 53 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Updates the list of shares. |
|
| 59 | - * |
|
| 60 | - * The first array is a list of people that are to be added to the |
|
| 61 | - * addressbook. |
|
| 62 | - * |
|
| 63 | - * Every element in the add array has the following properties: |
|
| 64 | - * * href - A url. Usually a mailto: address |
|
| 65 | - * * commonName - Usually a first and last name, or false |
|
| 66 | - * * summary - A description of the share, can also be false |
|
| 67 | - * * readOnly - A boolean value |
|
| 68 | - * |
|
| 69 | - * Every element in the remove array is just the address string. |
|
| 70 | - * |
|
| 71 | - * @param array $add |
|
| 72 | - * @param array $remove |
|
| 73 | - * @return void |
|
| 74 | - * @throws Forbidden |
|
| 75 | - */ |
|
| 76 | - public function updateShares(array $add, array $remove) { |
|
| 77 | - if ($this->isShared()) { |
|
| 78 | - throw new Forbidden(); |
|
| 79 | - } |
|
| 80 | - $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Returns the list of people whom this addressbook is shared with. |
|
| 85 | - * |
|
| 86 | - * Every element in this array should have the following properties: |
|
| 87 | - * * href - Often a mailto: address |
|
| 88 | - * * commonName - Optional, for example a first + last name |
|
| 89 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 90 | - * * readOnly - boolean |
|
| 91 | - * * summary - Optional, a description for the share |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function getShares() { |
|
| 96 | - if ($this->isShared()) { |
|
| 97 | - return []; |
|
| 98 | - } |
|
| 99 | - return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function getACL() { |
|
| 103 | - $acl = [ |
|
| 104 | - [ |
|
| 105 | - 'privilege' => '{DAV:}read', |
|
| 106 | - 'principal' => $this->getOwner(), |
|
| 107 | - 'protected' => true, |
|
| 108 | - ]]; |
|
| 109 | - $acl[] = [ |
|
| 110 | - 'privilege' => '{DAV:}write', |
|
| 111 | - 'principal' => $this->getOwner(), |
|
| 112 | - 'protected' => true, |
|
| 113 | - ]; |
|
| 114 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 115 | - $acl[] = [ |
|
| 116 | - 'privilege' => '{DAV:}read', |
|
| 117 | - 'principal' => parent::getOwner(), |
|
| 118 | - 'protected' => true, |
|
| 119 | - ]; |
|
| 120 | - if ($this->canWrite()) { |
|
| 121 | - $acl[] = [ |
|
| 122 | - 'privilege' => '{DAV:}write', |
|
| 123 | - 'principal' => parent::getOwner(), |
|
| 124 | - 'protected' => true, |
|
| 125 | - ]; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - if ($this->getOwner() === 'principals/system/system') { |
|
| 129 | - $acl[] = [ |
|
| 130 | - 'privilege' => '{DAV:}read', |
|
| 131 | - 'principal' => '{DAV:}authenticated', |
|
| 132 | - 'protected' => true, |
|
| 133 | - ]; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if ($this->isShared()) { |
|
| 137 | - return $acl; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function getChildACL() { |
|
| 144 | - return $this->getACL(); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function getChild($name) { |
|
| 148 | - |
|
| 149 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 150 | - if (!$obj) { |
|
| 151 | - throw new NotFound('Card not found'); |
|
| 152 | - } |
|
| 153 | - $obj['acl'] = $this->getChildACL(); |
|
| 154 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @return int |
|
| 160 | - */ |
|
| 161 | - public function getResourceId() { |
|
| 162 | - return $this->addressBookInfo['id']; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - public function getOwner() { |
|
| 166 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 167 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 168 | - } |
|
| 169 | - return parent::getOwner(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function delete() { |
|
| 173 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 174 | - $principal = 'principal:' . parent::getOwner(); |
|
| 175 | - $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 176 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 177 | - return $share['href'] === $principal; |
|
| 178 | - }); |
|
| 179 | - if (empty($shares)) { |
|
| 180 | - throw new Forbidden(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $this->carddavBackend->updateShares($this, [], [ |
|
| 184 | - $principal |
|
| 185 | - ]); |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - parent::delete(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public function propPatch(PropPatch $propPatch) { |
|
| 192 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 193 | - throw new Forbidden(); |
|
| 194 | - } |
|
| 195 | - parent::propPatch($propPatch); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - public function getContactsGroups() { |
|
| 199 | - return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - private function isShared() { |
|
| 203 | - if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - private function canWrite() { |
|
| 211 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 212 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 213 | - } |
|
| 214 | - return true; |
|
| 215 | - } |
|
| 41 | + /** |
|
| 42 | + * AddressBook constructor. |
|
| 43 | + * |
|
| 44 | + * @param BackendInterface $carddavBackend |
|
| 45 | + * @param array $addressBookInfo |
|
| 46 | + * @param IL10N $l10n |
|
| 47 | + */ |
|
| 48 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 49 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
| 50 | + |
|
| 51 | + if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 52 | + $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 53 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Updates the list of shares. |
|
| 59 | + * |
|
| 60 | + * The first array is a list of people that are to be added to the |
|
| 61 | + * addressbook. |
|
| 62 | + * |
|
| 63 | + * Every element in the add array has the following properties: |
|
| 64 | + * * href - A url. Usually a mailto: address |
|
| 65 | + * * commonName - Usually a first and last name, or false |
|
| 66 | + * * summary - A description of the share, can also be false |
|
| 67 | + * * readOnly - A boolean value |
|
| 68 | + * |
|
| 69 | + * Every element in the remove array is just the address string. |
|
| 70 | + * |
|
| 71 | + * @param array $add |
|
| 72 | + * @param array $remove |
|
| 73 | + * @return void |
|
| 74 | + * @throws Forbidden |
|
| 75 | + */ |
|
| 76 | + public function updateShares(array $add, array $remove) { |
|
| 77 | + if ($this->isShared()) { |
|
| 78 | + throw new Forbidden(); |
|
| 79 | + } |
|
| 80 | + $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Returns the list of people whom this addressbook is shared with. |
|
| 85 | + * |
|
| 86 | + * Every element in this array should have the following properties: |
|
| 87 | + * * href - Often a mailto: address |
|
| 88 | + * * commonName - Optional, for example a first + last name |
|
| 89 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 90 | + * * readOnly - boolean |
|
| 91 | + * * summary - Optional, a description for the share |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function getShares() { |
|
| 96 | + if ($this->isShared()) { |
|
| 97 | + return []; |
|
| 98 | + } |
|
| 99 | + return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function getACL() { |
|
| 103 | + $acl = [ |
|
| 104 | + [ |
|
| 105 | + 'privilege' => '{DAV:}read', |
|
| 106 | + 'principal' => $this->getOwner(), |
|
| 107 | + 'protected' => true, |
|
| 108 | + ]]; |
|
| 109 | + $acl[] = [ |
|
| 110 | + 'privilege' => '{DAV:}write', |
|
| 111 | + 'principal' => $this->getOwner(), |
|
| 112 | + 'protected' => true, |
|
| 113 | + ]; |
|
| 114 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 115 | + $acl[] = [ |
|
| 116 | + 'privilege' => '{DAV:}read', |
|
| 117 | + 'principal' => parent::getOwner(), |
|
| 118 | + 'protected' => true, |
|
| 119 | + ]; |
|
| 120 | + if ($this->canWrite()) { |
|
| 121 | + $acl[] = [ |
|
| 122 | + 'privilege' => '{DAV:}write', |
|
| 123 | + 'principal' => parent::getOwner(), |
|
| 124 | + 'protected' => true, |
|
| 125 | + ]; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + if ($this->getOwner() === 'principals/system/system') { |
|
| 129 | + $acl[] = [ |
|
| 130 | + 'privilege' => '{DAV:}read', |
|
| 131 | + 'principal' => '{DAV:}authenticated', |
|
| 132 | + 'protected' => true, |
|
| 133 | + ]; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if ($this->isShared()) { |
|
| 137 | + return $acl; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function getChildACL() { |
|
| 144 | + return $this->getACL(); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function getChild($name) { |
|
| 148 | + |
|
| 149 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 150 | + if (!$obj) { |
|
| 151 | + throw new NotFound('Card not found'); |
|
| 152 | + } |
|
| 153 | + $obj['acl'] = $this->getChildACL(); |
|
| 154 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @return int |
|
| 160 | + */ |
|
| 161 | + public function getResourceId() { |
|
| 162 | + return $this->addressBookInfo['id']; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + public function getOwner() { |
|
| 166 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 167 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 168 | + } |
|
| 169 | + return parent::getOwner(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function delete() { |
|
| 173 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 174 | + $principal = 'principal:' . parent::getOwner(); |
|
| 175 | + $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 176 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 177 | + return $share['href'] === $principal; |
|
| 178 | + }); |
|
| 179 | + if (empty($shares)) { |
|
| 180 | + throw new Forbidden(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $this->carddavBackend->updateShares($this, [], [ |
|
| 184 | + $principal |
|
| 185 | + ]); |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + parent::delete(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public function propPatch(PropPatch $propPatch) { |
|
| 192 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 193 | + throw new Forbidden(); |
|
| 194 | + } |
|
| 195 | + parent::propPatch($propPatch); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + public function getContactsGroups() { |
|
| 199 | + return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + private function isShared() { |
|
| 203 | + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + private function canWrite() { |
|
| 211 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 212 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 213 | + } |
|
| 214 | + return true; |
|
| 215 | + } |
|
| 216 | 216 | } |