Tuesday, May 4, 2010

Showing members' email addresses to other members

This skins folder script getEmailById.py allows members to see other members' email addresses. The has_role() does a check to make sure not all users are allowed to do this.
## Script (Python) "getEmailById"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=author_id
##title=
##
from Products.CMFCore.utils import getToolByName
mtool = getToolByName(context, 'portal_membership')
plone_portal_state = context.restrictedTraverse('@@plone_portal_state')

email = 'unauthorized'
current_member = plone_portal_state.member()
if current_member.has_role(
['Inspector','Archiver','FunctionalManager','Reviewer','Manager',]):
author = mtool.getMemberById(author_id)
email = author.getProperty('email')
return email

In order to call getMemberById you have to have the Manage users permission, which i don't want to give out to all members. Therefore the script is run with a proxy role for Manager, as specified in getEmailById.py.metadata:
[default]
proxy = Manager

The script is called from TAL in a customized author.cpt, which has this extra code:
            <div tal:condition="
python: authorinfo['has_email'] and member.has_role(
['Inspector','Archiver','FunctionalManager','Reviewer',
'Manager',])"
>
E-mail:
<a tal:define="
email python: context.getEmailById(author_id=author);
"
tal:attributes="href string:mailto:${email}"
tal:content="email">
[e-mail address]
</a>
</div>

Sunday, May 2, 2010

Plone 3 on Ubuntu Lucid Lynx: Hand-compiling Python 2.4

update 2010-05-31: Warning for /usr/local/bin/python

After the upgrade to Ubuntu 10.04 (Lucid Lynx), i had no python2.4 binary anymore (causing a bash: ./bin/instance: /usr/bin/python2.4: bad interpreter: No such file or directory error), so i had to compile it myself. Hand-compiling is a big word here, because it was very, very easy:
wget http://www.python.org/ftp/python/2.4.6/Python-2.4.6.tgz
tar -xzf Python-2.4.6.tgz
cd Python-2.4.6/
./configure
make
sudo make install

A typical case of CMMI (configure, make, make install)! Note: You may want to consider installing Python 2.4 in /opt, see the warning below.

(After this, you'll have to install PIL again, using easy_install which you'll have to install as well, see the post at http://plone.org/documentation/kb/installing-a-plone-buildout-on-ubuntu.)

Note that python2.4 now lives in /usr/local/bin/ instead of /usr/bin/, so you'll also have to run bootstrap and buildout again on existing buildouts.

Warning: This will also add a symlink called python to your /usr/local/bin/, which may take precedence over your system python (2.6). This is a problem for Ubuntu's system-config-printer.py, which uses #!/bin/env python. This will result in a an import error:
$ system-config-printer
Traceback (most recent call last):
File "/usr/share/system-config-printer/system-config-printer.py", line 30, in
from timedops import *
File "/usr/share/system-config-printer/timedops.py", line 20, in
import gobject
ImportError: No module named gobject


I think it's best to change the header line of that script to /usr/bin/python as recommended in the Launchpad issue, and additionally remove the python symlink in /usr/local/bin/. Maybe it's better to install Python 2.4 in /opt to avoid this kind of conflict.