Support disable user upload at post or topic but available for user avatar and profile backgrounds etc.
Set the max size to 0 and hide the upload button or options on post by CSS not really a good way, it break all upload even admin like category background image.
AI-generated summary
The discussion revolves around enhancing upload restrictions for users in Discourse. hawm seeks a way to disable user uploads in posts while allowing uploads for avatars and backgrounds, noting that setting max size to 0 or hiding upload buttons via CSS is ineffective as it breaks admin uploads. tshenry suggests using a theme component to restrict uploads based on trust level, which prevents upload buttons and drag-and-drop functionality in the composer. hawm acknowledges the component works but expresses concern that it only restricts the web editor and not the Upload API, potentially allowing bypass via direct HTTP requests. tshenry clarifies that such bypass would require a valid API key, which is only granted by admins, and notes that the solution is client-side, not server-side. hawm thanks for the clarification.
See if this will meet your needs:
@tshenry
A good component. But it seem too basic? The code looks only restrict the browser UI.
I’m not sure what you mean by too basic. It prevents the upload button from rendering on the composer toolbar and disables the drag-and-drop upload functionality of the composer. This will only apply to users under a trust-level you specify in the theme setting. It’s not just hiding a button with CSS if that’s what you are concerned about.
Theme components are super easy to add and remove, so there’s no harm in testing it out and seeing if it meets you needs.
Yes, i already install the component and actually it is working not bad.
What i mean about “too basic” is the component still restrict the web editor only.
The code below i guess it will only disable the upload or reply placeholder on the web editor(if i was wrong that i have no question with the component, ignore below).
https://github.com/tshenry/discourse-restrict-uploads/blob/master/common/head_tag.html
I know the upload using Upload API, so somebody which familiar with network programming may construct some HTTP requests(i dont know if some security like CORS can protect it) to bypass the component then upload file(even though the uploaded is harmless, but any upload by user are not our expected).
So, restrict the Upload API type field in the back-end may improve it? I am newbie to Discourse and programming.
Thanks.
Hopefully I will be corrected if I am wrong, but I believe they would need to have a valid API key do that. An API key would need to be explicitly generated for a user by an admin.
You are correct, though. This is not a server-side solution. If you need an extremely secure solution, you would need to build a plugin or hope that the feature is added to core.
I am clear now, thanks!