migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,288 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Db\DeprecatedCirclesRequest;
use OCA\Circles\Db\GSSharesRequest;
use OCA\Circles\Db\DeprecatedMembersRequest;
use OCA\Circles\Db\FileSharesRequest;
use OCA\Circles\Db\TokensRequest;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\EventsService;
use OCA\Circles\Service\MembersService;
use OCA\Circles\Service\MiscService;
use OCP\Defaults;
use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Mail\IMailer;
/**
* Class AGlobalScaleEvent
*
* @package OCA\Circles\GlobalScale
*/
abstract class AGlobalScaleEvent {
/** @var IRootFolder */
protected $rootFolder;
/** @var IURLGenerator */
protected $urlGenerator;
/** @var IL10N */
protected $l10n;
/** @var IMailer */
protected $mailer;
/** @var Defaults */
protected $defaults;
/** @var IUserManager */
protected $userManager;
/** @var FileSharesRequest */
protected $fileSharesRequest;
/** @var TokensRequest */
protected $tokensRequest;
/** @var DeprecatedCirclesRequest */
protected $circlesRequest;
/** @var DeprecatedMembersRequest */
protected $membersRequest;
/** @var GSSharesRequest */
protected $gsSharesRequest;
/** @var CirclesService */
protected $circlesService;
/** @var MembersService */
protected $membersService;
/** @var EventsService */
protected $eventsService;
/** @var ConfigService */
protected $configService;
/** @var MiscService */
protected $miscService;
/**
* AGlobalScaleEvent constructor.
*
* @param IRootFolder $rootFolder
* @param IURLGenerator $urlGenerator
* @param IL10N $l10n
* @param IMailer $mailer
* @param Defaults $defaults
* @param IUserManager $userManager
* @param FileSharesRequest $fileSharesRequest
* @param TokensRequest $tokensRequest
* @param DeprecatedCirclesRequest $circlesRequest
* @param DeprecatedMembersRequest $membersRequest
* @param GSSharesRequest $gsSharesRequest
* @param CirclesService $circlesService
* @param MembersService $membersService
* @param EventsService $eventsService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IL10N $l10n,
IMailer $mailer,
Defaults $defaults,
IUserManager $userManager,
FileSharesRequest $fileSharesRequest,
TokensRequest $tokensRequest,
DeprecatedCirclesRequest $circlesRequest,
DeprecatedMembersRequest $membersRequest,
GSSharesRequest $gsSharesRequest,
CirclesService $circlesService,
MembersService $membersService,
EventsService $eventsService,
ConfigService $configService,
MiscService $miscService
) {
$this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->mailer = $mailer;
$this->defaults = $defaults;
$this->userManager = $userManager;
$this->fileSharesRequest = $fileSharesRequest;
$this->tokensRequest = $tokensRequest;
$this->circlesRequest = $circlesRequest;
$this->membersRequest = $membersRequest;
$this->gsSharesRequest = $gsSharesRequest;
$this->circlesService = $circlesService;
$this->membersService = $membersService;
$this->eventsService = $eventsService;
$this->configService = $configService;
$this->miscService = $miscService;
}
/**
* @param GSEvent $event
* @param bool $localCheck
*
* @param bool $mustBeCheck
*
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeCheck = false): void {
if ($localCheck && !$event->isForced()) {
$this->checkViewer($event, $mustBeCheck);
}
}
/**
* @param GSEvent $event
*/
abstract public function manage(GSEvent $event): void;
/**
* @param GSEvent[] $events
*/
abstract public function result(array $events): void;
/**
* @param GSEvent $event
* @param bool $mustBeChecked
*
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
private function checkViewer(GSEvent $event, bool $mustBeChecked) {
if (!$event->hasCircle()
|| !$event->getDeprecatedCircle()
->hasViewer()) {
if ($mustBeChecked) {
throw new GlobalScaleEventException('GSEvent cannot be checked');
} else {
return;
}
}
$circle = $event->getDeprecatedCircle();
$viewer = $circle->getHigherViewer();
$this->cleanMember($viewer);
$localCircle = $this->circlesRequest->getCircle(
$circle->getUniqueId(), $viewer->getUserId(), $viewer->getType(), $viewer->getInstance()
);
if (!$this->compareMembers($viewer, $localCircle->getHigherViewer())) {
throw new GlobalScaleDSyncException('Viewer seems DSync');
}
$event->setDeprecatedCircle($localCircle);
}
/**
* @param DeprecatedMember $member1
* @param DeprecatedMember $member2
*
* @return bool
*/
protected function compareMembers(DeprecatedMember $member1, DeprecatedMember $member2) {
if ($member1->getInstance() === '') {
$member1->setInstance($this->configService->getFrontalInstance());
}
if ($member2->getInstance() === '') {
$member2->setInstance($this->configService->getFrontalInstance());
}
if ($member1->getCircleId() !== $member2->getCircleId()
|| $member1->getUserId() !== $member2->getUserId()
|| $member1->getType() <> $member2->getType()
|| $member1->getLevel() <> $member2->getLevel()
|| $member1->getStatus() !== $member2->getStatus()
|| $member1->getInstance() !== $member2->getInstance()) {
return false;
}
return true;
}
/**
* @param DeprecatedCircle $circle1
* @param DeprecatedCircle $circle2
*
* @return bool
*/
protected function compareCircles(DeprecatedCircle $circle1, DeprecatedCircle $circle2): bool {
if ($circle1->getName() !== $circle2->getName()
|| $circle1->getDescription() !== $circle2->getDescription()
|| $circle1->getSettings(true) !== $circle2->getSettings(true)
|| $circle1->getType() !== $circle2->getType()
|| $circle1->getUniqueId() !== $circle2->getUniqueId()) {
return false;
}
return true;
}
protected function cleanMember(DeprecatedMember $member) {
if ($this->configService->isLocalInstance($member->getInstance())) {
$member->setInstance('');
}
}
}
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class CircleCreate
*
* @package OCA\Circles\GlobalScale
*/
class CircleCreate extends AGlobalScaleEvent {
/**
* Circles are created on the original instance, so do no check;
*
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
//parent::verify($event, $localCheck, $mustBeChecked);
}
/**
* @param GSEvent $event
*
* @throws MemberAlreadyExistsException
*/
public function manage(GSEvent $event): void {
if (!$event->hasCircle()) {
return;
}
$circle = $event->getDeprecatedCircle();
$this->circlesRequest->createCircle($circle);
$owner = $circle->getOwner();
if ($owner->getInstance() === '') {
$owner->setInstance($event->getSource());
}
$this->membersRequest->createMember($owner);
$this->eventsService->onCircleCreation($circle);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\DeprecatedMember;
/**
* Class CircleStatus
*
* @package OCA\Circles\GlobalScale
*/
class CircleStatus extends AGlobalScaleEvent {
public const STATUS_ERROR = -1;
public const STATUS_OK = 1;
public const STATUS_NOT_OWNER = 8;
public const STATUS_NOT_FOUND = 404;
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
$status = self::STATUS_ERROR;
try {
$this->circlesRequest->forceGetCircle($circle->getUniqueId());
$owners = $this->membersRequest->forceGetMembers($circle->getUniqueId(), DeprecatedMember::LEVEL_OWNER);
if (!empty($owners)) {
$owner = $owners[0];
if ($owner->getInstance() === '') {
$status = self::STATUS_OK;
} else {
$status = self::STATUS_NOT_OWNER;
$event->getData()
->sObj('supposedOwner', $owner);
}
}
} catch (CircleDoesNotExistException $e) {
$status = self::STATUS_NOT_FOUND;
}
$event->getData()
->sInt('status', $status);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,478 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Tools\Traits\TArrayTools;
use Exception;
use OC;
use OC\Share20\Share;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\GSStatusException;
use OCA\Circles\Exceptions\TokenDoesNotExistException;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\GlobalScale\GSShare;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Model\SharesToken;
use OCA\Circles\Model\SharingFrame;
use OCA\Circles\Service\MiscService;
use OCP\Files\NotFoundException;
use OCP\IUser;
use OCP\Mail\IEMailTemplate;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use OCP\Util;
/**
* Class FileShare
*
* @package OCA\Circles\GlobalScale
*/
class FileShare extends AGlobalScaleEvent {
use TArrayTools;
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
// if event/file is local, we generate a federate share for the same circle on other instances
if (!$this->configService->isLocalInstance($event->getSource())) {
return;
}
try {
$share = $this->getShareFromData($event->getData());
} catch (Exception $e) {
return;
}
try {
$node = $share->getNode();
$filename = $node->getName();
} catch (NotFoundException $e) {
$this->miscService->log('issue while FileShare: ' . $e->getMessage());
return;
}
$event->getData()
->s('gs_federated', $share->getToken())
->s('gs_filename', '/' . $filename);
}
/**
* @param GSEvent $event
*
* @throws GSStatusException
* @throws CircleDoesNotExistException
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
// if event is not local, we create a federated file to the right instance of Nextcloud, using the right token
if (!$this->configService->isLocalInstance($event->getSource())) {
try {
$share = $this->getShareFromData($event->getData());
} catch (Exception $e) {
return;
}
$data = $event->getData();
$token = $data->g('gs_federated');
$filename = $data->g('gs_filename');
$gsShare = new GSShare($share->getSharedWith(), $token);
$gsShare->setOwner($share->getShareOwner());
$gsShare->setInstance($event->getSource());
$gsShare->setParent(-1);
$gsShare->setMountPoint($filename);
$this->gsSharesRequest->create($gsShare);
} else {
// if the event is local, we send mail to mail-as-members
$members = $this->membersRequest->forceGetMembers(
$circle->getUniqueId(), DeprecatedMember::LEVEL_MEMBER, DeprecatedMember::TYPE_MAIL, true
);
foreach ($members as $member) {
$this->sendShareToContact($event, $circle, $member->getMemberId(), [$member->getUserId()]);
}
}
// we also fill the event's result for further things, like contact-as-members
$members = $this->membersRequest->forceGetMembers(
$circle->getUniqueId(), DeprecatedMember::LEVEL_MEMBER, DeprecatedMember::TYPE_CONTACT, true
);
$accounts = [];
foreach ($members as $member) {
if ($member->getInstance() === '') {
$accounts[] = $this->miscService->getInfosFromContact($member);
}
}
$event->setResult(new SimpleDataStore(['contacts' => $accounts]));
}
/**
* @param GSEvent[] $events
*
* @throws CircleDoesNotExistException
*/
public function result(array $events): void {
$event = null;
$contacts = [];
foreach (array_keys($events) as $instance) {
$event = $events[$instance];
$contacts = array_merge(
$contacts, $event->getResult()
->gArray('contacts')
);
}
if ($event === null || !$event->hasCircle()) {
return;
}
$circle = $event->getDeprecatedCircle();
foreach ($contacts as $contact) {
$this->sendShareToContact($event, $circle, $contact['memberId'], $contact['emails']);
}
}
/**
* @param GSEvent $event
* @param DeprecatedCircle $circle
* @param string $memberId
* @param array $emails
*
* @throws CircleDoesNotExistException
*/
private function sendShareToContact(GSEvent $event, DeprecatedCircle $circle, string $memberId, array $emails) {
try {
$member = $this->membersRequest->forceGetMemberById($memberId);
$share = $this->getShareFromData($event->getData());
} catch (Exception $e) {
return;
}
$newCircle = $this->circlesRequest->forceGetCircle($circle->getUniqueId(), true);
$password = '';
$sendPasswordByMail = true;
// if ($this->configService->enforcePasswordProtection($newCircle)) {
// if ($newCircle->getSetting('password_single_enabled') === 'true') {
// $password = $newCircle->getPasswordSingle();
// $sendPasswordByMail = false;
// } else {
// $password = $this->miscService->token(15);
// }
// }
try {
$sharesToken =
$this->tokensRequest->generateTokenForMember($member, (int)$share->getId(), $password);
} catch (TokenDoesNotExistException $e) {
return;
}
if (!$sendPasswordByMail) {
$password = '';
}
foreach ($emails as $mail) {
$this->sharedByMail($circle, $share, $mail, $sharesToken, $password);
}
}
/**
* @param DeprecatedCircle $circle
* @param IShare $share
* @param string $email
* @param SharesToken $sharesToken
* @param string $password
*/
private function sharedByMail(
DeprecatedCircle $circle, IShare $share, string $email, SharesToken $sharesToken, string $password
) {
// genelink
$link = $this->urlGenerator->linkToRouteAbsolute(
'files_sharing.sharecontroller.showShare',
['token' => $sharesToken->getToken()]
);
$lang = $this->configService->getCoreValueForUser($share->getSharedBy(), 'lang', '');
if ($lang !== '') {
$this->l10n = OC::$server->getL10N(Application::APP_ID, $lang);
}
try {
$this->sendMail(
$share->getNode()
->getName(), $link,
MiscService::getDisplay($share->getSharedBy(), DeprecatedMember::TYPE_USER),
$circle->getName(), $email
);
$this->sendPasswordByMail(
$share, MiscService::getDisplay($share->getSharedBy(), DeprecatedMember::TYPE_USER),
$email, $password
);
} catch (Exception $e) {
OC::$server->getLogger()
->log(1, 'Circles::sharedByMail - mail were not sent: ' . $e->getMessage());
}
}
/**
* @param $fileName
* @param string $link
* @param string $author
* @param $circleName
* @param string $email
*
* @throws Exception
*/
protected function sendMail($fileName, $link, $author, $circleName, $email) {
$message = $this->mailer->createMessage();
$this->miscService->log(
"Sending mail to circle '" . $circleName . "': " . $email . ' file: ' . $fileName
. ' - link: ' . $link, 0
);
$subject = $this->l10n->t('%s shared »%s« with you.', [$author, $fileName]);
$text = $this->l10n->t('%s shared »%s« with "%s".', [$author, $fileName, $circleName]);
$emailTemplate =
$this->generateEmailTemplate($subject, $text, $fileName, $link, $author, $circleName);
$instanceName = $this->defaults->getName();
$senderName = $this->l10n->t('%s on %s', [$author, $instanceName]);
$message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]);
$message->setSubject($subject);
$message->setPlainBody($emailTemplate->renderText());
$message->setHtmlBody($emailTemplate->renderHtml());
$message->setTo([$email]);
$this->mailer->send($message);
}
/**
* @param IShare $share
* @param string $circleName
* @param string $email
*
* @param $password
*
* @throws NotFoundException
* @throws Exception
*/
protected function sendPasswordByMail(IShare $share, $circleName, $email, $password) {
// if (!$this->configService->sendPasswordByMail() || $password === '') {
// return;
// }
$message = $this->mailer->createMessage();
$this->miscService->log("Sending password mail to circle '" . $circleName . "': " . $email, 0);
$filename = $share->getNode()
->getName();
$initiator = $share->getSharedBy();
$shareWith = $share->getSharedWith();
$initiatorUser = $this->userManager->get($initiator);
$initiatorDisplayName =
($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
$initiatorEmailAddress =
($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
$plainBodyPart = $this->l10n->t(
"%1\$s shared »%2\$s« with you.\nYou should have already received a separate email with a link to access it.\n",
[$initiatorDisplayName, $filename]
);
$htmlBodyPart = $this->l10n->t(
'%1$s shared »%2$s« with you. You should have already received a separate email with a link to access it.',
[$initiatorDisplayName, $filename]
);
$emailTemplate = $this->mailer->createEMailTemplate(
'sharebymail.RecipientPasswordNotification', [
'filename' => $filename,
'password' => $password,
'initiator' => $initiatorDisplayName,
'initiatorEmail' => $initiatorEmailAddress,
'shareWith' => $shareWith,
]
);
$emailTemplate->setSubject(
$this->l10n->t(
'Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName]
)
);
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l10n->t('Password to access »%s«', [$filename]), false);
$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
$emailTemplate->addBodyText($password);
// The "From" contains the sharers name
$instanceName = $this->defaults->getName();
$senderName = $this->l10n->t(
'%1$s via %2$s',
[
$initiatorDisplayName,
$instanceName
]
);
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
if ($initiatorEmailAddress !== null) {
$message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]);
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
} else {
$emailTemplate->addFooter();
}
$message->setTo([$email]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
}
/**
* @param $subject
* @param $text
* @param $fileName
* @param $link
* @param string $author
* @param string $circleName
*
* @return IEMailTemplate
*/
private function generateEmailTemplate($subject, $text, $fileName, $link, $author, $circleName
) {
$emailTemplate = $this->mailer->createEMailTemplate(
'circles.ShareNotification', [
'fileName' => $fileName,
'fileLink' => $link,
'author' => $author,
'circleName' => $circleName,
]
);
$emailTemplate->addHeader();
$emailTemplate->addHeading($subject, false);
$emailTemplate->addBodyText(
htmlspecialchars($text) . '<br>' . htmlspecialchars(
$this->l10n->t('Click the button below to open it.')
), $text
);
$emailTemplate->addBodyButton(
$this->l10n->t('Open »%s«', [htmlspecialchars($fileName)]), $link
);
return $emailTemplate;
}
/**
* @param string $circleId
*
* @return array
*/
private function getMailAddressFromCircle(string $circleId): array {
$members = $this->membersRequest->forceGetMembers(
$circleId, DeprecatedMember::LEVEL_MEMBER, DeprecatedMember::TYPE_MAIL
);
return array_map(
function (DeprecatedMember $member) {
return $member->getUserId();
}, $members
);
}
/**
* @param SimpleDataStore $data
*
* @return IShare
* @throws ShareNotFound
* @throws IllegalIDChangeException
*/
private function getShareFromData(SimpleDataStore $data) {
$frame = SharingFrame::fromArray($data->gArray('frame'));
$payload = $frame->getPayload();
if (!key_exists('share', $payload)) {
throw new ShareNotFound();
}
return $this->generateShare($payload['share']);
}
/**
* recreate the share from the JSON payload.
*
* @param array $data
*
* @return IShare
* @throws IllegalIDChangeException
*/
private function generateShare($data): IShare {
$share = new Share($this->rootFolder, $this->userManager);
$share->setId($data['id']);
$share->setSharedBy($data['sharedBy']);
$share->setSharedWith($data['sharedWith']);
$share->setNodeId($data['nodeId']);
$share->setShareOwner($data['shareOwner']);
$share->setPermissions($data['permissions']);
$share->setToken($data['token']);
$share->setPassword($data['password']);
return $share;
}
}
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class FileUnshare
*
* @package OCA\Circles\GlobalScale
*/
class FileUnshare extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2020
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale\GSMount;
use OCA\Circles\Tools\Traits\TArrayTools;
use Exception;
use OC\Files\Mount\MountPoint;
use OC\Files\Mount\MoveableMount;
/**
* Class Mount
*
* @package OCA\Circles\GlobalScale\GSMount
*/
class Mount extends MountPoint implements MoveableMount {
use TArrayTools;
/** @var MountManager */
protected $mountManager;
/** @var int */
private $gsShareId = -1;
/**
* Mount constructor.
*
* @param $storage
* @param string $mountPoint
* @param array $options
* @param MountManager $manager
* @param null $loader
*
* @throws Exception
*/
public function __construct(
$storage, string $mountPoint, array $options, MountManager $manager, $loader = null
) {
parent::__construct($storage, $mountPoint, $options, $loader);
$this->gsShareId = $this->getInt('gsShareId', $options);
$this->mountManager = $manager;
}
/**
* Move the mount point to $target
*
* @param string $target the target mount point
*
* @return bool
*/
public function moveMount($target) {
$result = $this->mountManager->renameShare($this->gsShareId, $target);
$this->setMountPoint($target);
return $result;
}
/**
* Remove the mount points
*
* @return mixed
* @return bool
*/
public function removeMount() {
return $this->mountManager->unshare($this->gsShareId);
}
/**
* Get the type of mount point, used to distinguish things like shares and external storages
* in the web interface
*
* @return string
*/
public function getMountType() {
return 'shared';
}
}
@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2020
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale\GSMount;
use OCA\Circles\Db\GSSharesRequest;
use OCA\Circles\Model\GlobalScale\GSShareMountpoint;
use OCP\Share\Exceptions\ShareNotFound;
/**
* Class MountManager
*
* @package OCA\Circles\GlobalScale\GSMount
*/
class MountManager {
/** @var string */
private $userId;
/** @var GSSharesRequest */
private $gsSharesRequest;
/**
* MountManager constructor.
*
* @param string $userId
* @param GSSharesRequest $gsSharesRequest
*/
public function __construct($userId, GSSharesRequest $gsSharesRequest) {
$this->userId = $userId;
$this->gsSharesRequest = $gsSharesRequest;
}
/**
* @param int $gsShareId
* @param string $target
*
* @return bool
*/
public function renameShare(int $gsShareId, string $target) {
try {
if ($target !== '-') {
$target = $this->stripPath($target);
$this->gsSharesRequest->getShareMountPointByPath($this->userId, $target);
return false;
}
} catch (ShareNotFound $e) {
}
$mountPoint = new GSShareMountpoint($gsShareId, $this->userId, $target);
try {
$this->gsSharesRequest->getShareMountPointById($gsShareId, $this->userId);
$this->gsSharesRequest->updateShareMountPoint($mountPoint);
} catch (ShareNotFound $e) {
$this->gsSharesRequest->generateShareMountPoint($mountPoint);
}
return true;
}
// TODO: implement !
public function getMountManager() {
return $this;
}
// TODO: implement !
public function removeShare($mountPoint) {
}
// TODO: implement !
public function removeMount($mountPoint) {
}
/**
* @param int $gsShareId
*
* @return bool
*/
public function unshare(int $gsShareId) {
return $this->renameShare($gsShareId, '-');
}
/**
* remove '/user/files' from the path and trailing slashes
*
* @param string $path
*
* @return string
*/
protected function stripPath($path) {
$prefix = '/' . $this->userId . '/files';
return rtrim(substr($path, strlen($prefix)), '/');
}
}
@@ -0,0 +1,183 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2020
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale\GSMount;
use OCA\Circles\Tools\Traits\TArrayTools;
use Exception;
use OC;
use OCA\Circles\Db\GSSharesRequest;
use OCA\Circles\Model\GlobalScale\GSShare;
use OCA\Circles\Model\GlobalScale\GSShareMountpoint;
use OCA\Circles\Service\ConfigService;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
/**
* Class MountProvider
*
* @package OCA\Circles\GlobalScale\GSMount
*/
class MountProvider implements IMountProvider {
use TArrayTools;
public const STORAGE = '\OCA\Files_Sharing\External\Storage';
/** @var MountManager */
private $mountManager;
/** @var ICloudIdManager */
private $cloudIdManager;
/** @var GSSharesRequest */
private $gsSharesRequest;
/** @var ConfigService */
private $configService;
/**
* MountProvider constructor.
*
* @param MountManager $mountManager
* @param ICloudIdManager $cloudIdManager
* @param GSSharesRequest $gsSharesRequest
* @param ConfigService $configService
*/
public function __construct(
MountManager $mountManager, ICloudIdManager $cloudIdManager, GSSharesRequest $gsSharesRequest,
ConfigService $configService
) {
$this->mountManager = $mountManager;
$this->cloudIdManager = $cloudIdManager;
$this->gsSharesRequest = $gsSharesRequest;
$this->configService = $configService;
}
/**
* @param IUser $user
* @param IStorageFactory $loader
*
* @return IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
$shares = $this->gsSharesRequest->getForUser($user->getUID());
$mounts = [];
foreach ($shares as $share) {
try {
if ($share->getMountPoint() !== '-') {
$this->fixDuplicateFile($user->getUID(), $share);
$mounts[] = $this->generateMount($share, $user->getUID(), $loader);
}
} catch (Exception $e) {
}
}
return $mounts;
}
/**
* @param GSShare $share
* @param string $userId
* @param IStorageFactory $storageFactory
*
* @return Mount
* @throws Exception
*/
public function generateMount(
GSShare $share, string $userId, IStorageFactory $storageFactory
) {
$protocol = 'https';
if ($this->configService->isLocalNonSSL()) {
$protocol = 'http';
}
$data = $share->toMount($userId, $protocol);
$data['manager'] = $this->mountManager;
$data['gsShareId'] = $share->getId();
$data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']);
$data['certificateManager'] = OC::$server->getCertificateManager($userId);
$data['HttpClientService'] = OC::$server->getHTTPClientService();
return new Mount(
self::STORAGE, $share->getMountPoint($userId), $data, $this->mountManager, $storageFactory
);
}
/**
* @param string $userId
* @param GSShare $share
*
* @throws OC\User\NoUserException
* @throws NotPermittedException
*/
private function fixDuplicateFile(string $userId, GSShare $share) {
$fs = \OC::$server->getRootFolder()
->getUserFolder($userId);
try {
$fs->get($share->getMountPoint());
} catch (NotFoundException $e) {
return;
}
$info = pathinfo($share->getMountPoint());
$filename = $this->get('dirname', $info) . '/' . $this->get('filename', $info);
$extension = $this->get('extension', $info);
$extension = ($extension === '') ? '' : '.' . $extension;
$n = 2;
while (true) {
$path = $filename . " ($n)" . $extension;
try {
$fs->get($path);
} catch (NotFoundException $e) {
$share->setMountPoint($path);
$mountPoint = new GSShareMountpoint($share->getId(), $userId, $path);
$this->gsSharesRequest->updateShareMountPoint($mountPoint);
return;
}
$n++;
}
}
}
@@ -0,0 +1,444 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Tools\Model\SimpleDataStore;
use Exception;
use OC\User\NoUserException;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\CircleTypeNotValidException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\EmailAccountInvalidFormatException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
use OCA\Circles\Exceptions\MembersLimitException;
use OCA\Circles\Exceptions\TokenDoesNotExistException;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Model\SharesToken;
use OCP\IUser;
use OCP\Mail\IEMailTemplate;
use OCP\Util;
/**
* Class MemberAdd
* @deprecated
* @package OCA\Circles\GlobalScale
*/
class MemberAdd extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws EmailAccountInvalidFormatException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
* @throws MemberAlreadyExistsException
* @throws MemberCantJoinCircleException
* @throws MembersLimitException
* @throws NoUserException
* @throws CircleTypeNotValidException
* @throws MemberIsNotModeratorException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, $localCheck, true);
$eventMember = $event->getMember();
$this->cleanMember($eventMember);
if ($eventMember->getInstance() === '') {
$eventMember->setInstance($event->getSource());
}
$ident = $eventMember->getUserId();
$this->membersService->verifyIdentBasedOnItsType(
$ident, $eventMember->getType(), $eventMember->getInstance()
);
$circle = $event->getDeprecatedCircle();
if (!$event->isForced()) {
$circle->getHigherViewer()
->hasToBeModerator();
}
$member = $this->membersRequest->getFreshNewMember(
$circle->getUniqueId(), $ident, $eventMember->getType(), $eventMember->getInstance()
);
$member->hasToBeInviteAble();
$member->setCachedName($eventMember->getCachedName());
$this->circlesService->checkThatCircleIsNotFull($circle);
$this->membersService->addMemberBasedOnItsType($circle, $member);
$password = '';
$sendPasswordByMail = false;
// if ($this->configService->enforcePasswordProtection($circle)) {
// if ($circle->getSetting('password_single_enabled') === 'true') {
// $password = $circle->getPasswordSingle();
// } else {
// $sendPasswordByMail = true;
// $password = $this->miscService->token(15);
// }
// }
$event->setData(
new SimpleDataStore(
[
'password' => $password,
'passwordByMail' => $sendPasswordByMail
]
)
);
$event->setMember($member);
}
/**
* @param GSEvent $event
*
* @throws MemberAlreadyExistsException
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
if ($member->getJoined() === '') {
$this->membersRequest->createMember($member);
} else {
$this->membersRequest->updateMemberLevel($member);
}
//
// TODO: verifiez comment se passe le cached name sur un member_add
//
$cachedName = $member->getCachedName();
$password = $event->getData()
->g('password');
$shares = $this->generateUnknownSharesLinks($circle, $member, $password);
$result = [
'unknownShares' => $shares,
'cachedName' => $cachedName
];
if ($member->getType() === DeprecatedMember::TYPE_CONTACT
&& $this->configService->isLocalInstance($member->getInstance())) {
$result['contact'] = $this->miscService->getInfosFromContact($member);
}
$event->setResult(new SimpleDataStore($result));
$this->eventsService->onMemberNew($circle, $member);
}
/**
* @param GSEvent[] $events
*
* @throws Exception
*/
public function result(array $events): void {
$password = $cachedName = '';
$circle = $member = null;
$links = [];
$recipients = [];
foreach ($events as $event) {
$data = $event->getData();
if ($data->gBool('passwordByMail') !== false) {
$password = $data->g('password');
}
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
$result = $event->getResult();
if ($result->g('cachedName') !== '') {
$cachedName = $result->g('cachedName');
}
$links = array_merge($links, $result->gArray('unknownShares'));
$contact = $result->gArray('contact');
if (!empty($contact)) {
$recipients = $contact['emails'];
}
}
if (empty($links) || $circle === null || $member === null) {
return;
}
if ($cachedName !== '') {
$member->setCachedName($cachedName);
$this->membersService->updateMember($member);
}
if ($member->getType() === DeprecatedMember::TYPE_MAIL
|| $member->getType() === DeprecatedMember::TYPE_CONTACT) {
if ($member->getType() === DeprecatedMember::TYPE_MAIL) {
$recipients = [$member->getUserId()];
}
foreach ($recipients as $recipient) {
$this->memberIsMailbox($circle, $recipient, $links, $password);
}
}
}
/**
* @param DeprecatedCircle $circle
* @param string $recipient
* @param array $links
* @param string $password
*/
private function memberIsMailbox(DeprecatedCircle $circle, string $recipient, array $links, string $password) {
if ($circle->getViewer() === null) {
$author = $circle->getOwner()
->getUserId();
} else {
$author = $circle->getViewer()
->getUserId();
}
try {
$template = $this->generateMailExitingShares($author, $circle->getName());
$this->fillMailExistingShares($template, $links);
$this->sendMailExistingShares($template, $author, $recipient);
$this->sendPasswordExistingShares($author, $recipient, $password);
} catch (Exception $e) {
$this->miscService->log('Failed to send mail about existing share ' . $e->getMessage());
}
}
/**
* @param DeprecatedCircle $circle
* @param DeprecatedMember $member
* @param string $password
*
* @return array
*/
private function generateUnknownSharesLinks(DeprecatedCircle $circle, DeprecatedMember $member, string $password): array {
$unknownShares = $this->getUnknownShares($member);
$data = [];
foreach ($unknownShares as $share) {
try {
$data[] = $this->getMailLinkFromShare($share, $member, $password);
} catch (TokenDoesNotExistException $e) {
}
}
return $data;
}
/**
* @param DeprecatedMember $member
*
* @return array
*/
private function getUnknownShares(DeprecatedMember $member): array {
$allShares = $this->fileSharesRequest->getSharesForCircle($member->getCircleId());
$knownShares = array_map(
function (SharesToken $shareToken) {
return $shareToken->getShareId();
},
$this->tokensRequest->getTokensFromMember($member)
);
$unknownShares = [];
foreach ($allShares as $share) {
if (!in_array($share['id'], $knownShares)) {
$unknownShares[] = $share;
}
}
return $unknownShares;
}
/**
* @param array $share
* @param DeprecatedMember $member
* @param string $password
*
* @return array
* @throws TokenDoesNotExistException
*/
private function getMailLinkFromShare(array $share, DeprecatedMember $member, string $password = '') {
$sharesToken = $this->tokensRequest->generateTokenForMember($member, (int)$share['id'], $password);
$link = $this->urlGenerator->linkToRouteAbsolute(
'files_sharing.sharecontroller.showShare',
['token' => $sharesToken->getToken()]
);
$author = $share['uid_initiator'];
$filename = basename($share['file_target']);
return [
'author' => $author,
'link' => $link,
'filename' => $filename
];
}
/**
* @param string $author
* @param string $circleName
*
* @return IEMailTemplate
*/
private function generateMailExitingShares(string $author, string $circleName): IEMailTemplate {
$emailTemplate = $this->mailer->createEMailTemplate('circles.ExistingShareNotification', []);
$emailTemplate->addHeader();
$text = $this->l10n->t('%s shared multiple files with "%s".', [$author, $circleName]);
$emailTemplate->addBodyText(htmlspecialchars($text), $text);
return $emailTemplate;
}
/**
* @param IEMailTemplate $emailTemplate
* @param array $links
*/
private function fillMailExistingShares(IEMailTemplate $emailTemplate, array $links) {
foreach ($links as $item) {
$emailTemplate->addBodyButton(
$this->l10n->t('Open »%s«', [htmlspecialchars($item['filename'])]), $item['link']
);
}
}
/**
* @param IEMailTemplate $emailTemplate
* @param string $author
* @param string $recipient
*
* @throws Exception
*/
private function sendMailExistingShares(IEMailTemplate $emailTemplate, string $author, string $recipient
) {
$subject = $this->l10n->t('%s shared multiple files with you.', [$author]);
$instanceName = $this->defaults->getName();
$senderName = $this->l10n->t('%s on %s', [$author, $instanceName]);
$message = $this->mailer->createMessage();
$message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]);
$message->setSubject($subject);
$message->setPlainBody($emailTemplate->renderText());
$message->setHtmlBody($emailTemplate->renderHtml());
$message->setTo([$recipient]);
$this->mailer->send($message);
}
/**
* @param string $author
* @param string $email
* @param string $password
*
* @throws Exception
*/
protected function sendPasswordExistingShares(string $author, string $email, string $password) {
if ($password === '') {
return;
}
$message = $this->mailer->createMessage();
$authorUser = $this->userManager->get($author);
$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
$this->miscService->log("Sending password mail about existing files to '" . $email . "'", 0);
$plainBodyPart = $this->l10n->t(
"%1\$s shared multiple files with you.\nYou should have already received a separate email with a link to access them.\n",
[$authorName]
);
$htmlBodyPart = $this->l10n->t(
'%1$s shared multiple files with you. You should have already received a separate email with a link to access them.',
[$authorName]
);
$emailTemplate = $this->mailer->createEMailTemplate(
'sharebymail.RecipientPasswordNotification', [
'password' => $password,
'author' => $author
]
);
$emailTemplate->setSubject(
$this->l10n->t(
'Password to access files shared to you by %1$s', [$authorName]
)
);
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
$emailTemplate->addBodyText($password);
// The "From" contains the sharers name
$instanceName = $this->defaults->getName();
$senderName = $this->l10n->t(
'%1$s via %2$s',
[
$authorName,
$instanceName
]
);
$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
if ($authorEmail !== null) {
$message->setReplyTo([$authorEmail => $authorName]);
$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
} else {
$emailTemplate->addFooter();
}
$message->setTo([$email]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
}
}
@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
use OCA\Circles\Exceptions\MemberIsBlockedException;
use OCA\Circles\Exceptions\MembersLimitException;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\DeprecatedMember;
/**
* Class MemberJoin
*
* @package OCA\Circles\GlobalScale
*/
class MemberJoin extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws MemberAlreadyExistsException
* @throws MemberCantJoinCircleException
* @throws MemberIsBlockedException
* @throws MembersLimitException
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, false, false);
$circle = $event->getDeprecatedCircle();
$eventMember = $event->getMember();
$member = $this->membersRequest->getFreshNewMember(
$circle->getUniqueId(), $eventMember->getUserId(), DeprecatedMember::TYPE_USER, $eventMember->getInstance()
);
$member->hasToBeAbleToJoinTheCircle();
$member->joinCircle($circle->getType());
$member->setCachedName($eventMember->getCachedName());
$this->circlesService->checkThatCircleIsNotFull($circle);
$event->setMember($member);
}
/**
* @param GSEvent $event
*
* @throws MemberAlreadyExistsException
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
if ($member->getJoined() === '') {
$this->membersRequest->createMember($member);
} else {
$this->membersRequest->updateMemberLevel($member);
}
$this->eventsService->onMemberNew($circle, $member);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Exceptions\MemberDoesNotExistException;
use OCA\Circles\Exceptions\MemberIsOwnerException;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class MemberLeave
*
* @package OCA\Circles\GlobalScale
*/
class MemberLeave extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws MemberDoesNotExistException
* @throws MemberIsOwnerException
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, $localCheck, true);
$member = $event->getMember();
$member->hasToBeMemberOrAlmost();
$member->cantBeOwner();
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
$this->eventsService->onMemberLeaving($circle, $member);
$this->membersRequest->removeMember($member);
$this->fileSharesRequest->removeSharesFromMember($member);
$this->gsSharesRequest->removeGSSharesFromMember($member);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
use OCA\Circles\Exceptions\MemberDoesNotExistException;
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
use OCA\Circles\Exceptions\MemberIsOwnerException;
use OCA\Circles\Exceptions\ModeratorIsNotHighEnoughException;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class MemberDelete
*
* @package OCA\Circles\GlobalScale
*/
class MemberRemove extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws MemberDoesNotExistException
* @throws MemberIsNotModeratorException
* @throws MemberIsOwnerException
* @throws ModeratorIsNotHighEnoughException
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, $localCheck, true);
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
$member->hasToBeMemberOrAlmost();
$member->cantBeOwner();
if (!$event->isForced()) {
$circle->getHigherViewer()
->hasToBeModerator();
$circle->getHigherViewer()
->hasToBeHigherLevel($member->getLevel());
}
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
/**
* @param GSEvent $event
*
* @throws MemberAlreadyExistsException
*/
public function manage(GSEvent $event): void {
$circle = $event->getDeprecatedCircle();
$member = $event->getMember();
$this->eventsService->onMemberLeaving($circle, $member);
$this->membersRequest->removeMember($member);
$this->gsSharesRequest->removeGSSharesFromMember($member);
$this->fileSharesRequest->removeSharesFromMember($member);
$this->tokensRequest->removeTokensFromMember($member);
}
}
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class MemberUpdate
*
* @package OCA\Circles\GlobalScale
*/
class MemberUpdate extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, false, false);
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
$member = $event->getMember();
$this->membersRequest->updateMemberInfo($member);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Tools\Model\SimpleDataStore;
use OCA\Circles\Model\GlobalScale\GSEvent;
/**
* Class Test
*
* @package OCA\Circles\GlobalScale
*/
class Test extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
$event->setResult(new SimpleDataStore(['status' => 1]));
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
}
@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\GlobalScale;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
use OCA\Circles\Exceptions\GlobalScaleEventException;
use OCA\Circles\Exceptions\MemberDoesNotExistException;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\GlobalScale\GSEvent;
use OCA\Circles\Model\DeprecatedMember;
/**
* Class MemberDelete
*
* @package OCA\Circles\GlobalScale
*/
class UserDeleted extends AGlobalScaleEvent {
/**
* @param GSEvent $event
* @param bool $localCheck
* @param bool $mustBeChecked
*
* @throws CircleDoesNotExistException
* @throws ConfigNoCircleAvailableException
* @throws GlobalScaleDSyncException
* @throws GlobalScaleEventException
*/
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
parent::verify($event, $localCheck, true);
$member = $event->getMember();
$circles = $this->circlesRequest->getCircles($member->getUserId(), 0, '', DeprecatedMember::LEVEL_OWNER);
$destroyedCircles = [];
$promotedAdmins = [];
foreach ($circles as $circle) {
$members =
$this->membersRequest->forceGetMembers($circle->getUniqueId(), DeprecatedMember::LEVEL_MEMBER);
if ($circle->getType() === DeprecatedCircle::CIRCLES_PERSONAL || sizeof($members) === 1) {
$destroyedCircles[] = $circle->getUniqueId();
continue;
}
$promotedAdmins[] = $this->getOlderAdmin($members);
}
$event->getData()
->sArray('destroyedCircles', $destroyedCircles)
->sArray('promotedAdmins', $promotedAdmins);
}
/**
* @param GSEvent[] $events
*/
public function result(array $events): void {
}
/**
* @param GSEvent $event
*/
public function manage(GSEvent $event): void {
$member = $event->getMember();
$this->membersRequest->removeAllMembershipsFromUser($member);
$data = $event->getData();
$this->destroyCircles($data->gArray('destroyedCircles'));
$this->promotedAdmins($data->gArray('promotedAdmins'));
}
/**
* @param DeprecatedMember[] $members
*
* @return string
*/
private function getOlderAdmin(array $members) {
foreach ($members as $member) {
if ($member->getLevel() === DeprecatedMember::LEVEL_ADMIN) {
return $member->getMemberId();
}
}
foreach ($members as $member) {
if ($member->getLevel() === DeprecatedMember::LEVEL_MODERATOR) {
return $member->getMemberId();
}
}
foreach ($members as $member) {
if ($member->getLevel() === DeprecatedMember::LEVEL_MEMBER) {
return $member->getMemberId();
}
}
}
/**
* @param array $circleIds
*/
private function destroyCircles(array $circleIds) {
foreach ($circleIds as $circleId) {
$this->circlesRequest->destroyCircle($circleId);
$this->membersRequest->removeAllFromCircle($circleId);
}
}
/**
* @param array $memberIds
*/
private function promotedAdmins(array $memberIds) {
foreach ($memberIds as $memberId) {
try {
$member = $this->membersRequest->forceGetMemberById($memberId);
$member->setLevel(DeprecatedMember::LEVEL_OWNER);
$this->membersRequest->updateMemberLevel($member);
} catch (MemberDoesNotExistException $e) {
}
}
}
}