tiddlyhost
tiddlyhost copied to clipboard
How to check if the TW is read-only on frontend?
Currently, the ThostUploadPlugin for TWC has this bit: window.readOnly = false; However, it's sometimes desirable to understand whether the TW is in fact read-only (a non-owner has opened the site; the owner is not logged it).
Is there a simple way to check that on frontend? What endpoint to use?
I think, the proper approach would be to
- set
window.readOnly = false;ortrueon backend depending on the initial auth and rights and - with a frontend method to check the auth status, I can add some logic to the plugin which will help checking/updating
readOnly/refreshing things.
So besides my first question, I'd like to learn if there's a method or variable available to amend the initial value like window.readOnly = <%= has_user_editor_rights ? 'false' : 'true' %>
For TiddlyWiki5, Tiddlyhost writes either 'yes' or 'no' to a tiddler called $:/status/IsLoggedIn based on whether the user is logged in. So I expect we can find a way to do what you're looking for.
Do you think this should be the default behavior always? I'm wondering there are users who would prefer the "Edit" button to be visible even when the site can't be saved.
Right, so the first approximation would be window.readOnly = <%= status_is_logged_in ? 'false' : 'true' %>, right?
The "edit" button when readOnly == true is substituted with the "view" button (see TiddlyTools, for example), so I don't think there's any UX issues because of such a check. So yeah, I think it's safe to make this change.
What about an endpoint to check if the user has actually logged in/out after opening the page, is there such an endpoint?