Skip to content

Feature share link with token - #380

Merged
butonic merged 2 commits into
owncloud:masterfrom
butonic:feature_share_link_with_token
Nov 26, 2012
Merged

butonic merged 2 commits into
owncloud:masterfrom
butonic:feature_share_link_with_token

Conversation

@butonic

@butonic butonic commented Nov 12, 2012

Copy link
Copy Markdown
Contributor

To make reviewing easier I separated the changes into smaller commits with a - hopefully - meaningful commit message.

I plan to refactor some of the sharing code and add authorization mechanisms for shares by contacts and email. But let's first get this into core :)

@MTGap Please have a look at OCP\Share::getShareByToken($token) which I added to retrieve the share item. I admit that I bypass any magic in getItem(...) and cannot see whether that is a problem for other use cases like sharing a contact or an event ...

related to #105

@MTGap

MTGap commented Nov 12, 2012

Copy link
Copy Markdown
Contributor

What is the intention of using the alphaID() function?

@butonic

butonic commented Nov 12, 2012

Copy link
Copy Markdown
Contributor Author

alphaID() can be used to map numeric ids to a short alphanumeric string. I was first thinking of using it to generate the token from the share id but then I realized that then the token would not be random and could not be used as a pseudo password. I still like the way the token is generated because is uses a lot of characters but If there is already code in OC that generates tokens I'll use that.

@LukasReschke

Copy link
Copy Markdown
Contributor

but If there is already code in OC that generates tokens I'll use that.

OC_Util::generate_random_bytes()

@butonic

butonic commented Nov 12, 2012

Copy link
Copy Markdown
Contributor Author

I think I updated everything with the exception of the uid owner not being the actual owner ... any ideas how to do this in a clean way?

@butonic

butonic commented Nov 13, 2012

Copy link
Copy Markdown
Contributor Author

@MTGap @LukasReschke @DeepDiver1975 @karlitschek @tanghus I think this should do it. Please test and give it your thumbs up!

@MTGap

MTGap commented Nov 15, 2012

Copy link
Copy Markdown
Contributor

Everything seems to work and it fixes issue #382. The patch didn't apply cleanly for me, there was an issue with the db update. I think there was another update in master to it.

You still have the TOKEN_LENGTH constant in the code. After that :+1 What is our standard for pull requests is it alright that there are multiple commits that undo previous commits?

@tanghus

tanghus commented Nov 15, 2012

Copy link
Copy Markdown
Contributor

The patch didn't apply cleanly for me, there was an issue with the db update. I think there was another update in master to it.

That was me. I bumped the version last night. Sorry.

What is our standard for pull requests is it alright that there are multiple commits that undo previous commits?

If you merge it while @DeepDiver1975 is asleep ;) You should bump version to (4, 91, 02)

@butonic

butonic commented Nov 16, 2012

Copy link
Copy Markdown
Contributor Author

We should keep the individual commits if possible .. but the fixes removed a lot of code and my git rewrite foo was not as god as I had hoped, so I just squashed them into one commit.

The TOKEN_LENGTH is used to prevent a magic number in the call of generate_random_bytes.

Also increased the version to (4, 91, 02)

@butonic

butonic commented Nov 20, 2012

Copy link
Copy Markdown
Contributor Author

@MTGap @tanghus I think I addressed all the issues. Please retest and give me your 👍

@butonic

butonic commented Nov 20, 2012

Copy link
Copy Markdown
Contributor Author

@karlitschek. I have the backport ready for stable45 but will wait for this to be pulled before committing it

@DeepDiver1975

Copy link
Copy Markdown
Contributor

tested 👍

@schiessle

Copy link
Copy Markdown
Contributor

I just tried it especially with respect to issue #117

  • Sharing a file from the Shared folder with a public link works.
  • Sharing a whole directory from the shared folder results in "Cloud not found"

Another issue:

The sharing drop down shows "null" as token for public links created before I applied the patch. I also can't remove the link and create a new one because removing the broken link results in a error message. I think we need a update routine which transfer old share links to the new ones. It is probably enough to just generate all missing tokens in the database during the first run.

@MagicFab

Copy link
Copy Markdown

Can you provide an example of resulting shared file / directory URLs?

@butonic

butonic commented Nov 23, 2012

Copy link
Copy Markdown
Contributor Author

after this pull request the produced share links look like this
http://localhost/core/public.php?service=files&t=c01a7fb374c9c71d3e41d8c513ddaa6f

the hash could be shortened but that should be done in another pull request

@butonic

butonic commented Nov 23, 2012

Copy link
Copy Markdown
Contributor Author

@schiesbn Could you retest the issue with sharing a directory from a shared folder? null links should now be replaced by old pre token links.

@schiessle

Copy link
Copy Markdown
Contributor

@butonic I still get a "cloud not found" in some situations.

Let me give you an example:

  • user1 has a folder "/demo/foo/bar" and shares the top level folder "/demo" with user2
  • user2 can now reshare files within the folder with a public link
  • user2 can also reshare the folder "demo" with a public link
  • but user2 can not reshare folder below "/demo", e.g. "/demo/foo". This will result in "cloud not found"

I only had a short look at your code, but i think the problem is most likely that you use the function getID() in apps/files_sharing/public.php to find the file cache ID of the given folder. But this only works for the root folder ("demo" in the example above) because all the folders below the root folder are not stored in oc_share.

On stable45 I use the function getSourcePath() in apps/files_sharing/lib/util.php to get the real path of a file/folder stored somewhere in the shared folder. The same functions are also available in apps/files_sharing/lib/sharedstorage.php but marked as private. For stable45 I copied them to util.php to be able to use them outside of OC_Filestorage_Shared to find shared files, e.g. on the webdav back-end.

Maybe this is useful for you to resolve the issue.

@schiessle

Copy link
Copy Markdown
Contributor

Regarding the fallback mode for pre-token links. I would prefer to increase the version number of the files_sharing app and update the update script to add a token to all link-shares. This would avoid the overhead to maintain the fallback code.

@butonic

butonic commented Nov 23, 2012

Copy link
Copy Markdown
Contributor Author

@schiesbn I cannot reproduce the example you described. Are you using token based links? Has the folder previously been shared with a dil/dir based link? Could you try with a clean database? Are you using ldap (although I don't think it has anything to do with the issue)?

@schiessle

Copy link
Copy Markdown
Contributor

@butonic I just tried it with an empty database. The problem only appears if user2 creates a folder/file in a shared folder. So the right example is:

  • user1 has a folder "/demo" and shares the folder "/demo" with user2
  • user2 can reshare files and folders within the "demo"-folder with a public link
  • but if user2 creates a new folder "Shared/demo/foo" or file "Shared/demo/test.txt" and tries to share it with a public link he will get a "cloud not found"

@schiessle

Copy link
Copy Markdown
Contributor

@butonic I found the problem and fixed it in pull request 581. The problem was that we added the user who created the file as file owner to the file cache and not the actual owner.

This should fix the issue but I didn't test it until now together with your version

@butonic

butonic commented Nov 26, 2012

Copy link
Copy Markdown
Contributor Author

since the isses reported by @schiesbn are fixed in #581 and a fallback for old links has been implemented I'll merge this.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants