Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automations in activity stream #942

Merged
merged 1 commit into from
Apr 9, 2021
Merged
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
9 changes: 9 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ config = {
'chrome',
'firefox'
],
'servers': [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore after release!

'daily-master-qa',
],
},
'federatedSuites': {
'suites': {
Expand All @@ -54,12 +57,18 @@ config = {
'chrome',
'firefox'
],
'servers': [
'daily-master-qa',
],
'federatedServerNeeded': True
},
'api': {
'suites': [
'apiActivity'
],
'servers': [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore after release!

'daily-master-qa',
],
},
'core-api-acceptance': {
'suites': {
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Never again miss an important event related to content in ownCloud and always be
<screenshot>https://raw.githubusercontent.com/owncloud/screenshots/68550c2b7c53e6309132ca1c7b177adca976db0b/activity/activity.png</screenshot>
<category>tools</category>
<dependencies>
<owncloud min-version="10.2" max-version="10"/>
<owncloud min-version="10.7.1" max-version="10"/>
</dependencies>
<background-jobs>
<job>OCA\Activity\BackgroundJob\EmailNotification</job>
Expand Down
3 changes: 2 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function __construct(array $urlParams = []) {
return new Consumer(
$c->query('ActivityData'),
$c->query('UserSettings'),
$server->getL10NFactory()
$server->getL10NFactory(),
$c->query('OCP\Activity\IManager')
);
});

Expand Down
20 changes: 18 additions & 2 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OC\Files\View;
use OCA\Activity\Extension\Files;
use OCA\Activity\Extension\Files_Sharing;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -162,7 +163,12 @@ protected function addNotificationsForFileAction($filePath, $activityType, $subj
continue;
}

if ($user === $this->currentUser) {
$agentAuthor = $this->manager->getAgentAuthor();

if ($agentAuthor === IEvent::AUTOMATION_AUTHOR) {
$userSubject = $subjectBy;
$userParams = [[$fileId => $path]];
} elseif ($user === $this->currentUser) {
$userSubject = $subject;
$userParams = [[$fileId => $path]];
} else {
Expand Down Expand Up @@ -563,12 +569,22 @@ protected function addNotificationsForUser($user, $subject, $subjectParams, $fil
$event->setApp($app)
->setType($type)
->setAffectedUser($user)
->setAuthor($this->currentUser)
->setTimestamp(\time())
->setSubject($subject, $subjectParams)
->setObject($objectType, $fileId, $path)
->setLink($link);

$agentAuthor = $this->manager->getAgentAuthor();
if ($agentAuthor) {
$subjectParams[1] = $agentAuthor;
$event->setSubject($subject, $subjectParams);
$event->setAuthor($agentAuthor);
}

if ($event->getAuthor() === null) {
$event->setAuthor($this->currentUser);
}

// Add activity to stream
if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) {
$this->activityData->send($event);
Expand Down
11 changes: 9 additions & 2 deletions tests/Unit/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ConsumerTest extends TestCase {
/** @var \OCA\Activity\UserSettings */
protected $userSettings;

/** @var \OCP\Activity\IManager */
protected $manager;

protected function setUp(): void {
parent::setUp();
$this->deleteTestActivities();
Expand All @@ -69,6 +72,10 @@ protected function setUp(): void {
->with('activity')
->willReturn($l10n);

$this->manager = $this->getMockBuilder('OCP\Activity\IManager')
->disableOriginalConstructor()
->getMock();

$this->userSettings->expects($this->any())
->method('getUserSetting')
->with($this->stringContains('affectedUser'), $this->anything(), $this->anything())
Expand Down Expand Up @@ -134,7 +141,7 @@ public function testReceiveStream($type, $author, $affectedUser, $subject, $expe
]
]);

$consumer = new Consumer($this->data, $this->userSettings, $this->l10nFactory);
$consumer = new Consumer($this->data, $this->userSettings, $this->l10nFactory, $this->manager);
$event = \OC::$server->getActivityManager()->generateEvent();
$event->setApp('test')
->setType($type)
Expand Down Expand Up @@ -178,7 +185,7 @@ public function testReceiveEmail($type, $author, $affectedUser, $subject, $expec
]);

$time = \time();
$consumer = new Consumer($this->data, $this->userSettings, $this->l10nFactory);
$consumer = new Consumer($this->data, $this->userSettings, $this->l10nFactory, $this->manager);
$event = \OC::$server->getActivityManager()->generateEvent();
$event->setApp('test')
->setType($type)
Expand Down