Skip to content

Fix upload to a public share path - #22

Open
allexzander wants to merge 7 commits into
codelathe:mainfrom
allexzander:main
Open

allexzander wants to merge 7 commits into
codelathe:mainfrom
allexzander:main

Conversation

@allexzander

@allexzander allexzander commented Dec 2, 2026 •

Copy link
Copy Markdown

urlencode() encodes the ! of /SHARED/!<token> as %21. The fix-up in upload() never ran because it searched for "%%2FSHARED%2F%21" (doubled percent sign), so uploads to a public upload-only share failed. Fixed in both the empty file and the chunked branch, and removed the if find() guard, which was always true.

Verified with new unit tests for both branches and for a path outside /SHARED/. They fail on the old code and pass with the fix. isort, black and mypy are clean. Version bumped to 0.5.4.

Please merge and publish a 0.5.4 GitHub release so the release workflow pushes it to PyPI.

OleksandrFC and others added 2 commits December 2, 2026 14:01
…ncoded

urlencode() encodes the exclamation mark of a public share token as %21.
The server expects it unencoded, as the web UI sends it. The fix-up in
upload() never applied because it searched for "%%2FSHARED%2F%21" with a
doubled percent sign, so uploads to a public upload-only share failed. Its
guard was also always true since str.find() returns -1 when nothing matches.

Replace "%2FSHARED%2F%21" with "%2FSHARED%2F!" in both the empty file and
the chunked branch, and add unit tests for both branches plus a path
outside /SHARED/ that keeps its encoded !.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@allexzander

Copy link
Copy Markdown
Author

@krzysztofFC @konstantin-f

@krzysztofFC krzysztofFC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed and verified locally on a clean clone (Python 3.11 venv).

  • filecloudapi/tests: 5 passed. black, isort and mypy are clean.
  • The two new public share tests fail when run against the fcserver.py of main (the empty file branch and the chunked branch), so they catch the bug.
  • The query this builds matches the workaround in the FCD integration tests (test/util/fcserver_testcompat.py, upload_str_to_public_share), which uploads to a public upload-only share on a real server. After this is merged and 0.5.4 is on PyPI, a follow-up PR in the FCD repo can bump test/requirements.txt to 0.5.4 and replace that workaround with a plain upload_str call (one caller, test_shares.py test_public_share_upload_only).

Not verified end to end against a server with this branch.

Comment thread filecloudapi/fcserver.py Outdated
"%%2FSHARED%2F%21", "%2FSHARED%2F!"
) # WEBUI DOES NOT ENCODE THE !
# WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!<token>/...)
params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit, optional: the same two lines are also in the empty file branch above. A small helper (for example _upload_query(params)) would keep the two from drifting apart again. Fine as is.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, all addressed in the last 3 commits:

_upload_query helper for both upload branches (5f182c0)
PolicyList and ServerSettings keep their entries per instance. ServerSettings had the same class level dict (0bed0f0)
admin_createnewgroup returns the group id, deleteshare takes adminproxyuserid, new wrappers for updateshare, deleteuserfromshare, getsystemstatus, admin_deletememberfromgroup, admin_addusertoexternal, admin_deleteuserfromexternal, admin_deleteexternal, and FileListEntry gets createdepochutc and systemcreatedepochutc (139c1b9)
Response shapes are taken from the server source. Unit tests cover the request of each wrapper and the failure path. 21 passed, black, isort and mypy clean. Still 0.5.4, so one release lets the FCD tests drop all of these workarounds.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the server run. All addressed in f26d3fd:

deleteuserfromshare: the docstring says userid is the email (kept the name to match the server parameter and the other wrappers)
createdepochutc: comment reworded as you suggested
admin_deletegroup returns True on result 1
admin_addnewuser sends authtype without the trailing space. /admin/adduser requires it as an integer (AdminUserRouter.php)
Unit tests added for both bugs, they fail on the old code. 24 passed, black, isort and mypy clean. On HTTPError vs ServerError: agreed, a 400 raises from raise_for_status in _api_call before the command result is read, the fake 200 with result 0 covers the other path.

@krzysztofFC

Copy link
Copy Markdown
Collaborator

The FCD integration tests still work around more of filecloudapi in test/util/fcserver_testcompat.py (method names in brackets). These belong in filecloudapi too, here or in a follow-up PR. Plain wrappers of the existing server endpoints only, no test harness logic.

Bugs:

  • PolicyList.entries is a class attribute (datastructures.py), so every PolicyList in the process appends to the same list. A filtered get_all_policies returns the policies of earlier listings too. It should be an instance attribute set in __init__. The tests reset PolicyList.entries = [] before each call (get_all_policies, FCL-14138).
  • admin_createnewgroup drops the group id the server returns. The tests call /admin/addgroup directly to get it (admin_addgroup).

Missing parameter:

  • deleteshare has no adminproxyuserid, so a share owned by another user (for example a team folder share) cannot be deleted through the admin proxy (delete_share).

Missing endpoints:

  • /core/updateshare (updateshare)
  • /core/deleteuserfromshare (deleteuserfromshare)
  • /core/getsystemstatus, at least appversion and uploadchunksize (server_version, upload_chunk_size)
  • /admin/deletememberfromgroup (admin_deletememberfromgroup)
  • /admin/addusertoexternal (admin_addusertoexternal)
  • /admin/deleteuserfromexternal (admin_deleteuserfromexternal)
  • /admin/deleteexternal (admin_deleteexternal)

Missing field:

  • FileListEntry has modifiedepochutc but no createdepochutc, which fileinfo and getfilelist return on 23.253 and later (fileinfo_epoch_utc, filelist_epoch_utc).

Once these are released, the FCD tests can drop the workarounds and move to the new version.

OleksandrFC and others added 3 commits December 2, 2026 17:14
…anches cannot drift apart

Review comment on codelathe#22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
entries was a class attribute (a list in PolicyList, a dict in
ServerSettings), so every instance in the process appended to the same
object. A filtered get_all_policies returned the policies of all earlier
listings and admin_get_config_settings returned the settings of earlier
calls. Set entries in __init__ instead.

Review comment on codelathe#22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- admin_createnewgroup returns the group id the server answers with
- deleteshare takes adminproxyuserid, so a share owned by another user
  (for example a team folder share) can be deleted through the admin proxy
- New wrappers: updateshare, deleteuserfromshare, getsystemstatus
  (appversion and uploadchunksize as SystemStatus),
  admin_deletememberfromgroup, admin_addusertoexternal,
  admin_deleteuserfromexternal, admin_deleteexternal
- FileListEntry carries createdepochutc (getfilelist and fileinfo, servers
  23.253 and later) and systemcreatedepochutc (fileinfo, when the server
  stores the OS creation date). Both default to "" so code that builds a
  FileListEntry positionally keeps working.

updateshare answers with the share on success and with a meta error or a
command result on failure, both raise ServerError. The others answer with a
command result. Unit tests check the request each wrapper sends and that a
failed command raises.

Review comment on codelathe#22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against the server: ShareController::updateShare fills defaults for missing parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@krzysztofFC krzysztofFC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked 02bff8a. 21 unit tests pass, isort and mypy are clean. I also ran every new wrapper against a local 23.263.3 server with throwaway users, a group, an external and a share, all removed afterwards.

  • Works: getsystemstatus, PolicyList per instance (two listings return the same count), admin_createnewgroup returns the id, admin_deletememberfromgroup, admin_addusertoexternal, admin_deleteuserfromexternal, admin_deleteexternal, updateshare (new name and public flag visible afterwards, a deleted share raises ServerError), deleteuserfromshare, deleteshare with adminproxyuserid, createdepochutc from getfilelist and from fileinfo of a file.
  • A bad id on admin_deletememberfromgroup, admin_deleteexternal and deleteuserfromshare is answered with HTTP 400, so these raise HTTPError from _api_call, not ServerError. Still a failure, just not the command result 0 shape the unit tests fake.

Two small things inline.

Two older bugs I hit on the way, both outside this PR (the first one is mine):

  • admin_deletegroup returns True only when command/result is 0, so it returns False when the group was deleted. From PR 13.
  • admin_addnewuser sends the key "authtype " with a trailing space, so the server never gets authtype and answers 422 on 23.263.3.

Fine to fix them here while 0.5.4 is unreleased, or I can do it in a follow-up.

Comment thread filecloudapi/fcserver.py
)
self._raise_exception_from_server_message(message)

def deleteuserfromshare(self, share: FCShare, userid: str) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

userid has to be the user's email. The server validates it as one (ShareRouter.php, addRequiredParam('userid', Valid::VALID_EMAIL, Filter::LOWER_CASE)) and answers 422 for a user name. Worth naming it email or saying so in the docstring.

Comment thread filecloudapi/datastructures.py Outdated
isdatasyncable: bool
etag: ETag
# Empty when the server does not report them: createdepochutc (getfilelist
# and fileinfo, 23.253 and later), systemcreatedepochutc (fileinfo, only when

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On 23.263.3 fileinfo reports createdepochutc only for a file. For a folder it is empty, while getfilelist has it. Maybe "(getfilelist, and fileinfo of a file, 23.253 and later)".

…omshare and createdepochutc limits

- admin_deletegroup returned True only when command/result was 0, so it
  reported a deleted group as not deleted. It now returns True on result 1.
- admin_addnewuser sent the key "authtype " with a trailing space, so the
  server never got authtype, which /admin/adduser requires as an integer
  (HTTP 422 on 23.263.3).
- deleteuserfromshare: the server validates userid as an email.
- FileListEntry.createdepochutc: fileinfo reports it only for a file,
  getfilelist also for a folder.

Review comments on codelathe#22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@krzysztofFC krzysztofFC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved on f26d3fd: 24 unit tests, black, isort and mypy pass locally, and the new and fixed wrappers work against a 23.263.3 server.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants