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

Improve code occ files_external:list --short #34033

Merged
merged 1 commit into from
Feb 19, 2019
Merged

Improve code occ files_external:list --short #34033

merged 1 commit into from
Feb 19, 2019

Conversation

mmattel
Copy link
Contributor

@mmattel mmattel commented Jan 4, 2019

Description

This PR improves the code for the --short option in occ command files_external:list

  • removing unnecessary double code paths - make one code stream for:
    standard output and json output
  • greatly improving the array handling by using if statemens instead looping thru arrays
  • better output of --all and if a user is given

Related Issue

Motivation and Context

Better code, easier to handle and enhance. Better output

How Has This Been Tested?

Screenshots (if appropriate):

Commands

sudo -uwww-data ./occ files_external:list -s 
+----------+-------------+------------------+-------------------+------+-------+
| Mount ID | Mount Point | Applicable Users | Applicable Groups | Auth | Type  |
+----------+-------------+------------------+-------------------+------+-------+
| 2        | /test       | user_x           | admin, testg      | User | Admin |
+----------+-------------+------------------+-------------------+------+-------+

sudo -uwww-data ./occ files_external:list -s user_y
+----------+---------------+------+----------+
| Mount ID | Mount Point   | Auth | Type     |
+----------+---------------+------+----------+
| 1        | /martin@filer | User | Personal |
+----------+---------------+------+----------+

sudo -uwww-data ./occ files_external:list -s -a
+----------+---------------+------------------+-------------------+------+----------+
| Mount ID | Mount Point   | Applicable Users | Applicable Groups | Auth | Type     |
+----------+---------------+------------------+-------------------+------+----------+
| 1        | /martin@filer | user_y           |                   | User | Personal |
| 2        | /test         | user_x           | admin, testg      | User | Admin    |
+----------+---------------+------------------+-------------------+------+----------+

Auth
This new field shows if a mount is based on User/Pwd (User) or Session (Session).
This info is important when using files:scan as session based mounts cant be scanned by occ.

The output of json is tested and correct to the plain one

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

@codecov
Copy link

codecov bot commented Jan 5, 2019

Codecov Report

Merging #34033 into master will increase coverage by 1.28%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34033      +/-   ##
============================================
+ Coverage     64.77%   66.05%   +1.28%     
- Complexity    18340    18503     +163     
============================================
  Files          1198     1152      -46     
  Lines         69418    66556    -2862     
  Branches       1276     1276              
============================================
- Hits          44964    43966     -998     
+ Misses        24085    22221    -1864     
  Partials        369      369
Flag Coverage Δ Complexity Δ
#javascript 53.09% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 67.62% <ø> (+1.5%) 18503 <ø> (+163) ⬆️
Impacted Files Coverage Δ Complexity Δ
apps/files_external/lib/config.php 3.75% <0%> (-6.97%) 21% <0%> (+2%)
apps/files_external/lib/Lib/Api.php
apps/files_external/lib/Lib/Backend/SFTP_Key.php
apps/files_external/ajax/applicable.php
apps/files_external/lib/Command/Backends.php
apps/files_external/lib/Lib/Backend/DAV.php
apps/files_external/lib/Lib/Backend/OwnCloud.php
apps/files_external/lib/Lib/Storage/OwnCloud.php
apps/files_external/lib/Command/Verify.php
apps/files_external/lib/Lib/Backend/SMB.php
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 361472c...5babef9. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 5, 2019

Codecov Report

Merging #34033 into master will decrease coverage by 0.01%.
The diff coverage is 77.64%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #34033      +/-   ##
============================================
- Coverage     65.15%   65.14%   -0.02%     
  Complexity    18352    18352              
============================================
  Files          1200     1200              
  Lines         69698    69672      -26     
  Branches       1283     1283              
============================================
- Hits          45413    45388      -25     
+ Misses        23911    23910       -1     
  Partials        374      374
Flag Coverage Δ Complexity Δ
#javascript 53.1% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 66.53% <77.64%> (-0.02%) 18352 <0> (ø)
Impacted Files Coverage Δ Complexity Δ
apps/files_external/lib/Command/ListCommand.php 67.66% <77.64%> (-3.84%) 0 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2dedd3d...bccc328. Read the comment docs.

@mmattel
Copy link
Contributor Author

mmattel commented Jan 5, 2019

@sharidas can you help fixing the tests ?

@sharidas
Copy link
Contributor

sharidas commented Jan 9, 2019

I have made a change to my oC instance for example:
external

And in the user2 personal storage I added sftp:
external_user2

And after making this setting in the UI, I try to run the command as shown below:
For user2:
ex2
For user1:
ex3

From the user perspective who executes this command, I would expect the no mounts configured for user1. Am I missing something here? @mmattel

@mmattel
Copy link
Contributor Author

mmattel commented Jan 9, 2019

I agree with you - it is not clean, but it is a matter of the definition of --all which I did not change from the logic side. show both system wide mounts and all personal mounts

	protected function execute(InputInterface $input, OutputInterface $output) {
		if ($input->getOption('all')) {
			/** @var  $mounts IStorageConfig[] */
			$mounts = $this->globalService->getStorageForAllUsers();
			$userId = self::ALL;
		} else {
			$userId = $input->getArgument('user_id');
			$storageService = $this->getStorageService($userId);

			/** @var  $mounts IStorageConfig[] */
			$mounts = $storageService->getAllStorages();
		}

		$this->listMounts($userId, $mounts, $input, $output);
	}

From that what I read above and from the other code elements where ALL is queried, --all has precedence over a user

So if we want to combine --all and user we would need an additional filter logic - or?
Or just be more precise in the helptext of --all...

@mmattel
Copy link
Contributor Author

mmattel commented Jan 16, 2019

Improved helptext

Arguments:
  user_id                User id to list the personal mounts for, if no user is provided admin mounts will be listed

Options:
      --show-password    Show passwords and secrets
      --full             Don't truncate long values in table output
  -a, --all              Show mounts for all users. All has precedence over user_id
  -s, --short            Show only a reduced mount info
      --output[=OUTPUT]  The output format to use (plain, json or json_pretty). [default: "plain"]

@davitol
Copy link
Contributor

davitol commented Jan 17, 2019

Tested and the behavior is like commented in #34033 (comment)

IMHO, behavior should be like commented in #34033 (comment) . From the user perspective who executes this command, I would expect the no mounts configured for user1 when using -a option. Anyway, now it is documented in the help with Show mounts for all users. All has precedence over user_id

@PVince81
Copy link
Contributor

Seems this implementation aligns with how occ files:scan --all user1 works, so let's keep it for consistency.

@PVince81
Copy link
Contributor

@ownclouders rebase

@ownclouders
Copy link
Contributor

Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently ⚠️

@ownclouders
Copy link
Contributor

Automated rebase with GitMate.io was successful! 🎉

@PVince81
Copy link
Contributor

PVince81 commented Feb 8, 2019

@mmattel please run make test-php-style-fix

@mmattel
Copy link
Contributor Author

mmattel commented Feb 8, 2019

@PVince81 Question:
updating master, running make clean and make rebasing this PR and running make test-php-style-fix I get following error message:

composer bin owncloud-codestyle install --no-progress
                                 
  [InvalidArgumentException]     
  Command "bin" is not defined.  
                                 

Makefile:364: recipe for target 'vendor-bin/owncloud-codestyle/vendor' failed
make: *** [vendor-bin/owncloud-codestyle/vendor] Error 1

Any ideas ?

@PVince81
Copy link
Contributor

PVince81 commented Feb 8, 2019

@phil-davis ^

@phil-davis
Copy link
Contributor

phil-davis commented Feb 11, 2019

What to say? I just did

git fetch origin
git checkout master
git pull
make clean
make
make test-php-style

and it works hard for a while loading loads of dependencies for make and then for make test-php-style and finally it runs the style tests:

Changed current directory to vendor-bin/php_codesniffer
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing squizlabs/php_codesniffer (3.4.0): Loading from cache
Writing lock file
Generating autoload files
php -d zend.enable_gc=0 vendor-bin/owncloud-codestyle/vendor/bin/php-cs-fixer fix -v --diff --diff-format udiff --allow-risky yes --dry-run
Loaded config ownCloud coding standard from "/home/phil/git/owncloud/core/.php_cs.dist".
Using cache file ".php_cs.cache".
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error

Checked all files in 29.321 seconds, 28.000 MB memory used
vendor-bin/php_codesniffer/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit --standard=phpcs.xml tests/acceptance tests/TestHelpers
............................................................  60 / 107 (56%)
...............................................              107 / 107 (100%)


Time: 7.6 secs; Memory: 26MB

php build/OCPSinceChecker.php
Parsing all files in lib/public for the presence of @since or @deprecated on each method...

in the make it should be getting:

  - Installing bamarni/composer-bin-plugin (v1.2.0): Loading from cache

that is the magic thing that makes the composer bin command exist.

@mmattel
Copy link
Contributor Author

mmattel commented Feb 18, 2019

I have updated the PR, run php-style-fix, added tests, squashed the commits

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PVince81 PVince81 merged commit c62fd07 into master Feb 19, 2019
@PVince81 PVince81 deleted the improve_short branch February 19, 2019 08:27
@PVince81
Copy link
Contributor

@mmattel please backport

mmattel pushed a commit that referenced this pull request Feb 19, 2019
Improve code occ files_external:list --short
@lock lock bot locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants