|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
|
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
|
7
|
|
|
# Foundation, version 2. |
|
8
|
|
|
# |
|
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
12
|
|
|
# details. |
|
13
|
|
|
# |
|
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
|
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17
|
|
|
# |
|
18
|
|
|
# Copyright 2018-2024 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from bika.lims import api |
|
22
|
|
|
from Products.CMFCore.utils import getToolByName |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def ObjectModifiedEventHandler(obj, event): |
|
26
|
|
|
""" Various types need automation on edit. |
|
27
|
|
|
""" |
|
28
|
|
|
try: |
|
29
|
|
|
portal_type = api.get_portal_type(obj) |
|
30
|
|
|
except api.APIError: |
|
31
|
|
|
# BBB: Might be an `at_references` folder |
|
32
|
|
|
return |
|
33
|
|
|
|
|
34
|
|
|
if portal_type == 'Contact': |
|
35
|
|
|
# Verify that the Contact details are the same as the Plone user. |
|
36
|
|
|
contact_username = obj.Schema()['Username'].get(obj) |
|
37
|
|
|
if contact_username: |
|
38
|
|
|
contact_email = obj.Schema()['EmailAddress'].get(obj) |
|
39
|
|
|
contact_fullname = obj.Schema()['Fullname'].get(obj) |
|
40
|
|
|
mt = getToolByName(obj, 'portal_membership') |
|
41
|
|
|
member = mt.getMemberById(contact_username) |
|
42
|
|
|
if member: |
|
43
|
|
|
properties = {'username': contact_username, |
|
44
|
|
|
'email': contact_email, |
|
45
|
|
|
'fullname': contact_fullname} |
|
46
|
|
|
member.setMemberProperties(properties) |
|
47
|
|
|
|