|
|
|
@ -33,13 +33,21 @@ namespace OC\Federation;
|
|
|
|
|
use OCP\Contacts\IManager;
|
|
|
|
|
use OCP\Federation\ICloudId;
|
|
|
|
|
use OCP\Federation\ICloudIdManager;
|
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
|
|
|
|
|
class CloudIdManager implements ICloudIdManager {
|
|
|
|
|
/** @var IManager */
|
|
|
|
|
private $contactsManager;
|
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
|
private $urlGenerator;
|
|
|
|
|
/** @var IUserManager */
|
|
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
|
|
public function __construct(IManager $contactsManager) {
|
|
|
|
|
public function __construct(IManager $contactsManager, IURLGenerator $urlGenerator, IUserManager $userManager) {
|
|
|
|
|
$this->contactsManager = $contactsManager;
|
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -103,24 +111,39 @@ class CloudIdManager implements ICloudIdManager {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $user
|
|
|
|
|
* @param string $remote
|
|
|
|
|
* @param string|null $remote
|
|
|
|
|
* @return CloudId
|
|
|
|
|
*/
|
|
|
|
|
public function getCloudId(string $user, string $remote): ICloudId {
|
|
|
|
|
// TODO check what the correct url is for remote (asking the remote)
|
|
|
|
|
$fixedRemote = $this->fixRemoteURL($remote);
|
|
|
|
|
if (strpos($fixedRemote, 'http://') === 0) {
|
|
|
|
|
$host = substr($fixedRemote, strlen('http://'));
|
|
|
|
|
} elseif (strpos($fixedRemote, 'https://') === 0) {
|
|
|
|
|
$host = substr($fixedRemote, strlen('https://'));
|
|
|
|
|
public function getCloudId(string $user, ?string $remote): ICloudId {
|
|
|
|
|
if ($remote === null) {
|
|
|
|
|
$remote = rtrim($this->removeProtocolFromUrl($this->urlGenerator->getAbsoluteURL('/')), '/');
|
|
|
|
|
$fixedRemote = $this->fixRemoteURL($remote);
|
|
|
|
|
$localUser = $this->userManager->get($user);
|
|
|
|
|
$displayName = !is_null($localUser) ? $localUser->getDisplayName() : '';
|
|
|
|
|
} else {
|
|
|
|
|
$host = $fixedRemote;
|
|
|
|
|
// TODO check what the correct url is for remote (asking the remote)
|
|
|
|
|
$fixedRemote = $this->fixRemoteURL($remote);
|
|
|
|
|
$host = $this->removeProtocolFromUrl($fixedRemote);
|
|
|
|
|
$displayName = $this->getDisplayNameFromContact($user . '@' . $host);
|
|
|
|
|
}
|
|
|
|
|
$id = $user . '@' . $remote;
|
|
|
|
|
$displayName = $this->getDisplayNameFromContact($user . '@' . $host);
|
|
|
|
|
return new CloudId($id, $user, $fixedRemote, $displayName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $url
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function removeProtocolFromUrl($url) {
|
|
|
|
|
if (strpos($url, 'https://') === 0) {
|
|
|
|
|
return substr($url, strlen('https://'));
|
|
|
|
|
} elseif (strpos($url, 'http://') === 0) {
|
|
|
|
|
return substr($url, strlen('http://'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Strips away a potential file names and trailing slashes:
|
|
|
|
|
* - http://localhost
|
|
|
|
|