2016-11-16 14:09:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2016-11-16 14:09:41 +03:00
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-11-16 14:09:41 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_Sharing\Activity\Providers;
|
|
|
|
|
|
|
|
use OCP\Activity\IEvent;
|
2018-01-24 15:54:49 +03:00
|
|
|
use OCP\Activity\IManager;
|
2020-01-28 14:27:47 +03:00
|
|
|
use OCP\Contacts\IManager as IContactsManager;
|
2020-01-28 14:51:43 +03:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2018-01-24 15:54:49 +03:00
|
|
|
use OCP\IGroup;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\L10N\IFactory;
|
2016-11-16 14:09:41 +03:00
|
|
|
|
2017-02-08 13:55:50 +03:00
|
|
|
class Groups extends Base {
|
2016-11-16 14:09:41 +03:00
|
|
|
|
|
|
|
const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
|
|
|
|
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
|
2019-08-12 11:56:23 +03:00
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
|
|
|
|
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
|
|
|
|
|
2019-08-12 11:56:23 +03:00
|
|
|
const SUBJECT_EXPIRED_GROUP = 'expired_group';
|
|
|
|
|
2018-01-24 15:54:49 +03:00
|
|
|
/** @var IGroupManager */
|
|
|
|
protected $groupManager;
|
|
|
|
|
|
|
|
/** @var string[] */
|
|
|
|
protected $groupDisplayNames = [];
|
|
|
|
|
2020-01-28 14:27:47 +03:00
|
|
|
public function __construct(IFactory $languageFactory,
|
|
|
|
IURLGenerator $url,
|
|
|
|
IManager $activityManager,
|
|
|
|
IUserManager $userManager,
|
2020-01-28 14:51:43 +03:00
|
|
|
ICloudIdManager $cloudIdManager,
|
2020-01-28 14:27:47 +03:00
|
|
|
IContactsManager $contactsManager,
|
|
|
|
IGroupManager $groupManager) {
|
2020-01-28 14:51:43 +03:00
|
|
|
parent::__construct($languageFactory, $url, $activityManager, $userManager, $cloudIdManager, $contactsManager);
|
2018-01-24 15:54:49 +03:00
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
|
|
|
public function parseShortVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('Shared with group {group}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('Removed share for group {group}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{actor} shared with group {group}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{actor} removed share for group {group}');
|
2019-08-12 11:56:23 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
|
|
|
|
$subject = $this->l->t('Share for group {group} expired');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2017-02-08 13:55:50 +03:00
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEvent $event
|
|
|
|
* @return IEvent
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @since 11.0.0
|
|
|
|
*/
|
|
|
|
public function parseLongVersion(IEvent $event) {
|
|
|
|
$parsedParameters = $this->getParsedParameters($event);
|
|
|
|
|
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('You shared {file} with group {group}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('You removed group {group} from {file}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{actor} shared {file} with group {group}');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
|
2017-02-08 13:55:50 +03:00
|
|
|
$subject = $this->l->t('{actor} removed group {group} from {file}');
|
2019-08-12 11:56:23 +03:00
|
|
|
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
|
|
|
|
$subject = $this->l->t('Share for file {file} with group {group} expired');
|
2016-11-16 14:09:41 +03:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
|
2017-06-20 14:48:51 +03:00
|
|
|
if ($this->activityManager->getRequirePNG()) {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
|
|
|
|
} else {
|
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
|
|
|
|
}
|
2017-02-08 13:55:50 +03:00
|
|
|
$this->setSubjects($event, $subject, $parsedParameters);
|
|
|
|
|
2016-11-16 14:09:41 +03:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getParsedParameters(IEvent $event) {
|
|
|
|
$subject = $event->getSubject();
|
|
|
|
$parameters = $event->getSubjectParameters();
|
|
|
|
|
|
|
|
switch ($subject) {
|
|
|
|
case self::SUBJECT_RESHARED_GROUP_BY:
|
|
|
|
case self::SUBJECT_UNSHARED_GROUP_BY:
|
|
|
|
return [
|
2017-02-08 13:55:50 +03:00
|
|
|
'file' => $this->getFile($parameters[0], $event),
|
2018-01-24 15:54:49 +03:00
|
|
|
'group' => $this->generateGroupParameter($parameters[2]),
|
2017-02-08 13:55:50 +03:00
|
|
|
'actor' => $this->getUser($parameters[1]),
|
2016-11-16 14:09:41 +03:00
|
|
|
];
|
|
|
|
case self::SUBJECT_SHARED_GROUP_SELF:
|
|
|
|
case self::SUBJECT_UNSHARED_GROUP_SELF:
|
2019-08-12 11:56:23 +03:00
|
|
|
case self::SUBJECT_EXPIRED_GROUP:
|
2016-11-16 14:09:41 +03:00
|
|
|
return [
|
2017-02-08 13:55:50 +03:00
|
|
|
'file' => $this->getFile($parameters[0], $event),
|
2018-01-24 15:54:49 +03:00
|
|
|
'group' => $this->generateGroupParameter($parameters[1]),
|
2016-11-16 14:09:41 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
2018-01-24 15:54:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $gid
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function generateGroupParameter($gid) {
|
|
|
|
if (!isset($this->groupDisplayNames[$gid])) {
|
|
|
|
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2018-11-23 14:38:24 +03:00
|
|
|
'type' => 'user-group',
|
2018-01-24 15:54:49 +03:00
|
|
|
'id' => $gid,
|
|
|
|
'name' => $this->groupDisplayNames[$gid],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $gid
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getGroupDisplayName($gid) {
|
|
|
|
$group = $this->groupManager->get($gid);
|
|
|
|
if ($group instanceof IGroup) {
|
|
|
|
return $group->getDisplayName();
|
|
|
|
}
|
|
|
|
return $gid;
|
|
|
|
}
|
2016-11-16 14:09:41 +03:00
|
|
|
}
|