Skip to content

Commit

Permalink
Enable audit by configuration nextcloud#163
Browse files Browse the repository at this point in the history
  • Loading branch information
Flávio Gomes da Silva Lisboa committed Dec 19, 2017
1 parent 41bb627 commit c733a80
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 19 deletions.
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
$app->registerNavigation();
$app->registerFilesNavigation();
$app->registerFilesPlugin();

$app->registerHooks();

11 changes: 10 additions & 1 deletion js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ $(document).ready(function () {
elements.test_async_result = $('#test_async_result');
elements.allow_linked_groups = $('#allow_linked_groups');
elements.allow_federated_circles = $('#allow_federated_circles');
elements.enable_audit = $('#enable_audit');

elements.test_async_wait.hide().on('click', function () {
self.refreshResult();
Expand Down Expand Up @@ -74,6 +75,10 @@ $(document).ready(function () {
elements.allow_federated_circles.on('change', function () {
saveChange();
});

elements.enable_audit.on('change', function () {
saveChange();
});

saveChange = function () {
$.ajax({
Expand All @@ -83,11 +88,14 @@ $(document).ready(function () {
allow_linked_groups: (elements.allow_linked_groups.is(
':checked')) ? '1' : '0',
allow_federated_circles: (elements.allow_federated_circles.is(
':checked')) ? '1' : '0'
':checked')) ? '1' : '0',
enable_audit: (elements.enable_audit.is(
':checked')) ? '1' : '0'
}
}).done(function (res) {
elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1'));
elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1'));
elements.enable_audit.prop('checked', (res.enableAudit === '1'));
});
};

Expand Down Expand Up @@ -170,6 +178,7 @@ $(document).ready(function () {
}).done(function (res) {
elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1'));
elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1'));
elements.enable_audit.prop('checked', (res.enableAudit === '1'));
});

var timerTestAsync = setInterval(function () {
Expand Down
3 changes: 2 additions & 1 deletion js/circles.app.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ var actions = {
circle_desc: elements.settingsDesc.val(),
allow_links: (elements.settingsLink.is(":checked")),
allow_links_auto: (elements.settingsLinkAuto.is(":checked")),
allow_links_files: (elements.settingsLinkFiles.is(":checked"))
allow_links_files: (elements.settingsLinkFiles.is(":checked")),
enable_audit: (elements.settingsEnableAudit.is(":checked"))
};

api.settingsCircle(curr.circle, data, settings.saveSettingsResult);
Expand Down
2 changes: 2 additions & 0 deletions js/circles.app.elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var elements = {
settingsEntryLink: null,
settingsEntryLinkAuto: null,
settingsEntryLinkFiles: null,
settingsEnableAudit: null,
settingsSave: null,

addMember: null,
Expand Down Expand Up @@ -131,6 +132,7 @@ var elements = {
elements.settingsEntryLink = $('#settings-entry-link');
elements.settingsEntryLinkAuto = $('#settings-entry-link-auto');
elements.settingsEntryLinkFiles = $('#settings-entry-link-files');
elements.settingsEnableAudit = $('#settings-enable-audit');
elements.settingsSave = $('#settings-submit');

elements.addMember = $('#addmember');
Expand Down
2 changes: 2 additions & 0 deletions js/circles.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var curr = {
allowed_linked_groups: 0,
allowed_federated_circles: 0,
allowed_circles: 0,
enabled_audit: 0,

defineCircle: function (data) {
curr.circle = data.circle_id;
Expand Down Expand Up @@ -192,6 +193,7 @@ $(document).ready(function () {
curr.allowed_circles = result.allowed_circles;
curr.allowed_linked_groups = result.allowed_linked_groups;
curr.allowed_federated_circles = result.allowed_federated_circles;
curr.enabled_audit = result.enabled_audit;

var circleId = window.location.hash.substr(1);
if (circleId) {
Expand Down
10 changes: 6 additions & 4 deletions js/circles.app.settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var settings = {
(curr.circleSettings['allow_links_auto'] === 'true'));
elements.settingsLinkFiles.prop('checked',
(curr.circleSettings['allow_links_files'] === 'true'));
elements.settingsEnableAudit.prop('checked',
(curr.circleSettings['enable_audit'] === 'true'));

elements.settingsLink.on('change', function () {
settings.interactUISettings();
Expand All @@ -79,6 +81,9 @@ var settings = {
(elements.settingsLink.is(":checked")));
settings.enableSetting(elements.settingsEntryLinkFiles, elements.settingsLinkFiles,
(elements.settingsLink.is(":checked")));
settings.enableSetting(elements.settingsEntryEnableAudit, elements.settingsEnableAudit,
(elements.settingsEnableAudit.is(":checked")));

},

enableSetting: function (entry, input, enable) {
Expand All @@ -100,7 +105,4 @@ var settings = {
nav.displayMembersInteraction(result.details);
OCA.notification.onSuccess(t('circles', "Settings saved."));
}
};



};
4 changes: 3 additions & 1 deletion l10n/pt_BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ OC.L10N.register(
"Allow linking of groups:" : "Permitir links dos grupos:",
"Groups can be linked to circles." : "Grupos podem ser linkados a círculos.",
"Allow federated circles:" : "Permitir círculos federados:",
"Circles from different Nextclouds can be linked together." : "Círculos de diferentes Nextclouds podem ser linkados juntos."
"Circles from different Nextclouds can be linked together." : "Círculos de diferentes Nextclouds podem ser linkados juntos.",
"Enable audit:" : "Habilitar auditoria:",
"Actions of circles, members and sharing can be audited." : "Ações de círculos, membros e compartilhamentos podem ser auditadas."
},
"nplurals=2; plural=(n > 1);");
4 changes: 3 additions & 1 deletion l10n/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
"Allow linking of groups:" : "Permitir links dos grupos:",
"Groups can be linked to circles." : "Grupos podem ser linkados a círculos.",
"Allow federated circles:" : "Permitir círculos federados:",
"Circles from different Nextclouds can be linked together." : "Círculos de diferentes Nextclouds podem ser linkados juntos."
"Circles from different Nextclouds can be linked together." : "Círculos de diferentes Nextclouds podem ser linkados juntos.",
"Enable audit:" : "Habilitar auditoria:",
"Actions of circles, members and sharing can be audited." : "Ações de círculos, membros e compartilhamentos podem ser auditadas."
},"pluralForm" :"nplurals=2; plural=(n > 1);"
}
4 changes: 3 additions & 1 deletion lib/Api/v1/Circles.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@ public static function shareToCircle(
$frame = new SharingFrame((string)$source, (string)$type);
$frame->setPayload($payload);

return $c->query(SharingFrameService::class)
$result = $c->query(SharingFrameService::class)
->createFrame($circleUniqueId, $frame, (string)$broadcaster);

return $result;
}


Expand Down
21 changes: 21 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ public function registerHooks() {
Util::connectHook(
'OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted'
);
Util::connectHook(
'OCA\Circles', 'post_createCircle', '\OCA\Circles\Hooks\UserHooks', 'onCircleCreated'
);
Util::connectHook(
'OCA\Circles', 'post_destroyCircle', '\OCA\Circles\Hooks\UserHooks', 'onCircleDestroyed'
);
Util::connectHook(
'OCA\Circles', 'post_updateCircle', '\OCA\Circles\Hooks\UserHooks', 'onCircleUpdated'
);
Util::connectHook(
'OCA\Circles', 'post_addMember', '\OCA\Circles\Hooks\UserHooks', 'onMemberAdded'
);
Util::connectHook(
'OCA\Circles', 'post_removeMember', '\OCA\Circles\Hooks\UserHooks', 'onMemberRemoved'
);
Util::connectHook(
'OCP\Share', 'post_share', '\OCA\Circles\Hooks\UserHooks', 'onItemShared'
);
Util::connectHook(
'OCP\Share', 'post_unshare', '\OCA\Circles\Hooks\UserHooks', 'onItemUnshared'
);
}


Expand Down
19 changes: 16 additions & 3 deletions lib/Controller/CirclesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use OCA\Circles\Exceptions\CircleTypeDisabledException;
use OCA\Circles\Exceptions\FederatedCircleNotAllowedException;
use OCP\AppFramework\Http\DataResponse;
use OCA\Circles\Model\Circle;
use OCP\Util;

class CirclesController extends BaseController {

Expand All @@ -51,7 +53,9 @@ public function create($type, $name) {
try {
$this->verifyCreationName($name);
$data = $this->circlesService->createCircle($type, $name);

if ($this->configService->isAuditEnabled()){
Util::emitHook('OCA\Circles', 'post_createCircle', ['circle' => $name]);
}
return $this->success(['name' => $name, 'circle' => $data, 'type' => $type]);
} catch (Exception $e) {
return $this->fail(['type' => $type, 'name' => $name, 'error' => $e->getMessage()]);
Expand Down Expand Up @@ -116,8 +120,13 @@ public function details($uniqueId) {
public function settings($uniqueId, $settings) {
try {
$this->verifyCreationName($settings['circle_name']);
$formerCircle = $this->details($uniqueId)->getData()['details']->getName();
$circle = $this->circlesService->settingsCircle($uniqueId, $settings);

if ($this->configService->isAuditEnabled()){
$settings['former_name']= $formerCircle;
Util::emitHook('OCA\Circles', 'post_updateCircle', $settings);
}

return $this->success(['circle_id' => $uniqueId, 'details' => $circle]);
} catch (\Exception $e) {

Expand Down Expand Up @@ -178,8 +187,12 @@ public function leave($uniqueId) {
*/
public function destroy($uniqueId) {
try {
$circle = $this->details($uniqueId)->getData()['details']->getName();
$this->circlesService->removeCircle($uniqueId);

if ($this->configService->isAuditEnabled()){
Util::emitHook('OCA\Circles', 'post_destroyCircle', ['circle' => $circle]);
}

return $this->success(['circle_id' => $uniqueId]);
} catch (\Exception $e) {
return $this->fail(['circle_id' => $uniqueId, 'error' => $e->getMessage()]);
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/MembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Circles\Model\Member;
use OCA\Circles\Service\MiscService;
use OCP\AppFramework\Http\DataResponse;
use OCP\Util;

class MembersController extends BaseController {

Expand All @@ -47,6 +48,10 @@ public function addMember($uniqueId, $ident, $type) {

try {
$data = $this->membersService->addMember($uniqueId, $ident, (int)$type);
if ($this->configService->isAuditEnabled()){
$circle = $this->circlesService->detailsCircle($uniqueId);
Util::emitHook('OCA\Circles', 'post_addMember', ['circle' => $circle->getName(), 'member' => $ident]);
}
} catch (\Exception $e) {
return $this->fail(
[
Expand Down Expand Up @@ -127,6 +132,10 @@ public function removeMember($uniqueId, $member, $type) {

try {
$data = $this->membersService->removeMember($uniqueId, $member, (int)$type);
if ($this->configService->isAuditEnabled()){
$circle = $this->circlesService->detailsCircle($uniqueId);
Util::emitHook('OCA\Circles', 'post_removeMember', ['circle' => $circle->getName(), 'member' => $member]);
}
} catch (\Exception $e) {
return
$this->fail(
Expand Down
8 changes: 7 additions & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,26 @@ public function getSettings() {
),
'allowFederatedCircles' => $this->configService->getAppValue(
ConfigService::CIRCLES_ALLOW_FEDERATED_CIRCLES
),
'enableAudit' => $this->configService->getAppValue(
ConfigService::CIRCLES_ENABLE_AUDIT
)
];

return $params;
}


public function setSettings($allow_linked_groups, $allow_federated_circles) {
public function setSettings($allow_linked_groups, $allow_federated_circles, $enable_audit) {
$this->configService->setAppValue(
ConfigService::CIRCLES_ALLOW_LINKED_GROUPS, $allow_linked_groups
);
$this->configService->setAppValue(
ConfigService::CIRCLES_ALLOW_FEDERATED_CIRCLES, $allow_federated_circles
);
$this->configService->setAppValue(
ConfigService::CIRCLES_ENABLE_AUDIT, $enable_audit
);

return $this->getSettings();
}
Expand Down
Loading

0 comments on commit c733a80

Please sign in to comment.