Commit faf3fa14 authored by Romain Courteaud's avatar Romain Courteaud

Surcharge person.getTitle

parent 88bdb0e7
from AccessControl import ClassSecurityInfo, Unauthorized, getSecurityManager from AccessControl import ClassSecurityInfo, Unauthorized, getSecurityManager
from Products.ERP5.Document.Person import Person as ERP5Person from Products.ERP5.Document.Person import Person as ERP5Person
from Products.ERP5Type import Permissions
class Person(ERP5Person): class Person(ERP5Person):
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -36,3 +37,17 @@ class Person(ERP5Person): ...@@ -36,3 +37,17 @@ class Person(ERP5Person):
"""Revokes existing certificate""" """Revokes existing certificate"""
self._checkCertificateRequest() self._checkCertificateRequest()
self._revokeCertificate() self._revokeCertificate()
security.declareProtected(Permissions.AccessContentsInformation,
'getTitle')
def getTitle(self, **kw):
"""
Returns the title if it exists or a combination of
first name and last name
"""
title = ERP5Person.getTitle(self, **kw)
test_title = title.replace(' ', '')
if test_title == '':
return self.getDefaultEmailCoordinateText()
else:
return title
# -*- coding: utf-8 -*-
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved.
import transaction
from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin
class TestSlapOSPersonDocument(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def test_getTitle(self):
person = self.portal.person_module.newContent(
portal_type="Person")
# Default title is empty
self.assertEquals(person.getTitle(), None)
# If not title, the email is used
person.edit(default_email_coordinate_text="foo@example.org")
self.assertEquals(person.getTitle(), 'foo@example.org')
# But if first name, last name are set, use them
person.edit(first_name="foo", last_name="bar")
self.assertEquals(person.getTitle(), 'foo bar')
# Finally, if the title is set
person.edit(title="foobar")
self.assertEquals(person.getTitle(), 'foobar')
276 277
\ No newline at end of file \ No newline at end of file
...@@ -3,3 +3,4 @@ testSlapOSCloudConstraint ...@@ -3,3 +3,4 @@ testSlapOSCloudConstraint
testSlapOSCloudSecurityGroup testSlapOSCloudSecurityGroup
testSlapOSCloudShadow testSlapOSCloudShadow
testSlapOSCloudWorkflow testSlapOSCloudWorkflow
testSlapOSCloudDocument
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment