I have many image nodes in my site, but they are not for viewing directly by visitors, they are uploaded for the authors to attach or insert into content. Hence the image nodes are all unpublished. The current image_attach code only allows published images to be attachced to nodes, because status=1 is hard-coded into the query which selects the image nodes available.

So I have written the following enhancement which provides the admin with a new permission 'attach unpublished images'. If this is granted for the user then the selection list of existing images will not be limited to just the published images. If the permission is not granted (which is the default) then the list will be restricted to published nodes just the same as before.

Apart from defining the new permission, the only change is in _image_attach_get_image_nodes() where

$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.sticky FROM {node} n WHERE n.status = 1 AND n.type = 'image' ". $placeholder ."ORDER BY n.sticky DESC, n.title ASC"), $nids);

becomes:

// If the user does not have 'attach unpublished images' authority then the query requires 'status = 1' to only select published images.
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.sticky FROM {node} n WHERE n.type = 'image' "
  . (user_access('attach unpublished images') ? '' : 'AND n.status = 1 ')
  . $placeholder ."ORDER BY n.sticky DESC, n.title ASC"), $nids);

The patch for this change was rolled against the dev dated 2009-11-07. It is a very simple change, but was vital for my site. Hopefully you will find this a useful enhancement and incorporate it into version 1.0 as I can't be the only person who stores unpublished images reading for attaching in this way. However I understand that you want to concentrate on getting a stable release 1.0, so its OK if you want to leave this for version 1.1

Jonathan

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Needs review » Closed (won't fix)

I'm not sure I see the point of this -- users can attach unpublished images, but they won't be able to actually see them on the node once they save it!

So I'm afraid I don't think this is a feature suitable for inclusion in the module.

I'm going to wontfix it, though I could probably be convinced that we should allow a user who can see an unpublished image node to attach that node, but that wouldn't require a new permission, it should be automatic.

If you want to implement this on your site without hacking the module, you can use hook_form_alter to put in your own list of nodes.

jonathan1055’s picture

Priority: Normal » Minor
Status: Closed (won't fix) » Postponed (maintainer needs more info)

Thanks for your reply Joachim. I think I disagree with your statement "users can attach unpublished images, but they won't be able to actually see them on the node once they save it!. This is not how it is on my site - the authors can definitely see the attached unpublished images once I've given them the ability to select them. However, I need to do more testing on a clean D6 install to prove what I'm trying to get at, or to show me where I'm wrong, as it could be a conflict with other permissions/modules I have.

I will come back to this thread with more info when I have checked the above, but I am happy for you to defer this until after the release of 1.0 as it is an enhancement not a bug fix. I have changed the status to 'postponed - maintainer needs more info' and I hope that's OK with you. You need not do anything more on this until after I come back with answers, and I will continue to apply my patch to newly-downloaded versions of image, until it is resolved.

Thanks

Jonathan

joachim’s picture

I'm pretty sure if an image node is unpublished then you shouldn't be able to see it as an attached image on another node -- unless of course you're an admin or it's your own node -- in other words if you can see that node anyway. If not, then there's a bug.

jonathan1055’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
2.39 KB

Hi Joachim,
Yes you are right that attached unpublished images are not currently viewable in the parent node by anonymous users, and would not be viewable by authenticated users unless they were the owner of the image. In my case the images were being shown because I had removed the call to node_access('view', $image) in mytheme_image_attach_body() - I made this change a few months ago and had forgotten I'd done it.

So to make this enhancement complete and useable I have added another permission 'view attached unpublished images'. This is better because it gives full customisation on who can see the unpublished images by role. theme_image_attach_body() returns nothing if the user has neither node_access('view') nor user_acces('view attached unpublished images'). Likewise for theme_image_attach_teaser().

If you want to leave this until after the stable 1.0 release that is fine with me.

Jonathan

jonathan1055’s picture

Title: New permission to attach unpublished images » New permissions to attach and view unpublished images
Version: 6.x-1.x-dev » 6.x-1.1
Priority: Minor » Normal
FileSize
2.46 KB

Here is an updated patch, re-rolled for image1.1
There are five functions affected by the change

  1. image_attach_help: This function did not exist, now created with link to permissions
  2. image_attach_perm: Add two new permissions 'attach unpublished images' and 'view attached unpublished images'
  3. image_attach_block: Check for 'view attached unpublished images'
  4. _image_attach_get_image_nodes: Check for 'attach unpublished images'
  5. theme_image_attach_attached_images: Check for 'view attached unpublished images'
drzraf’s picture

Version: 6.x-1.1 » 6.x-1.2
Priority: Normal » Major

That solves #984082: unpublished image nodes lose parent node which is IMHO major.
It's a must-have : every site allowing anonymous contribution + moderation + image attachment expect freshly uploaded (but still unpublished) images to be attachable to the new node !

thanks

drzraf’s picture

Version: 6.x-1.2 » 6.x-1.x-dev

ping ?

jonathan1055’s picture

Issue summary: View changes

edit for line break

joachim’s picture

I'm somewhat worried about the upgrade path for this feature.

Granted, we have no upgrade path to speak of at the moment, but so far most of the Image D6 features would be doable in D7.

Does anyone know how Entityreference handles referencing unpublished nodes?

drzraf’s picture

I understand your worry about the upgrade. And I personally can live with the D6 partly patched with the OP patch as I intend to upgrade to D7 as quickly as I can.
But the fact that unpublished images get dropped from translations if the node wasn't published yet was, in the past, very annoying on my side.
I can't say for other people but in my case I only grabbed the hunk about db_rewrite_sql and an if (modr8|i18n module) would have been enough for me.

In D7 image fields are part of the whole node and are published accordingly. I don't about the use of nodereference and image nodes in D7.

drzraf’s picture

Issue summary: View changes

spelling