Skip to content

Commit 7b2811b

Browse files
feat: Create shares list report + send it by email + diff
Co-Authored-By: Florent Poinsaut <florent@solution-libre.fr> Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
1 parent db965ff commit 7b2811b

7 files changed

Lines changed: 608 additions & 47 deletions

File tree

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ This app allows generating reports of shares on the system.
44

55
## Usage
66

7-
### Command
7+
### Commands
8+
9+
#### List
810

911
```sh
1012
./occ sharing:list [-u|--user [USER]] [-p|--path [PATH]] [-t|--token [TOKEN]] [-f|--filter [FILTER]] [-o|--output FORMAT]
@@ -13,7 +15,7 @@ This app allows generating reports of shares on the system.
1315
Without options, the command yields the unfiltered list of all shares.\
1416
With options, the list is narrowed down using the filters set.
1517
16-
### Options
18+
##### Options
1719
1820
* `-u [USER]` or `--user [USER]`\
1921
List only shares of the given user.
@@ -27,6 +29,33 @@ With options, the list is narrowed down using the filters set.
2729
* `-o FORMAT` or `--output FORMAT`\
2830
Set the output format (json or csv, default is json).
2931
32+
#### Send
33+
34+
```sh
35+
./occ sharing:send [-u|--user USER] [-p|--path PATH] [-t|--token TOKEN] [-f|--filter FILTER] [-o|--output FORMAT]
36+
```
37+
38+
Without options, the command yields the unfiltered list of all shares.\
39+
With options, the list is narrowed down using the filters set.
40+
41+
##### Options
42+
43+
* `-r` or `--recipients`\
44+
Recipients users of generated reports.
45+
* `-x` or `--target-path`\
46+
Generated reports will be stored on this path.
47+
* `-d` or `--diff`\
48+
Create a differential report in json format from the last available report.
49+
* `-u [USER]` or `--user [USER]`\
50+
List only shares of the given user.
51+
* `-p [PATH]` or `--path [PATH]`\
52+
List only shares within the given path.
53+
* `-t [TOKEN]` or `--token [TOKEN]`\
54+
List only shares that use a token that (at least partly) matches the argument.
55+
* `-f [FILTER]` or `--filter [FILTER]`\
56+
List only shares where the TYPE matches the argument.\
57+
Possible values for the filter argument: {owner, initiator, recipient}
58+
3059
## Examples
3160
3261
To better illustrate how the app work see the examples below:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"require": {
4040
"nikic/iter": "^2.4",
4141
"symfony/serializer": "^5.4",
42-
"bamarni/composer-bin-plugin": "^1.8"
42+
"bamarni/composer-bin-plugin": "^1.8",
43+
"swaggest/json-diff": "^3.12"
4344
}
4445
}

composer.lock

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Command/AbstractCommand.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2022 Solution Libre SAS
5+
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @author Florent Poinsaut <florent@solution-libre.fr>
8+
* @author Roeland Jago Douma <roeland@famdouma.nl>
9+
* @author John Molakvoæ <skjnldsv@protonmail.com>
10+
*
11+
* @license GNU AGPL version 3 or any later version
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Affero General Public License as
15+
* published by the Free Software Foundation, either version 3 of the
16+
* License, or (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*
26+
*/
27+
28+
namespace OCA\ShareListing\Command;
29+
30+
use OCA\ShareListing\Service\SharesList;
31+
use OC\Core\Command\Base;
32+
use Symfony\Component\Console\Input\InputInterface;
33+
use Symfony\Component\Console\Input\InputOption;
34+
35+
abstract class AbstractCommand extends Base {
36+
/** @var SharesList */
37+
protected $sharesList;
38+
39+
public function __construct(SharesList $sharesList) {
40+
parent::__construct();
41+
42+
$this->sharesList = $sharesList;
43+
}
44+
45+
public function configure() {
46+
$this->addOption(
47+
'user',
48+
'u',
49+
InputOption::VALUE_OPTIONAL,
50+
'Will list shares of the given user'
51+
)
52+
->addOption(
53+
'path',
54+
'p',
55+
InputOption::VALUE_OPTIONAL,
56+
'Will only consider the given path'
57+
)->addOption(
58+
'token',
59+
't',
60+
InputOption::VALUE_OPTIONAL,
61+
'Will only consider the given token'
62+
)->addOption(
63+
'filter',
64+
'f',
65+
InputOption::VALUE_OPTIONAL,
66+
'Filter shares, possible values: owner, initiator, recipient, token, has-expiration, no-expiration'
67+
);
68+
}
69+
70+
protected function getOptions(InputInterface $input): array {
71+
$user = $input->getOption('user');
72+
$path = $input->getOption('path');
73+
$token = $input->getOption('token');
74+
$filter = $this->sharesList->filterStringToInt($input->getOption('filter'));
75+
76+
return [$user, $path, $token, $filter];
77+
}
78+
}

lib/Command/ListShares.php

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,15 @@
2727

2828
namespace OCA\ShareListing\Command;
2929

30-
use OC\Core\Command\Base;
31-
use OCA\ShareListing\Service\SharesList;
32-
use OCP\Files\IRootFolder;
33-
use OCP\IUserManager;
34-
use OCP\Share\IManager as ShareManager;
3530
use Symfony\Component\Console\Input\InputInterface;
3631
use Symfony\Component\Console\Input\InputOption;
3732
use Symfony\Component\Console\Output\OutputInterface;
3833
use function iter\toArray;
3934

40-
class ListShares extends Base {
41-
42-
public function __construct(
43-
private ShareManager $shareManager,
44-
private IUserManager $userManager,
45-
private IRootFolder $rootFolder,
46-
private SharesList $sharesList,
47-
) {
48-
parent::__construct();
49-
50-
}
51-
35+
class ListShares extends AbstractCommand {
5236
public function configure() {
5337
$this->setName('sharing:list')
5438
->setDescription('List who has access to shares by owner')
55-
->addOption(
56-
'user',
57-
'u',
58-
InputOption::VALUE_OPTIONAL,
59-
'Will list shares of the given user'
60-
)
61-
->addOption(
62-
'path',
63-
'p',
64-
InputOption::VALUE_OPTIONAL,
65-
'Will only consider the given path'
66-
)->addOption(
67-
'token',
68-
't',
69-
InputOption::VALUE_OPTIONAL,
70-
'Will only consider the given token'
71-
)->addOption(
72-
'filter',
73-
'f',
74-
InputOption::VALUE_OPTIONAL,
75-
'Filter shares, possible values: owner, initiator, recipient, token, has-expiration, no-expiration'
76-
)
7739
->addOption(
7840
'output',
7941
'o',
@@ -84,10 +46,7 @@ public function configure() {
8446
}
8547

8648
protected function execute(InputInterface $input, OutputInterface $output): int {
87-
$user = $input->getOption('user');
88-
$path = $input->getOption('path');
89-
$token = $input->getOption('token');
90-
$filter = $this->sharesList->filterStringToInt($input->getOption('filter'));
49+
[$user, $path, $token, $filter] = $this->getOptions($input);
9150
$outputOpt = $input->getOption('output');
9251

9352
$shares = toArray($this->sharesList->getFormattedShares($user, $filter, $path, $token));

0 commit comments

Comments
 (0)