@@ -12,7 +12,10 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | 14 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 15 | - value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 15 | + value="1" <?php if ($_['outgoingServer2serverShareEnabled']) { |
|
| 16 | + print_unescaped('checked="checked"'); |
|
| 17 | +} |
|
| 18 | +?> /> |
|
| 16 | 19 | <label for="outgoingServer2serverShareEnabled"> |
| 17 | 20 | <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
| 18 | 21 | </label> |
@@ -20,21 +23,30 @@ discard block |
||
| 20 | 23 | |
| 21 | 24 | <p> |
| 22 | 25 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 23 | - value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 26 | + value="1" <?php if ($_['incomingServer2serverShareEnabled']) { |
|
| 27 | + print_unescaped('checked="checked"'); |
|
| 28 | +} |
|
| 29 | +?> /> |
|
| 24 | 30 | <label for="incomingServer2serverShareEnabled"> |
| 25 | 31 | <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
| 26 | 32 | </label><br/> |
| 27 | 33 | </p> |
| 28 | 34 | <p> |
| 29 | 35 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 30 | - value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 36 | + value="1" <?php if ($_['lookupServerEnabled']) { |
|
| 37 | + print_unescaped('checked="checked"'); |
|
| 38 | +} |
|
| 39 | +?> /> |
|
| 31 | 40 | <label for="lookupServerEnabled"> |
| 32 | 41 | <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
| 33 | 42 | </label><br/> |
| 34 | 43 | </p> |
| 35 | 44 | <p> |
| 36 | 45 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 37 | - value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
| 46 | + value="1" <?php if ($_['lookupServerUploadEnabled']) { |
|
| 47 | + print_unescaped('checked="checked"'); |
|
| 48 | +} |
|
| 49 | +?> /> |
|
| 38 | 50 | <label for="lookupServerUploadEnabled"> |
| 39 | 51 | <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
| 40 | 52 | </label><br/> |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | ?> |
| 6 | 6 | |
| 7 | 7 | <div id="fileSharingSettings" class="followupsection"> |
| 8 | - <h3><?php p($l->t('Federated Cloud Sharing'));?></h3> |
|
| 8 | + <h3><?php p($l->t('Federated Cloud Sharing')); ?></h3> |
|
| 9 | 9 | <a target="_blank" rel="noreferrer" class="icon-info svg" |
| 10 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 10 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 11 | 11 | href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a> |
| 12 | 12 | <p class="settings-hint"><?php p($l->t('Adjust how people can share between servers.')); ?></p> |
| 13 | 13 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
| 16 | 16 | value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 17 | 17 | <label for="outgoingServer2serverShareEnabled"> |
| 18 | - <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
|
| 18 | + <?php p($l->t('Allow users on this server to send shares to other servers')); ?> |
|
| 19 | 19 | </label> |
| 20 | 20 | </p> |
| 21 | 21 | |
@@ -23,21 +23,21 @@ discard block |
||
| 23 | 23 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
| 24 | 24 | value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 25 | 25 | <label for="incomingServer2serverShareEnabled"> |
| 26 | - <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
|
| 26 | + <?php p($l->t('Allow users on this server to receive shares from other servers')); ?> |
|
| 27 | 27 | </label><br/> |
| 28 | 28 | </p> |
| 29 | 29 | <p> |
| 30 | 30 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
| 31 | 31 | value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 32 | 32 | <label for="lookupServerEnabled"> |
| 33 | - <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
|
| 33 | + <?php p($l->t('Search global and public address book for users and let local users publish their data')); ?> |
|
| 34 | 34 | </label><br/> |
| 35 | 35 | </p> |
| 36 | 36 | <p> |
| 37 | 37 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
| 38 | 38 | value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
| 39 | 39 | <label for="lookupServerUploadEnabled"> |
| 40 | - <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
|
| 40 | + <?php p($l->t('Allow users to publish their data to a global and public address book')); ?> |
|
| 41 | 41 | </label><br/> |
| 42 | 42 | </p> |
| 43 | 43 | |
@@ -36,77 +36,77 @@ |
||
| 36 | 36 | |
| 37 | 37 | $application = new Application(); |
| 38 | 38 | $application->registerRoutes($this, [ |
| 39 | - 'resources' => [ |
|
| 40 | - 'users' => ['url' => '/settings/users/users'], |
|
| 41 | - 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
| 42 | - ], |
|
| 43 | - 'routes' => [ |
|
| 44 | - ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
| 45 | - ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
| 46 | - ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
| 47 | - ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
| 48 | - ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
| 49 | - ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
| 50 | - ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
| 51 | - ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
| 52 | - ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
| 53 | - ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
| 54 | - ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
| 55 | - ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'], |
|
| 56 | - ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
| 57 | - ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
| 58 | - ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
| 59 | - ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
| 60 | - ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
| 61 | - ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
| 62 | - ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
| 63 | - ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
| 64 | - ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
| 65 | - ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
| 66 | - ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
| 67 | - ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
| 68 | - ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
| 69 | - ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
| 70 | - ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
| 71 | - ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
| 72 | - ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
| 73 | - ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
| 74 | - ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
| 75 | - ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
| 76 | - ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
| 77 | - ] |
|
| 39 | + 'resources' => [ |
|
| 40 | + 'users' => ['url' => '/settings/users/users'], |
|
| 41 | + 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
| 42 | + ], |
|
| 43 | + 'routes' => [ |
|
| 44 | + ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
| 45 | + ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
| 46 | + ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
| 47 | + ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
| 48 | + ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
| 49 | + ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
| 50 | + ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
| 51 | + ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
| 52 | + ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
| 53 | + ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
| 54 | + ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
| 55 | + ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'], |
|
| 56 | + ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
| 57 | + ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
| 58 | + ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
| 59 | + ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
| 60 | + ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
| 61 | + ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
| 62 | + ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
| 63 | + ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
| 64 | + ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
| 65 | + ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
| 66 | + ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
| 67 | + ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
| 68 | + ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
| 69 | + ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
| 70 | + ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
| 71 | + ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
| 72 | + ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
| 73 | + ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
| 74 | + ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
| 75 | + ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
| 76 | + ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
| 77 | + ] |
|
| 78 | 78 | ]); |
| 79 | 79 | |
| 80 | 80 | /** @var $this \OCP\Route\IRouter */ |
| 81 | 81 | |
| 82 | 82 | // Settings pages |
| 83 | 83 | $this->create('settings_help', '/settings/help') |
| 84 | - ->actionInclude('settings/help.php'); |
|
| 84 | + ->actionInclude('settings/help.php'); |
|
| 85 | 85 | $this->create('settings_personal', '/settings/personal') |
| 86 | - ->actionInclude('settings/personal.php'); |
|
| 86 | + ->actionInclude('settings/personal.php'); |
|
| 87 | 87 | $this->create('settings_users', '/settings/users') |
| 88 | - ->actionInclude('settings/users.php'); |
|
| 88 | + ->actionInclude('settings/users.php'); |
|
| 89 | 89 | // Settings ajax actions |
| 90 | 90 | // users |
| 91 | 91 | $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php') |
| 92 | - ->actionInclude('settings/ajax/setquota.php'); |
|
| 92 | + ->actionInclude('settings/ajax/setquota.php'); |
|
| 93 | 93 | $this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php') |
| 94 | - ->actionInclude('settings/ajax/togglegroups.php'); |
|
| 94 | + ->actionInclude('settings/ajax/togglegroups.php'); |
|
| 95 | 95 | $this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php') |
| 96 | - ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
| 96 | + ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
| 97 | 97 | $this->create('settings_ajax_changegorupname', '/settings/ajax/changegroupname.php') |
| 98 | - ->actionInclude('settings/ajax/changegroupname.php'); |
|
| 98 | + ->actionInclude('settings/ajax/changegroupname.php'); |
|
| 99 | 99 | // apps |
| 100 | 100 | $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') |
| 101 | - ->actionInclude('settings/ajax/enableapp.php'); |
|
| 101 | + ->actionInclude('settings/ajax/enableapp.php'); |
|
| 102 | 102 | $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') |
| 103 | - ->actionInclude('settings/ajax/disableapp.php'); |
|
| 103 | + ->actionInclude('settings/ajax/disableapp.php'); |
|
| 104 | 104 | $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php') |
| 105 | - ->actionInclude('settings/ajax/updateapp.php'); |
|
| 105 | + ->actionInclude('settings/ajax/updateapp.php'); |
|
| 106 | 106 | $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php') |
| 107 | - ->actionInclude('settings/ajax/uninstallapp.php'); |
|
| 107 | + ->actionInclude('settings/ajax/uninstallapp.php'); |
|
| 108 | 108 | $this->create('settings_ajax_navigationdetect', '/settings/ajax/navigationdetect.php') |
| 109 | - ->actionInclude('settings/ajax/navigationdetect.php'); |
|
| 109 | + ->actionInclude('settings/ajax/navigationdetect.php'); |
|
| 110 | 110 | // admin |
| 111 | 111 | $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php') |
| 112 | - ->actionInclude('settings/ajax/excludegroups.php'); |
|
| 112 | + ->actionInclude('settings/ajax/excludegroups.php'); |
|
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * split user and remote from federated cloud id |
| 386 | 386 | * |
| 387 | 387 | * @param string $address federated share address |
| 388 | - * @return array [user, remoteURL] |
|
| 388 | + * @return string[] [user, remoteURL] |
|
| 389 | 389 | * @throws \Exception |
| 390 | 390 | */ |
| 391 | 391 | public function splitUserRemote($address) { |
@@ -652,6 +652,9 @@ discard block |
||
| 652 | 652 | return $result; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | + /** |
|
| 656 | + * @param string $search |
|
| 657 | + */ |
|
| 655 | 658 | protected function getLookup($search) { |
| 656 | 659 | $isEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
| 657 | 660 | $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
@@ -43,674 +43,674 @@ |
||
| 43 | 43 | |
| 44 | 44 | class ShareesAPIController extends OCSController { |
| 45 | 45 | |
| 46 | - /** @var IGroupManager */ |
|
| 47 | - protected $groupManager; |
|
| 48 | - |
|
| 49 | - /** @var IUserManager */ |
|
| 50 | - protected $userManager; |
|
| 51 | - |
|
| 52 | - /** @var IManager */ |
|
| 53 | - protected $contactsManager; |
|
| 54 | - |
|
| 55 | - /** @var IConfig */ |
|
| 56 | - protected $config; |
|
| 57 | - |
|
| 58 | - /** @var IUserSession */ |
|
| 59 | - protected $userSession; |
|
| 60 | - |
|
| 61 | - /** @var IURLGenerator */ |
|
| 62 | - protected $urlGenerator; |
|
| 63 | - |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - protected $logger; |
|
| 66 | - |
|
| 67 | - /** @var \OCP\Share\IManager */ |
|
| 68 | - protected $shareManager; |
|
| 69 | - |
|
| 70 | - /** @var IClientService */ |
|
| 71 | - protected $clientService; |
|
| 72 | - |
|
| 73 | - /** @var ICloudIdManager */ |
|
| 74 | - protected $cloudIdManager; |
|
| 75 | - |
|
| 76 | - /** @var bool */ |
|
| 77 | - protected $shareWithGroupOnly = false; |
|
| 78 | - |
|
| 79 | - /** @var bool */ |
|
| 80 | - protected $shareeEnumeration = true; |
|
| 81 | - |
|
| 82 | - /** @var int */ |
|
| 83 | - protected $offset = 0; |
|
| 84 | - |
|
| 85 | - /** @var int */ |
|
| 86 | - protected $limit = 10; |
|
| 87 | - |
|
| 88 | - /** @var array */ |
|
| 89 | - protected $result = [ |
|
| 90 | - 'exact' => [ |
|
| 91 | - 'users' => [], |
|
| 92 | - 'groups' => [], |
|
| 93 | - 'remotes' => [], |
|
| 94 | - 'emails' => [], |
|
| 95 | - 'circles' => [], |
|
| 96 | - ], |
|
| 97 | - 'users' => [], |
|
| 98 | - 'groups' => [], |
|
| 99 | - 'remotes' => [], |
|
| 100 | - 'emails' => [], |
|
| 101 | - 'lookup' => [], |
|
| 102 | - 'circles' => [], |
|
| 103 | - ]; |
|
| 104 | - |
|
| 105 | - protected $reachedEndFor = []; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $appName |
|
| 109 | - * @param IRequest $request |
|
| 110 | - * @param IGroupManager $groupManager |
|
| 111 | - * @param IUserManager $userManager |
|
| 112 | - * @param IManager $contactsManager |
|
| 113 | - * @param IConfig $config |
|
| 114 | - * @param IUserSession $userSession |
|
| 115 | - * @param IURLGenerator $urlGenerator |
|
| 116 | - * @param ILogger $logger |
|
| 117 | - * @param \OCP\Share\IManager $shareManager |
|
| 118 | - * @param IClientService $clientService |
|
| 119 | - * @param ICloudIdManager $cloudIdManager |
|
| 120 | - */ |
|
| 121 | - public function __construct($appName, |
|
| 122 | - IRequest $request, |
|
| 123 | - IGroupManager $groupManager, |
|
| 124 | - IUserManager $userManager, |
|
| 125 | - IManager $contactsManager, |
|
| 126 | - IConfig $config, |
|
| 127 | - IUserSession $userSession, |
|
| 128 | - IURLGenerator $urlGenerator, |
|
| 129 | - ILogger $logger, |
|
| 130 | - \OCP\Share\IManager $shareManager, |
|
| 131 | - IClientService $clientService, |
|
| 132 | - ICloudIdManager $cloudIdManager |
|
| 133 | - ) { |
|
| 134 | - parent::__construct($appName, $request); |
|
| 135 | - |
|
| 136 | - $this->groupManager = $groupManager; |
|
| 137 | - $this->userManager = $userManager; |
|
| 138 | - $this->contactsManager = $contactsManager; |
|
| 139 | - $this->config = $config; |
|
| 140 | - $this->userSession = $userSession; |
|
| 141 | - $this->urlGenerator = $urlGenerator; |
|
| 142 | - $this->logger = $logger; |
|
| 143 | - $this->shareManager = $shareManager; |
|
| 144 | - $this->clientService = $clientService; |
|
| 145 | - $this->cloudIdManager = $cloudIdManager; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param string $search |
|
| 150 | - */ |
|
| 151 | - protected function getUsers($search) { |
|
| 152 | - $this->result['users'] = $this->result['exact']['users'] = $users = []; |
|
| 153 | - |
|
| 154 | - $userGroups = []; |
|
| 155 | - if ($this->shareWithGroupOnly) { |
|
| 156 | - // Search in all the groups this user is part of |
|
| 157 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 158 | - foreach ($userGroups as $userGroup) { |
|
| 159 | - $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $this->limit, $this->offset); |
|
| 160 | - foreach ($usersTmp as $uid => $userDisplayName) { |
|
| 161 | - $users[$uid] = $userDisplayName; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } else { |
|
| 165 | - // Search in all users |
|
| 166 | - $usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset); |
|
| 167 | - |
|
| 168 | - foreach ($usersTmp as $user) { |
|
| 169 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (!$this->shareeEnumeration || sizeof($users) < $this->limit) { |
|
| 174 | - $this->reachedEndFor[] = 'users'; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $foundUserById = false; |
|
| 178 | - $lowerSearch = strtolower($search); |
|
| 179 | - foreach ($users as $uid => $userDisplayName) { |
|
| 180 | - if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
| 181 | - if (strtolower($uid) === $lowerSearch) { |
|
| 182 | - $foundUserById = true; |
|
| 183 | - } |
|
| 184 | - $this->result['exact']['users'][] = [ |
|
| 185 | - 'label' => $userDisplayName, |
|
| 186 | - 'value' => [ |
|
| 187 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
| 188 | - 'shareWith' => $uid, |
|
| 189 | - ], |
|
| 190 | - ]; |
|
| 191 | - } else { |
|
| 192 | - $this->result['users'][] = [ |
|
| 193 | - 'label' => $userDisplayName, |
|
| 194 | - 'value' => [ |
|
| 195 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
| 196 | - 'shareWith' => $uid, |
|
| 197 | - ], |
|
| 198 | - ]; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($this->offset === 0 && !$foundUserById) { |
|
| 203 | - // On page one we try if the search result has a direct hit on the |
|
| 204 | - // user id and if so, we add that to the exact match list |
|
| 205 | - $user = $this->userManager->get($search); |
|
| 206 | - if ($user instanceof IUser) { |
|
| 207 | - $addUser = true; |
|
| 208 | - |
|
| 209 | - if ($this->shareWithGroupOnly) { |
|
| 210 | - // Only add, if we have a common group |
|
| 211 | - $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
| 212 | - $addUser = !empty($commonGroups); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ($addUser) { |
|
| 216 | - array_push($this->result['exact']['users'], [ |
|
| 217 | - 'label' => $user->getDisplayName(), |
|
| 218 | - 'value' => [ |
|
| 219 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
| 220 | - 'shareWith' => $user->getUID(), |
|
| 221 | - ], |
|
| 222 | - ]); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if (!$this->shareeEnumeration) { |
|
| 228 | - $this->result['users'] = []; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param string $search |
|
| 234 | - */ |
|
| 235 | - protected function getGroups($search) { |
|
| 236 | - $this->result['groups'] = $this->result['exact']['groups'] = []; |
|
| 237 | - |
|
| 238 | - $groups = $this->groupManager->search($search, $this->limit, $this->offset); |
|
| 239 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
| 240 | - |
|
| 241 | - if (!$this->shareeEnumeration || sizeof($groups) < $this->limit) { |
|
| 242 | - $this->reachedEndFor[] = 'groups'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $userGroups = []; |
|
| 246 | - if (!empty($groups) && $this->shareWithGroupOnly) { |
|
| 247 | - // Intersect all the groups that match with the groups this user is a member of |
|
| 248 | - $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
| 249 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
| 250 | - $groupIds = array_intersect($groupIds, $userGroups); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $lowerSearch = strtolower($search); |
|
| 254 | - foreach ($groups as $group) { |
|
| 255 | - // FIXME: use a more efficient approach |
|
| 256 | - $gid = $group->getGID(); |
|
| 257 | - if (!in_array($gid, $groupIds)) { |
|
| 258 | - continue; |
|
| 259 | - } |
|
| 260 | - if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
| 261 | - $this->result['exact']['groups'][] = [ |
|
| 262 | - 'label' => $group->getDisplayName(), |
|
| 263 | - 'value' => [ |
|
| 264 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 265 | - 'shareWith' => $gid, |
|
| 266 | - ], |
|
| 267 | - ]; |
|
| 268 | - } else { |
|
| 269 | - $this->result['groups'][] = [ |
|
| 270 | - 'label' => $group->getDisplayName(), |
|
| 271 | - 'value' => [ |
|
| 272 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 273 | - 'shareWith' => $gid, |
|
| 274 | - ], |
|
| 275 | - ]; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if ($this->offset === 0 && empty($this->result['exact']['groups'])) { |
|
| 280 | - // On page one we try if the search result has a direct hit on the |
|
| 281 | - // user id and if so, we add that to the exact match list |
|
| 282 | - $group = $this->groupManager->get($search); |
|
| 283 | - if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
| 284 | - array_push($this->result['exact']['groups'], [ |
|
| 285 | - 'label' => $group->getDisplayName(), |
|
| 286 | - 'value' => [ |
|
| 287 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 288 | - 'shareWith' => $group->getGID(), |
|
| 289 | - ], |
|
| 290 | - ]); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$this->shareeEnumeration) { |
|
| 295 | - $this->result['groups'] = []; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $search |
|
| 302 | - */ |
|
| 303 | - protected function getCircles($search) { |
|
| 304 | - $this->result['circles'] = $this->result['exact']['circles'] = []; |
|
| 305 | - |
|
| 306 | - $result = \OCA\Circles\Api\Sharees::search($search, $this->limit, $this->offset); |
|
| 307 | - if (array_key_exists('circles', $result['exact'])) { |
|
| 308 | - $this->result['exact']['circles'] = $result['exact']['circles']; |
|
| 309 | - } |
|
| 310 | - if (array_key_exists('circles', $result)) { |
|
| 311 | - $this->result['circles'] = $result['circles']; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param string $search |
|
| 318 | - * @return array |
|
| 319 | - */ |
|
| 320 | - protected function getRemote($search) { |
|
| 321 | - $result = ['results' => [], 'exact' => []]; |
|
| 322 | - |
|
| 323 | - // Search in contacts |
|
| 324 | - //@todo Pagination missing |
|
| 325 | - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
| 326 | - $result['exactIdMatch'] = false; |
|
| 327 | - foreach ($addressBookContacts as $contact) { |
|
| 328 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 329 | - continue; |
|
| 330 | - } |
|
| 331 | - if (isset($contact['CLOUD'])) { |
|
| 332 | - $cloudIds = $contact['CLOUD']; |
|
| 333 | - if (!is_array($cloudIds)) { |
|
| 334 | - $cloudIds = [$cloudIds]; |
|
| 335 | - } |
|
| 336 | - $lowerSearch = strtolower($search); |
|
| 337 | - foreach ($cloudIds as $cloudId) { |
|
| 338 | - list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
| 339 | - if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
| 340 | - if (strtolower($cloudId) === $lowerSearch) { |
|
| 341 | - $result['exactIdMatch'] = true; |
|
| 342 | - } |
|
| 343 | - $result['exact'][] = [ |
|
| 344 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
| 345 | - 'value' => [ |
|
| 346 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 347 | - 'shareWith' => $cloudId, |
|
| 348 | - 'server' => $serverUrl, |
|
| 349 | - ], |
|
| 350 | - ]; |
|
| 351 | - } else { |
|
| 352 | - $result['results'][] = [ |
|
| 353 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
| 354 | - 'value' => [ |
|
| 355 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 356 | - 'shareWith' => $cloudId, |
|
| 357 | - 'server' => $serverUrl, |
|
| 358 | - ], |
|
| 359 | - ]; |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (!$this->shareeEnumeration) { |
|
| 366 | - $result['results'] = []; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if (!$result['exactIdMatch'] && $this->cloudIdManager->isValidCloudId($search) && $this->offset === 0) { |
|
| 370 | - $result['exact'][] = [ |
|
| 371 | - 'label' => $search, |
|
| 372 | - 'value' => [ |
|
| 373 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 374 | - 'shareWith' => $search, |
|
| 375 | - ], |
|
| 376 | - ]; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $this->reachedEndFor[] = 'remotes'; |
|
| 380 | - |
|
| 381 | - return $result; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * split user and remote from federated cloud id |
|
| 386 | - * |
|
| 387 | - * @param string $address federated share address |
|
| 388 | - * @return array [user, remoteURL] |
|
| 389 | - * @throws \Exception |
|
| 390 | - */ |
|
| 391 | - public function splitUserRemote($address) { |
|
| 392 | - try { |
|
| 393 | - $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
| 394 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
| 395 | - } catch (\InvalidArgumentException $e) { |
|
| 396 | - throw new \Exception('Invalid Federated Cloud ID', 0, $e); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Strips away a potential file names and trailing slashes: |
|
| 402 | - * - http://localhost |
|
| 403 | - * - http://localhost/ |
|
| 404 | - * - http://localhost/index.php |
|
| 405 | - * - http://localhost/index.php/s/{shareToken} |
|
| 406 | - * |
|
| 407 | - * all return: http://localhost |
|
| 408 | - * |
|
| 409 | - * @param string $remote |
|
| 410 | - * @return string |
|
| 411 | - */ |
|
| 412 | - protected function fixRemoteURL($remote) { |
|
| 413 | - $remote = str_replace('\\', '/', $remote); |
|
| 414 | - if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
| 415 | - $remote = substr($remote, 0, $fileNamePosition); |
|
| 416 | - } |
|
| 417 | - $remote = rtrim($remote, '/'); |
|
| 418 | - |
|
| 419 | - return $remote; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * @NoAdminRequired |
|
| 424 | - * |
|
| 425 | - * @param string $search |
|
| 426 | - * @param string $itemType |
|
| 427 | - * @param int $page |
|
| 428 | - * @param int $perPage |
|
| 429 | - * @param int|int[] $shareType |
|
| 430 | - * @param bool $lookup |
|
| 431 | - * @return DataResponse |
|
| 432 | - * @throws OCSBadRequestException |
|
| 433 | - */ |
|
| 434 | - public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
|
| 435 | - |
|
| 436 | - // only search for string larger than a given threshold |
|
| 437 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
| 438 | - if (strlen($search) < $threshold) { |
|
| 439 | - return new DataResponse($this->result); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - // never return more than the max. number of results configured in the config.php |
|
| 443 | - $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
| 444 | - if ($maxResults > 0) { |
|
| 445 | - $perPage = min($perPage, $maxResults); |
|
| 446 | - } |
|
| 447 | - if ($perPage <= 0) { |
|
| 448 | - throw new OCSBadRequestException('Invalid perPage argument'); |
|
| 449 | - } |
|
| 450 | - if ($page <= 0) { |
|
| 451 | - throw new OCSBadRequestException('Invalid page'); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - $shareTypes = [ |
|
| 455 | - Share::SHARE_TYPE_USER, |
|
| 456 | - ]; |
|
| 457 | - |
|
| 458 | - if ($itemType === 'file' || $itemType === 'folder') { |
|
| 459 | - if ($this->shareManager->allowGroupSharing()) { |
|
| 460 | - $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - if ($this->isRemoteSharingAllowed($itemType)) { |
|
| 464 | - $shareTypes[] = Share::SHARE_TYPE_REMOTE; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { |
|
| 468 | - $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
| 469 | - } |
|
| 470 | - } else { |
|
| 471 | - $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
| 472 | - $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - if (\OCP\App::isEnabled('circles')) { |
|
| 476 | - $shareTypes[] = Share::SHARE_TYPE_CIRCLE; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
| 480 | - $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
| 481 | - sort($shareTypes); |
|
| 482 | - } else if (is_numeric($shareType)) { |
|
| 483 | - $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
| 484 | - sort($shareTypes); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 488 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 489 | - $this->limit = (int) $perPage; |
|
| 490 | - $this->offset = $perPage * ($page - 1); |
|
| 491 | - |
|
| 492 | - return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage, $lookup); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Method to get out the static call for better testing |
|
| 497 | - * |
|
| 498 | - * @param string $itemType |
|
| 499 | - * @return bool |
|
| 500 | - */ |
|
| 501 | - protected function isRemoteSharingAllowed($itemType) { |
|
| 502 | - try { |
|
| 503 | - $backend = Share::getBackend($itemType); |
|
| 504 | - return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE); |
|
| 505 | - } catch (\Exception $e) { |
|
| 506 | - return false; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Testable search function that does not need globals |
|
| 512 | - * |
|
| 513 | - * @param string $search |
|
| 514 | - * @param string $itemType |
|
| 515 | - * @param array $shareTypes |
|
| 516 | - * @param int $page |
|
| 517 | - * @param int $perPage |
|
| 518 | - * @param bool $lookup |
|
| 519 | - * @return DataResponse |
|
| 520 | - * @throws OCSBadRequestException |
|
| 521 | - */ |
|
| 522 | - protected function searchSharees($search, $itemType, array $shareTypes, $page, $perPage, $lookup) { |
|
| 523 | - // Verify arguments |
|
| 524 | - if ($itemType === null) { |
|
| 525 | - throw new OCSBadRequestException('Missing itemType'); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - // Get users |
|
| 529 | - if (in_array(Share::SHARE_TYPE_USER, $shareTypes)) { |
|
| 530 | - $this->getUsers($search); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - // Get groups |
|
| 534 | - if (in_array(Share::SHARE_TYPE_GROUP, $shareTypes)) { |
|
| 535 | - $this->getGroups($search); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - // Get circles |
|
| 539 | - if (in_array(Share::SHARE_TYPE_CIRCLE, $shareTypes)) { |
|
| 540 | - $this->getCircles($search); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - // Get remote |
|
| 545 | - $remoteResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false]; |
|
| 546 | - if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) { |
|
| 547 | - $remoteResults = $this->getRemote($search); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - // Get emails |
|
| 551 | - $mailResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false]; |
|
| 552 | - if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) { |
|
| 553 | - $mailResults = $this->getEmail($search); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - // Get from lookup server |
|
| 557 | - if ($lookup) { |
|
| 558 | - $this->getLookup($search); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - // if we have a exact match, either for the federated cloud id or for the |
|
| 562 | - // email address we only return the exact match. It is highly unlikely |
|
| 563 | - // that the exact same email address and federated cloud id exists |
|
| 564 | - if ($mailResults['exactIdMatch'] && !$remoteResults['exactIdMatch']) { |
|
| 565 | - $this->result['emails'] = $mailResults['results']; |
|
| 566 | - $this->result['exact']['emails'] = $mailResults['exact']; |
|
| 567 | - } else if (!$mailResults['exactIdMatch'] && $remoteResults['exactIdMatch']) { |
|
| 568 | - $this->result['remotes'] = $remoteResults['results']; |
|
| 569 | - $this->result['exact']['remotes'] = $remoteResults['exact']; |
|
| 570 | - } else { |
|
| 571 | - $this->result['remotes'] = $remoteResults['results']; |
|
| 572 | - $this->result['exact']['remotes'] = $remoteResults['exact']; |
|
| 573 | - $this->result['emails'] = $mailResults['results']; |
|
| 574 | - $this->result['exact']['emails'] = $mailResults['exact']; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $response = new DataResponse($this->result); |
|
| 578 | - |
|
| 579 | - if (sizeof($this->reachedEndFor) < 3) { |
|
| 580 | - $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
| 581 | - 'search' => $search, |
|
| 582 | - 'itemType' => $itemType, |
|
| 583 | - 'shareType' => $shareTypes, |
|
| 584 | - 'perPage' => $perPage, |
|
| 585 | - ])); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - return $response; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @param string $search |
|
| 593 | - * @return array |
|
| 594 | - */ |
|
| 595 | - protected function getEmail($search) { |
|
| 596 | - $result = ['results' => [], 'exact' => []]; |
|
| 597 | - |
|
| 598 | - // Search in contacts |
|
| 599 | - //@todo Pagination missing |
|
| 600 | - $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
| 601 | - $result['exactIdMatch'] = false; |
|
| 602 | - foreach ($addressBookContacts as $contact) { |
|
| 603 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 604 | - continue; |
|
| 605 | - } |
|
| 606 | - if (isset($contact['EMAIL'])) { |
|
| 607 | - $emailAddresses = $contact['EMAIL']; |
|
| 608 | - if (!is_array($emailAddresses)) { |
|
| 609 | - $emailAddresses = [$emailAddresses]; |
|
| 610 | - } |
|
| 611 | - foreach ($emailAddresses as $emailAddress) { |
|
| 612 | - if (strtolower($contact['FN']) === strtolower($search) || strtolower($emailAddress) === strtolower($search)) { |
|
| 613 | - if (strtolower($emailAddress) === strtolower($search)) { |
|
| 614 | - $result['exactIdMatch'] = true; |
|
| 615 | - } |
|
| 616 | - $result['exact'][] = [ |
|
| 617 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 618 | - 'value' => [ |
|
| 619 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 620 | - 'shareWith' => $emailAddress, |
|
| 621 | - ], |
|
| 622 | - ]; |
|
| 623 | - } else { |
|
| 624 | - $result['results'][] = [ |
|
| 625 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 626 | - 'value' => [ |
|
| 627 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 628 | - 'shareWith' => $emailAddress, |
|
| 629 | - ], |
|
| 630 | - ]; |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - if (!$this->shareeEnumeration) { |
|
| 637 | - $result['results'] = []; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - if (!$result['exactIdMatch'] && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
| 641 | - $result['exact'][] = [ |
|
| 642 | - 'label' => $search, |
|
| 643 | - 'value' => [ |
|
| 644 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 645 | - 'shareWith' => $search, |
|
| 646 | - ], |
|
| 647 | - ]; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - $this->reachedEndFor[] = 'emails'; |
|
| 651 | - |
|
| 652 | - return $result; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - protected function getLookup($search) { |
|
| 656 | - $isEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 657 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 658 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 659 | - $result = []; |
|
| 660 | - |
|
| 661 | - if($isEnabled === 'yes') { |
|
| 662 | - try { |
|
| 663 | - $client = $this->clientService->newClient(); |
|
| 664 | - $response = $client->get( |
|
| 665 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 666 | - [ |
|
| 667 | - 'timeout' => 10, |
|
| 668 | - 'connect_timeout' => 3, |
|
| 669 | - ] |
|
| 670 | - ); |
|
| 671 | - |
|
| 672 | - $body = json_decode($response->getBody(), true); |
|
| 673 | - |
|
| 674 | - $result = []; |
|
| 675 | - foreach ($body as $lookup) { |
|
| 676 | - $result[] = [ |
|
| 677 | - 'label' => $lookup['federationId'], |
|
| 678 | - 'value' => [ |
|
| 679 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 680 | - 'shareWith' => $lookup['federationId'], |
|
| 681 | - ], |
|
| 682 | - 'extra' => $lookup, |
|
| 683 | - ]; |
|
| 684 | - } |
|
| 685 | - } catch (\Exception $e) {} |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - $this->result['lookup'] = $result; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Generates a bunch of pagination links for the current page |
|
| 693 | - * |
|
| 694 | - * @param int $page Current page |
|
| 695 | - * @param array $params Parameters for the URL |
|
| 696 | - * @return string |
|
| 697 | - */ |
|
| 698 | - protected function getPaginationLink($page, array $params) { |
|
| 699 | - if ($this->isV2()) { |
|
| 700 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 701 | - } else { |
|
| 702 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 703 | - } |
|
| 704 | - $params['page'] = $page + 1; |
|
| 705 | - $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
| 706 | - |
|
| 707 | - return $link; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * @return bool |
|
| 712 | - */ |
|
| 713 | - protected function isV2() { |
|
| 714 | - return $this->request->getScriptName() === '/ocs/v2.php'; |
|
| 715 | - } |
|
| 46 | + /** @var IGroupManager */ |
|
| 47 | + protected $groupManager; |
|
| 48 | + |
|
| 49 | + /** @var IUserManager */ |
|
| 50 | + protected $userManager; |
|
| 51 | + |
|
| 52 | + /** @var IManager */ |
|
| 53 | + protected $contactsManager; |
|
| 54 | + |
|
| 55 | + /** @var IConfig */ |
|
| 56 | + protected $config; |
|
| 57 | + |
|
| 58 | + /** @var IUserSession */ |
|
| 59 | + protected $userSession; |
|
| 60 | + |
|
| 61 | + /** @var IURLGenerator */ |
|
| 62 | + protected $urlGenerator; |
|
| 63 | + |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + protected $logger; |
|
| 66 | + |
|
| 67 | + /** @var \OCP\Share\IManager */ |
|
| 68 | + protected $shareManager; |
|
| 69 | + |
|
| 70 | + /** @var IClientService */ |
|
| 71 | + protected $clientService; |
|
| 72 | + |
|
| 73 | + /** @var ICloudIdManager */ |
|
| 74 | + protected $cloudIdManager; |
|
| 75 | + |
|
| 76 | + /** @var bool */ |
|
| 77 | + protected $shareWithGroupOnly = false; |
|
| 78 | + |
|
| 79 | + /** @var bool */ |
|
| 80 | + protected $shareeEnumeration = true; |
|
| 81 | + |
|
| 82 | + /** @var int */ |
|
| 83 | + protected $offset = 0; |
|
| 84 | + |
|
| 85 | + /** @var int */ |
|
| 86 | + protected $limit = 10; |
|
| 87 | + |
|
| 88 | + /** @var array */ |
|
| 89 | + protected $result = [ |
|
| 90 | + 'exact' => [ |
|
| 91 | + 'users' => [], |
|
| 92 | + 'groups' => [], |
|
| 93 | + 'remotes' => [], |
|
| 94 | + 'emails' => [], |
|
| 95 | + 'circles' => [], |
|
| 96 | + ], |
|
| 97 | + 'users' => [], |
|
| 98 | + 'groups' => [], |
|
| 99 | + 'remotes' => [], |
|
| 100 | + 'emails' => [], |
|
| 101 | + 'lookup' => [], |
|
| 102 | + 'circles' => [], |
|
| 103 | + ]; |
|
| 104 | + |
|
| 105 | + protected $reachedEndFor = []; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $appName |
|
| 109 | + * @param IRequest $request |
|
| 110 | + * @param IGroupManager $groupManager |
|
| 111 | + * @param IUserManager $userManager |
|
| 112 | + * @param IManager $contactsManager |
|
| 113 | + * @param IConfig $config |
|
| 114 | + * @param IUserSession $userSession |
|
| 115 | + * @param IURLGenerator $urlGenerator |
|
| 116 | + * @param ILogger $logger |
|
| 117 | + * @param \OCP\Share\IManager $shareManager |
|
| 118 | + * @param IClientService $clientService |
|
| 119 | + * @param ICloudIdManager $cloudIdManager |
|
| 120 | + */ |
|
| 121 | + public function __construct($appName, |
|
| 122 | + IRequest $request, |
|
| 123 | + IGroupManager $groupManager, |
|
| 124 | + IUserManager $userManager, |
|
| 125 | + IManager $contactsManager, |
|
| 126 | + IConfig $config, |
|
| 127 | + IUserSession $userSession, |
|
| 128 | + IURLGenerator $urlGenerator, |
|
| 129 | + ILogger $logger, |
|
| 130 | + \OCP\Share\IManager $shareManager, |
|
| 131 | + IClientService $clientService, |
|
| 132 | + ICloudIdManager $cloudIdManager |
|
| 133 | + ) { |
|
| 134 | + parent::__construct($appName, $request); |
|
| 135 | + |
|
| 136 | + $this->groupManager = $groupManager; |
|
| 137 | + $this->userManager = $userManager; |
|
| 138 | + $this->contactsManager = $contactsManager; |
|
| 139 | + $this->config = $config; |
|
| 140 | + $this->userSession = $userSession; |
|
| 141 | + $this->urlGenerator = $urlGenerator; |
|
| 142 | + $this->logger = $logger; |
|
| 143 | + $this->shareManager = $shareManager; |
|
| 144 | + $this->clientService = $clientService; |
|
| 145 | + $this->cloudIdManager = $cloudIdManager; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param string $search |
|
| 150 | + */ |
|
| 151 | + protected function getUsers($search) { |
|
| 152 | + $this->result['users'] = $this->result['exact']['users'] = $users = []; |
|
| 153 | + |
|
| 154 | + $userGroups = []; |
|
| 155 | + if ($this->shareWithGroupOnly) { |
|
| 156 | + // Search in all the groups this user is part of |
|
| 157 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 158 | + foreach ($userGroups as $userGroup) { |
|
| 159 | + $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $this->limit, $this->offset); |
|
| 160 | + foreach ($usersTmp as $uid => $userDisplayName) { |
|
| 161 | + $users[$uid] = $userDisplayName; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } else { |
|
| 165 | + // Search in all users |
|
| 166 | + $usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset); |
|
| 167 | + |
|
| 168 | + foreach ($usersTmp as $user) { |
|
| 169 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (!$this->shareeEnumeration || sizeof($users) < $this->limit) { |
|
| 174 | + $this->reachedEndFor[] = 'users'; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $foundUserById = false; |
|
| 178 | + $lowerSearch = strtolower($search); |
|
| 179 | + foreach ($users as $uid => $userDisplayName) { |
|
| 180 | + if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
| 181 | + if (strtolower($uid) === $lowerSearch) { |
|
| 182 | + $foundUserById = true; |
|
| 183 | + } |
|
| 184 | + $this->result['exact']['users'][] = [ |
|
| 185 | + 'label' => $userDisplayName, |
|
| 186 | + 'value' => [ |
|
| 187 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
| 188 | + 'shareWith' => $uid, |
|
| 189 | + ], |
|
| 190 | + ]; |
|
| 191 | + } else { |
|
| 192 | + $this->result['users'][] = [ |
|
| 193 | + 'label' => $userDisplayName, |
|
| 194 | + 'value' => [ |
|
| 195 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
| 196 | + 'shareWith' => $uid, |
|
| 197 | + ], |
|
| 198 | + ]; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($this->offset === 0 && !$foundUserById) { |
|
| 203 | + // On page one we try if the search result has a direct hit on the |
|
| 204 | + // user id and if so, we add that to the exact match list |
|
| 205 | + $user = $this->userManager->get($search); |
|
| 206 | + if ($user instanceof IUser) { |
|
| 207 | + $addUser = true; |
|
| 208 | + |
|
| 209 | + if ($this->shareWithGroupOnly) { |
|
| 210 | + // Only add, if we have a common group |
|
| 211 | + $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
| 212 | + $addUser = !empty($commonGroups); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ($addUser) { |
|
| 216 | + array_push($this->result['exact']['users'], [ |
|
| 217 | + 'label' => $user->getDisplayName(), |
|
| 218 | + 'value' => [ |
|
| 219 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
| 220 | + 'shareWith' => $user->getUID(), |
|
| 221 | + ], |
|
| 222 | + ]); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if (!$this->shareeEnumeration) { |
|
| 228 | + $this->result['users'] = []; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param string $search |
|
| 234 | + */ |
|
| 235 | + protected function getGroups($search) { |
|
| 236 | + $this->result['groups'] = $this->result['exact']['groups'] = []; |
|
| 237 | + |
|
| 238 | + $groups = $this->groupManager->search($search, $this->limit, $this->offset); |
|
| 239 | + $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
| 240 | + |
|
| 241 | + if (!$this->shareeEnumeration || sizeof($groups) < $this->limit) { |
|
| 242 | + $this->reachedEndFor[] = 'groups'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $userGroups = []; |
|
| 246 | + if (!empty($groups) && $this->shareWithGroupOnly) { |
|
| 247 | + // Intersect all the groups that match with the groups this user is a member of |
|
| 248 | + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
| 249 | + $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
| 250 | + $groupIds = array_intersect($groupIds, $userGroups); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $lowerSearch = strtolower($search); |
|
| 254 | + foreach ($groups as $group) { |
|
| 255 | + // FIXME: use a more efficient approach |
|
| 256 | + $gid = $group->getGID(); |
|
| 257 | + if (!in_array($gid, $groupIds)) { |
|
| 258 | + continue; |
|
| 259 | + } |
|
| 260 | + if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
| 261 | + $this->result['exact']['groups'][] = [ |
|
| 262 | + 'label' => $group->getDisplayName(), |
|
| 263 | + 'value' => [ |
|
| 264 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 265 | + 'shareWith' => $gid, |
|
| 266 | + ], |
|
| 267 | + ]; |
|
| 268 | + } else { |
|
| 269 | + $this->result['groups'][] = [ |
|
| 270 | + 'label' => $group->getDisplayName(), |
|
| 271 | + 'value' => [ |
|
| 272 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 273 | + 'shareWith' => $gid, |
|
| 274 | + ], |
|
| 275 | + ]; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if ($this->offset === 0 && empty($this->result['exact']['groups'])) { |
|
| 280 | + // On page one we try if the search result has a direct hit on the |
|
| 281 | + // user id and if so, we add that to the exact match list |
|
| 282 | + $group = $this->groupManager->get($search); |
|
| 283 | + if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
| 284 | + array_push($this->result['exact']['groups'], [ |
|
| 285 | + 'label' => $group->getDisplayName(), |
|
| 286 | + 'value' => [ |
|
| 287 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
| 288 | + 'shareWith' => $group->getGID(), |
|
| 289 | + ], |
|
| 290 | + ]); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$this->shareeEnumeration) { |
|
| 295 | + $this->result['groups'] = []; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $search |
|
| 302 | + */ |
|
| 303 | + protected function getCircles($search) { |
|
| 304 | + $this->result['circles'] = $this->result['exact']['circles'] = []; |
|
| 305 | + |
|
| 306 | + $result = \OCA\Circles\Api\Sharees::search($search, $this->limit, $this->offset); |
|
| 307 | + if (array_key_exists('circles', $result['exact'])) { |
|
| 308 | + $this->result['exact']['circles'] = $result['exact']['circles']; |
|
| 309 | + } |
|
| 310 | + if (array_key_exists('circles', $result)) { |
|
| 311 | + $this->result['circles'] = $result['circles']; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param string $search |
|
| 318 | + * @return array |
|
| 319 | + */ |
|
| 320 | + protected function getRemote($search) { |
|
| 321 | + $result = ['results' => [], 'exact' => []]; |
|
| 322 | + |
|
| 323 | + // Search in contacts |
|
| 324 | + //@todo Pagination missing |
|
| 325 | + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
|
| 326 | + $result['exactIdMatch'] = false; |
|
| 327 | + foreach ($addressBookContacts as $contact) { |
|
| 328 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 331 | + if (isset($contact['CLOUD'])) { |
|
| 332 | + $cloudIds = $contact['CLOUD']; |
|
| 333 | + if (!is_array($cloudIds)) { |
|
| 334 | + $cloudIds = [$cloudIds]; |
|
| 335 | + } |
|
| 336 | + $lowerSearch = strtolower($search); |
|
| 337 | + foreach ($cloudIds as $cloudId) { |
|
| 338 | + list(, $serverUrl) = $this->splitUserRemote($cloudId); |
|
| 339 | + if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
|
| 340 | + if (strtolower($cloudId) === $lowerSearch) { |
|
| 341 | + $result['exactIdMatch'] = true; |
|
| 342 | + } |
|
| 343 | + $result['exact'][] = [ |
|
| 344 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
| 345 | + 'value' => [ |
|
| 346 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 347 | + 'shareWith' => $cloudId, |
|
| 348 | + 'server' => $serverUrl, |
|
| 349 | + ], |
|
| 350 | + ]; |
|
| 351 | + } else { |
|
| 352 | + $result['results'][] = [ |
|
| 353 | + 'label' => $contact['FN'] . " ($cloudId)", |
|
| 354 | + 'value' => [ |
|
| 355 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 356 | + 'shareWith' => $cloudId, |
|
| 357 | + 'server' => $serverUrl, |
|
| 358 | + ], |
|
| 359 | + ]; |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (!$this->shareeEnumeration) { |
|
| 366 | + $result['results'] = []; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if (!$result['exactIdMatch'] && $this->cloudIdManager->isValidCloudId($search) && $this->offset === 0) { |
|
| 370 | + $result['exact'][] = [ |
|
| 371 | + 'label' => $search, |
|
| 372 | + 'value' => [ |
|
| 373 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 374 | + 'shareWith' => $search, |
|
| 375 | + ], |
|
| 376 | + ]; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $this->reachedEndFor[] = 'remotes'; |
|
| 380 | + |
|
| 381 | + return $result; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * split user and remote from federated cloud id |
|
| 386 | + * |
|
| 387 | + * @param string $address federated share address |
|
| 388 | + * @return array [user, remoteURL] |
|
| 389 | + * @throws \Exception |
|
| 390 | + */ |
|
| 391 | + public function splitUserRemote($address) { |
|
| 392 | + try { |
|
| 393 | + $cloudId = $this->cloudIdManager->resolveCloudId($address); |
|
| 394 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
| 395 | + } catch (\InvalidArgumentException $e) { |
|
| 396 | + throw new \Exception('Invalid Federated Cloud ID', 0, $e); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Strips away a potential file names and trailing slashes: |
|
| 402 | + * - http://localhost |
|
| 403 | + * - http://localhost/ |
|
| 404 | + * - http://localhost/index.php |
|
| 405 | + * - http://localhost/index.php/s/{shareToken} |
|
| 406 | + * |
|
| 407 | + * all return: http://localhost |
|
| 408 | + * |
|
| 409 | + * @param string $remote |
|
| 410 | + * @return string |
|
| 411 | + */ |
|
| 412 | + protected function fixRemoteURL($remote) { |
|
| 413 | + $remote = str_replace('\\', '/', $remote); |
|
| 414 | + if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
| 415 | + $remote = substr($remote, 0, $fileNamePosition); |
|
| 416 | + } |
|
| 417 | + $remote = rtrim($remote, '/'); |
|
| 418 | + |
|
| 419 | + return $remote; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @NoAdminRequired |
|
| 424 | + * |
|
| 425 | + * @param string $search |
|
| 426 | + * @param string $itemType |
|
| 427 | + * @param int $page |
|
| 428 | + * @param int $perPage |
|
| 429 | + * @param int|int[] $shareType |
|
| 430 | + * @param bool $lookup |
|
| 431 | + * @return DataResponse |
|
| 432 | + * @throws OCSBadRequestException |
|
| 433 | + */ |
|
| 434 | + public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
|
| 435 | + |
|
| 436 | + // only search for string larger than a given threshold |
|
| 437 | + $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
| 438 | + if (strlen($search) < $threshold) { |
|
| 439 | + return new DataResponse($this->result); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + // never return more than the max. number of results configured in the config.php |
|
| 443 | + $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
| 444 | + if ($maxResults > 0) { |
|
| 445 | + $perPage = min($perPage, $maxResults); |
|
| 446 | + } |
|
| 447 | + if ($perPage <= 0) { |
|
| 448 | + throw new OCSBadRequestException('Invalid perPage argument'); |
|
| 449 | + } |
|
| 450 | + if ($page <= 0) { |
|
| 451 | + throw new OCSBadRequestException('Invalid page'); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + $shareTypes = [ |
|
| 455 | + Share::SHARE_TYPE_USER, |
|
| 456 | + ]; |
|
| 457 | + |
|
| 458 | + if ($itemType === 'file' || $itemType === 'folder') { |
|
| 459 | + if ($this->shareManager->allowGroupSharing()) { |
|
| 460 | + $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + if ($this->isRemoteSharingAllowed($itemType)) { |
|
| 464 | + $shareTypes[] = Share::SHARE_TYPE_REMOTE; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { |
|
| 468 | + $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
| 469 | + } |
|
| 470 | + } else { |
|
| 471 | + $shareTypes[] = Share::SHARE_TYPE_GROUP; |
|
| 472 | + $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + if (\OCP\App::isEnabled('circles')) { |
|
| 476 | + $shareTypes[] = Share::SHARE_TYPE_CIRCLE; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
| 480 | + $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
| 481 | + sort($shareTypes); |
|
| 482 | + } else if (is_numeric($shareType)) { |
|
| 483 | + $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
| 484 | + sort($shareTypes); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 488 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 489 | + $this->limit = (int) $perPage; |
|
| 490 | + $this->offset = $perPage * ($page - 1); |
|
| 491 | + |
|
| 492 | + return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage, $lookup); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Method to get out the static call for better testing |
|
| 497 | + * |
|
| 498 | + * @param string $itemType |
|
| 499 | + * @return bool |
|
| 500 | + */ |
|
| 501 | + protected function isRemoteSharingAllowed($itemType) { |
|
| 502 | + try { |
|
| 503 | + $backend = Share::getBackend($itemType); |
|
| 504 | + return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE); |
|
| 505 | + } catch (\Exception $e) { |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Testable search function that does not need globals |
|
| 512 | + * |
|
| 513 | + * @param string $search |
|
| 514 | + * @param string $itemType |
|
| 515 | + * @param array $shareTypes |
|
| 516 | + * @param int $page |
|
| 517 | + * @param int $perPage |
|
| 518 | + * @param bool $lookup |
|
| 519 | + * @return DataResponse |
|
| 520 | + * @throws OCSBadRequestException |
|
| 521 | + */ |
|
| 522 | + protected function searchSharees($search, $itemType, array $shareTypes, $page, $perPage, $lookup) { |
|
| 523 | + // Verify arguments |
|
| 524 | + if ($itemType === null) { |
|
| 525 | + throw new OCSBadRequestException('Missing itemType'); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + // Get users |
|
| 529 | + if (in_array(Share::SHARE_TYPE_USER, $shareTypes)) { |
|
| 530 | + $this->getUsers($search); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + // Get groups |
|
| 534 | + if (in_array(Share::SHARE_TYPE_GROUP, $shareTypes)) { |
|
| 535 | + $this->getGroups($search); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + // Get circles |
|
| 539 | + if (in_array(Share::SHARE_TYPE_CIRCLE, $shareTypes)) { |
|
| 540 | + $this->getCircles($search); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + // Get remote |
|
| 545 | + $remoteResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false]; |
|
| 546 | + if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) { |
|
| 547 | + $remoteResults = $this->getRemote($search); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + // Get emails |
|
| 551 | + $mailResults = ['results' => [], 'exact' => [], 'exactIdMatch' => false]; |
|
| 552 | + if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) { |
|
| 553 | + $mailResults = $this->getEmail($search); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + // Get from lookup server |
|
| 557 | + if ($lookup) { |
|
| 558 | + $this->getLookup($search); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + // if we have a exact match, either for the federated cloud id or for the |
|
| 562 | + // email address we only return the exact match. It is highly unlikely |
|
| 563 | + // that the exact same email address and federated cloud id exists |
|
| 564 | + if ($mailResults['exactIdMatch'] && !$remoteResults['exactIdMatch']) { |
|
| 565 | + $this->result['emails'] = $mailResults['results']; |
|
| 566 | + $this->result['exact']['emails'] = $mailResults['exact']; |
|
| 567 | + } else if (!$mailResults['exactIdMatch'] && $remoteResults['exactIdMatch']) { |
|
| 568 | + $this->result['remotes'] = $remoteResults['results']; |
|
| 569 | + $this->result['exact']['remotes'] = $remoteResults['exact']; |
|
| 570 | + } else { |
|
| 571 | + $this->result['remotes'] = $remoteResults['results']; |
|
| 572 | + $this->result['exact']['remotes'] = $remoteResults['exact']; |
|
| 573 | + $this->result['emails'] = $mailResults['results']; |
|
| 574 | + $this->result['exact']['emails'] = $mailResults['exact']; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $response = new DataResponse($this->result); |
|
| 578 | + |
|
| 579 | + if (sizeof($this->reachedEndFor) < 3) { |
|
| 580 | + $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
| 581 | + 'search' => $search, |
|
| 582 | + 'itemType' => $itemType, |
|
| 583 | + 'shareType' => $shareTypes, |
|
| 584 | + 'perPage' => $perPage, |
|
| 585 | + ])); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + return $response; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @param string $search |
|
| 593 | + * @return array |
|
| 594 | + */ |
|
| 595 | + protected function getEmail($search) { |
|
| 596 | + $result = ['results' => [], 'exact' => []]; |
|
| 597 | + |
|
| 598 | + // Search in contacts |
|
| 599 | + //@todo Pagination missing |
|
| 600 | + $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
| 601 | + $result['exactIdMatch'] = false; |
|
| 602 | + foreach ($addressBookContacts as $contact) { |
|
| 603 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 604 | + continue; |
|
| 605 | + } |
|
| 606 | + if (isset($contact['EMAIL'])) { |
|
| 607 | + $emailAddresses = $contact['EMAIL']; |
|
| 608 | + if (!is_array($emailAddresses)) { |
|
| 609 | + $emailAddresses = [$emailAddresses]; |
|
| 610 | + } |
|
| 611 | + foreach ($emailAddresses as $emailAddress) { |
|
| 612 | + if (strtolower($contact['FN']) === strtolower($search) || strtolower($emailAddress) === strtolower($search)) { |
|
| 613 | + if (strtolower($emailAddress) === strtolower($search)) { |
|
| 614 | + $result['exactIdMatch'] = true; |
|
| 615 | + } |
|
| 616 | + $result['exact'][] = [ |
|
| 617 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 618 | + 'value' => [ |
|
| 619 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 620 | + 'shareWith' => $emailAddress, |
|
| 621 | + ], |
|
| 622 | + ]; |
|
| 623 | + } else { |
|
| 624 | + $result['results'][] = [ |
|
| 625 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 626 | + 'value' => [ |
|
| 627 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 628 | + 'shareWith' => $emailAddress, |
|
| 629 | + ], |
|
| 630 | + ]; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + if (!$this->shareeEnumeration) { |
|
| 637 | + $result['results'] = []; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + if (!$result['exactIdMatch'] && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
| 641 | + $result['exact'][] = [ |
|
| 642 | + 'label' => $search, |
|
| 643 | + 'value' => [ |
|
| 644 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
| 645 | + 'shareWith' => $search, |
|
| 646 | + ], |
|
| 647 | + ]; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + $this->reachedEndFor[] = 'emails'; |
|
| 651 | + |
|
| 652 | + return $result; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + protected function getLookup($search) { |
|
| 656 | + $isEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
| 657 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 658 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 659 | + $result = []; |
|
| 660 | + |
|
| 661 | + if($isEnabled === 'yes') { |
|
| 662 | + try { |
|
| 663 | + $client = $this->clientService->newClient(); |
|
| 664 | + $response = $client->get( |
|
| 665 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 666 | + [ |
|
| 667 | + 'timeout' => 10, |
|
| 668 | + 'connect_timeout' => 3, |
|
| 669 | + ] |
|
| 670 | + ); |
|
| 671 | + |
|
| 672 | + $body = json_decode($response->getBody(), true); |
|
| 673 | + |
|
| 674 | + $result = []; |
|
| 675 | + foreach ($body as $lookup) { |
|
| 676 | + $result[] = [ |
|
| 677 | + 'label' => $lookup['federationId'], |
|
| 678 | + 'value' => [ |
|
| 679 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 680 | + 'shareWith' => $lookup['federationId'], |
|
| 681 | + ], |
|
| 682 | + 'extra' => $lookup, |
|
| 683 | + ]; |
|
| 684 | + } |
|
| 685 | + } catch (\Exception $e) {} |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + $this->result['lookup'] = $result; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Generates a bunch of pagination links for the current page |
|
| 693 | + * |
|
| 694 | + * @param int $page Current page |
|
| 695 | + * @param array $params Parameters for the URL |
|
| 696 | + * @return string |
|
| 697 | + */ |
|
| 698 | + protected function getPaginationLink($page, array $params) { |
|
| 699 | + if ($this->isV2()) { |
|
| 700 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 701 | + } else { |
|
| 702 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 703 | + } |
|
| 704 | + $params['page'] = $page + 1; |
|
| 705 | + $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
| 706 | + |
|
| 707 | + return $link; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * @return bool |
|
| 712 | + */ |
|
| 713 | + protected function isV2() { |
|
| 714 | + return $this->request->getScriptName() === '/ocs/v2.php'; |
|
| 715 | + } |
|
| 716 | 716 | } |
@@ -236,17 +236,17 @@ discard block |
||
| 236 | 236 | $this->result['groups'] = $this->result['exact']['groups'] = []; |
| 237 | 237 | |
| 238 | 238 | $groups = $this->groupManager->search($search, $this->limit, $this->offset); |
| 239 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
| 239 | + $groupIds = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
| 240 | 240 | |
| 241 | 241 | if (!$this->shareeEnumeration || sizeof($groups) < $this->limit) { |
| 242 | 242 | $this->reachedEndFor[] = 'groups'; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $userGroups = []; |
|
| 245 | + $userGroups = []; |
|
| 246 | 246 | if (!empty($groups) && $this->shareWithGroupOnly) { |
| 247 | 247 | // Intersect all the groups that match with the groups this user is a member of |
| 248 | 248 | $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
| 249 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
| 249 | + $userGroups = array_map(function(IGroup $group) { return $group->getGID(); }, $userGroups); |
|
| 250 | 250 | $groupIds = array_intersect($groupIds, $userGroups); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | $result['exactIdMatch'] = true; |
| 342 | 342 | } |
| 343 | 343 | $result['exact'][] = [ |
| 344 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
| 344 | + 'label' => $contact['FN']." ($cloudId)", |
|
| 345 | 345 | 'value' => [ |
| 346 | 346 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
| 347 | 347 | 'shareWith' => $cloudId, |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | ]; |
| 351 | 351 | } else { |
| 352 | 352 | $result['results'][] = [ |
| 353 | - 'label' => $contact['FN'] . " ($cloudId)", |
|
| 353 | + 'label' => $contact['FN']." ($cloudId)", |
|
| 354 | 354 | 'value' => [ |
| 355 | 355 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
| 356 | 356 | 'shareWith' => $cloudId, |
@@ -434,13 +434,13 @@ discard block |
||
| 434 | 434 | public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { |
| 435 | 435 | |
| 436 | 436 | // only search for string larger than a given threshold |
| 437 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
| 437 | + $threshold = (int) $this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
| 438 | 438 | if (strlen($search) < $threshold) { |
| 439 | 439 | return new DataResponse($this->result); |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // never return more than the max. number of results configured in the config.php |
| 443 | - $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
| 443 | + $maxResults = (int) $this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
|
| 444 | 444 | if ($maxResults > 0) { |
| 445 | 445 | $perPage = min($perPage, $maxResults); |
| 446 | 446 | } |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | $result['exactIdMatch'] = true; |
| 615 | 615 | } |
| 616 | 616 | $result['exact'][] = [ |
| 617 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 617 | + 'label' => $contact['FN']." ($emailAddress)", |
|
| 618 | 618 | 'value' => [ |
| 619 | 619 | 'shareType' => Share::SHARE_TYPE_EMAIL, |
| 620 | 620 | 'shareWith' => $emailAddress, |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | ]; |
| 623 | 623 | } else { |
| 624 | 624 | $result['results'][] = [ |
| 625 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
| 625 | + 'label' => $contact['FN']." ($emailAddress)", |
|
| 626 | 626 | 'value' => [ |
| 627 | 627 | 'shareType' => Share::SHARE_TYPE_EMAIL, |
| 628 | 628 | 'shareWith' => $emailAddress, |
@@ -658,11 +658,11 @@ discard block |
||
| 658 | 658 | $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
| 659 | 659 | $result = []; |
| 660 | 660 | |
| 661 | - if($isEnabled === 'yes') { |
|
| 661 | + if ($isEnabled === 'yes') { |
|
| 662 | 662 | try { |
| 663 | 663 | $client = $this->clientService->newClient(); |
| 664 | 664 | $response = $client->get( |
| 665 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 665 | + $lookupServerUrl.'/users?search='.urlencode($search), |
|
| 666 | 666 | [ |
| 667 | 667 | 'timeout' => 10, |
| 668 | 668 | 'connect_timeout' => 3, |
@@ -697,12 +697,12 @@ discard block |
||
| 697 | 697 | */ |
| 698 | 698 | protected function getPaginationLink($page, array $params) { |
| 699 | 699 | if ($this->isV2()) { |
| 700 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 700 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees').'?'; |
|
| 701 | 701 | } else { |
| 702 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
| 702 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees').'?'; |
|
| 703 | 703 | } |
| 704 | 704 | $params['page'] = $page + 1; |
| 705 | - $link = '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
| 705 | + $link = '<'.$url.http_build_query($params).'>; rel="next"'; |
|
| 706 | 706 | |
| 707 | 707 | return $link; |
| 708 | 708 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | // check for encryption state - TODO see formatUserForIndex |
| 159 | 159 | $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
| 160 | - if($this->isEncryptionAppEnabled) { |
|
| 160 | + if ($this->isEncryptionAppEnabled) { |
|
| 161 | 161 | // putting this directly in empty is possible in PHP 5.5+ |
| 162 | 162 | $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
| 163 | 163 | $this->isRestoreEnabled = !empty($result); |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
| 200 | - foreach($subAdminGroups as $key => $subAdminGroup) { |
|
| 200 | + foreach ($subAdminGroups as $key => $subAdminGroup) { |
|
| 201 | 201 | $subAdminGroups[$key] = $subAdminGroup->getGID(); |
| 202 | 202 | } |
| 203 | 203 | |
@@ -254,16 +254,16 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
| 256 | 256 | // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
| 257 | - if($gid === '_everyone') { |
|
| 257 | + if ($gid === '_everyone') { |
|
| 258 | 258 | $gid = ''; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Remove backends |
| 262 | - if(!empty($backend)) { |
|
| 262 | + if (!empty($backend)) { |
|
| 263 | 263 | $activeBackends = $this->userManager->getBackends(); |
| 264 | 264 | $this->userManager->clearBackends(); |
| 265 | - foreach($activeBackends as $singleActiveBackend) { |
|
| 266 | - if($backend === get_class($singleActiveBackend)) { |
|
| 265 | + foreach ($activeBackends as $singleActiveBackend) { |
|
| 266 | + if ($backend === get_class($singleActiveBackend)) { |
|
| 267 | 267 | $this->userManager->registerBackend($singleActiveBackend); |
| 268 | 268 | break; |
| 269 | 269 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | $users = []; |
| 274 | 274 | if ($this->isAdmin) { |
| 275 | 275 | |
| 276 | - if($gid !== '') { |
|
| 276 | + if ($gid !== '') { |
|
| 277 | 277 | $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
| 278 | 278 | } else { |
| 279 | 279 | $batch = $this->userManager->search($pattern, $limit, $offset); |
@@ -293,17 +293,17 @@ discard block |
||
| 293 | 293 | $subAdminOfGroups = $gids; |
| 294 | 294 | |
| 295 | 295 | // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
| 296 | - if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
| 296 | + if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
| 297 | 297 | $gid = ''; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // Batch all groups the user is subadmin of when a group is specified |
| 301 | 301 | $batch = []; |
| 302 | - if($gid === '') { |
|
| 303 | - foreach($subAdminOfGroups as $group) { |
|
| 302 | + if ($gid === '') { |
|
| 303 | + foreach ($subAdminOfGroups as $group) { |
|
| 304 | 304 | $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
| 305 | 305 | |
| 306 | - foreach($groupUsers as $uid => $displayName) { |
|
| 306 | + foreach ($groupUsers as $uid => $displayName) { |
|
| 307 | 307 | $batch[$uid] = $displayName; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -335,11 +335,11 @@ discard block |
||
| 335 | 335 | * @param string $email |
| 336 | 336 | * @return DataResponse |
| 337 | 337 | */ |
| 338 | - public function create($username, $password, array $groups=array(), $email='') { |
|
| 339 | - if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
| 338 | + public function create($username, $password, array $groups = array(), $email = '') { |
|
| 339 | + if ($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
| 340 | 340 | return new DataResponse( |
| 341 | 341 | array( |
| 342 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 342 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
| 343 | 343 | ), |
| 344 | 344 | Http::STATUS_UNPROCESSABLE_ENTITY |
| 345 | 345 | ); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | if (!empty($groups)) { |
| 352 | 352 | foreach ($groups as $key => $group) { |
| 353 | 353 | $groupObject = $this->groupManager->get($group); |
| 354 | - if($groupObject === null) { |
|
| 354 | + if ($groupObject === null) { |
|
| 355 | 355 | unset($groups[$key]); |
| 356 | 356 | continue; |
| 357 | 357 | } |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | if ($this->userManager->userExists($username)) { |
| 376 | 376 | return new DataResponse( |
| 377 | 377 | array( |
| 378 | - 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
| 378 | + 'message' => (string) $this->l10n->t('A user with that name already exists.') |
|
| 379 | 379 | ), |
| 380 | 380 | Http::STATUS_CONFLICT |
| 381 | 381 | ); |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | if ($email === '') { |
| 387 | 387 | return new DataResponse( |
| 388 | 388 | array( |
| 389 | - 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
| 389 | + 'message' => (string) $this->l10n->t('To send a password link to the user an email address is required.') |
|
| 390 | 390 | ), |
| 391 | 391 | Http::STATUS_UNPROCESSABLE_ENTITY |
| 392 | 392 | ); |
@@ -411,12 +411,12 @@ discard block |
||
| 411 | 411 | ); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if($user instanceof IUser) { |
|
| 415 | - if($groups !== null) { |
|
| 416 | - foreach($groups as $groupName) { |
|
| 414 | + if ($user instanceof IUser) { |
|
| 415 | + if ($groups !== null) { |
|
| 416 | + foreach ($groups as $groupName) { |
|
| 417 | 417 | $group = $this->groupManager->get($groupName); |
| 418 | 418 | |
| 419 | - if(empty($group)) { |
|
| 419 | + if (empty($group)) { |
|
| 420 | 420 | $group = $this->groupManager->createGroup($groupName); |
| 421 | 421 | } |
| 422 | 422 | $group->addUser($user); |
@@ -425,13 +425,13 @@ discard block |
||
| 425 | 425 | /** |
| 426 | 426 | * Send new user mail only if a mail is set |
| 427 | 427 | */ |
| 428 | - if($email !== '') { |
|
| 428 | + if ($email !== '') { |
|
| 429 | 429 | $user->setEMailAddress($email); |
| 430 | 430 | try { |
| 431 | 431 | $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
| 432 | 432 | $this->newUserMailHelper->sendMail($user, $emailTemplate); |
| 433 | - } catch(\Exception $e) { |
|
| 434 | - $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
| 433 | + } catch (\Exception $e) { |
|
| 434 | + $this->log->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings')); |
|
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | // fetch users groups |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | |
| 446 | 446 | return new DataResponse( |
| 447 | 447 | array( |
| 448 | - 'message' => (string)$this->l10n->t('Unable to create user.') |
|
| 448 | + 'message' => (string) $this->l10n->t('Unable to create user.') |
|
| 449 | 449 | ), |
| 450 | 450 | Http::STATUS_FORBIDDEN |
| 451 | 451 | ); |
@@ -463,32 +463,32 @@ discard block |
||
| 463 | 463 | $userId = $this->userSession->getUser()->getUID(); |
| 464 | 464 | $user = $this->userManager->get($id); |
| 465 | 465 | |
| 466 | - if($userId === $id) { |
|
| 466 | + if ($userId === $id) { |
|
| 467 | 467 | return new DataResponse( |
| 468 | 468 | array( |
| 469 | 469 | 'status' => 'error', |
| 470 | 470 | 'data' => array( |
| 471 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 471 | + 'message' => (string) $this->l10n->t('Unable to delete user.') |
|
| 472 | 472 | ) |
| 473 | 473 | ), |
| 474 | 474 | Http::STATUS_FORBIDDEN |
| 475 | 475 | ); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
| 478 | + if (!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
| 479 | 479 | return new DataResponse( |
| 480 | 480 | array( |
| 481 | 481 | 'status' => 'error', |
| 482 | 482 | 'data' => array( |
| 483 | - 'message' => (string)$this->l10n->t('Authentication error') |
|
| 483 | + 'message' => (string) $this->l10n->t('Authentication error') |
|
| 484 | 484 | ) |
| 485 | 485 | ), |
| 486 | 486 | Http::STATUS_FORBIDDEN |
| 487 | 487 | ); |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if($user) { |
|
| 491 | - if($user->delete()) { |
|
| 490 | + if ($user) { |
|
| 491 | + if ($user->delete()) { |
|
| 492 | 492 | return new DataResponse( |
| 493 | 493 | array( |
| 494 | 494 | 'status' => 'success', |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | array( |
| 506 | 506 | 'status' => 'error', |
| 507 | 507 | 'data' => array( |
| 508 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 508 | + 'message' => (string) $this->l10n->t('Unable to delete user.') |
|
| 509 | 509 | ) |
| 510 | 510 | ), |
| 511 | 511 | Http::STATUS_FORBIDDEN |
@@ -530,11 +530,11 @@ discard block |
||
| 530 | 530 | |
| 531 | 531 | $accountData = $this->accountManager->getUser($user); |
| 532 | 532 | $cloudId = $user->getCloudId(); |
| 533 | - $message = "Use my Federated Cloud ID to share with me: " . $cloudId; |
|
| 533 | + $message = "Use my Federated Cloud ID to share with me: ".$cloudId; |
|
| 534 | 534 | $signature = $this->signMessage($user, $message); |
| 535 | 535 | |
| 536 | - $code = $message . ' ' . $signature; |
|
| 537 | - $codeMd5 = $message . ' ' . md5($signature); |
|
| 536 | + $code = $message.' '.$signature; |
|
| 537 | + $codeMd5 = $message.' '.md5($signature); |
|
| 538 | 538 | |
| 539 | 539 | switch ($account) { |
| 540 | 540 | case 'verify-twitter': |
@@ -631,12 +631,12 @@ discard block |
||
| 631 | 631 | $twitterScope |
| 632 | 632 | ) { |
| 633 | 633 | |
| 634 | - if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
| 634 | + if (!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
| 635 | 635 | return new DataResponse( |
| 636 | 636 | array( |
| 637 | 637 | 'status' => 'error', |
| 638 | 638 | 'data' => array( |
| 639 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 639 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
| 640 | 640 | ) |
| 641 | 641 | ), |
| 642 | 642 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | 'websiteScope' => $websiteScope, |
| 672 | 672 | 'address' => $address, |
| 673 | 673 | 'addressScope' => $addressScope, |
| 674 | - 'message' => (string)$this->l10n->t('Settings saved') |
|
| 674 | + 'message' => (string) $this->l10n->t('Settings saved') |
|
| 675 | 675 | ) |
| 676 | 676 | ), |
| 677 | 677 | Http::STATUS_OK |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | |
| 749 | 749 | $uniqueUsers = []; |
| 750 | 750 | foreach ($groups as $group) { |
| 751 | - foreach($group->getUsers() as $uid => $displayName) { |
|
| 751 | + foreach ($group->getUsers() as $uid => $displayName) { |
|
| 752 | 752 | $uniqueUsers[$uid] = true; |
| 753 | 753 | } |
| 754 | 754 | } |
@@ -842,19 +842,19 @@ discard block |
||
| 842 | 842 | array( |
| 843 | 843 | 'status' => 'error', |
| 844 | 844 | 'data' => array( |
| 845 | - 'message' => (string)$this->l10n->t('Forbidden') |
|
| 845 | + 'message' => (string) $this->l10n->t('Forbidden') |
|
| 846 | 846 | ) |
| 847 | 847 | ), |
| 848 | 848 | Http::STATUS_FORBIDDEN |
| 849 | 849 | ); |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | - if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
| 852 | + if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
| 853 | 853 | return new DataResponse( |
| 854 | 854 | array( |
| 855 | 855 | 'status' => 'error', |
| 856 | 856 | 'data' => array( |
| 857 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 857 | + 'message' => (string) $this->l10n->t('Invalid mail address') |
|
| 858 | 858 | ) |
| 859 | 859 | ), |
| 860 | 860 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | array( |
| 867 | 867 | 'status' => 'error', |
| 868 | 868 | 'data' => array( |
| 869 | - 'message' => (string)$this->l10n->t('Invalid user') |
|
| 869 | + 'message' => (string) $this->l10n->t('Invalid user') |
|
| 870 | 870 | ) |
| 871 | 871 | ), |
| 872 | 872 | Http::STATUS_UNPROCESSABLE_ENTITY |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | array( |
| 880 | 880 | 'status' => 'error', |
| 881 | 881 | 'data' => array( |
| 882 | - 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
| 882 | + 'message' => (string) $this->l10n->t('Unable to change mail address') |
|
| 883 | 883 | ) |
| 884 | 884 | ), |
| 885 | 885 | Http::STATUS_FORBIDDEN |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | 'data' => array( |
| 898 | 898 | 'username' => $id, |
| 899 | 899 | 'mailAddress' => $mailAddress, |
| 900 | - 'message' => (string)$this->l10n->t('Email saved') |
|
| 900 | + 'message' => (string) $this->l10n->t('Email saved') |
|
| 901 | 901 | ) |
| 902 | 902 | ), |
| 903 | 903 | Http::STATUS_OK |
@@ -58,860 +58,860 @@ |
||
| 58 | 58 | * @package OC\Settings\Controller |
| 59 | 59 | */ |
| 60 | 60 | class UsersController extends Controller { |
| 61 | - /** @var IL10N */ |
|
| 62 | - private $l10n; |
|
| 63 | - /** @var IUserSession */ |
|
| 64 | - private $userSession; |
|
| 65 | - /** @var bool */ |
|
| 66 | - private $isAdmin; |
|
| 67 | - /** @var IUserManager */ |
|
| 68 | - private $userManager; |
|
| 69 | - /** @var IGroupManager */ |
|
| 70 | - private $groupManager; |
|
| 71 | - /** @var IConfig */ |
|
| 72 | - private $config; |
|
| 73 | - /** @var ILogger */ |
|
| 74 | - private $log; |
|
| 75 | - /** @var IMailer */ |
|
| 76 | - private $mailer; |
|
| 77 | - /** @var bool contains the state of the encryption app */ |
|
| 78 | - private $isEncryptionAppEnabled; |
|
| 79 | - /** @var bool contains the state of the admin recovery setting */ |
|
| 80 | - private $isRestoreEnabled = false; |
|
| 81 | - /** @var IAvatarManager */ |
|
| 82 | - private $avatarManager; |
|
| 83 | - /** @var AccountManager */ |
|
| 84 | - private $accountManager; |
|
| 85 | - /** @var ISecureRandom */ |
|
| 86 | - private $secureRandom; |
|
| 87 | - /** @var NewUserMailHelper */ |
|
| 88 | - private $newUserMailHelper; |
|
| 89 | - /** @var ITimeFactory */ |
|
| 90 | - private $timeFactory; |
|
| 91 | - /** @var ICrypto */ |
|
| 92 | - private $crypto; |
|
| 93 | - /** @var Manager */ |
|
| 94 | - private $keyManager; |
|
| 95 | - /** @var IJobList */ |
|
| 96 | - private $jobList; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param string $appName |
|
| 100 | - * @param IRequest $request |
|
| 101 | - * @param IUserManager $userManager |
|
| 102 | - * @param IGroupManager $groupManager |
|
| 103 | - * @param IUserSession $userSession |
|
| 104 | - * @param IConfig $config |
|
| 105 | - * @param bool $isAdmin |
|
| 106 | - * @param IL10N $l10n |
|
| 107 | - * @param ILogger $log |
|
| 108 | - * @param IMailer $mailer |
|
| 109 | - * @param IURLGenerator $urlGenerator |
|
| 110 | - * @param IAppManager $appManager |
|
| 111 | - * @param IAvatarManager $avatarManager |
|
| 112 | - * @param AccountManager $accountManager |
|
| 113 | - * @param ISecureRandom $secureRandom |
|
| 114 | - * @param NewUserMailHelper $newUserMailHelper |
|
| 115 | - * @param ITimeFactory $timeFactory |
|
| 116 | - * @param ICrypto $crypto |
|
| 117 | - * @param Manager $keyManager |
|
| 118 | - * @param IJobList $jobList |
|
| 119 | - */ |
|
| 120 | - public function __construct($appName, |
|
| 121 | - IRequest $request, |
|
| 122 | - IUserManager $userManager, |
|
| 123 | - IGroupManager $groupManager, |
|
| 124 | - IUserSession $userSession, |
|
| 125 | - IConfig $config, |
|
| 126 | - $isAdmin, |
|
| 127 | - IL10N $l10n, |
|
| 128 | - ILogger $log, |
|
| 129 | - IMailer $mailer, |
|
| 130 | - IURLGenerator $urlGenerator, |
|
| 131 | - IAppManager $appManager, |
|
| 132 | - IAvatarManager $avatarManager, |
|
| 133 | - AccountManager $accountManager, |
|
| 134 | - ISecureRandom $secureRandom, |
|
| 135 | - NewUserMailHelper $newUserMailHelper, |
|
| 136 | - ITimeFactory $timeFactory, |
|
| 137 | - ICrypto $crypto, |
|
| 138 | - Manager $keyManager, |
|
| 139 | - IJobList $jobList) { |
|
| 140 | - parent::__construct($appName, $request); |
|
| 141 | - $this->userManager = $userManager; |
|
| 142 | - $this->groupManager = $groupManager; |
|
| 143 | - $this->userSession = $userSession; |
|
| 144 | - $this->config = $config; |
|
| 145 | - $this->isAdmin = $isAdmin; |
|
| 146 | - $this->l10n = $l10n; |
|
| 147 | - $this->log = $log; |
|
| 148 | - $this->mailer = $mailer; |
|
| 149 | - $this->avatarManager = $avatarManager; |
|
| 150 | - $this->accountManager = $accountManager; |
|
| 151 | - $this->secureRandom = $secureRandom; |
|
| 152 | - $this->newUserMailHelper = $newUserMailHelper; |
|
| 153 | - $this->timeFactory = $timeFactory; |
|
| 154 | - $this->crypto = $crypto; |
|
| 155 | - $this->keyManager = $keyManager; |
|
| 156 | - $this->jobList = $jobList; |
|
| 157 | - |
|
| 158 | - // check for encryption state - TODO see formatUserForIndex |
|
| 159 | - $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
|
| 160 | - if($this->isEncryptionAppEnabled) { |
|
| 161 | - // putting this directly in empty is possible in PHP 5.5+ |
|
| 162 | - $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
|
| 163 | - $this->isRestoreEnabled = !empty($result); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param IUser $user |
|
| 169 | - * @param array $userGroups |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - private function formatUserForIndex(IUser $user, array $userGroups = null) { |
|
| 173 | - |
|
| 174 | - // TODO: eliminate this encryption specific code below and somehow |
|
| 175 | - // hook in additional user info from other apps |
|
| 176 | - |
|
| 177 | - // recovery isn't possible if admin or user has it disabled and encryption |
|
| 178 | - // is enabled - so we eliminate the else paths in the conditional tree |
|
| 179 | - // below |
|
| 180 | - $restorePossible = false; |
|
| 181 | - |
|
| 182 | - if ($this->isEncryptionAppEnabled) { |
|
| 183 | - if ($this->isRestoreEnabled) { |
|
| 184 | - // check for the users recovery setting |
|
| 185 | - $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0'); |
|
| 186 | - // method call inside empty is possible with PHP 5.5+ |
|
| 187 | - $recoveryModeEnabled = !empty($recoveryMode); |
|
| 188 | - if ($recoveryModeEnabled) { |
|
| 189 | - // user also has recovery mode enabled |
|
| 190 | - $restorePossible = true; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } else { |
|
| 194 | - // recovery is possible if encryption is disabled (plain files are |
|
| 195 | - // available) |
|
| 196 | - $restorePossible = true; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 200 | - foreach($subAdminGroups as $key => $subAdminGroup) { |
|
| 201 | - $subAdminGroups[$key] = $subAdminGroup->getGID(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $displayName = $user->getEMailAddress(); |
|
| 205 | - if (is_null($displayName)) { |
|
| 206 | - $displayName = ''; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $avatarAvailable = false; |
|
| 210 | - try { |
|
| 211 | - $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists(); |
|
| 212 | - } catch (\Exception $e) { |
|
| 213 | - //No avatar yet |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return [ |
|
| 217 | - 'name' => $user->getUID(), |
|
| 218 | - 'displayname' => $user->getDisplayName(), |
|
| 219 | - 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, |
|
| 220 | - 'subadmin' => $subAdminGroups, |
|
| 221 | - 'quota' => $user->getQuota(), |
|
| 222 | - 'storageLocation' => $user->getHome(), |
|
| 223 | - 'lastLogin' => $user->getLastLogin() * 1000, |
|
| 224 | - 'backend' => $user->getBackendClassName(), |
|
| 225 | - 'email' => $displayName, |
|
| 226 | - 'isRestoreDisabled' => !$restorePossible, |
|
| 227 | - 'isAvatarAvailable' => $avatarAvailable, |
|
| 228 | - ]; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param array $userIDs Array with schema [$uid => $displayName] |
|
| 233 | - * @return IUser[] |
|
| 234 | - */ |
|
| 235 | - private function getUsersForUID(array $userIDs) { |
|
| 236 | - $users = []; |
|
| 237 | - foreach ($userIDs as $uid => $displayName) { |
|
| 238 | - $users[$uid] = $this->userManager->get($uid); |
|
| 239 | - } |
|
| 240 | - return $users; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @NoAdminRequired |
|
| 245 | - * |
|
| 246 | - * @param int $offset |
|
| 247 | - * @param int $limit |
|
| 248 | - * @param string $gid GID to filter for |
|
| 249 | - * @param string $pattern Pattern to search for in the username |
|
| 250 | - * @param string $backend Backend to filter for (class-name) |
|
| 251 | - * @return DataResponse |
|
| 252 | - * |
|
| 253 | - * TODO: Tidy up and write unit tests - code is mainly static method calls |
|
| 254 | - */ |
|
| 255 | - public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
|
| 256 | - // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
|
| 257 | - if($gid === '_everyone') { |
|
| 258 | - $gid = ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Remove backends |
|
| 262 | - if(!empty($backend)) { |
|
| 263 | - $activeBackends = $this->userManager->getBackends(); |
|
| 264 | - $this->userManager->clearBackends(); |
|
| 265 | - foreach($activeBackends as $singleActiveBackend) { |
|
| 266 | - if($backend === get_class($singleActiveBackend)) { |
|
| 267 | - $this->userManager->registerBackend($singleActiveBackend); |
|
| 268 | - break; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $users = []; |
|
| 274 | - if ($this->isAdmin) { |
|
| 275 | - |
|
| 276 | - if($gid !== '') { |
|
| 277 | - $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
|
| 278 | - } else { |
|
| 279 | - $batch = $this->userManager->search($pattern, $limit, $offset); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - foreach ($batch as $user) { |
|
| 283 | - $users[] = $this->formatUserForIndex($user); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - } else { |
|
| 287 | - $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
| 288 | - // New class returns IGroup[] so convert back |
|
| 289 | - $gids = []; |
|
| 290 | - foreach ($subAdminOfGroups as $group) { |
|
| 291 | - $gids[] = $group->getGID(); |
|
| 292 | - } |
|
| 293 | - $subAdminOfGroups = $gids; |
|
| 294 | - |
|
| 295 | - // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
|
| 296 | - if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
| 297 | - $gid = ''; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // Batch all groups the user is subadmin of when a group is specified |
|
| 301 | - $batch = []; |
|
| 302 | - if($gid === '') { |
|
| 303 | - foreach($subAdminOfGroups as $group) { |
|
| 304 | - $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
|
| 305 | - |
|
| 306 | - foreach($groupUsers as $uid => $displayName) { |
|
| 307 | - $batch[$uid] = $displayName; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } else { |
|
| 311 | - $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset); |
|
| 312 | - } |
|
| 313 | - $batch = $this->getUsersForUID($batch); |
|
| 314 | - |
|
| 315 | - foreach ($batch as $user) { |
|
| 316 | - // Only add the groups, this user is a subadmin of |
|
| 317 | - $userGroups = array_values(array_intersect( |
|
| 318 | - $this->groupManager->getUserGroupIds($user), |
|
| 319 | - $subAdminOfGroups |
|
| 320 | - )); |
|
| 321 | - $users[] = $this->formatUserForIndex($user, $userGroups); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return new DataResponse($users); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @NoAdminRequired |
|
| 330 | - * @PasswordConfirmationRequired |
|
| 331 | - * |
|
| 332 | - * @param string $username |
|
| 333 | - * @param string $password |
|
| 334 | - * @param array $groups |
|
| 335 | - * @param string $email |
|
| 336 | - * @return DataResponse |
|
| 337 | - */ |
|
| 338 | - public function create($username, $password, array $groups=array(), $email='') { |
|
| 339 | - if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
| 340 | - return new DataResponse( |
|
| 341 | - array( |
|
| 342 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 343 | - ), |
|
| 344 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 345 | - ); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $currentUser = $this->userSession->getUser(); |
|
| 349 | - |
|
| 350 | - if (!$this->isAdmin) { |
|
| 351 | - if (!empty($groups)) { |
|
| 352 | - foreach ($groups as $key => $group) { |
|
| 353 | - $groupObject = $this->groupManager->get($group); |
|
| 354 | - if($groupObject === null) { |
|
| 355 | - unset($groups[$key]); |
|
| 356 | - continue; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { |
|
| 360 | - unset($groups[$key]); |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (empty($groups)) { |
|
| 366 | - return new DataResponse( |
|
| 367 | - array( |
|
| 368 | - 'message' => $this->l10n->t('No valid group selected'), |
|
| 369 | - ), |
|
| 370 | - Http::STATUS_FORBIDDEN |
|
| 371 | - ); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ($this->userManager->userExists($username)) { |
|
| 376 | - return new DataResponse( |
|
| 377 | - array( |
|
| 378 | - 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
| 379 | - ), |
|
| 380 | - Http::STATUS_CONFLICT |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - $generatePasswordResetToken = false; |
|
| 385 | - if ($password === '') { |
|
| 386 | - if ($email === '') { |
|
| 387 | - return new DataResponse( |
|
| 388 | - array( |
|
| 389 | - 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
| 390 | - ), |
|
| 391 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 392 | - ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $password = $this->secureRandom->generate(32); |
|
| 396 | - $generatePasswordResetToken = true; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - try { |
|
| 400 | - $user = $this->userManager->createUser($username, $password); |
|
| 401 | - } catch (\Exception $exception) { |
|
| 402 | - $message = $exception->getMessage(); |
|
| 403 | - if (!$message) { |
|
| 404 | - $message = $this->l10n->t('Unable to create user.'); |
|
| 405 | - } |
|
| 406 | - return new DataResponse( |
|
| 407 | - array( |
|
| 408 | - 'message' => (string) $message, |
|
| 409 | - ), |
|
| 410 | - Http::STATUS_FORBIDDEN |
|
| 411 | - ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - if($user instanceof IUser) { |
|
| 415 | - if($groups !== null) { |
|
| 416 | - foreach($groups as $groupName) { |
|
| 417 | - $group = $this->groupManager->get($groupName); |
|
| 418 | - |
|
| 419 | - if(empty($group)) { |
|
| 420 | - $group = $this->groupManager->createGroup($groupName); |
|
| 421 | - } |
|
| 422 | - $group->addUser($user); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - /** |
|
| 426 | - * Send new user mail only if a mail is set |
|
| 427 | - */ |
|
| 428 | - if($email !== '') { |
|
| 429 | - $user->setEMailAddress($email); |
|
| 430 | - try { |
|
| 431 | - $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
|
| 432 | - $this->newUserMailHelper->sendMail($user, $emailTemplate); |
|
| 433 | - } catch(\Exception $e) { |
|
| 434 | - $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - // fetch users groups |
|
| 438 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 439 | - |
|
| 440 | - return new DataResponse( |
|
| 441 | - $this->formatUserForIndex($user, $userGroups), |
|
| 442 | - Http::STATUS_CREATED |
|
| 443 | - ); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return new DataResponse( |
|
| 447 | - array( |
|
| 448 | - 'message' => (string)$this->l10n->t('Unable to create user.') |
|
| 449 | - ), |
|
| 450 | - Http::STATUS_FORBIDDEN |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @NoAdminRequired |
|
| 457 | - * @PasswordConfirmationRequired |
|
| 458 | - * |
|
| 459 | - * @param string $id |
|
| 460 | - * @return DataResponse |
|
| 461 | - */ |
|
| 462 | - public function destroy($id) { |
|
| 463 | - $userId = $this->userSession->getUser()->getUID(); |
|
| 464 | - $user = $this->userManager->get($id); |
|
| 465 | - |
|
| 466 | - if($userId === $id) { |
|
| 467 | - return new DataResponse( |
|
| 468 | - array( |
|
| 469 | - 'status' => 'error', |
|
| 470 | - 'data' => array( |
|
| 471 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 472 | - ) |
|
| 473 | - ), |
|
| 474 | - Http::STATUS_FORBIDDEN |
|
| 475 | - ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
| 479 | - return new DataResponse( |
|
| 480 | - array( |
|
| 481 | - 'status' => 'error', |
|
| 482 | - 'data' => array( |
|
| 483 | - 'message' => (string)$this->l10n->t('Authentication error') |
|
| 484 | - ) |
|
| 485 | - ), |
|
| 486 | - Http::STATUS_FORBIDDEN |
|
| 487 | - ); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - if($user) { |
|
| 491 | - if($user->delete()) { |
|
| 492 | - return new DataResponse( |
|
| 493 | - array( |
|
| 494 | - 'status' => 'success', |
|
| 495 | - 'data' => array( |
|
| 496 | - 'username' => $id |
|
| 497 | - ) |
|
| 498 | - ), |
|
| 499 | - Http::STATUS_NO_CONTENT |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - return new DataResponse( |
|
| 505 | - array( |
|
| 506 | - 'status' => 'error', |
|
| 507 | - 'data' => array( |
|
| 508 | - 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 509 | - ) |
|
| 510 | - ), |
|
| 511 | - Http::STATUS_FORBIDDEN |
|
| 512 | - ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * @NoAdminRequired |
|
| 517 | - * @NoSubadminRequired |
|
| 518 | - * @PasswordConfirmationRequired |
|
| 519 | - * |
|
| 520 | - * @param string $account |
|
| 521 | - * @param bool $onlyVerificationCode only return verification code without updating the data |
|
| 522 | - * @return DataResponse |
|
| 523 | - */ |
|
| 524 | - public function getVerificationCode($account, $onlyVerificationCode) { |
|
| 525 | - |
|
| 526 | - $user = $this->userSession->getUser(); |
|
| 527 | - |
|
| 528 | - if ($user === null) { |
|
| 529 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $accountData = $this->accountManager->getUser($user); |
|
| 533 | - $cloudId = $user->getCloudId(); |
|
| 534 | - $message = "Use my Federated Cloud ID to share with me: " . $cloudId; |
|
| 535 | - $signature = $this->signMessage($user, $message); |
|
| 536 | - |
|
| 537 | - $code = $message . ' ' . $signature; |
|
| 538 | - $codeMd5 = $message . ' ' . md5($signature); |
|
| 539 | - |
|
| 540 | - switch ($account) { |
|
| 541 | - case 'verify-twitter': |
|
| 542 | - $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 543 | - $msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter (please make sure to post it without any line breaks):'); |
|
| 544 | - $code = $codeMd5; |
|
| 545 | - $type = AccountManager::PROPERTY_TWITTER; |
|
| 546 | - $data = $accountData[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 547 | - break; |
|
| 548 | - case 'verify-website': |
|
| 549 | - $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 550 | - $msg = $this->l10n->t('In order to verify your Website store following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):'); |
|
| 551 | - $type = AccountManager::PROPERTY_WEBSITE; |
|
| 552 | - $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 553 | - break; |
|
| 554 | - default: |
|
| 555 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - if ($onlyVerificationCode === false) { |
|
| 559 | - $this->accountManager->updateUser($user, $accountData); |
|
| 560 | - |
|
| 561 | - $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 562 | - [ |
|
| 563 | - 'verificationCode' => $code, |
|
| 564 | - 'data' => $data, |
|
| 565 | - 'type' => $type, |
|
| 566 | - 'uid' => $user->getUID(), |
|
| 567 | - 'try' => 0, |
|
| 568 | - 'lastRun' => $this->getCurrentTime() |
|
| 569 | - ] |
|
| 570 | - ); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return new DataResponse(['msg' => $msg, 'code' => $code]); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * get current timestamp |
|
| 578 | - * |
|
| 579 | - * @return int |
|
| 580 | - */ |
|
| 581 | - protected function getCurrentTime() { |
|
| 582 | - return time(); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * sign message with users private key |
|
| 587 | - * |
|
| 588 | - * @param IUser $user |
|
| 589 | - * @param string $message |
|
| 590 | - * |
|
| 591 | - * @return string base64 encoded signature |
|
| 592 | - */ |
|
| 593 | - protected function signMessage(IUser $user, $message) { |
|
| 594 | - $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
| 595 | - openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
| 596 | - $signatureBase64 = base64_encode($signature); |
|
| 597 | - |
|
| 598 | - return $signatureBase64; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @NoAdminRequired |
|
| 603 | - * @NoSubadminRequired |
|
| 604 | - * @PasswordConfirmationRequired |
|
| 605 | - * |
|
| 606 | - * @param string $avatarScope |
|
| 607 | - * @param string $displayname |
|
| 608 | - * @param string $displaynameScope |
|
| 609 | - * @param string $phone |
|
| 610 | - * @param string $phoneScope |
|
| 611 | - * @param string $email |
|
| 612 | - * @param string $emailScope |
|
| 613 | - * @param string $website |
|
| 614 | - * @param string $websiteScope |
|
| 615 | - * @param string $address |
|
| 616 | - * @param string $addressScope |
|
| 617 | - * @param string $twitter |
|
| 618 | - * @param string $twitterScope |
|
| 619 | - * @return DataResponse |
|
| 620 | - */ |
|
| 621 | - public function setUserSettings($avatarScope, |
|
| 622 | - $displayname, |
|
| 623 | - $displaynameScope, |
|
| 624 | - $phone, |
|
| 625 | - $phoneScope, |
|
| 626 | - $email, |
|
| 627 | - $emailScope, |
|
| 628 | - $website, |
|
| 629 | - $websiteScope, |
|
| 630 | - $address, |
|
| 631 | - $addressScope, |
|
| 632 | - $twitter, |
|
| 633 | - $twitterScope |
|
| 634 | - ) { |
|
| 635 | - |
|
| 636 | - if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
| 637 | - return new DataResponse( |
|
| 638 | - array( |
|
| 639 | - 'status' => 'error', |
|
| 640 | - 'data' => array( |
|
| 641 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 642 | - ) |
|
| 643 | - ), |
|
| 644 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - $data = [ |
|
| 649 | - AccountManager::PROPERTY_AVATAR => ['scope' => $avatarScope], |
|
| 650 | - AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope], |
|
| 651 | - AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope], |
|
| 652 | - AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope], |
|
| 653 | - AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope], |
|
| 654 | - AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope], |
|
| 655 | - AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope] |
|
| 656 | - ]; |
|
| 657 | - |
|
| 658 | - $user = $this->userSession->getUser(); |
|
| 659 | - |
|
| 660 | - try { |
|
| 661 | - $this->saveUserSettings($user, $data); |
|
| 662 | - return new DataResponse( |
|
| 663 | - array( |
|
| 664 | - 'status' => 'success', |
|
| 665 | - 'data' => array( |
|
| 666 | - 'userId' => $user->getUID(), |
|
| 667 | - 'avatarScope' => $avatarScope, |
|
| 668 | - 'displayname' => $displayname, |
|
| 669 | - 'displaynameScope' => $displaynameScope, |
|
| 670 | - 'email' => $email, |
|
| 671 | - 'emailScope' => $emailScope, |
|
| 672 | - 'website' => $website, |
|
| 673 | - 'websiteScope' => $websiteScope, |
|
| 674 | - 'address' => $address, |
|
| 675 | - 'addressScope' => $addressScope, |
|
| 676 | - 'message' => (string)$this->l10n->t('Settings saved') |
|
| 677 | - ) |
|
| 678 | - ), |
|
| 679 | - Http::STATUS_OK |
|
| 680 | - ); |
|
| 681 | - } catch (ForbiddenException $e) { |
|
| 682 | - return new DataResponse([ |
|
| 683 | - 'status' => 'error', |
|
| 684 | - 'data' => [ |
|
| 685 | - 'message' => $e->getMessage() |
|
| 686 | - ], |
|
| 687 | - ]); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * update account manager with new user data |
|
| 695 | - * |
|
| 696 | - * @param IUser $user |
|
| 697 | - * @param array $data |
|
| 698 | - * @throws ForbiddenException |
|
| 699 | - */ |
|
| 700 | - protected function saveUserSettings(IUser $user, $data) { |
|
| 701 | - |
|
| 702 | - // keep the user back-end up-to-date with the latest display name and email |
|
| 703 | - // address |
|
| 704 | - $oldDisplayName = $user->getDisplayName(); |
|
| 705 | - $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
| 706 | - if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
| 707 | - && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
| 708 | - ) { |
|
| 709 | - $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
| 710 | - if ($result === false) { |
|
| 711 | - throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - $oldEmailAddress = $user->getEMailAddress(); |
|
| 716 | - $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
| 717 | - if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
| 718 | - && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
| 719 | - ) { |
|
| 720 | - // this is the only permission a backend provides and is also used |
|
| 721 | - // for the permission of setting a email address |
|
| 722 | - if (!$user->canChangeDisplayName()) { |
|
| 723 | - throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
| 724 | - } |
|
| 725 | - $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - $this->accountManager->updateUser($user, $data); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * Count all unique users visible for the current admin/subadmin. |
|
| 733 | - * |
|
| 734 | - * @NoAdminRequired |
|
| 735 | - * |
|
| 736 | - * @return DataResponse |
|
| 737 | - */ |
|
| 738 | - public function stats() { |
|
| 739 | - $userCount = 0; |
|
| 740 | - if ($this->isAdmin) { |
|
| 741 | - $countByBackend = $this->userManager->countUsers(); |
|
| 742 | - |
|
| 743 | - if (!empty($countByBackend)) { |
|
| 744 | - foreach ($countByBackend as $count) { |
|
| 745 | - $userCount += $count; |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - } else { |
|
| 749 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
| 750 | - |
|
| 751 | - $uniqueUsers = []; |
|
| 752 | - foreach ($groups as $group) { |
|
| 753 | - foreach($group->getUsers() as $uid => $displayName) { |
|
| 754 | - $uniqueUsers[$uid] = true; |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - $userCount = count($uniqueUsers); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - return new DataResponse( |
|
| 762 | - [ |
|
| 763 | - 'totalUsers' => $userCount |
|
| 764 | - ] |
|
| 765 | - ); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Set the displayName of a user |
|
| 771 | - * |
|
| 772 | - * @NoAdminRequired |
|
| 773 | - * @NoSubadminRequired |
|
| 774 | - * @PasswordConfirmationRequired |
|
| 775 | - * @todo merge into saveUserSettings |
|
| 776 | - * |
|
| 777 | - * @param string $username |
|
| 778 | - * @param string $displayName |
|
| 779 | - * @return DataResponse |
|
| 780 | - */ |
|
| 781 | - public function setDisplayName($username, $displayName) { |
|
| 782 | - $currentUser = $this->userSession->getUser(); |
|
| 783 | - $user = $this->userManager->get($username); |
|
| 784 | - |
|
| 785 | - if ($user === null || |
|
| 786 | - !$user->canChangeDisplayName() || |
|
| 787 | - ( |
|
| 788 | - !$this->groupManager->isAdmin($currentUser->getUID()) && |
|
| 789 | - !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) && |
|
| 790 | - $currentUser->getUID() !== $username |
|
| 791 | - |
|
| 792 | - ) |
|
| 793 | - ) { |
|
| 794 | - return new DataResponse([ |
|
| 795 | - 'status' => 'error', |
|
| 796 | - 'data' => [ |
|
| 797 | - 'message' => $this->l10n->t('Authentication error'), |
|
| 798 | - ], |
|
| 799 | - ]); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - $userData = $this->accountManager->getUser($user); |
|
| 803 | - $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
| 804 | - |
|
| 805 | - |
|
| 806 | - try { |
|
| 807 | - $this->saveUserSettings($user, $userData); |
|
| 808 | - return new DataResponse([ |
|
| 809 | - 'status' => 'success', |
|
| 810 | - 'data' => [ |
|
| 811 | - 'message' => $this->l10n->t('Your full name has been changed.'), |
|
| 812 | - 'username' => $username, |
|
| 813 | - 'displayName' => $displayName, |
|
| 814 | - ], |
|
| 815 | - ]); |
|
| 816 | - } catch (ForbiddenException $e) { |
|
| 817 | - return new DataResponse([ |
|
| 818 | - 'status' => 'error', |
|
| 819 | - 'data' => [ |
|
| 820 | - 'message' => $e->getMessage(), |
|
| 821 | - 'displayName' => $user->getDisplayName(), |
|
| 822 | - ], |
|
| 823 | - ]); |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Set the mail address of a user |
|
| 829 | - * |
|
| 830 | - * @NoAdminRequired |
|
| 831 | - * @NoSubadminRequired |
|
| 832 | - * @PasswordConfirmationRequired |
|
| 833 | - * |
|
| 834 | - * @param string $id |
|
| 835 | - * @param string $mailAddress |
|
| 836 | - * @return DataResponse |
|
| 837 | - */ |
|
| 838 | - public function setEMailAddress($id, $mailAddress) { |
|
| 839 | - $user = $this->userManager->get($id); |
|
| 840 | - if (!$this->isAdmin |
|
| 841 | - && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user) |
|
| 842 | - ) { |
|
| 843 | - return new DataResponse( |
|
| 844 | - array( |
|
| 845 | - 'status' => 'error', |
|
| 846 | - 'data' => array( |
|
| 847 | - 'message' => (string)$this->l10n->t('Forbidden') |
|
| 848 | - ) |
|
| 849 | - ), |
|
| 850 | - Http::STATUS_FORBIDDEN |
|
| 851 | - ); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
| 855 | - return new DataResponse( |
|
| 856 | - array( |
|
| 857 | - 'status' => 'error', |
|
| 858 | - 'data' => array( |
|
| 859 | - 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 860 | - ) |
|
| 861 | - ), |
|
| 862 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 863 | - ); |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - if (!$user) { |
|
| 867 | - return new DataResponse( |
|
| 868 | - array( |
|
| 869 | - 'status' => 'error', |
|
| 870 | - 'data' => array( |
|
| 871 | - 'message' => (string)$this->l10n->t('Invalid user') |
|
| 872 | - ) |
|
| 873 | - ), |
|
| 874 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 875 | - ); |
|
| 876 | - } |
|
| 877 | - // this is the only permission a backend provides and is also used |
|
| 878 | - // for the permission of setting a email address |
|
| 879 | - if (!$user->canChangeDisplayName()) { |
|
| 880 | - return new DataResponse( |
|
| 881 | - array( |
|
| 882 | - 'status' => 'error', |
|
| 883 | - 'data' => array( |
|
| 884 | - 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
| 885 | - ) |
|
| 886 | - ), |
|
| 887 | - Http::STATUS_FORBIDDEN |
|
| 888 | - ); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $userData = $this->accountManager->getUser($user); |
|
| 892 | - $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress; |
|
| 893 | - |
|
| 894 | - try { |
|
| 895 | - $this->saveUserSettings($user, $userData); |
|
| 896 | - return new DataResponse( |
|
| 897 | - array( |
|
| 898 | - 'status' => 'success', |
|
| 899 | - 'data' => array( |
|
| 900 | - 'username' => $id, |
|
| 901 | - 'mailAddress' => $mailAddress, |
|
| 902 | - 'message' => (string)$this->l10n->t('Email saved') |
|
| 903 | - ) |
|
| 904 | - ), |
|
| 905 | - Http::STATUS_OK |
|
| 906 | - ); |
|
| 907 | - } catch (ForbiddenException $e) { |
|
| 908 | - return new DataResponse([ |
|
| 909 | - 'status' => 'error', |
|
| 910 | - 'data' => [ |
|
| 911 | - 'message' => $e->getMessage() |
|
| 912 | - ], |
|
| 913 | - ]); |
|
| 914 | - } |
|
| 915 | - } |
|
| 61 | + /** @var IL10N */ |
|
| 62 | + private $l10n; |
|
| 63 | + /** @var IUserSession */ |
|
| 64 | + private $userSession; |
|
| 65 | + /** @var bool */ |
|
| 66 | + private $isAdmin; |
|
| 67 | + /** @var IUserManager */ |
|
| 68 | + private $userManager; |
|
| 69 | + /** @var IGroupManager */ |
|
| 70 | + private $groupManager; |
|
| 71 | + /** @var IConfig */ |
|
| 72 | + private $config; |
|
| 73 | + /** @var ILogger */ |
|
| 74 | + private $log; |
|
| 75 | + /** @var IMailer */ |
|
| 76 | + private $mailer; |
|
| 77 | + /** @var bool contains the state of the encryption app */ |
|
| 78 | + private $isEncryptionAppEnabled; |
|
| 79 | + /** @var bool contains the state of the admin recovery setting */ |
|
| 80 | + private $isRestoreEnabled = false; |
|
| 81 | + /** @var IAvatarManager */ |
|
| 82 | + private $avatarManager; |
|
| 83 | + /** @var AccountManager */ |
|
| 84 | + private $accountManager; |
|
| 85 | + /** @var ISecureRandom */ |
|
| 86 | + private $secureRandom; |
|
| 87 | + /** @var NewUserMailHelper */ |
|
| 88 | + private $newUserMailHelper; |
|
| 89 | + /** @var ITimeFactory */ |
|
| 90 | + private $timeFactory; |
|
| 91 | + /** @var ICrypto */ |
|
| 92 | + private $crypto; |
|
| 93 | + /** @var Manager */ |
|
| 94 | + private $keyManager; |
|
| 95 | + /** @var IJobList */ |
|
| 96 | + private $jobList; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param string $appName |
|
| 100 | + * @param IRequest $request |
|
| 101 | + * @param IUserManager $userManager |
|
| 102 | + * @param IGroupManager $groupManager |
|
| 103 | + * @param IUserSession $userSession |
|
| 104 | + * @param IConfig $config |
|
| 105 | + * @param bool $isAdmin |
|
| 106 | + * @param IL10N $l10n |
|
| 107 | + * @param ILogger $log |
|
| 108 | + * @param IMailer $mailer |
|
| 109 | + * @param IURLGenerator $urlGenerator |
|
| 110 | + * @param IAppManager $appManager |
|
| 111 | + * @param IAvatarManager $avatarManager |
|
| 112 | + * @param AccountManager $accountManager |
|
| 113 | + * @param ISecureRandom $secureRandom |
|
| 114 | + * @param NewUserMailHelper $newUserMailHelper |
|
| 115 | + * @param ITimeFactory $timeFactory |
|
| 116 | + * @param ICrypto $crypto |
|
| 117 | + * @param Manager $keyManager |
|
| 118 | + * @param IJobList $jobList |
|
| 119 | + */ |
|
| 120 | + public function __construct($appName, |
|
| 121 | + IRequest $request, |
|
| 122 | + IUserManager $userManager, |
|
| 123 | + IGroupManager $groupManager, |
|
| 124 | + IUserSession $userSession, |
|
| 125 | + IConfig $config, |
|
| 126 | + $isAdmin, |
|
| 127 | + IL10N $l10n, |
|
| 128 | + ILogger $log, |
|
| 129 | + IMailer $mailer, |
|
| 130 | + IURLGenerator $urlGenerator, |
|
| 131 | + IAppManager $appManager, |
|
| 132 | + IAvatarManager $avatarManager, |
|
| 133 | + AccountManager $accountManager, |
|
| 134 | + ISecureRandom $secureRandom, |
|
| 135 | + NewUserMailHelper $newUserMailHelper, |
|
| 136 | + ITimeFactory $timeFactory, |
|
| 137 | + ICrypto $crypto, |
|
| 138 | + Manager $keyManager, |
|
| 139 | + IJobList $jobList) { |
|
| 140 | + parent::__construct($appName, $request); |
|
| 141 | + $this->userManager = $userManager; |
|
| 142 | + $this->groupManager = $groupManager; |
|
| 143 | + $this->userSession = $userSession; |
|
| 144 | + $this->config = $config; |
|
| 145 | + $this->isAdmin = $isAdmin; |
|
| 146 | + $this->l10n = $l10n; |
|
| 147 | + $this->log = $log; |
|
| 148 | + $this->mailer = $mailer; |
|
| 149 | + $this->avatarManager = $avatarManager; |
|
| 150 | + $this->accountManager = $accountManager; |
|
| 151 | + $this->secureRandom = $secureRandom; |
|
| 152 | + $this->newUserMailHelper = $newUserMailHelper; |
|
| 153 | + $this->timeFactory = $timeFactory; |
|
| 154 | + $this->crypto = $crypto; |
|
| 155 | + $this->keyManager = $keyManager; |
|
| 156 | + $this->jobList = $jobList; |
|
| 157 | + |
|
| 158 | + // check for encryption state - TODO see formatUserForIndex |
|
| 159 | + $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); |
|
| 160 | + if($this->isEncryptionAppEnabled) { |
|
| 161 | + // putting this directly in empty is possible in PHP 5.5+ |
|
| 162 | + $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0); |
|
| 163 | + $this->isRestoreEnabled = !empty($result); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param IUser $user |
|
| 169 | + * @param array $userGroups |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + private function formatUserForIndex(IUser $user, array $userGroups = null) { |
|
| 173 | + |
|
| 174 | + // TODO: eliminate this encryption specific code below and somehow |
|
| 175 | + // hook in additional user info from other apps |
|
| 176 | + |
|
| 177 | + // recovery isn't possible if admin or user has it disabled and encryption |
|
| 178 | + // is enabled - so we eliminate the else paths in the conditional tree |
|
| 179 | + // below |
|
| 180 | + $restorePossible = false; |
|
| 181 | + |
|
| 182 | + if ($this->isEncryptionAppEnabled) { |
|
| 183 | + if ($this->isRestoreEnabled) { |
|
| 184 | + // check for the users recovery setting |
|
| 185 | + $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0'); |
|
| 186 | + // method call inside empty is possible with PHP 5.5+ |
|
| 187 | + $recoveryModeEnabled = !empty($recoveryMode); |
|
| 188 | + if ($recoveryModeEnabled) { |
|
| 189 | + // user also has recovery mode enabled |
|
| 190 | + $restorePossible = true; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } else { |
|
| 194 | + // recovery is possible if encryption is disabled (plain files are |
|
| 195 | + // available) |
|
| 196 | + $restorePossible = true; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 200 | + foreach($subAdminGroups as $key => $subAdminGroup) { |
|
| 201 | + $subAdminGroups[$key] = $subAdminGroup->getGID(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $displayName = $user->getEMailAddress(); |
|
| 205 | + if (is_null($displayName)) { |
|
| 206 | + $displayName = ''; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $avatarAvailable = false; |
|
| 210 | + try { |
|
| 211 | + $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists(); |
|
| 212 | + } catch (\Exception $e) { |
|
| 213 | + //No avatar yet |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return [ |
|
| 217 | + 'name' => $user->getUID(), |
|
| 218 | + 'displayname' => $user->getDisplayName(), |
|
| 219 | + 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, |
|
| 220 | + 'subadmin' => $subAdminGroups, |
|
| 221 | + 'quota' => $user->getQuota(), |
|
| 222 | + 'storageLocation' => $user->getHome(), |
|
| 223 | + 'lastLogin' => $user->getLastLogin() * 1000, |
|
| 224 | + 'backend' => $user->getBackendClassName(), |
|
| 225 | + 'email' => $displayName, |
|
| 226 | + 'isRestoreDisabled' => !$restorePossible, |
|
| 227 | + 'isAvatarAvailable' => $avatarAvailable, |
|
| 228 | + ]; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param array $userIDs Array with schema [$uid => $displayName] |
|
| 233 | + * @return IUser[] |
|
| 234 | + */ |
|
| 235 | + private function getUsersForUID(array $userIDs) { |
|
| 236 | + $users = []; |
|
| 237 | + foreach ($userIDs as $uid => $displayName) { |
|
| 238 | + $users[$uid] = $this->userManager->get($uid); |
|
| 239 | + } |
|
| 240 | + return $users; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @NoAdminRequired |
|
| 245 | + * |
|
| 246 | + * @param int $offset |
|
| 247 | + * @param int $limit |
|
| 248 | + * @param string $gid GID to filter for |
|
| 249 | + * @param string $pattern Pattern to search for in the username |
|
| 250 | + * @param string $backend Backend to filter for (class-name) |
|
| 251 | + * @return DataResponse |
|
| 252 | + * |
|
| 253 | + * TODO: Tidy up and write unit tests - code is mainly static method calls |
|
| 254 | + */ |
|
| 255 | + public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') { |
|
| 256 | + // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group. |
|
| 257 | + if($gid === '_everyone') { |
|
| 258 | + $gid = ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // Remove backends |
|
| 262 | + if(!empty($backend)) { |
|
| 263 | + $activeBackends = $this->userManager->getBackends(); |
|
| 264 | + $this->userManager->clearBackends(); |
|
| 265 | + foreach($activeBackends as $singleActiveBackend) { |
|
| 266 | + if($backend === get_class($singleActiveBackend)) { |
|
| 267 | + $this->userManager->registerBackend($singleActiveBackend); |
|
| 268 | + break; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $users = []; |
|
| 274 | + if ($this->isAdmin) { |
|
| 275 | + |
|
| 276 | + if($gid !== '') { |
|
| 277 | + $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); |
|
| 278 | + } else { |
|
| 279 | + $batch = $this->userManager->search($pattern, $limit, $offset); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + foreach ($batch as $user) { |
|
| 283 | + $users[] = $this->formatUserForIndex($user); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + } else { |
|
| 287 | + $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
| 288 | + // New class returns IGroup[] so convert back |
|
| 289 | + $gids = []; |
|
| 290 | + foreach ($subAdminOfGroups as $group) { |
|
| 291 | + $gids[] = $group->getGID(); |
|
| 292 | + } |
|
| 293 | + $subAdminOfGroups = $gids; |
|
| 294 | + |
|
| 295 | + // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group |
|
| 296 | + if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { |
|
| 297 | + $gid = ''; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // Batch all groups the user is subadmin of when a group is specified |
|
| 301 | + $batch = []; |
|
| 302 | + if($gid === '') { |
|
| 303 | + foreach($subAdminOfGroups as $group) { |
|
| 304 | + $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); |
|
| 305 | + |
|
| 306 | + foreach($groupUsers as $uid => $displayName) { |
|
| 307 | + $batch[$uid] = $displayName; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } else { |
|
| 311 | + $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset); |
|
| 312 | + } |
|
| 313 | + $batch = $this->getUsersForUID($batch); |
|
| 314 | + |
|
| 315 | + foreach ($batch as $user) { |
|
| 316 | + // Only add the groups, this user is a subadmin of |
|
| 317 | + $userGroups = array_values(array_intersect( |
|
| 318 | + $this->groupManager->getUserGroupIds($user), |
|
| 319 | + $subAdminOfGroups |
|
| 320 | + )); |
|
| 321 | + $users[] = $this->formatUserForIndex($user, $userGroups); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return new DataResponse($users); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @NoAdminRequired |
|
| 330 | + * @PasswordConfirmationRequired |
|
| 331 | + * |
|
| 332 | + * @param string $username |
|
| 333 | + * @param string $password |
|
| 334 | + * @param array $groups |
|
| 335 | + * @param string $email |
|
| 336 | + * @return DataResponse |
|
| 337 | + */ |
|
| 338 | + public function create($username, $password, array $groups=array(), $email='') { |
|
| 339 | + if($email !== '' && !$this->mailer->validateMailAddress($email)) { |
|
| 340 | + return new DataResponse( |
|
| 341 | + array( |
|
| 342 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 343 | + ), |
|
| 344 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 345 | + ); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $currentUser = $this->userSession->getUser(); |
|
| 349 | + |
|
| 350 | + if (!$this->isAdmin) { |
|
| 351 | + if (!empty($groups)) { |
|
| 352 | + foreach ($groups as $key => $group) { |
|
| 353 | + $groupObject = $this->groupManager->get($group); |
|
| 354 | + if($groupObject === null) { |
|
| 355 | + unset($groups[$key]); |
|
| 356 | + continue; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { |
|
| 360 | + unset($groups[$key]); |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (empty($groups)) { |
|
| 366 | + return new DataResponse( |
|
| 367 | + array( |
|
| 368 | + 'message' => $this->l10n->t('No valid group selected'), |
|
| 369 | + ), |
|
| 370 | + Http::STATUS_FORBIDDEN |
|
| 371 | + ); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ($this->userManager->userExists($username)) { |
|
| 376 | + return new DataResponse( |
|
| 377 | + array( |
|
| 378 | + 'message' => (string)$this->l10n->t('A user with that name already exists.') |
|
| 379 | + ), |
|
| 380 | + Http::STATUS_CONFLICT |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + $generatePasswordResetToken = false; |
|
| 385 | + if ($password === '') { |
|
| 386 | + if ($email === '') { |
|
| 387 | + return new DataResponse( |
|
| 388 | + array( |
|
| 389 | + 'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.') |
|
| 390 | + ), |
|
| 391 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 392 | + ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $password = $this->secureRandom->generate(32); |
|
| 396 | + $generatePasswordResetToken = true; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + try { |
|
| 400 | + $user = $this->userManager->createUser($username, $password); |
|
| 401 | + } catch (\Exception $exception) { |
|
| 402 | + $message = $exception->getMessage(); |
|
| 403 | + if (!$message) { |
|
| 404 | + $message = $this->l10n->t('Unable to create user.'); |
|
| 405 | + } |
|
| 406 | + return new DataResponse( |
|
| 407 | + array( |
|
| 408 | + 'message' => (string) $message, |
|
| 409 | + ), |
|
| 410 | + Http::STATUS_FORBIDDEN |
|
| 411 | + ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + if($user instanceof IUser) { |
|
| 415 | + if($groups !== null) { |
|
| 416 | + foreach($groups as $groupName) { |
|
| 417 | + $group = $this->groupManager->get($groupName); |
|
| 418 | + |
|
| 419 | + if(empty($group)) { |
|
| 420 | + $group = $this->groupManager->createGroup($groupName); |
|
| 421 | + } |
|
| 422 | + $group->addUser($user); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + /** |
|
| 426 | + * Send new user mail only if a mail is set |
|
| 427 | + */ |
|
| 428 | + if($email !== '') { |
|
| 429 | + $user->setEMailAddress($email); |
|
| 430 | + try { |
|
| 431 | + $emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken); |
|
| 432 | + $this->newUserMailHelper->sendMail($user, $emailTemplate); |
|
| 433 | + } catch(\Exception $e) { |
|
| 434 | + $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + // fetch users groups |
|
| 438 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 439 | + |
|
| 440 | + return new DataResponse( |
|
| 441 | + $this->formatUserForIndex($user, $userGroups), |
|
| 442 | + Http::STATUS_CREATED |
|
| 443 | + ); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return new DataResponse( |
|
| 447 | + array( |
|
| 448 | + 'message' => (string)$this->l10n->t('Unable to create user.') |
|
| 449 | + ), |
|
| 450 | + Http::STATUS_FORBIDDEN |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @NoAdminRequired |
|
| 457 | + * @PasswordConfirmationRequired |
|
| 458 | + * |
|
| 459 | + * @param string $id |
|
| 460 | + * @return DataResponse |
|
| 461 | + */ |
|
| 462 | + public function destroy($id) { |
|
| 463 | + $userId = $this->userSession->getUser()->getUID(); |
|
| 464 | + $user = $this->userManager->get($id); |
|
| 465 | + |
|
| 466 | + if($userId === $id) { |
|
| 467 | + return new DataResponse( |
|
| 468 | + array( |
|
| 469 | + 'status' => 'error', |
|
| 470 | + 'data' => array( |
|
| 471 | + 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 472 | + ) |
|
| 473 | + ), |
|
| 474 | + Http::STATUS_FORBIDDEN |
|
| 475 | + ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { |
|
| 479 | + return new DataResponse( |
|
| 480 | + array( |
|
| 481 | + 'status' => 'error', |
|
| 482 | + 'data' => array( |
|
| 483 | + 'message' => (string)$this->l10n->t('Authentication error') |
|
| 484 | + ) |
|
| 485 | + ), |
|
| 486 | + Http::STATUS_FORBIDDEN |
|
| 487 | + ); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + if($user) { |
|
| 491 | + if($user->delete()) { |
|
| 492 | + return new DataResponse( |
|
| 493 | + array( |
|
| 494 | + 'status' => 'success', |
|
| 495 | + 'data' => array( |
|
| 496 | + 'username' => $id |
|
| 497 | + ) |
|
| 498 | + ), |
|
| 499 | + Http::STATUS_NO_CONTENT |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + return new DataResponse( |
|
| 505 | + array( |
|
| 506 | + 'status' => 'error', |
|
| 507 | + 'data' => array( |
|
| 508 | + 'message' => (string)$this->l10n->t('Unable to delete user.') |
|
| 509 | + ) |
|
| 510 | + ), |
|
| 511 | + Http::STATUS_FORBIDDEN |
|
| 512 | + ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * @NoAdminRequired |
|
| 517 | + * @NoSubadminRequired |
|
| 518 | + * @PasswordConfirmationRequired |
|
| 519 | + * |
|
| 520 | + * @param string $account |
|
| 521 | + * @param bool $onlyVerificationCode only return verification code without updating the data |
|
| 522 | + * @return DataResponse |
|
| 523 | + */ |
|
| 524 | + public function getVerificationCode($account, $onlyVerificationCode) { |
|
| 525 | + |
|
| 526 | + $user = $this->userSession->getUser(); |
|
| 527 | + |
|
| 528 | + if ($user === null) { |
|
| 529 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $accountData = $this->accountManager->getUser($user); |
|
| 533 | + $cloudId = $user->getCloudId(); |
|
| 534 | + $message = "Use my Federated Cloud ID to share with me: " . $cloudId; |
|
| 535 | + $signature = $this->signMessage($user, $message); |
|
| 536 | + |
|
| 537 | + $code = $message . ' ' . $signature; |
|
| 538 | + $codeMd5 = $message . ' ' . md5($signature); |
|
| 539 | + |
|
| 540 | + switch ($account) { |
|
| 541 | + case 'verify-twitter': |
|
| 542 | + $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 543 | + $msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter (please make sure to post it without any line breaks):'); |
|
| 544 | + $code = $codeMd5; |
|
| 545 | + $type = AccountManager::PROPERTY_TWITTER; |
|
| 546 | + $data = $accountData[AccountManager::PROPERTY_TWITTER]['value']; |
|
| 547 | + break; |
|
| 548 | + case 'verify-website': |
|
| 549 | + $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 550 | + $msg = $this->l10n->t('In order to verify your Website store following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):'); |
|
| 551 | + $type = AccountManager::PROPERTY_WEBSITE; |
|
| 552 | + $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value']; |
|
| 553 | + break; |
|
| 554 | + default: |
|
| 555 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + if ($onlyVerificationCode === false) { |
|
| 559 | + $this->accountManager->updateUser($user, $accountData); |
|
| 560 | + |
|
| 561 | + $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 562 | + [ |
|
| 563 | + 'verificationCode' => $code, |
|
| 564 | + 'data' => $data, |
|
| 565 | + 'type' => $type, |
|
| 566 | + 'uid' => $user->getUID(), |
|
| 567 | + 'try' => 0, |
|
| 568 | + 'lastRun' => $this->getCurrentTime() |
|
| 569 | + ] |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return new DataResponse(['msg' => $msg, 'code' => $code]); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * get current timestamp |
|
| 578 | + * |
|
| 579 | + * @return int |
|
| 580 | + */ |
|
| 581 | + protected function getCurrentTime() { |
|
| 582 | + return time(); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * sign message with users private key |
|
| 587 | + * |
|
| 588 | + * @param IUser $user |
|
| 589 | + * @param string $message |
|
| 590 | + * |
|
| 591 | + * @return string base64 encoded signature |
|
| 592 | + */ |
|
| 593 | + protected function signMessage(IUser $user, $message) { |
|
| 594 | + $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
| 595 | + openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
| 596 | + $signatureBase64 = base64_encode($signature); |
|
| 597 | + |
|
| 598 | + return $signatureBase64; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @NoAdminRequired |
|
| 603 | + * @NoSubadminRequired |
|
| 604 | + * @PasswordConfirmationRequired |
|
| 605 | + * |
|
| 606 | + * @param string $avatarScope |
|
| 607 | + * @param string $displayname |
|
| 608 | + * @param string $displaynameScope |
|
| 609 | + * @param string $phone |
|
| 610 | + * @param string $phoneScope |
|
| 611 | + * @param string $email |
|
| 612 | + * @param string $emailScope |
|
| 613 | + * @param string $website |
|
| 614 | + * @param string $websiteScope |
|
| 615 | + * @param string $address |
|
| 616 | + * @param string $addressScope |
|
| 617 | + * @param string $twitter |
|
| 618 | + * @param string $twitterScope |
|
| 619 | + * @return DataResponse |
|
| 620 | + */ |
|
| 621 | + public function setUserSettings($avatarScope, |
|
| 622 | + $displayname, |
|
| 623 | + $displaynameScope, |
|
| 624 | + $phone, |
|
| 625 | + $phoneScope, |
|
| 626 | + $email, |
|
| 627 | + $emailScope, |
|
| 628 | + $website, |
|
| 629 | + $websiteScope, |
|
| 630 | + $address, |
|
| 631 | + $addressScope, |
|
| 632 | + $twitter, |
|
| 633 | + $twitterScope |
|
| 634 | + ) { |
|
| 635 | + |
|
| 636 | + if(!empty($email) && !$this->mailer->validateMailAddress($email)) { |
|
| 637 | + return new DataResponse( |
|
| 638 | + array( |
|
| 639 | + 'status' => 'error', |
|
| 640 | + 'data' => array( |
|
| 641 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 642 | + ) |
|
| 643 | + ), |
|
| 644 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + $data = [ |
|
| 649 | + AccountManager::PROPERTY_AVATAR => ['scope' => $avatarScope], |
|
| 650 | + AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope], |
|
| 651 | + AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope], |
|
| 652 | + AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope], |
|
| 653 | + AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope], |
|
| 654 | + AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope], |
|
| 655 | + AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope] |
|
| 656 | + ]; |
|
| 657 | + |
|
| 658 | + $user = $this->userSession->getUser(); |
|
| 659 | + |
|
| 660 | + try { |
|
| 661 | + $this->saveUserSettings($user, $data); |
|
| 662 | + return new DataResponse( |
|
| 663 | + array( |
|
| 664 | + 'status' => 'success', |
|
| 665 | + 'data' => array( |
|
| 666 | + 'userId' => $user->getUID(), |
|
| 667 | + 'avatarScope' => $avatarScope, |
|
| 668 | + 'displayname' => $displayname, |
|
| 669 | + 'displaynameScope' => $displaynameScope, |
|
| 670 | + 'email' => $email, |
|
| 671 | + 'emailScope' => $emailScope, |
|
| 672 | + 'website' => $website, |
|
| 673 | + 'websiteScope' => $websiteScope, |
|
| 674 | + 'address' => $address, |
|
| 675 | + 'addressScope' => $addressScope, |
|
| 676 | + 'message' => (string)$this->l10n->t('Settings saved') |
|
| 677 | + ) |
|
| 678 | + ), |
|
| 679 | + Http::STATUS_OK |
|
| 680 | + ); |
|
| 681 | + } catch (ForbiddenException $e) { |
|
| 682 | + return new DataResponse([ |
|
| 683 | + 'status' => 'error', |
|
| 684 | + 'data' => [ |
|
| 685 | + 'message' => $e->getMessage() |
|
| 686 | + ], |
|
| 687 | + ]); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * update account manager with new user data |
|
| 695 | + * |
|
| 696 | + * @param IUser $user |
|
| 697 | + * @param array $data |
|
| 698 | + * @throws ForbiddenException |
|
| 699 | + */ |
|
| 700 | + protected function saveUserSettings(IUser $user, $data) { |
|
| 701 | + |
|
| 702 | + // keep the user back-end up-to-date with the latest display name and email |
|
| 703 | + // address |
|
| 704 | + $oldDisplayName = $user->getDisplayName(); |
|
| 705 | + $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName; |
|
| 706 | + if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
| 707 | + && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] |
|
| 708 | + ) { |
|
| 709 | + $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
| 710 | + if ($result === false) { |
|
| 711 | + throw new ForbiddenException($this->l10n->t('Unable to change full name')); |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + $oldEmailAddress = $user->getEMailAddress(); |
|
| 716 | + $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress; |
|
| 717 | + if (isset($data[AccountManager::PROPERTY_EMAIL]['value']) |
|
| 718 | + && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value'] |
|
| 719 | + ) { |
|
| 720 | + // this is the only permission a backend provides and is also used |
|
| 721 | + // for the permission of setting a email address |
|
| 722 | + if (!$user->canChangeDisplayName()) { |
|
| 723 | + throw new ForbiddenException($this->l10n->t('Unable to change email address')); |
|
| 724 | + } |
|
| 725 | + $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + $this->accountManager->updateUser($user, $data); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * Count all unique users visible for the current admin/subadmin. |
|
| 733 | + * |
|
| 734 | + * @NoAdminRequired |
|
| 735 | + * |
|
| 736 | + * @return DataResponse |
|
| 737 | + */ |
|
| 738 | + public function stats() { |
|
| 739 | + $userCount = 0; |
|
| 740 | + if ($this->isAdmin) { |
|
| 741 | + $countByBackend = $this->userManager->countUsers(); |
|
| 742 | + |
|
| 743 | + if (!empty($countByBackend)) { |
|
| 744 | + foreach ($countByBackend as $count) { |
|
| 745 | + $userCount += $count; |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + } else { |
|
| 749 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); |
|
| 750 | + |
|
| 751 | + $uniqueUsers = []; |
|
| 752 | + foreach ($groups as $group) { |
|
| 753 | + foreach($group->getUsers() as $uid => $displayName) { |
|
| 754 | + $uniqueUsers[$uid] = true; |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + $userCount = count($uniqueUsers); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + return new DataResponse( |
|
| 762 | + [ |
|
| 763 | + 'totalUsers' => $userCount |
|
| 764 | + ] |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Set the displayName of a user |
|
| 771 | + * |
|
| 772 | + * @NoAdminRequired |
|
| 773 | + * @NoSubadminRequired |
|
| 774 | + * @PasswordConfirmationRequired |
|
| 775 | + * @todo merge into saveUserSettings |
|
| 776 | + * |
|
| 777 | + * @param string $username |
|
| 778 | + * @param string $displayName |
|
| 779 | + * @return DataResponse |
|
| 780 | + */ |
|
| 781 | + public function setDisplayName($username, $displayName) { |
|
| 782 | + $currentUser = $this->userSession->getUser(); |
|
| 783 | + $user = $this->userManager->get($username); |
|
| 784 | + |
|
| 785 | + if ($user === null || |
|
| 786 | + !$user->canChangeDisplayName() || |
|
| 787 | + ( |
|
| 788 | + !$this->groupManager->isAdmin($currentUser->getUID()) && |
|
| 789 | + !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) && |
|
| 790 | + $currentUser->getUID() !== $username |
|
| 791 | + |
|
| 792 | + ) |
|
| 793 | + ) { |
|
| 794 | + return new DataResponse([ |
|
| 795 | + 'status' => 'error', |
|
| 796 | + 'data' => [ |
|
| 797 | + 'message' => $this->l10n->t('Authentication error'), |
|
| 798 | + ], |
|
| 799 | + ]); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + $userData = $this->accountManager->getUser($user); |
|
| 803 | + $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
| 804 | + |
|
| 805 | + |
|
| 806 | + try { |
|
| 807 | + $this->saveUserSettings($user, $userData); |
|
| 808 | + return new DataResponse([ |
|
| 809 | + 'status' => 'success', |
|
| 810 | + 'data' => [ |
|
| 811 | + 'message' => $this->l10n->t('Your full name has been changed.'), |
|
| 812 | + 'username' => $username, |
|
| 813 | + 'displayName' => $displayName, |
|
| 814 | + ], |
|
| 815 | + ]); |
|
| 816 | + } catch (ForbiddenException $e) { |
|
| 817 | + return new DataResponse([ |
|
| 818 | + 'status' => 'error', |
|
| 819 | + 'data' => [ |
|
| 820 | + 'message' => $e->getMessage(), |
|
| 821 | + 'displayName' => $user->getDisplayName(), |
|
| 822 | + ], |
|
| 823 | + ]); |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Set the mail address of a user |
|
| 829 | + * |
|
| 830 | + * @NoAdminRequired |
|
| 831 | + * @NoSubadminRequired |
|
| 832 | + * @PasswordConfirmationRequired |
|
| 833 | + * |
|
| 834 | + * @param string $id |
|
| 835 | + * @param string $mailAddress |
|
| 836 | + * @return DataResponse |
|
| 837 | + */ |
|
| 838 | + public function setEMailAddress($id, $mailAddress) { |
|
| 839 | + $user = $this->userManager->get($id); |
|
| 840 | + if (!$this->isAdmin |
|
| 841 | + && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user) |
|
| 842 | + ) { |
|
| 843 | + return new DataResponse( |
|
| 844 | + array( |
|
| 845 | + 'status' => 'error', |
|
| 846 | + 'data' => array( |
|
| 847 | + 'message' => (string)$this->l10n->t('Forbidden') |
|
| 848 | + ) |
|
| 849 | + ), |
|
| 850 | + Http::STATUS_FORBIDDEN |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) { |
|
| 855 | + return new DataResponse( |
|
| 856 | + array( |
|
| 857 | + 'status' => 'error', |
|
| 858 | + 'data' => array( |
|
| 859 | + 'message' => (string)$this->l10n->t('Invalid mail address') |
|
| 860 | + ) |
|
| 861 | + ), |
|
| 862 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 863 | + ); |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + if (!$user) { |
|
| 867 | + return new DataResponse( |
|
| 868 | + array( |
|
| 869 | + 'status' => 'error', |
|
| 870 | + 'data' => array( |
|
| 871 | + 'message' => (string)$this->l10n->t('Invalid user') |
|
| 872 | + ) |
|
| 873 | + ), |
|
| 874 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 875 | + ); |
|
| 876 | + } |
|
| 877 | + // this is the only permission a backend provides and is also used |
|
| 878 | + // for the permission of setting a email address |
|
| 879 | + if (!$user->canChangeDisplayName()) { |
|
| 880 | + return new DataResponse( |
|
| 881 | + array( |
|
| 882 | + 'status' => 'error', |
|
| 883 | + 'data' => array( |
|
| 884 | + 'message' => (string)$this->l10n->t('Unable to change mail address') |
|
| 885 | + ) |
|
| 886 | + ), |
|
| 887 | + Http::STATUS_FORBIDDEN |
|
| 888 | + ); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $userData = $this->accountManager->getUser($user); |
|
| 892 | + $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress; |
|
| 893 | + |
|
| 894 | + try { |
|
| 895 | + $this->saveUserSettings($user, $userData); |
|
| 896 | + return new DataResponse( |
|
| 897 | + array( |
|
| 898 | + 'status' => 'success', |
|
| 899 | + 'data' => array( |
|
| 900 | + 'username' => $id, |
|
| 901 | + 'mailAddress' => $mailAddress, |
|
| 902 | + 'message' => (string)$this->l10n->t('Email saved') |
|
| 903 | + ) |
|
| 904 | + ), |
|
| 905 | + Http::STATUS_OK |
|
| 906 | + ); |
|
| 907 | + } catch (ForbiddenException $e) { |
|
| 908 | + return new DataResponse([ |
|
| 909 | + 'status' => 'error', |
|
| 910 | + 'data' => [ |
|
| 911 | + 'message' => $e->getMessage() |
|
| 912 | + ], |
|
| 913 | + ]); |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | 917 | } |
@@ -27,73 +27,73 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Hooks { |
| 29 | 29 | |
| 30 | - /** @var AccountManager */ |
|
| 31 | - private $accountManager = null; |
|
| 32 | - |
|
| 33 | - /** @var ILogger */ |
|
| 34 | - private $logger; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Hooks constructor. |
|
| 38 | - * |
|
| 39 | - * @param ILogger $logger |
|
| 40 | - */ |
|
| 41 | - public function __construct(ILogger $logger) { |
|
| 42 | - $this->logger = $logger; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * update accounts table if email address or display name was changed from outside |
|
| 47 | - * |
|
| 48 | - * @param array $params |
|
| 49 | - */ |
|
| 50 | - public function changeUserHook($params) { |
|
| 51 | - |
|
| 52 | - $accountManager = $this->getAccountManager(); |
|
| 53 | - |
|
| 54 | - /** @var IUser $user */ |
|
| 55 | - $user = isset($params['user']) ? $params['user'] : null; |
|
| 56 | - $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 57 | - $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 58 | - |
|
| 59 | - if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 60 | - $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $accountData = $accountManager->getUser($user); |
|
| 65 | - |
|
| 66 | - switch ($feature) { |
|
| 67 | - case 'eMailAddress': |
|
| 68 | - if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 69 | - $accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 70 | - $accountManager->updateUser($user, $accountData); |
|
| 71 | - } |
|
| 72 | - break; |
|
| 73 | - case 'displayName': |
|
| 74 | - if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 75 | - $accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 76 | - $accountManager->updateUser($user, $accountData); |
|
| 77 | - } |
|
| 78 | - break; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * return instance of accountManager |
|
| 85 | - * |
|
| 86 | - * @return AccountManager |
|
| 87 | - */ |
|
| 88 | - protected function getAccountManager() { |
|
| 89 | - if (is_null($this->accountManager)) { |
|
| 90 | - $this->accountManager = new AccountManager( |
|
| 91 | - \OC::$server->getDatabaseConnection(), |
|
| 92 | - \OC::$server->getEventDispatcher(), |
|
| 93 | - \OC::$server->getJobList() |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - return $this->accountManager; |
|
| 97 | - } |
|
| 30 | + /** @var AccountManager */ |
|
| 31 | + private $accountManager = null; |
|
| 32 | + |
|
| 33 | + /** @var ILogger */ |
|
| 34 | + private $logger; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Hooks constructor. |
|
| 38 | + * |
|
| 39 | + * @param ILogger $logger |
|
| 40 | + */ |
|
| 41 | + public function __construct(ILogger $logger) { |
|
| 42 | + $this->logger = $logger; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * update accounts table if email address or display name was changed from outside |
|
| 47 | + * |
|
| 48 | + * @param array $params |
|
| 49 | + */ |
|
| 50 | + public function changeUserHook($params) { |
|
| 51 | + |
|
| 52 | + $accountManager = $this->getAccountManager(); |
|
| 53 | + |
|
| 54 | + /** @var IUser $user */ |
|
| 55 | + $user = isset($params['user']) ? $params['user'] : null; |
|
| 56 | + $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 57 | + $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 58 | + |
|
| 59 | + if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 60 | + $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $accountData = $accountManager->getUser($user); |
|
| 65 | + |
|
| 66 | + switch ($feature) { |
|
| 67 | + case 'eMailAddress': |
|
| 68 | + if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 69 | + $accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 70 | + $accountManager->updateUser($user, $accountData); |
|
| 71 | + } |
|
| 72 | + break; |
|
| 73 | + case 'displayName': |
|
| 74 | + if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 75 | + $accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 76 | + $accountManager->updateUser($user, $accountData); |
|
| 77 | + } |
|
| 78 | + break; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * return instance of accountManager |
|
| 85 | + * |
|
| 86 | + * @return AccountManager |
|
| 87 | + */ |
|
| 88 | + protected function getAccountManager() { |
|
| 89 | + if (is_null($this->accountManager)) { |
|
| 90 | + $this->accountManager = new AccountManager( |
|
| 91 | + \OC::$server->getDatabaseConnection(), |
|
| 92 | + \OC::$server->getEventDispatcher(), |
|
| 93 | + \OC::$server->getJobList() |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + return $this->accountManager; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | } |
@@ -35,107 +35,107 @@ |
||
| 35 | 35 | * @package OCA\LookupServerConnector |
| 36 | 36 | */ |
| 37 | 37 | class UpdateLookupServer { |
| 38 | - /** @var AccountManager */ |
|
| 39 | - private $accountManager; |
|
| 40 | - /** @var IClientService */ |
|
| 41 | - private $clientService; |
|
| 42 | - /** @var Signer */ |
|
| 43 | - private $signer; |
|
| 44 | - /** @var IJobList */ |
|
| 45 | - private $jobList; |
|
| 46 | - /** @var string URL point to lookup server */ |
|
| 47 | - private $lookupServer = 'https://lookup.nextcloud.com'; |
|
| 38 | + /** @var AccountManager */ |
|
| 39 | + private $accountManager; |
|
| 40 | + /** @var IClientService */ |
|
| 41 | + private $clientService; |
|
| 42 | + /** @var Signer */ |
|
| 43 | + private $signer; |
|
| 44 | + /** @var IJobList */ |
|
| 45 | + private $jobList; |
|
| 46 | + /** @var string URL point to lookup server */ |
|
| 47 | + private $lookupServer = 'https://lookup.nextcloud.com'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param AccountManager $accountManager |
|
| 51 | - * @param IClientService $clientService |
|
| 52 | - * @param Signer $signer |
|
| 53 | - * @param IJobList $jobList |
|
| 54 | - * @param string $lookupServer if nothing is given we use the default lookup server |
|
| 55 | - */ |
|
| 56 | - public function __construct(AccountManager $accountManager, |
|
| 57 | - IClientService $clientService, |
|
| 58 | - Signer $signer, |
|
| 59 | - IJobList $jobList, |
|
| 60 | - $lookupServer = '') { |
|
| 61 | - $this->accountManager = $accountManager; |
|
| 62 | - $this->clientService = $clientService; |
|
| 63 | - $this->signer = $signer; |
|
| 64 | - $this->jobList = $jobList; |
|
| 65 | - if ($lookupServer !== '') { |
|
| 66 | - $this->lookupServer = $lookupServer; |
|
| 67 | - } |
|
| 68 | - $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
| 69 | - $this->lookupServer .= '/users'; |
|
| 70 | - } |
|
| 49 | + /** |
|
| 50 | + * @param AccountManager $accountManager |
|
| 51 | + * @param IClientService $clientService |
|
| 52 | + * @param Signer $signer |
|
| 53 | + * @param IJobList $jobList |
|
| 54 | + * @param string $lookupServer if nothing is given we use the default lookup server |
|
| 55 | + */ |
|
| 56 | + public function __construct(AccountManager $accountManager, |
|
| 57 | + IClientService $clientService, |
|
| 58 | + Signer $signer, |
|
| 59 | + IJobList $jobList, |
|
| 60 | + $lookupServer = '') { |
|
| 61 | + $this->accountManager = $accountManager; |
|
| 62 | + $this->clientService = $clientService; |
|
| 63 | + $this->signer = $signer; |
|
| 64 | + $this->jobList = $jobList; |
|
| 65 | + if ($lookupServer !== '') { |
|
| 66 | + $this->lookupServer = $lookupServer; |
|
| 67 | + } |
|
| 68 | + $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
| 69 | + $this->lookupServer .= '/users'; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param IUser $user |
|
| 74 | - */ |
|
| 75 | - public function userUpdated(IUser $user) { |
|
| 76 | - $userData = $this->accountManager->getUser($user); |
|
| 77 | - $publicData = []; |
|
| 72 | + /** |
|
| 73 | + * @param IUser $user |
|
| 74 | + */ |
|
| 75 | + public function userUpdated(IUser $user) { |
|
| 76 | + $userData = $this->accountManager->getUser($user); |
|
| 77 | + $publicData = []; |
|
| 78 | 78 | |
| 79 | - foreach ($userData as $key => $data) { |
|
| 80 | - if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { |
|
| 81 | - $publicData[$key] = $data; |
|
| 82 | - } |
|
| 83 | - } |
|
| 79 | + foreach ($userData as $key => $data) { |
|
| 80 | + if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { |
|
| 81 | + $publicData[$key] = $data; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - $this->sendToLookupServer($user, $publicData); |
|
| 86 | - } |
|
| 85 | + $this->sendToLookupServer($user, $publicData); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * send public user data to the lookup server |
|
| 90 | - * |
|
| 91 | - * @param IUser $user |
|
| 92 | - * @param array $publicData |
|
| 93 | - */ |
|
| 94 | - protected function sendToLookupServer(IUser $user, array $publicData) { |
|
| 88 | + /** |
|
| 89 | + * send public user data to the lookup server |
|
| 90 | + * |
|
| 91 | + * @param IUser $user |
|
| 92 | + * @param array $publicData |
|
| 93 | + */ |
|
| 94 | + protected function sendToLookupServer(IUser $user, array $publicData) { |
|
| 95 | 95 | |
| 96 | - $dataArray = ['federationId' => $user->getCloudId()]; |
|
| 96 | + $dataArray = ['federationId' => $user->getCloudId()]; |
|
| 97 | 97 | |
| 98 | - if (!empty($publicData)) { |
|
| 99 | - $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; |
|
| 100 | - $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; |
|
| 101 | - $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; |
|
| 102 | - $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; |
|
| 103 | - $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; |
|
| 104 | - $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; |
|
| 105 | - $dataArray['verificationStatus'] = |
|
| 106 | - [ |
|
| 107 | - AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', |
|
| 108 | - AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 98 | + if (!empty($publicData)) { |
|
| 99 | + $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; |
|
| 100 | + $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; |
|
| 101 | + $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; |
|
| 102 | + $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; |
|
| 103 | + $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; |
|
| 104 | + $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; |
|
| 105 | + $dataArray['verificationStatus'] = |
|
| 106 | + [ |
|
| 107 | + AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', |
|
| 108 | + AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $dataArray = $this->signer->sign('lookupserver', $dataArray, $user); |
|
| 113 | - $httpClient = $this->clientService->newClient(); |
|
| 114 | - try { |
|
| 115 | - if (empty($publicData)) { |
|
| 116 | - $httpClient->delete($this->lookupServer, |
|
| 117 | - [ |
|
| 118 | - 'body' => json_encode($dataArray), |
|
| 119 | - 'timeout' => 10, |
|
| 120 | - 'connect_timeout' => 3, |
|
| 121 | - ] |
|
| 122 | - ); |
|
| 123 | - } else { |
|
| 124 | - $httpClient->post($this->lookupServer, |
|
| 125 | - [ |
|
| 126 | - 'body' => json_encode($dataArray), |
|
| 127 | - 'timeout' => 10, |
|
| 128 | - 'connect_timeout' => 3, |
|
| 129 | - ] |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - } catch (\Exception $e) { |
|
| 133 | - $this->jobList->add(RetryJob::class, |
|
| 134 | - [ |
|
| 135 | - 'dataArray' => $dataArray, |
|
| 136 | - 'retryNo' => 0, |
|
| 137 | - ] |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } |
|
| 112 | + $dataArray = $this->signer->sign('lookupserver', $dataArray, $user); |
|
| 113 | + $httpClient = $this->clientService->newClient(); |
|
| 114 | + try { |
|
| 115 | + if (empty($publicData)) { |
|
| 116 | + $httpClient->delete($this->lookupServer, |
|
| 117 | + [ |
|
| 118 | + 'body' => json_encode($dataArray), |
|
| 119 | + 'timeout' => 10, |
|
| 120 | + 'connect_timeout' => 3, |
|
| 121 | + ] |
|
| 122 | + ); |
|
| 123 | + } else { |
|
| 124 | + $httpClient->post($this->lookupServer, |
|
| 125 | + [ |
|
| 126 | + 'body' => json_encode($dataArray), |
|
| 127 | + 'timeout' => 10, |
|
| 128 | + 'connect_timeout' => 3, |
|
| 129 | + ] |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + } catch (\Exception $e) { |
|
| 133 | + $this->jobList->add(RetryJob::class, |
|
| 134 | + [ |
|
| 135 | + 'dataArray' => $dataArray, |
|
| 136 | + 'retryNo' => 0, |
|
| 137 | + ] |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
@@ -22,30 +22,30 @@ |
||
| 22 | 22 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 23 | 23 | |
| 24 | 24 | $dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Component\EventDispatcher\GenericEvent $event) { |
| 25 | - $user = $event->getSubject(); |
|
| 25 | + $user = $event->getSubject(); |
|
| 26 | 26 | |
| 27 | - $keyManager = new \OC\Security\IdentityProof\Manager( |
|
| 28 | - \OC::$server->getAppDataDir('identityproof'), |
|
| 29 | - \OC::$server->getCrypto() |
|
| 30 | - ); |
|
| 27 | + $keyManager = new \OC\Security\IdentityProof\Manager( |
|
| 28 | + \OC::$server->getAppDataDir('identityproof'), |
|
| 29 | + \OC::$server->getCrypto() |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - $config = \OC::$server->getConfig(); |
|
| 33 | - $lookupServer = $config->getSystemValue('lookup_server', ''); |
|
| 32 | + $config = \OC::$server->getConfig(); |
|
| 33 | + $lookupServer = $config->getSystemValue('lookup_server', ''); |
|
| 34 | 34 | |
| 35 | - $updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer( |
|
| 36 | - new \OC\Accounts\AccountManager( |
|
| 37 | - \OC::$server->getDatabaseConnection(), |
|
| 38 | - \OC::$server->getEventDispatcher(), |
|
| 39 | - \OC::$server->getJobList() |
|
| 40 | - ), |
|
| 41 | - \OC::$server->getHTTPClientService(), |
|
| 42 | - new \OC\Security\IdentityProof\Signer( |
|
| 43 | - $keyManager, |
|
| 44 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 45 | - \OC::$server->getUserManager() |
|
| 46 | - ), |
|
| 47 | - \OC::$server->getJobList(), |
|
| 48 | - $lookupServer |
|
| 49 | - ); |
|
| 50 | - $updateLookupServer->userUpdated($user); |
|
| 35 | + $updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer( |
|
| 36 | + new \OC\Accounts\AccountManager( |
|
| 37 | + \OC::$server->getDatabaseConnection(), |
|
| 38 | + \OC::$server->getEventDispatcher(), |
|
| 39 | + \OC::$server->getJobList() |
|
| 40 | + ), |
|
| 41 | + \OC::$server->getHTTPClientService(), |
|
| 42 | + new \OC\Security\IdentityProof\Signer( |
|
| 43 | + $keyManager, |
|
| 44 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 45 | + \OC::$server->getUserManager() |
|
| 46 | + ), |
|
| 47 | + \OC::$server->getJobList(), |
|
| 48 | + $lookupServer |
|
| 49 | + ); |
|
| 50 | + $updateLookupServer->userUpdated($user); |
|
| 51 | 51 | }); |
@@ -195,38 +195,38 @@ |
||
| 195 | 195 | $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
| 196 | 196 | |
| 197 | 197 | // keep old verification status if we don't have a new one |
| 198 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 198 | + if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 199 | 199 | // keep old verification status if value didn't changed and an old value exists |
| 200 | 200 | $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
| 201 | 201 | $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 204 | + if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 205 | 205 | // keep old verification status if value didn't changed and an old value exists |
| 206 | 206 | $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
| 207 | 207 | $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 210 | + if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 211 | 211 | // keep old verification status if value didn't changed and an old value exists |
| 212 | 212 | $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
| 213 | 213 | $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // reset verification status if a value from a previously verified data was changed |
| 217 | - if($twitterVerified && |
|
| 217 | + if ($twitterVerified && |
|
| 218 | 218 | $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
| 219 | 219 | ) { |
| 220 | 220 | $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if($websiteVerified && |
|
| 223 | + if ($websiteVerified && |
|
| 224 | 224 | $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
| 225 | 225 | ) { |
| 226 | 226 | $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if($emailVerified && |
|
| 229 | + if ($emailVerified && |
|
| 230 | 230 | $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
| 231 | 231 | ) { |
| 232 | 232 | $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
@@ -39,292 +39,292 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class AccountManager { |
| 41 | 41 | |
| 42 | - /** nobody can see my account details */ |
|
| 43 | - const VISIBILITY_PRIVATE = 'private'; |
|
| 44 | - /** only contacts, especially trusted servers can see my contact details */ |
|
| 45 | - const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 46 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 47 | - const VISIBILITY_PUBLIC = 'public'; |
|
| 48 | - |
|
| 49 | - const PROPERTY_AVATAR = 'avatar'; |
|
| 50 | - const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 51 | - const PROPERTY_PHONE = 'phone'; |
|
| 52 | - const PROPERTY_EMAIL = 'email'; |
|
| 53 | - const PROPERTY_WEBSITE = 'website'; |
|
| 54 | - const PROPERTY_ADDRESS = 'address'; |
|
| 55 | - const PROPERTY_TWITTER = 'twitter'; |
|
| 56 | - |
|
| 57 | - const NOT_VERIFIED = '0'; |
|
| 58 | - const VERIFICATION_IN_PROGRESS = '1'; |
|
| 59 | - const VERIFIED = '2'; |
|
| 60 | - |
|
| 61 | - /** @var IDBConnection database connection */ |
|
| 62 | - private $connection; |
|
| 63 | - |
|
| 64 | - /** @var string table name */ |
|
| 65 | - private $table = 'accounts'; |
|
| 66 | - |
|
| 67 | - /** @var EventDispatcherInterface */ |
|
| 68 | - private $eventDispatcher; |
|
| 69 | - |
|
| 70 | - /** @var IJobList */ |
|
| 71 | - private $jobList; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * AccountManager constructor. |
|
| 75 | - * |
|
| 76 | - * @param IDBConnection $connection |
|
| 77 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 78 | - * @param IJobList $jobList |
|
| 79 | - */ |
|
| 80 | - public function __construct(IDBConnection $connection, |
|
| 81 | - EventDispatcherInterface $eventDispatcher, |
|
| 82 | - IJobList $jobList) { |
|
| 83 | - $this->connection = $connection; |
|
| 84 | - $this->eventDispatcher = $eventDispatcher; |
|
| 85 | - $this->jobList = $jobList; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * update user record |
|
| 90 | - * |
|
| 91 | - * @param IUser $user |
|
| 92 | - * @param $data |
|
| 93 | - */ |
|
| 94 | - public function updateUser(IUser $user, $data) { |
|
| 95 | - $userData = $this->getUser($user); |
|
| 96 | - $updated = true; |
|
| 97 | - if (empty($userData)) { |
|
| 98 | - $this->insertNewUser($user, $data); |
|
| 99 | - } elseif ($userData !== $data) { |
|
| 100 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 101 | - $data = $this->updateVerifyStatus($userData, $data); |
|
| 102 | - $this->updateExistingUser($user, $data); |
|
| 103 | - } else { |
|
| 104 | - // nothing needs to be done if new and old data set are the same |
|
| 105 | - $updated = false; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($updated) { |
|
| 109 | - $this->eventDispatcher->dispatch( |
|
| 110 | - 'OC\AccountManager::userUpdated', |
|
| 111 | - new GenericEvent($user, $data) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get stored data from a given user |
|
| 118 | - * |
|
| 119 | - * @param IUser $user |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function getUser(IUser $user) { |
|
| 123 | - $uid = $user->getUID(); |
|
| 124 | - $query = $this->connection->getQueryBuilder(); |
|
| 125 | - $query->select('data')->from($this->table) |
|
| 126 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 127 | - ->setParameter('uid', $uid); |
|
| 128 | - $query->execute(); |
|
| 129 | - $result = $query->execute()->fetchAll(); |
|
| 130 | - |
|
| 131 | - if (empty($result)) { |
|
| 132 | - $userData = $this->buildDefaultUserRecord($user); |
|
| 133 | - $this->insertNewUser($user, $userData); |
|
| 134 | - return $userData; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $userDataArray = json_decode($result[0]['data'], true); |
|
| 138 | - |
|
| 139 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 140 | - |
|
| 141 | - return $userDataArray; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 146 | - * |
|
| 147 | - * @param $oldData |
|
| 148 | - * @param $newData |
|
| 149 | - * @param IUser $user |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 153 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 154 | - $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 155 | - [ |
|
| 156 | - 'verificationCode' => '', |
|
| 157 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 158 | - 'type' => self::PROPERTY_EMAIL, |
|
| 159 | - 'uid' => $user->getUID(), |
|
| 160 | - 'try' => 0, |
|
| 161 | - 'lastRun' => time() |
|
| 162 | - ] |
|
| 163 | - ); |
|
| 164 | - $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return $newData; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * make sure that all expected data are set |
|
| 172 | - * |
|
| 173 | - * @param array $userData |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - protected function addMissingDefaultValues(array $userData) { |
|
| 177 | - |
|
| 178 | - foreach ($userData as $key => $value) { |
|
| 179 | - if (!isset($userData[$key]['verified'])) { |
|
| 180 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $userData; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * reset verification status if personal data changed |
|
| 189 | - * |
|
| 190 | - * @param array $oldData |
|
| 191 | - * @param array $newData |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - protected function updateVerifyStatus($oldData, $newData) { |
|
| 195 | - |
|
| 196 | - // which account was already verified successfully? |
|
| 197 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 198 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 199 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 200 | - |
|
| 201 | - // keep old verification status if we don't have a new one |
|
| 202 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 203 | - // keep old verification status if value didn't changed and an old value exists |
|
| 204 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 205 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 209 | - // keep old verification status if value didn't changed and an old value exists |
|
| 210 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 211 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 215 | - // keep old verification status if value didn't changed and an old value exists |
|
| 216 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 217 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // reset verification status if a value from a previously verified data was changed |
|
| 221 | - if($twitterVerified && |
|
| 222 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 223 | - ) { |
|
| 224 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if($websiteVerified && |
|
| 228 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 229 | - ) { |
|
| 230 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if($emailVerified && |
|
| 234 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 235 | - ) { |
|
| 236 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $newData; |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * add new user to accounts table |
|
| 245 | - * |
|
| 246 | - * @param IUser $user |
|
| 247 | - * @param array $data |
|
| 248 | - */ |
|
| 249 | - protected function insertNewUser(IUser $user, $data) { |
|
| 250 | - $uid = $user->getUID(); |
|
| 251 | - $jsonEncodedData = json_encode($data); |
|
| 252 | - $query = $this->connection->getQueryBuilder(); |
|
| 253 | - $query->insert($this->table) |
|
| 254 | - ->values( |
|
| 255 | - [ |
|
| 256 | - 'uid' => $query->createNamedParameter($uid), |
|
| 257 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 258 | - ] |
|
| 259 | - ) |
|
| 260 | - ->execute(); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * update existing user in accounts table |
|
| 265 | - * |
|
| 266 | - * @param IUser $user |
|
| 267 | - * @param array $data |
|
| 268 | - */ |
|
| 269 | - protected function updateExistingUser(IUser $user, $data) { |
|
| 270 | - $uid = $user->getUID(); |
|
| 271 | - $jsonEncodedData = json_encode($data); |
|
| 272 | - $query = $this->connection->getQueryBuilder(); |
|
| 273 | - $query->update($this->table) |
|
| 274 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 275 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 276 | - ->execute(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * build default user record in case not data set exists yet |
|
| 281 | - * |
|
| 282 | - * @param IUser $user |
|
| 283 | - * @return array |
|
| 284 | - */ |
|
| 285 | - protected function buildDefaultUserRecord(IUser $user) { |
|
| 286 | - return [ |
|
| 287 | - self::PROPERTY_DISPLAYNAME => |
|
| 288 | - [ |
|
| 289 | - 'value' => $user->getDisplayName(), |
|
| 290 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 291 | - 'verified' => self::NOT_VERIFIED, |
|
| 292 | - ], |
|
| 293 | - self::PROPERTY_ADDRESS => |
|
| 294 | - [ |
|
| 295 | - 'value' => '', |
|
| 296 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 297 | - 'verified' => self::NOT_VERIFIED, |
|
| 298 | - ], |
|
| 299 | - self::PROPERTY_WEBSITE => |
|
| 300 | - [ |
|
| 301 | - 'value' => '', |
|
| 302 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 303 | - 'verified' => self::NOT_VERIFIED, |
|
| 304 | - ], |
|
| 305 | - self::PROPERTY_EMAIL => |
|
| 306 | - [ |
|
| 307 | - 'value' => $user->getEMailAddress(), |
|
| 308 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 309 | - 'verified' => self::NOT_VERIFIED, |
|
| 310 | - ], |
|
| 311 | - self::PROPERTY_AVATAR => |
|
| 312 | - [ |
|
| 313 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 314 | - ], |
|
| 315 | - self::PROPERTY_PHONE => |
|
| 316 | - [ |
|
| 317 | - 'value' => '', |
|
| 318 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 319 | - 'verified' => self::NOT_VERIFIED, |
|
| 320 | - ], |
|
| 321 | - self::PROPERTY_TWITTER => |
|
| 322 | - [ |
|
| 323 | - 'value' => '', |
|
| 324 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 325 | - 'verified' => self::NOT_VERIFIED, |
|
| 326 | - ], |
|
| 327 | - ]; |
|
| 328 | - } |
|
| 42 | + /** nobody can see my account details */ |
|
| 43 | + const VISIBILITY_PRIVATE = 'private'; |
|
| 44 | + /** only contacts, especially trusted servers can see my contact details */ |
|
| 45 | + const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 46 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 47 | + const VISIBILITY_PUBLIC = 'public'; |
|
| 48 | + |
|
| 49 | + const PROPERTY_AVATAR = 'avatar'; |
|
| 50 | + const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 51 | + const PROPERTY_PHONE = 'phone'; |
|
| 52 | + const PROPERTY_EMAIL = 'email'; |
|
| 53 | + const PROPERTY_WEBSITE = 'website'; |
|
| 54 | + const PROPERTY_ADDRESS = 'address'; |
|
| 55 | + const PROPERTY_TWITTER = 'twitter'; |
|
| 56 | + |
|
| 57 | + const NOT_VERIFIED = '0'; |
|
| 58 | + const VERIFICATION_IN_PROGRESS = '1'; |
|
| 59 | + const VERIFIED = '2'; |
|
| 60 | + |
|
| 61 | + /** @var IDBConnection database connection */ |
|
| 62 | + private $connection; |
|
| 63 | + |
|
| 64 | + /** @var string table name */ |
|
| 65 | + private $table = 'accounts'; |
|
| 66 | + |
|
| 67 | + /** @var EventDispatcherInterface */ |
|
| 68 | + private $eventDispatcher; |
|
| 69 | + |
|
| 70 | + /** @var IJobList */ |
|
| 71 | + private $jobList; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * AccountManager constructor. |
|
| 75 | + * |
|
| 76 | + * @param IDBConnection $connection |
|
| 77 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 78 | + * @param IJobList $jobList |
|
| 79 | + */ |
|
| 80 | + public function __construct(IDBConnection $connection, |
|
| 81 | + EventDispatcherInterface $eventDispatcher, |
|
| 82 | + IJobList $jobList) { |
|
| 83 | + $this->connection = $connection; |
|
| 84 | + $this->eventDispatcher = $eventDispatcher; |
|
| 85 | + $this->jobList = $jobList; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * update user record |
|
| 90 | + * |
|
| 91 | + * @param IUser $user |
|
| 92 | + * @param $data |
|
| 93 | + */ |
|
| 94 | + public function updateUser(IUser $user, $data) { |
|
| 95 | + $userData = $this->getUser($user); |
|
| 96 | + $updated = true; |
|
| 97 | + if (empty($userData)) { |
|
| 98 | + $this->insertNewUser($user, $data); |
|
| 99 | + } elseif ($userData !== $data) { |
|
| 100 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 101 | + $data = $this->updateVerifyStatus($userData, $data); |
|
| 102 | + $this->updateExistingUser($user, $data); |
|
| 103 | + } else { |
|
| 104 | + // nothing needs to be done if new and old data set are the same |
|
| 105 | + $updated = false; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($updated) { |
|
| 109 | + $this->eventDispatcher->dispatch( |
|
| 110 | + 'OC\AccountManager::userUpdated', |
|
| 111 | + new GenericEvent($user, $data) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get stored data from a given user |
|
| 118 | + * |
|
| 119 | + * @param IUser $user |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function getUser(IUser $user) { |
|
| 123 | + $uid = $user->getUID(); |
|
| 124 | + $query = $this->connection->getQueryBuilder(); |
|
| 125 | + $query->select('data')->from($this->table) |
|
| 126 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 127 | + ->setParameter('uid', $uid); |
|
| 128 | + $query->execute(); |
|
| 129 | + $result = $query->execute()->fetchAll(); |
|
| 130 | + |
|
| 131 | + if (empty($result)) { |
|
| 132 | + $userData = $this->buildDefaultUserRecord($user); |
|
| 133 | + $this->insertNewUser($user, $userData); |
|
| 134 | + return $userData; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $userDataArray = json_decode($result[0]['data'], true); |
|
| 138 | + |
|
| 139 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 140 | + |
|
| 141 | + return $userDataArray; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 146 | + * |
|
| 147 | + * @param $oldData |
|
| 148 | + * @param $newData |
|
| 149 | + * @param IUser $user |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 153 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 154 | + $this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData', |
|
| 155 | + [ |
|
| 156 | + 'verificationCode' => '', |
|
| 157 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 158 | + 'type' => self::PROPERTY_EMAIL, |
|
| 159 | + 'uid' => $user->getUID(), |
|
| 160 | + 'try' => 0, |
|
| 161 | + 'lastRun' => time() |
|
| 162 | + ] |
|
| 163 | + ); |
|
| 164 | + $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return $newData; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * make sure that all expected data are set |
|
| 172 | + * |
|
| 173 | + * @param array $userData |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + protected function addMissingDefaultValues(array $userData) { |
|
| 177 | + |
|
| 178 | + foreach ($userData as $key => $value) { |
|
| 179 | + if (!isset($userData[$key]['verified'])) { |
|
| 180 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $userData; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * reset verification status if personal data changed |
|
| 189 | + * |
|
| 190 | + * @param array $oldData |
|
| 191 | + * @param array $newData |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + protected function updateVerifyStatus($oldData, $newData) { |
|
| 195 | + |
|
| 196 | + // which account was already verified successfully? |
|
| 197 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 198 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 199 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 200 | + |
|
| 201 | + // keep old verification status if we don't have a new one |
|
| 202 | + if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 203 | + // keep old verification status if value didn't changed and an old value exists |
|
| 204 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 205 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 209 | + // keep old verification status if value didn't changed and an old value exists |
|
| 210 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 211 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 215 | + // keep old verification status if value didn't changed and an old value exists |
|
| 216 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 217 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // reset verification status if a value from a previously verified data was changed |
|
| 221 | + if($twitterVerified && |
|
| 222 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 223 | + ) { |
|
| 224 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if($websiteVerified && |
|
| 228 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 229 | + ) { |
|
| 230 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if($emailVerified && |
|
| 234 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 235 | + ) { |
|
| 236 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $newData; |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * add new user to accounts table |
|
| 245 | + * |
|
| 246 | + * @param IUser $user |
|
| 247 | + * @param array $data |
|
| 248 | + */ |
|
| 249 | + protected function insertNewUser(IUser $user, $data) { |
|
| 250 | + $uid = $user->getUID(); |
|
| 251 | + $jsonEncodedData = json_encode($data); |
|
| 252 | + $query = $this->connection->getQueryBuilder(); |
|
| 253 | + $query->insert($this->table) |
|
| 254 | + ->values( |
|
| 255 | + [ |
|
| 256 | + 'uid' => $query->createNamedParameter($uid), |
|
| 257 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 258 | + ] |
|
| 259 | + ) |
|
| 260 | + ->execute(); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * update existing user in accounts table |
|
| 265 | + * |
|
| 266 | + * @param IUser $user |
|
| 267 | + * @param array $data |
|
| 268 | + */ |
|
| 269 | + protected function updateExistingUser(IUser $user, $data) { |
|
| 270 | + $uid = $user->getUID(); |
|
| 271 | + $jsonEncodedData = json_encode($data); |
|
| 272 | + $query = $this->connection->getQueryBuilder(); |
|
| 273 | + $query->update($this->table) |
|
| 274 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 275 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 276 | + ->execute(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * build default user record in case not data set exists yet |
|
| 281 | + * |
|
| 282 | + * @param IUser $user |
|
| 283 | + * @return array |
|
| 284 | + */ |
|
| 285 | + protected function buildDefaultUserRecord(IUser $user) { |
|
| 286 | + return [ |
|
| 287 | + self::PROPERTY_DISPLAYNAME => |
|
| 288 | + [ |
|
| 289 | + 'value' => $user->getDisplayName(), |
|
| 290 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 291 | + 'verified' => self::NOT_VERIFIED, |
|
| 292 | + ], |
|
| 293 | + self::PROPERTY_ADDRESS => |
|
| 294 | + [ |
|
| 295 | + 'value' => '', |
|
| 296 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 297 | + 'verified' => self::NOT_VERIFIED, |
|
| 298 | + ], |
|
| 299 | + self::PROPERTY_WEBSITE => |
|
| 300 | + [ |
|
| 301 | + 'value' => '', |
|
| 302 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 303 | + 'verified' => self::NOT_VERIFIED, |
|
| 304 | + ], |
|
| 305 | + self::PROPERTY_EMAIL => |
|
| 306 | + [ |
|
| 307 | + 'value' => $user->getEMailAddress(), |
|
| 308 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 309 | + 'verified' => self::NOT_VERIFIED, |
|
| 310 | + ], |
|
| 311 | + self::PROPERTY_AVATAR => |
|
| 312 | + [ |
|
| 313 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 314 | + ], |
|
| 315 | + self::PROPERTY_PHONE => |
|
| 316 | + [ |
|
| 317 | + 'value' => '', |
|
| 318 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 319 | + 'verified' => self::NOT_VERIFIED, |
|
| 320 | + ], |
|
| 321 | + self::PROPERTY_TWITTER => |
|
| 322 | + [ |
|
| 323 | + 'value' => '', |
|
| 324 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 325 | + 'verified' => self::NOT_VERIFIED, |
|
| 326 | + ], |
|
| 327 | + ]; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | <h2 class="inlineblock"><?php p($_['heading']); ?></h2> |
| 27 | 27 | <?php if (!empty($_['docs'])): ?> |
| 28 | 28 | <a target="_blank" rel="noreferrer" class="icon-info svg" |
| 29 | - title="<?php p($l->t('Open documentation'));?>" |
|
| 29 | + title="<?php p($l->t('Open documentation')); ?>" |
|
| 30 | 30 | href="<?php p(link_to_docs($_['docs'])); ?>"> |
| 31 | 31 | </a> |
| 32 | 32 | <?php endif; ?> |