3

In Plone 4.1, I'd like to make member portraits (found in portal_memberdata/portraits) viewable by Anonymous users.

Even if I return the correct url to the image in a public View, the image is always protected, and the default one ('defaultUser.png') is returned instead.

How can I accomplish this and display author portraits to Anonymous users inside my viewlets?

Just to clarify:

author.getPersonalPortrait().absolute_url()

will return the correct url to the image. When the image is then fetched by the browser when the view is accessed, the resource is protected.

Giacomo Spettoli
  • 4,476
  • 1
  • 16
  • 24
Rigel Di Scala
  • 3,150
  • 2
  • 17
  • 23
  • if verifyPermission and not _checkPermission('View', portrait): # Don't return the portrait if the user can't get to it this is the check done in getPersonalPortrait. – Yuri Oct 19 '11 at 09:36
  • 1
    However, the verifyPermission kwarg is always called with 0 as default value, so this check is never enforced. – Rigel Di Scala Oct 19 '11 at 10:09

2 Answers2

3

After a bit of prodding around with pdb, I solved the problem in this way:

def get_author_image(self, member_id):
    """
    Fetch the author portrait image url accoding to member_id
    """
    mtool = getToolByName(self.context, 'portal_membership')
    mtool.getPersonalPortrait(id=member.id)

The secret is passing the id kwarg. Weird, but it works.

It wasn't a permission problem, but rather an issue on the way getPersonalPortrait returns the correct url to the image. If you do not specify the id, somehow it won't be able to work out the correct member id, hence fallback to showing the default user image.

Rigel Di Scala
  • 3,150
  • 2
  • 17
  • 23
  • 1
    It's because member object does not have getPersonalPortrait method. It was acquired from the portal_membership tool, which returns current authenticated member portrait if id is not given. You should update your code accordingly to avoid confusion: return mtool.getPersonalPortrait(id=member.id) – quyetnd Nov 08 '11 at 06:12
1
def __init__(self):
    BaseTool.__init__(self)
    self.portraits=BTreeFolder2(id='portraits')

you've to add the View permission to the portal_memberdata.portraits folder.

You can do it by going to:

http://mysite.xx/portal_memberdata/portraits/manage_main

and managing permissions there :) portraits are simple images

Yuri
  • 1,074
  • 5
  • 9