Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private function parseAsMember(

$this->parserCircle->parseSubjectCircleCreate($event, $params);
$this->parserCircle->parseSubjectCircleDelete($event, $params);
$this->parserCircle->parseSubjectCircleEdit($event, $params);
$this->parserCircle->parseSubjectCircleSettingChanged($event, $params);
$this->parseMemberAsMember($event, $params);
$this->parseCircleMemberAsMember($event, $params);
}
Expand Down
13 changes: 12 additions & 1 deletion lib/Activity/ProviderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ protected function parseCircleEvent(
array $params,
string $ownEvent,
string $othersEvent,
array $additionalData = [],
): void {
$data = [
'author' => $this->generateUserParameter($params['initiator'] ?? []),
'circle' => $this->generateCircleParameter($params['circle'])
];
] + $additionalData;

if ($this->isViewerTheAuthor($params['initiator'] ?? [], $this->activityManager->getCurrentUserId())) {
$this->setSubject($event, $ownEvent, $data);
Expand Down Expand Up @@ -265,4 +266,14 @@ protected function generateGroupParameter(array $group): array {
'_parsed' => $group['userId']
];
}

/** @return array<string, string> */
protected function generateHighlightParameter(string $value): array {
return [
'type' => 'highlight',
'id' => $value,
'name' => $value,
'_parsed' => $value,
];
}
}
126 changes: 126 additions & 0 deletions lib/Activity/ProviderSubjectCircle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,31 @@
namespace OCA\Circles\Activity;

use OCA\Circles\Exceptions\FakeException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Service\ConfigService;
use OCP\Activity\IEvent;

class ProviderSubjectCircle extends ProviderParser {
private const SETTING_TEAM_TAB_ORDER = 'teamsTabOrder';
private const SETTING_PASSWORD_SINGLE = 'password_single';
private const SETTING_PASSWORD_SINGLE_ENABLED = 'password_single_enabled';
private const CONFIG_ACTIVITY_SUBJECTS = [
'config_open_enabled' => ['enabled', 'Anyone can request membership'],
'config_open_disabled' => ['disabled', 'Anyone can request membership'],
'config_invite_enabled' => ['enabled', 'Members need to accept invitation'],
'config_invite_disabled' => ['disabled', 'Members need to accept invitation'],
'config_request_enabled' => ['enabled', 'Memberships must be confirmed or accepted by a moderator'],
'config_request_disabled' => ['disabled', 'Memberships must be confirmed or accepted by a moderator'],
'config_friend_enabled' => ['enabled', 'Members can also invite'],
'config_friend_disabled' => ['disabled', 'Members can also invite'],
'config_root_enabled' => ['enabled', 'Prevent teams from being a member of another team'],
'config_root_disabled' => ['disabled', 'Prevent teams from being a member of another team'],
'config_federated_enabled' => ['enabled', 'Allow federated members'],
'config_federated_disabled' => ['disabled', 'Allow federated members'],
'config_visible_enabled' => ['enabled', 'Visible to everyone'],
'config_visible_disabled' => ['disabled', 'Visible to everyone'],
];

public function parseSubjectCircleCreate(IEvent $event, array $params): void {
if ($event->getSubject() !== 'circle_create') {
return;
Expand Down Expand Up @@ -46,4 +68,108 @@ public function parseSubjectCircleDelete(IEvent $event, array $params): void {

throw new FakeException();
}

public function parseSubjectCircleEdit(IEvent $event, array $params): void {
if ($event->getSubject() !== 'circle_edit') {
return;
}

$change = (string)($params['change'] ?? 'details');
if ($change === 'name' || $change === 'displayName') {
$data = [
'author' => $this->generateUserParameter($params['initiator'] ?? []),
'title' => $this->generateHighlightParameter((string)($params['title'] ?? '')),
];
if ($this->isViewerTheAuthor($params['initiator'] ?? [], $this->activityManager->getCurrentUserId())) {
$this->setSubject($event, $this->l10n->t('You changed the team title to {title}'), $data);
} else {
$this->setSubject($event, $this->l10n->t('{author} changed the team title to {title}'), $data);
}

throw new FakeException();
}

if ($change === 'description') {
$this->parseCircleEvent(
$event,
$params,
$this->l10n->t('You changed the description of {circle}'),
$this->l10n->t('{author} changed the description of {circle}'),
);

throw new FakeException();
}

$this->parseCircleEvent(
$event, $params,
$this->l10n->t('You edited the team {circle}'),
$this->l10n->t('{author} edited the team {circle}')
);

throw new FakeException();
}

public function parseSubjectCircleSettingChanged(IEvent $event, array $params): void {
if ($event->getSubject() !== 'circle_setting_changed') {
return;
}

$setting = (string)($params['setting'] ?? '');
if (isset(self::CONFIG_ACTIVITY_SUBJECTS[$setting])) {
[$state, $label] = self::CONFIG_ACTIVITY_SUBJECTS[$setting];
$data = [
'author' => $this->generateUserParameter($params['initiator'] ?? []),
'circle' => $this->generateCircleParameter($params['circle']),
'state' => $this->generateHighlightParameter($state),
'setting' => $this->generateHighlightParameter($label),
];
if ($this->isViewerTheAuthor($params['initiator'] ?? [], $this->activityManager->getCurrentUserId())) {
$this->setSubject($event, $this->l10n->t('You {state} "{setting}" for {circle}'), $data);
} else {
$this->setSubject($event, $this->l10n->t('{author} {state} "{setting}" for {circle}'), $data);
}

throw new FakeException();
}

[$ownEvent, $othersEvent] = $this->getSettingActivitySubjects($setting);

$this->parseCircleEvent(
$event, $params,
$ownEvent,
$othersEvent,
);

throw new FakeException();
}

/** @return array{string, string} */
private function getSettingActivitySubjects(string $setting): array {
return match ($setting) {
Circle::SETTING_TEAM_FOLDER_QUOTA => [
$this->l10n->t('You changed the Team Folder quota of {circle}'),
$this->l10n->t('{author} changed the Team Folder quota of {circle}'),
],
self::SETTING_TEAM_TAB_ORDER => [
$this->l10n->t('You changed the navigation order of {circle}'),
$this->l10n->t('{author} changed the navigation order of {circle}'),
],
ConfigService::MEMBERS_LIMIT => [
$this->l10n->t('You changed the member limit of {circle}'),
$this->l10n->t('{author} changed the member limit of {circle}'),
],
ConfigService::ENFORCE_PASSWORD, self::SETTING_PASSWORD_SINGLE_ENABLED => [
$this->l10n->t('You changed the password protection of {circle}'),
$this->l10n->t('{author} changed the password protection of {circle}'),
],
self::SETTING_PASSWORD_SINGLE => [
$this->l10n->t('You changed the password of {circle}'),
$this->l10n->t('{author} changed the password of {circle}'),
],
default => [
$this->l10n->t('You changed the settings of {circle}'),
$this->l10n->t('{author} changed the settings of {circle}'),
],
};
}
}
9 changes: 9 additions & 0 deletions lib/Db/CircleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function __construct(
parent::__construct($timezoneService, $configService);
}

public function getActivityObjectId(string $singleId): int {
$qb = $this->getQueryBuilder();
$qb->select('id')
->from(self::TABLE_CIRCLE)
->where($qb->expr()->eq('unique_id', $qb->createNamedParameter($singleId)));

return (int)$qb->executeQuery()->fetchOne();
}

/**
* @param Circle $circle
*
Expand Down
7 changes: 7 additions & 0 deletions lib/FederatedItems/CircleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\Circles\Model\Federated\FederatedEvent;
use OCA\Circles\Model\Helpers\MemberHelper;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\EventService;
use OCA\Circles\Service\PermissionService;
use OCA\Circles\Tools\Traits\TDeserialize;

Expand All @@ -41,6 +42,7 @@ public function __construct(
private CircleRequest $circleRequest,
private PermissionService $permissionService,
private ConfigService $configService,
private EventService $eventService,
) {
}

Expand Down Expand Up @@ -146,6 +148,11 @@ public function manage(FederatedEvent $event): void {
// TODO: sync if it is to broadcast to Trusted RemoteInstance

$this->circleRequest->updateConfig($circle);
$this->eventService->circleConfigChanged(
$circle,
$event->getCircle()->getConfig(),
$config,
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/FederatedItems/CircleEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function manage(FederatedEvent $event): void {
}

$this->circleRequest->edit($circle);
$event->setCircle($circle);
$this->memberRequest->updateDisplayName($circle->getSingleId(), $circle->getDisplayName());
$this->eventService->circleEditing($event);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/FederatedItems/CircleSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCA\Circles\Model\Federated\FederatedEvent;
use OCA\Circles\Model\Helpers\MemberHelper;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\EventService;
use OCA\Circles\Service\ShareTokenService;
use OCA\Circles\Tools\Traits\TDeserialize;

Expand All @@ -29,6 +30,7 @@ public function __construct(
private CircleRequest $circleRequest,
private ShareTokenService $shareTokenService,
private ConfigService $configService,
private EventService $eventService,
) {
}

Expand Down Expand Up @@ -91,6 +93,7 @@ public function manage(FederatedEvent $event): void {
// TODO: sync if it is to broadcast to Trusted RemoteInstance

$this->circleRequest->updateSettings($circle);
$this->eventService->circleSettingChanged($circle, $event->getParams()->g('setting'));

// refresh share password (in case of static password changes)
// only is password are enforced for this Circle
Expand Down
Loading
Loading