Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Aiheen aloitti: VE3JOC - huhtikuu 18, 2020, 12:43:07 IP

Otsikko: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 12:43:07 IP
Is there a way to allow guests to read posts in a specific forum but not be able to download attachments?  I have a tutorial forum that will have tutorials in .pdf format and I want everyone to be able to read the posts in that forum but only allow registered users to download the .pdf files.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: Doug Heffernan - huhtikuu 18, 2020, 12:46:13 IP
Lainaus käyttäjältä: VE3JOC - huhtikuu 18, 2020, 12:43:07 IP
Is there a way to allow guests to read posts in a specific forum but not be able to download attachments?  I have a tutorial forum that will have tutorials in .pdf format and I want everyone to be able to read the posts in that forum but only allow registered users to download the .pdf files.

Yes, you can do that at the board permissions page. Untick View attachments permission set.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: vbgamer45 - huhtikuu 18, 2020, 01:14:26 IP
Also I have a mod that adds a permission for downloads/view
So you can see their are attachments in the post but not allow downloads

https://custom.simplemachines.org/mods/index.php?mod=4189
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 01:41:53 IP
Thanks vbgamer45.  If this mod was installed, where would you go in the admin to limit the downloading of attachments?
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: vbgamer45 - huhtikuu 18, 2020, 01:47:42 IP
It is a membergroup level permissions. So under permissions for each membergroup
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 02:09:08 IP
Ok, I tried it.  I checked the View Attachments and unchecked the Download attachments but when I log in as a guest I cannot see any attachments.  Maybe I am not understanding how it works but my impression was that they could see that there is a file attached but not be able to download it.

Thanks
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: vbgamer45 - huhtikuu 18, 2020, 02:21:15 IP
That's what it should do. Using a custom theme or default theme?
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 03:28:42 IP
I have a custom theme.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: vbgamer45 - huhtikuu 18, 2020, 03:38:43 IP
Want to double check you made the change for guest group as well?

If you did attach your display.template.php file for your theme.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 03:53:09 IP
The only display.template.php file that I can find is in the default theme.  I have attached it.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: vbgamer45 - huhtikuu 18, 2020, 04:28:12 IP
Just confirming you gave the guests membergroup the "View Attachments " permission
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 05:17:15 IP
Yes,... I did that.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 18, 2020, 07:11:39 IP
Still can't get it to work properly.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 19, 2020, 01:16:32 IP
Can't get it to work properly so I uninstalled it.  Guess I'll have to see if I can find another way of doing this.

Thanks anyway.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: Tonyvic - huhtikuu 19, 2020, 05:29:04 IP
Lainaus käyttäjältä: VE3JOC - huhtikuu 18, 2020, 02:09:08 IP
Ok, I tried it.  I checked the View Attachments and unchecked the Download attachments but when I log in as a guest I cannot see any attachments.  Maybe I am not understanding how it works but my impression was that they could see that there is a file attached but not be able to download it.

Thanks
I thought 'Guests' were people who were not logged in! :P
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: drewactual - huhtikuu 19, 2020, 09:30:19 IP
this will show the attachments, but they aren't available for download. 

Lainaaedited to add:  you MUST have attachments visible to guests in your forum's permissions for this to work

first off, if you're using a custom theme or theme OTHER than default, and that theme DOES NOT have a Display.template, COPY the Display.template from your default file and paste it to the theme you are using's directory- leaving the virgin copy behind in default theme... this will retain a virgin copy of your Default.template if you choose to get rid of this code/function...

open the Display/template you just made (or the default one if you're using the default theme)

find:

echo '
<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />&nbsp;' . $attachment['name'] . '</a> ';


it should be around or on line 530 of 2.0.17's virgin Default.template....

replace it with:

// code inject for only members able to download attachments
if ($context['user']['is_guest'])
                       echo '
                       <a href="' . $scripturl . '?action=login">Login</a> or <a href="' . $scripturl . '?action=register">Register</a> to download attachment.
                       ';
           elseif   ($context['user']['is_logged'])         
                   echo'
<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />&nbsp;' . $attachment['name'] . ' click to download</a> <br /> ';
// end inject for members only attachments download.


that's pretty much all there is to it... it doesn't have a back-end admin control, obviously, so... the code will have to be removed to revert back... folks around here don't like their code being hacked, so don't expect this to be popular.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 20, 2020, 04:39:28 IP
Thanks drewactual.  I have "allow viewing of attachments" checked but having inserted the code the attachment is only visible to logged-in users.  Guests do not see that attachment.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: drewactual - huhtikuu 20, 2020, 06:22:15 IP
There USED to be a server side apache rpm that would open Microsoft and Adobe files on webpages... it was a resource hungry thing, but it worked.  To my knowledge and without massive amounts of coding and IF that rpm was adaptable, I still think it would be near impossible to have a working "view" documents... an image? All day long... a file? Different animal...

The code I offered will at least show there is an attachment to a guest, and will allow an image to be seen but not downloaded.
Otsikko: Re: Allow guests to read posts but not download attachments?
Kirjoitti: VE3JOC - huhtikuu 21, 2020, 02:49:01 AP
Thanks drewactual.  No problem.  As long as users know that there is a tutorial that they can download if they log-in, that's great.

Thanks again.