Skip to content

Prevent creation of empty files/folders for accounts having no available quota#40505

Closed
pako81 wants to merge 1 commit intoowncloud:masterfrom
pako81:prevent_empty_folders
Closed

Prevent creation of empty files/folders for accounts having no available quota#40505
pako81 wants to merge 1 commit intoowncloud:masterfrom
pako81:prevent_empty_folders

Conversation

@pako81
Copy link
Copy Markdown

@pako81 pako81 commented Nov 22, 2022

Description

Prevent creation of empty files/folders for accounts having no available quota

Related Issue

Motivation and Context

Until now it was possible for users having 0 quota or who already reached the limit of their assigned quota to still create empty files/folders, which generates confusion. The PR fixes this behaviour.

How Has This Been Tested?

Manually:

Test 1. :

  • as admin user admin assign quota 0 B to user user1
  • login as user user1 over WebUI and try to create empty files or folders: an error Could not create.. is returned

Test 2. :

  • as user1 who has a valid quota assigned create a folder for guests and share it with full permissions with guest user guest@owncloud.com
  • as admin user admin assign now quota 0 B to user user1
  • login as guest user guest@owncloud.com, enter the folder for guests and try to create empty files or (sub)folders: an error Could not create.. is returned

Test 3. :

  • Same steps as Test 1. and 2. but this time with user1 having i.e. 10MB quota assigned and already using 100% of the available space

Test 4. :

  • as admin user admin assign quota 0 B to user user1
  • connect user1 via desktop client to his personal storage: sync client returns a 403 Forbidden to MKCOL and PUT operations when trying to respectively create empty folders and files.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised
  • Changelog item

@pako81 pako81 added this to the development milestone Nov 22, 2022
@pako81 pako81 self-assigned this Nov 22, 2022
@update-docs
Copy link
Copy Markdown

update-docs bot commented Nov 22, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@pako81 pako81 changed the title Prevent creation empty files/folder for 0 quota accounts Prevent creation empty files/folders for 0 quota accounts Nov 22, 2022
@pako81 pako81 changed the title Prevent creation empty files/folders for 0 quota accounts Prevent creation of empty files/folders for 0 quota accounts Nov 22, 2022
@pako81 pako81 changed the title Prevent creation of empty files/folders for 0 quota accounts Prevent creation of empty files/folders for accounts having no available quota Nov 22, 2022
@ownclouders
Copy link
Copy Markdown
Contributor

💥 Acceptance tests pipeline apiFilesExt-mariadb10.2-php7.4 failed. The build has been cancelled.

https://drone.owncloud.com/owncloud/core/37319/90

@pako81
Copy link
Copy Markdown
Author

pako81 commented Dec 7, 2022

@jvillafanez do you think the approach here is correct?

@jvillafanez
Copy link
Copy Markdown
Member

The approach could be fine if we want to allow to create folders under special circumstances. I mean, the 0 quota only applies to access through the webdav interface, but there could be other type of accesses that could bypass that check by using the view object directly. There is probably no good use case for this, but it's an option.

If we need to ensure that no folder is added under any circumstance (having 0 quota), we'll have to move the check elsewhere.

@pako81 pako81 closed this by deleting the head repository Dec 9, 2022
@pako81 pako81 reopened this Jan 1, 2023
}

list($used, $free) = $this->getQuotaInfo();
if ($free == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Always use ===. If == is used, it needs a comment explaining why it's needed.


list($used, $free) = $this->getQuotaInfo();
if ($free == 0) {
throw new SabreForbidden();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm sure you can include a meaningful message in the exception. It probably doesn't need to be translated, but in any case it will help to know what happened if we ever hit this exception, otherwise we could mistake the actual error for any of the other forbidden exceptions this method throws.

@jvillafanez
Copy link
Copy Markdown
Member

Not sure why I left the review as pending... anyway I'm assuming the approach is ok (regarding my previous post)

@pako81
Copy link
Copy Markdown
Author

pako81 commented Jan 9, 2023

Re-opened on #40567.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants