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

Enable audit by configuration #163 #226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion l10n/pt_BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ OC.L10N.register(
"Members limit:" : "Limite de membros:",
"Default limit to the number of members in a circle." : "Limite de membros em um círculo.",
"Allow linking of groups:" : "Permitir links dos grupos:",
"Allow federated circles:" : "Permitir círculos federados:"
"Allow federated circles:" : "Permitir círculos federados:",
"You shared {file} with circle {circle}" : "Você compartilhou {file} com o círculo {circle}",
"{author} shared {file} with the circle {circle}" : "{author} compartilhou {file} com o círculo {circle}",
"You unshared {file} with the circle {circle}" : "Você descompartilhou {file} com o círculo {circle}",
"{author} unshared {file} with the circle {circle}" : "{author} descompartilhou {file} com o círculo {circle}"
},
"nplurals=2; plural=(n > 1);");
6 changes: 5 additions & 1 deletion l10n/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@
"Members limit:" : "Limite de membros:",
"Default limit to the number of members in a circle." : "Limite de membros em um círculo.",
"Allow linking of groups:" : "Permitir links dos grupos:",
"Allow federated circles:" : "Permitir círculos federados:"
"Allow federated circles:" : "Permitir círculos federados:",
"You shared {file} with circle {circle}" : "Você compartilhou {file} com o círculo {circle}",
"{author} shared {file} with the circle {circle}" : "{author} compartilhou {file} com o círculo {circle}",
"You unshared {file} with the circle {circle}" : "Você descompartilhou {file} com o círculo {circle}",
"{author} unshared {file} with the circle {circle}" : "{author} descompartilhou {file} com o círculo {circle}"
},"pluralForm" :"nplurals=2; plural=(n > 1);"
}
93 changes: 93 additions & 0 deletions lib/Activity/Consumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* 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 Flávio Gomes da Silva Lisboa <flavio.lisboa@fgsl.eti.br>
* @copyright 2018
* @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\Activity;

use OCP\Activity\IConsumer;
use OCP\Activity\IManager;
use OCA\Activity\Data;
use OCA\Activity\UserSettings;
use OCP\L10N\IFactory;
use OCP\Activity\IEvent;

class Consumer implements IConsumer {
/** @var Data */
protected $data;
/** @var IManager */
protected $manager;

/** @var UserSettings */
protected $userSettings;

/** @var IFactory */
protected $l10nFactory;

/**
* Constructor
*
* @param Data $data
* @param IManager $manager
* @param UserSettings $userSettings
* @param IFactory $l10nFactory
*/
public function __construct(Data $data, IManager $manager, UserSettings $userSettings, IFactory $l10nFactory) {
$this->data = $data;
$this->manager = $manager;
$this->userSettings = $userSettings;
$this->l10nFactory = $l10nFactory;
}

/**
* Send an event to the notifications of a user
*
* @param IEvent $event
* @return null
*/
public function receive(IEvent $event) {
$selfAction = $event->getAffectedUser() === $event->getAuthor();
$emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType());
$emailSetting = ($emailSetting) ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false;

// User is not the author or wants to see their own actions
$createStream = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self');

// Add activity to stream
try {
$this->data->send($event);
} catch (\Exception $e) {
OC::$server->getLogger()->logException($e);
}
// User is not the author or wants to see their own actions
$createEmail = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail');

// Add activity to mail queue
if ($emailSetting !== false && $createEmail) {
$latestSend = $event->getTimestamp() + $emailSetting;
$this->data->storeMail($event, $latestSend);
}
}
}
32 changes: 27 additions & 5 deletions lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Provider implements IProvider {

/** @var ProviderSubjectLink */
private $parserLink;

/** @var ProviderSubjectShared */
private $parserShared;

/** @var MiscService */
protected $miscService;
Expand All @@ -66,7 +69,7 @@ class Provider implements IProvider {
public function __construct(
IManager $activityManager, MiscService $miscService, ProviderSubjectCircle $parserCircle,
ProviderSubjectMember $parserMember, ProviderSubjectGroup $parserGroup,
ProviderSubjectLink $parserLink
ProviderSubjectLink $parserLink, ProviderSubjectShared $parserShared
) {
$this->activityManager = $activityManager;
$this->miscService = $miscService;
Expand All @@ -75,6 +78,7 @@ public function __construct(
$this->parserMember = $parserMember;
$this->parserGroup = $parserGroup;
$this->parserLink = $parserLink;
$this->parserShared = $parserShared;
}


Expand All @@ -92,9 +96,11 @@ public function parse($lang, IEvent $event, IEvent $previousEvent = null) {
$this->setIcon($event, $circle);
$this->parseAsMember($event, $circle, $params);
$this->parseAsModerator($event, $circle, $params);

} catch (FakeException $e) {
/** clean exit */
} catch (InvalidArgumentException $e) {
/** sharing is a special case because app is files **/
$this->parseShared($event, $params);
}

return $event;
Expand All @@ -110,7 +116,7 @@ private function initActivityParser(IEvent $event, $params) {
throw new InvalidArgumentException();
}

if (!key_exists('circle', $params)) {
if ($event->getApp() === Application::APP_NAME && !key_exists('circle', $params)) {
throw new InvalidArgumentException();
}
}
Expand Down Expand Up @@ -252,5 +258,21 @@ private function parseLinkAsModerator(IEvent $event, Circle $circle, $params) {
$this->parserLink->parseLinkRemove($event, $circle, $remote);
}


}
/**
* @param IEvent $event
* @param array $params
*
* @throws FakeException
*/
private function parseShared(IEvent &$event, $params) {
if ($event->getSubject() === 'shared_circle_self') {
$this->parserShared->parseSubjectSharedWithCircle($event, $params);
return;
}
if ($event->getSubject() === 'unshared_circle_self') {
$this->parserShared->parseSubjectUnsharedWithCircle($event, $params);
return;
}
throw new InvalidArgumentException();
}
}
109 changes: 109 additions & 0 deletions lib/Activity/ProviderSubjectShared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* 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 Flávio Gomes da Silva Lisboa <flavio.lisboa@fgsl.eti.br>
* @copyright 2018
* @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\Activity;

use OCA\Circles\Exceptions\FakeException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\FederatedLink;
use OCA\Circles\Model\Member;
use OCP\Activity\IEvent;
use OCA\Circles\Api\v1\Circles;

class ProviderSubjectShared extends ProviderParser {
/**
* @param IEvent $event
* @param array $params
*
* @throws FakeException
*/
public function parseSubjectSharedWithCircle(IEvent &$event, array $params) {
$this->parseSharedEvent(
$event, $params, null,
$this->l10n->t('You shared {file} with circle {circle}'),
$this->l10n->t('{author} shared {file} with the circle {circle}')
);
}

/**
* @param IEvent $event
* @param array $params
*
* @throws FakeException
*/
public function parseSubjectUnsharedWithCircle(IEvent &$event, array $params) {
$this->parseSharedEvent(
$event, $params, null,
$this->l10n->t('You unshared {file} with the circle {circle}'),
$this->l10n->t('{author} unshared {file} with the circle {circle}')
);
}

/**
* general function to generate Circle event.
*
* @param IEvent $event
* @param array $params
* @param FederatedLink|null $remote
* @param string $ownEvent
* @param string $othersEvent
*/
protected function parseSharedEvent(IEvent &$event, array $params, $remote, $ownEvent, $othersEvent
) {
$circle = Circles::infoCircleByName($params['circle']['name']);
$path = Circles::getViewPath($params['file']['id']);

$data = [
'author' => [
'type' => 'user',
'id' => $params['author']['id'],
'name' => $params['author']['name'],
'_parsed' => $params['author']['name']
],
'circle' => [
'type' => 'circle',
'id' => $circle->getId(),
'name' => $circle->getName(),
'_parsed' => $circle->getName(),
'link' => Circles::generateLink($circle->getUniqueId())
],
'file' => [
'type' => 'file',
'id' => $params['file']['id'],
'name' => $params['file']['name'],
'path' => $path,
'link' => \OC::$server->getURLGenerator ()->linkToRouteAbsolute('files.view.index', array (
'dir' => ($params['file']['type'] !== 'file') ? dirname($path) : $path) )
]
];

if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) {
$this->setSubject($event, $ownEvent, $data);
return;
}

$this->setSubject($event, $othersEvent, $data);
}
}
34 changes: 33 additions & 1 deletion lib/Api/v1/Circles.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCA\Circles\Service\SharingFrameService;
use OCP\AppFramework\QueryException;
use OCP\Util;
use OC\Files\View;

class Circles {

Expand Down Expand Up @@ -544,4 +545,35 @@ public static function getFilesForCircles($circleUniqueIds) {
return $c->query(CirclesService::class)
->getFilesForCircles($circleUniqueIds);
}
}

/**
* Get a list of objects which are shred with $circleUniqueId.
*
* @since 0.15.0
*
* @param string $circleName
*
* @return Circle|null
* @throws CircleDoesNotExistException
*/
public static function infoCircleByName($circleName) {
$c = self::getContainer();
return $c->query(CirclesService::class)
->infoCircleByName($circleName);
}

/**
* Get path of a file from id.
*
* @since 0.15.0
*
* @param string $id
*
* @return string|null
*/
public static function getViewPath($id) {
$c = self::getContainer();
return $c->query(View::class)
->getPath($id);
}
}
20 changes: 18 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Util;

use OCA\Circles\Activity\Consumer;

class Application extends App {

Expand Down Expand Up @@ -70,6 +70,12 @@ public function registerHooks() {
Util::connectHook(
'OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted'
);
Util::connectHook(
'OCP\Share', 'post_shared', '\OCA\Circles\Hooks\UserHooks', 'onItemShared'
);
Util::connectHook(
'OCP\Share', 'post_unshared', '\OCA\Circles\Hooks\UserHooks', 'onItemUnshared'
);
}


Expand Down Expand Up @@ -134,6 +140,16 @@ function() {
}
);
}


/**
*
*/
public function registerConsumers()
{
$c = $this->getContainer();
\OC::$server->getActivityManager()->registerConsumer(function() use ($c){
return $c->query(Consumer::class);
});
}
}

Loading