<tr>
<th>Identifiant collection privée</th>
<td>
- <input type="text" name="wedding_id" tal:attributes="value options/wedding_id"/>
+ <input type="text" name="collection_id" tal:attributes="value options/collection_id"/>
</td>
</tr>
<tr>
<th>Mot de passe associé</th>
<td>
- <input type="password" name="wedding_password" tal:attributes="value options/wedding_password" />
+ <input type="password" name="collection_password" tal:attributes="value options/collection_password" />
</td>
</tr>
<tr>
<th>Confirmation du mot de passe</th>
<td>
- <input type="password" name="wedding_password_confirm" tal:attributes="value options/wedding_password_confirm" />
+ <input type="password" name="collection_password_confirm" tal:attributes="value options/collection_password_confirm" />
</td>
</tr>
<tr>
##parameters=**kw
+from Products.photoprint.utils import grantAccess
kg = lambda name : kw.get(name,'').strip()
-weddingId = kg('wedding_id')
-if not weddingId :
+collectionId = kg('collection_id')
+if not collectionId :
return True
else :
- password = kg('wedding_password')
- confirm = kg('wedding_password_confirm')
+ password = kg('collection_password')
+ confirm = kg('collection_password_confirm')
memberId = kg('member_id')
- msg = context.grantAccess(context, weddingId, password, confirm, memberId)
+ msg = grantAccess(collectionId, password, confirm, memberId)
if msg :
return context.setStatus(False, msg)
else :
from zope.i18n import translate as i18ntranslate
from zope.i18nmessageid import MessageFactory
from zope.globalrequest import getRequest
+from Products.CMFCore.utils import getUtilityByInterfaceName
+from Products.Plinn.utils import _sudo
+import transaction
+
security = ModuleSecurityInfo('Products.photoprint.utils')
security.declarePublic('Message')
Message = _ = MessageFactory('photoprint')
+
+security.declarePublic('grantAccess')
+def grantAccess(collectionId, password, confirm, memberId) :
+ utool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool')
+ mtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IMembershipTool')
+ portal = utool.getPortalObject()
+
+ data = portal.private_collections.data
+ lines = filter(None, [l.strip() for l in data.split('\n')])
+ assert len(lines) % 3 == 0
+ collecInfos = {}
+ for i in xrange(0, len(lines), 3) :
+ collecInfos[lines[i]] = {'pw' : lines[i+1],
+ 'path' : lines[i+2]}
+
+ if not collecInfos.has_key(collectionId) :
+ transaction.abort()
+ return _('Wrong private collection identifier.')
+ elif password != confirm :
+ transaction.abort()
+ return _("Collection's password does not match confirmation.")
+ else :
+ if collecInfos[collectionId]['pw'] != password :
+ transaction.abort()
+ return _("Wrong collection's password.")
+ else :
+ collec = portal.unrestrictedTraverse(collecInfos[collectionId]['path'])
+ def do() :
+ mtool.setLocalRoles(collec, [memberId], 'Reader')
+
+ _sudo(do)