Restrict uploads

This is a very small theme component that will remove the upload button from the composer toolbar and disable drag-and-drop uploading for users that are under a specified trust level.

Illustration

Settings

Install this theme component

29 Likes

My forum is pushing 1.1GB in uploaded media. Weā€™re growing in a way I wasnā€™t super prepared for and have been trying to coerce users to use places like imgur instead. This really, really helps!

3 Likes

I have try this components but its not working.

Can @tshenry help me?

This are the screen shot of my installation. I want to restrict user who have trust level 2 or below

2 Likes

Hi there :wave:

I just checked and it appears to be working correctly. Can you make sure you have added the Restrict Uploads component to your main theme? You will also need to hard-refresh the page for the component to take effect. Oh, and make sure the account you are using for testing is not a staff user.

5 Likes

:warning: A note to anyone using this component - there is an update to the component that requires you to be running the latest tests-passed version of Discourse. If your Discourse site is not up to date, DO NOT update the component as it will reference core code that you do not have yet which will break the composer functionality of your site.

7 Likes

Hi,

Just posting to note this:

I think it is broken (for Admins and Mods) on 2.6.0.beta2, but Iā€™m unable to get more confirmation besides my own experience.

2 Likes

Thanks so much for the report @Iceman! I just pushed a fix that should get things back on track :slight_smile:
Let me know if there are any issues after you update the component.

https://github.com/tshenry/discourse-restrict-uploads/commit/b52fb9def1a00773ca4462e2d15444eea1ff934c

3 Likes

Just tested and works just as before, that is, like a charm!

Thank you very much!

2 Likes

doesnā€™t restrict avi uploads

would be nice if it did

Can you elaborate a little more?

I just tried uploading an AVI from a trust level lower than the one defined in the restrict to trust level theme setting and it prevented the upload as expected.

If you would like to prevent non-staff users from uploading AVI files specifically, you should ensure the AVI extension isnā€™t added to authorized extensions. You can add the extension to
authorized extensions for staff if you want staff to be able to upload AVIs.

2 Likes

it is really cool.
Could it separate the restriction between post and personal message?
for example, only allow staff upload image in personal message but tl2 can upload images in normal post

2 Likes

Hey, just want to point out that this ā€œbreaksā€ with Discourse Latest ( 2.8.0.beta6 (0d809197aa) ).

TypeError: null is not an object (evaluating Ā“this.mobileUploadButton.addEventListenerĀ“)

Details:

  • Started to happen after a Rebuild (and therefore, update to latest).

  • This only happens on Mobile.

  • Doesnā€™t happen on all browsers, neither on all devices (could be a cache thing? idk). But once it happens there is no way to ā€œfix itā€ from a userā€™s perspective.

  • The behavior is weird because it ā€œchangesā€ how the buttons behave. The ā€œdiscardā€ button (trash can) and Preview buttons reload the page. The ā€œDiscourse Gifs Theme Componentā€ Button just expands the composer.

  • I thought it was some compatibility issue with the ā€œDiscourse Gifsā€ Theme Component but if I disable that one the issue persists.

I can provide more details if necessary. I tried removing as much as possible but it seems that he problem only stops happening after disabling this Theme Component.


btw, just want to use the opportunity and point out what a great Theme Component this is and how much I do think that it should be a core feature :love_letter:

4 Likes

Thanks for reporting this! There has been some recent work on our core upload system and there appears to be a little bug. Iā€™m actually able to reproduce the error even without the component under the right circumstances. Iā€™ll pass this by the engineer thatā€™s been focusing on uploads to see if we can get this fixed up!

That sounds like a reasonable feature request! Iā€™ll see what I can do.

3 Likes

Hi @Iceman. Thanks for the report, the issue is fixed by FIX: Do not error mobile upload button if !allowUpload by martin-brennan Ā· Pull Request #14317 Ā· discourse/discourse Ā· GitHub which is in tests-passed now.

4 Likes

I am noticing this message in console.

[THEME 6 ā€˜Restrict Uploadsā€™] To prevent errors in tests, add a pluginId key to your modifyClass call. This will ensure the modification is only applied once.

Just thought to raise it as it may become a potential issue once the recent changes go live for everyone.

1 Like

Thanks for the report. I made a PR :+1:

3 Likes

:rocket: Merged, thanks!

3 Likes