1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
6 # This program is free software; you can redistribute it #
7 # and/or modify it under the terms of the Creative Commons #
8 # "Attribution-Noncommercial 2.0 Generic" #
9 # http://creativecommons.org/licenses/by-nc/2.0/ #
10 ############################################################
18 from AccessControl
import ModuleSecurityInfo
19 from zope
.i18n
import translate
as i18ntranslate
20 from zope
.i18nmessageid
import MessageFactory
21 from zope
.globalrequest
import getRequest
22 from Products
.CMFCore
.utils
import getUtilityByInterfaceName
23 from Products
.Plinn
.utils
import _sudo
27 security
= ModuleSecurityInfo('Products.photoprint.utils')
29 security
.declarePublic('translate')
30 def translate(msgid
, mapping
=None, default
=None) :
31 """ traduction dans le domaine photoprint """
32 return i18ntranslate(msgid
, domain
='photoprint', mapping
=mapping
, context
=getRequest(), default
=default
)
34 security
.declarePublic('Message')
35 Message
= _
= MessageFactory('photoprint')
37 security
.declarePublic('grantAccess')
38 def grantAccess(collectionId
, password
, confirm
, memberId
) :
39 utool
= getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool')
40 mtool
= getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool')
41 portal
= utool
.getPortalObject()
43 data
= portal
.private_collections
.data
44 lines
= filter(None, [l
.strip() for l
in data
.split('\n')])
45 assert len(lines
) % 3 == 0
47 for i
in xrange(0, len(lines
), 3) :
48 collecInfos
[lines
[i
]] = {'pw' : lines
[i
+1],
51 if not collecInfos
.has_key(collectionId
) :
53 return _('Wrong private collection identifier.')
54 elif password
!= confirm
:
56 return _("Collection's password does not match confirmation.")
58 if collecInfos
[collectionId
]['pw'] != password
:
60 return _("Wrong collection's password.")
62 collec
= portal
.unrestrictedTraverse(collecInfos
[collectionId
]['path'])
64 mtool
.setLocalRoles(collec
, [memberId
], 'Reader')