def _linkUser(self, user):
        """Set the UID of the current Contact in the User properties and update
        all relevant own properties.
        """
        KEY = "linked_contact_uid"

        username = user.getId()
        contact = self.getContactByUsername(username)

        # User is linked to another contact (fix in UI)
        if contact and contact.UID() != self.UID():
            raise ValueError("User '{}' is already linked to Contact '{}'"
                             .format(username, contact.Title()))

        # User is linked to multiple other contacts (fix in Data)
        if isinstance(contact, list):
            raise ValueError("User '{}' is linked to multiple Contacts: '{}'"
                             .format(username, ",".join(
                                 map(lambda x: x.Title(), contact))))

        # XXX: Does it make sense to "remember" the UID as a User property?
        tool = user.getTool()
        try:
            user.getProperty(KEY)
        except ValueError:
            logger.info("Adding User property {}".format(KEY))
            tool.manage_addProperty(KEY, "", "string")

        # Set the UID as a User Property
        uid = self.UID()
        user.setMemberProperties({KEY: uid})
        logger.info("Linked Contact UID {} to User {}".format(
            user.getProperty(KEY), username))

        # Set the Username
        self.setUsername(user.getId())

        # Update the Email address from the user
        self.setEmailAddress(user.getProperty("email"))

        # somehow the `getUsername` index gets out of sync
        self.reindexObject()

        # N.B. Local owner role and client group applies only to client
        #      contacts, but not lab contacts.
        if IClient.providedBy(self.aq_parent):
            # Grant local Owner role
            self._addLocalOwnerRole(username)
            # Add user to "Clients" group
            self._addUserToGroup(username, group="Clients")

        return True
def _linkUser ( self , user ) : KEY = "linked_contact_uid" username = user . getId ( ) contact = self . getContactByUsername ( username ) if contact and contact . UID ( ) != self . UID ( ) : raise ValueError ( "User '{}' is already linked to Contact '{}'" . format ( username , contact . Title ( ) ) ) if isinstance ( contact , list ) : raise ValueError ( "User '{}' is linked to multiple Contacts: '{}'" . format ( username , "," . join ( map ( lambda x : x . Title ( ) , contact ) ) ) ) tool = user . getTool ( ) try : user . getProperty ( KEY ) except ValueError : logger . info ( "Adding User property {}" . format ( KEY ) ) tool . manage_addProperty ( KEY , "" , "string" ) uid = self . UID ( ) user . setMemberProperties ( { KEY : uid } ) logger . info ( "Linked Contact UID {} to User {}" . format ( user . getProperty ( KEY ) , username ) ) self . setUsername ( user . getId ( ) ) self . setEmailAddress ( user . getProperty ( "email" ) ) self . reindexObject ( ) if IClient . providedBy ( self . aq_parent ) : self . _addLocalOwnerRole ( username ) self . _addUserToGroup ( username , group = "Clients" ) return True
Set the UID of the current Contact in the User properties and update
        all relevant own properties.