Skip to content

Commit

Permalink
Enable audit by configuration nextcloud#163
Browse files Browse the repository at this point in the history
- audit of following actions:
- user X created circle Z;
- user X removed circle Z;
- user X change name of circle Z for circle W;
- user X was added to circle U by user Z;
- user X shared file/folder with circle Y;
- user X, that created circle, unshared file/folder with circle Y
- member X accepted invitation to circle Y by user Z;
- member X left circle Y;
- user X change role of member Y in circle Z for W.
- user X was invited to circle U by user Z
- adjust circles to emit signals of sharing to activity
  • Loading branch information
Flávio Gomes da Silva Lisboa committed Aug 16, 2018
1 parent 8a2fdbb commit 6a6ce03
Show file tree
Hide file tree
Showing 19 changed files with 670 additions and 55 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ Anyone can find the circle and request an invitation; but only members will see
- A **Secret Circle** is an hidden group that can only be seen by its members or by people knowing the exact name of the circle.
Non-members won't be able to find your secret circle using the search bar.

## Settings

Circles settings is available in Nextcloud interface in **Settings / Additional Settings**.

### Async Testing

This option allows to initiate an async test in Circles.

### Allow linking of groups

This option allows that groups be linked to circles.

### Allow federated circles

This option allows that circles from different Nextclouds can be linked together.

### Enable audit

This options allows that actions of circles, members and sharing can be audit with records into log. Following actions are audited:

* User X created circle Z;
* User X removed circle Z;
* User X change name of circle Z for circle W;
* User X was added to circle U by user Z;
* User X shared file/folder with circle Y;
* User X, that created circle, unshared file/folder with circle Y
* Member X accepted invitation to circle Y by user Z;
* Member X left circle Y;
* User X change role of member Y in circle Z for W.
* User X was invited to circle U by user Z

***
# API (PHP & Javascript)
Expand Down
32 changes: 16 additions & 16 deletions css/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
padding: 20px;
}

#circle-navigation .navigation-element, #circle-navigation .navigation-element option {
#app-navigation .navigation-element, #app-navigation .navigation-element option {
padding: 3px 12px;
}

#circle-navigation input#circles_search, #circle-navigation select#circles_filters {
#app-navigation input#circles_search, #app-navigation select#circles_filters {
margin: 10px;
width: 225px;
width: 285px;
}

#circle-navigation select#circles_filters {
#app-navigation select#circles_filters {
margin-top: 0;
font-style: italic;
color: #777777;
}

#circle-navigation input, #circle-navigation select, #circle-navigation option {
#app-navigation input, #app-navigation select, #app-navigation option {
width: 100%;
box-sizing: border-box;
background: #ffffffaa !important;
Expand All @@ -29,7 +29,7 @@
overflow-x: hidden;
}

#circle-navigation .header {
#app-navigation .header {
padding: 0 12px;
line-height: 44px;
min-height: 44px;
Expand All @@ -39,7 +39,7 @@
#circles_new_type_definition div {
margin-top: 20px;
position: absolute;
width: 190px;
width: 255px;
color: #474747b0;
word-wrap: break-word;
}
Expand All @@ -51,7 +51,7 @@ SELECT.select_none {
#circles_list, #circles_list .lightenbg {
position: absolute;
width: 100%;
top: 350px;
top: 300px;
}

#circles_list div {
Expand All @@ -75,28 +75,28 @@ SELECT.select_none {
font-weight: bold !important;
}

#circle-navigation {
#app-navigation {
width: 300px;
border-right: 1px solid #ddd;
}

#circle-navigation.circles {
#app-navigation.circles {
overflow-y: auto;
width: 350px;
overflow-x: hidden;
z-index: 1002;
}

#circle-navigation.circles, #circle-navigation.circles .circle, #circle-navigation.circles .selected {
#app-navigation.circles, #app-navigation.circles .circle, #app-navigation.circles .selected {
-webkit-transition: background-color 0.3s ease-in;
transition: background-color 0.3s ease-in;
}

#circle-navigation.selected {
#app-navigation.selected {
background: #ededed !important;
}

#circle-navigation.circles .selected {
#app-navigation.circles .selected {
background: #e5e5e5;
}

Expand Down Expand Up @@ -216,8 +216,8 @@ div.circle .owner, div.circle .type, div.circle .resume {

#emptycontent {
position: absolute;
z-index: 1001;
left: 0px;
z-index: -99;
left: 200px;
}

#circle-actions {
Expand Down Expand Up @@ -354,4 +354,4 @@ DIV.result_bot {
padding: 5px;
height: 10px;
font-style: italic;
}
}
2 changes: 1 addition & 1 deletion js/circles.app.elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var elements = {
elements.newType = $('#circles_new_type');
elements.newSubmit = $('#circles_new_submit');
elements.newName = $('#circles_new_name');
elements.navigation = $('#circle-navigation.circles');
elements.navigation = $('#app-navigation.circles');
elements.circlesList = $('#circles_list');
elements.circlesSearch = $('#circles_search');
elements.circlesFilters = $('#circles_filters');
Expand Down
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);
}
}
}
30 changes: 26 additions & 4 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();
}
}
6 changes: 3 additions & 3 deletions lib/Activity/ProviderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function parseCircleEvent(IEvent &$event, Circle $circle, $remote, $ow
* @param string $line
* @param array $data
*/
private function setSubject(IEvent $event, $line, $data) {
protected function setSubject(IEvent $event, $line, $data) {
$this->setParsedSubject($event, $line, $data);
$this->setRichSubject($event, $line, $data);
}
Expand All @@ -110,7 +110,7 @@ private function setSubject(IEvent $event, $line, $data) {
* @param string $line
* @param array $data
*/
private function setRichSubject(IEvent $event, $line, $data) {
protected function setRichSubject(IEvent $event, $line, $data) {
$ak = array_keys($data);
foreach ($ak as $k) {
$subAk = array_keys($data[$k]);
Expand All @@ -130,7 +130,7 @@ private function setRichSubject(IEvent $event, $line, $data) {
* @param string $line
* @param array $data
*/
private function setParsedSubject(IEvent $event, $line, $data) {
protected function setParsedSubject(IEvent $event, $line, $data) {
$ak = array_keys($data);
$replace = [];
foreach ($ak as $k) {
Expand Down
Loading

0 comments on commit 6a6ce03

Please sign in to comment.