2

The Goal: I'm trying to setup functionality similar to a library with downloadable files. Only one user can download a file at a time.

The Solution: Use the Flag module.

Open to suggestions but through my research it seems like people are using the Flag module for this type of functionality. My question is how do I actually get this to work? I'm using a file field to add a file to a node. An admin comes along, wants to "checkout" that file, and they click the checkout flag, and then download the file. Now no other admin can download that file.

Once the original admin comes back, they can just click the flag again, setting it to open. (I know, they aren't really returning a digital file.) They just need to simulate returning it by basically just telling the system someone else can get this file.

Anyone set up something similar to this or just have an idea of how I would do this? Thanks for any suggestions and help.

1

I haven't done this, but if you want a library check in/check out system this is the approach I would try. Create a flag (here I'll call it Check out) that allows users to "check out" files. Make sure this is a global flag. Name the unflag link "Check in" or something similar. (You could also automatically have files checked back in after a certain interval with Rules Scheduler.)

Then, I would create views so that users cannot see the nodes that are checked out. To actually enforce security, I would also add a rule that automatically redirects users away from the page of any node that they did not flag that has been flagged (this probably will cause a performance hit and may not be the most secure way but will probably work for general cases).

  • Hmmm. I should have been thinking of this. I can see a couple of pitfalls for my use-case, but I'm upvoting regardless because this is something I should have considered and the thought never crossed my mind. Thanks for the suggestion. – o_O May 24 '13 at 15:14
0

Well the maintainer of the module said it probably isn't possible to do what I want without writing a custom module. The maintainer also stated you can't flag files out of the box like I'm referring to here. Since I want to disable the file download on flag, I can't add the flag to the node and disable because that will disable the node--not my intention.

So since my php skills are virtually equal to nothing I accomplished this via javascript. First, I added the flag to the node. Then I added some js:

$(".flagged").each(function(){
    $(".checkout-file").remove();
});

Easy to get around, I know, but I don't really need to protect the files at all and only admin will be perusing these files anyway. I only wanted to disable the download as an extra measure in case they don't notice the flag. The purpose being to state, "Don't bother wasting your time downloading this file since someone else is already reviewing it." So maybe someone else will need something like this.

0

you should consider a less popular module called "conditional flags" - you can create two flags that effectively represent "checked out" and "available" and make the "available" set to "not available" when a user "checks out" an item.

there are also code examples on the project page and so it may be possible to customize the module for a more elaborate need (e.g. a rule/trigger/action linked to a download or something more robust) enter link description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.