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

Create shares list report + send it by email + diff #332

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ This app allows generating reports of shares on the system.

## Usage

### Command
### Commands

#### List

```sh
./occ sharing:list [-u|--user [USER]] [-p|--path [PATH]] [-t|--token [TOKEN]] [-f|--filter [FILTER]] [-o|--output FORMAT]
Expand All @@ -13,7 +15,7 @@ This app allows generating reports of shares on the system.
Without options, the command yields the unfiltered list of all shares.\
With options, the list is narrowed down using the filters set.

### Options
##### Options

* `-u [USER]` or `--user [USER]`\
List only shares of the given user.
Expand All @@ -27,6 +29,33 @@ With options, the list is narrowed down using the filters set.
* `-o FORMAT` or `--output FORMAT`\
Set the output format (json or csv, default is json).

#### Send

```sh
./occ sharing:send [-u|--user USER] [-p|--path PATH] [-t|--token TOKEN] [-f|--filter FILTER] [-o|--output FORMAT]
```

Without options, the command yields the unfiltered list of all shares.\
With options, the list is narrowed down using the filters set.

##### Options

* `-r` or `--recipients`\
Recipients users of generated reports.
* `-x` or `--target-path`\
Generated reports will be stored on this path.
* `-d` or `--diff`\
Create a differential report in json format from the last available report.
* `-u [USER]` or `--user [USER]`\
List only shares of the given user.
* `-p [PATH]` or `--path [PATH]`\
List only shares within the given path.
* `-t [TOKEN]` or `--token [TOKEN]`\
List only shares that use a token that (at least partly) matches the argument.
* `-f [FILTER]` or `--filter [FILTER]`\
List only shares where the TYPE matches the argument.\
Possible values for the filter argument: {owner, initiator, recipient}

## Examples

To better illustrate how the app work see the examples below:
Expand Down
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

<commands>
<command>OCA\ShareListing\Command\ListShares</command>
<command>OCA\ShareListing\Command\SendShares</command>
</commands>
</info>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"require": {
"nikic/iter": "^2.2",
"symfony/serializer": "^5.4"
"symfony/serializer": "^5.4",
"swaggest/json-diff": "^3.9"
},
"require-dev": {
"phpunit/phpunit": "^9",
Expand Down
45 changes: 44 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions lib/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Solution Libre SAS
* @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]>
*
* @author Florent Poinsaut <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author John Molakvoæ <[email protected]>
*
* @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\ShareListing\Command;

use OCA\ShareListing\Service\SharesList;
use OC\Core\Command\Base;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

abstract class AbstractCommand extends Base {
/** @var SharesList */
protected $sharesList;

public function __construct(SharesList $sharesList) {
parent::__construct();

$this->sharesList = $sharesList;
}

public function configure() {
$this->addOption(
'user',
'u',
InputOption::VALUE_OPTIONAL,
'Will list shares of the given user'
)
->addOption(
'path',
'p',
InputOption::VALUE_OPTIONAL,
'Will only consider the given path'
)->addOption(
'token',
't',
InputOption::VALUE_OPTIONAL,
'Will only consider the given token'
)->addOption(
'filter',
'f',
InputOption::VALUE_OPTIONAL,
'Filter shares, possible values: owner, initiator, recipient, token, has-expiration, no-expiration'
);
}

protected function getOptions(InputInterface $input): array {
$user = $input->getOption('user');
$path = $input->getOption('path');
$token = $input->getOption('token');
$filter = $this->sharesList->filterStringToInt($input->getOption('filter'));

return [$user, $path, $token, $filter];
}
}
66 changes: 5 additions & 61 deletions lib/Command/ListShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,16 @@
namespace OCA\ShareListing\Command;

use iter;
use OCA\ShareListing\Service\SharesList;
use OCP\Files\IRootFolder;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Share\IManager as ShareManager;
use OC\Core\Command\Base;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ListShares extends Base {

/** @var ShareManager */
private $shareManager;

/** @var IUserManager */
private $userManager;

/** @var IRootFolder */
private $rootFolder;

/** @var SharesList */
private $sharesList;

public function __construct(ShareManager $shareManager,
IUserManager $userManager,
IRootFolder $rootFolder,
SharesList $sharesList) {
parent::__construct();

$this->shareManager = $shareManager;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->sharesList = $sharesList;

}

class ListShares extends AbstractCommand {
public function configure() {
parent::configure();

$this->setName('sharing:list')
->setDescription('List who has access to shares by owner')
->addOption(
'user',
'u',
InputOption::VALUE_OPTIONAL,
'Will list shares of the given user'
)
->addOption(
'path',
'p',
InputOption::VALUE_OPTIONAL,
'Will only consider the given path'
)->addOption(
'token',
't',
InputOption::VALUE_OPTIONAL,
'Will only consider the given token'
)->addOption(
'filter',
'f',
InputOption::VALUE_OPTIONAL,
'Filter shares, possible values: owner, initiator, recipient, token, has-expiration, no-expiration'
)
->addOption(
'output',
'o',
Expand All @@ -98,12 +45,9 @@ public function configure() {
'json'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$user = $input->getOption('user');
$path = $input->getOption('path');
$token = $input->getOption('token');
$filter = $this->sharesList->filterStringToInt($input->getOption('filter'));
[$user, $path, $token, $filter] = $this->getOptions($input);
$outputOpt = $input->getOption('output');

$shares = iter\toArray($this->sharesList->getFormattedShares($user, $filter, $path, $token));
Expand Down
Loading