Browse Source

GDPR Modules for OCA V11

- Line length to max 79 characters
pull/10/head
ITISAG-OCA 6 years ago
parent
commit
e9e5699edf
  1. 14
      contact_search_form/__manifest__.py
  2. 28
      contact_search_form/models/contact_search.py
  3. 13
      website_contact_extend/__manifest__.py
  4. 82
      website_contact_extend/controllers/myfilter.py
  5. 2
      website_contact_extend/models/res_partner.py

14
contact_search_form/__manifest__.py

@ -1,24 +1,28 @@
##############################################################################
#####################################################################
# #
# IT IS AG, software solutions: http://www.itis.de # IT IS AG, software solutions: http://www.itis.de
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# #
##############################################################################
#####################################################################
{ {
'name': "Contact Search Form", 'name': "Contact Search Form",
'summary': """ 'summary': """
View for Data Protection Officer (DPO) to look up Customer Data. Odoo models can be searched for specified string.
To access contact search in contacts view, user must activate 'Data Protection Officer' checkbox in Technical Settings.
View for Data Protection Officer (DPO) to look up Customer Data.
Odoo models can be searched for specified string.
To access contact search in contacts view, user must activate
'Data Protection Officer' checkbox
in Technical Settings.
""", """,
'author': "IT IS AG, Odoo Community Association (OCA)", 'author': "IT IS AG, Odoo Community Association (OCA)",
'website': "https://github.com/OCA/data-protection", 'website': "https://github.com/OCA/data-protection",
# Categories can be used to filter modules in modules listing # Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# Check https://github.com/odoo/odoo/blob/master/
# openerp/addons/base/module/module_data.xml
# for the full list # for the full list
'version': '11.0.1.0.0', 'version': '11.0.1.0.0',
'license': 'AGPL-3', 'license': 'AGPL-3',

28
contact_search_form/models/contact_search.py

@ -9,7 +9,8 @@ class SearchLine(models.Model):
model_id = fields.Many2one('ir.model', string="Found in Model") model_id = fields.Many2one('ir.model', string="Found in Model")
record_id = fields.Integer(string="Record ID") record_id = fields.Integer(string="Record ID")
search_id = fields.Many2one("dpo.view", string="Search Terms") search_id = fields.Many2one("dpo.view", string="Search Terms")
record_name = fields.Char(string="Record Name", compute="_compute_record_name")
record_name = fields.Char(string="Record Name",
compute="_compute_record_name")
@api.multi @api.multi
def open_record(self): def open_record(self):
@ -26,7 +27,8 @@ class SearchLine(models.Model):
@api.one @api.one
def _compute_record_name(self): def _compute_record_name(self):
for record in self: for record in self:
record_object = self.env[self.model_id.model].search([('id', '=', int(self.record_id))])
record_object = self.env[self.model_id.model].\
search([('id', '=', int(self.record_id))])
try: try:
record.record_name = record_object.name record.record_name = record_object.name
except: except:
@ -36,22 +38,34 @@ class ItisDpoView(models.Model):
_name = "dpo.view" _name = "dpo.view"
name = fields.Char(string="Search Term") name = fields.Char(string="Search Term")
model_ids = fields.Many2many('ir.model', 'dpo_view_ir_model_rel', string="Search in Model")
search_lines = fields.One2many('search.line', 'search_id', string='Search Result')
model_ids = fields.Many2many('ir.model',
'dpo_view_ir_model_rel',
string="Search in Model")
search_lines = fields.One2many('search.line',
'search_id',
string='Search Result')
@api.multi @api.multi
def search_string(self): def search_string(self):
search_line_ids = self.env['search.line'].search([('search_id', '=', self.id)])
search_line_ids = self.env['search.line'].search([('search_id',
'=',
self.id)])
search_line_ids.unlink() search_line_ids.unlink()
final_list = [] final_list = []
for model_id in self.model_ids: for model_id in self.model_ids:
field_list = [] field_list = []
found_match = {} found_match = {}
for field_id in model_id.field_id: for field_id in model_id.field_id:
if field_id.ttype in ['char', 'html', 'text'] and field_id.store:
if field_id.ttype in ['char', 'html', 'text'] \
and field_id.store:
field_list.append(field_id.name) field_list.append(field_id.name)
for field in field_list: for field in field_list:
records = self.env[model_id.model].search([(field, 'ilike', self.name), (field, '!=', '')])
records = self.env[model_id.model].search([(field,
'ilike',
self.name),
(field,
'!=',
'')])
for rec in records: for rec in records:
temp_list = found_match.get(rec.id, False) temp_list = found_match.get(rec.id, False)
if temp_list: if temp_list:

13
website_contact_extend/__manifest__.py

@ -1,18 +1,20 @@
##############################################################################
###################################################################
# #
# IT IS AG, software solutions: http://www.itis.de # IT IS AG, software solutions: http://www.itis.de
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# #
##############################################################################
###################################################################
{ {
'name': "Website Contact Form Extend", 'name': "Website Contact Form Extend",
'summary': """ 'summary': """
Extended Website Contact View to give Customer the option on how to be contacted.
Extended Website Contact View to give Customer the option
on how to be contacted.
Customer can verifiy his email address with a verification link. Following that the mode of future contact can be chosen and
Customer can verifiy his email address with a verification link.
Following that the mode of future contact can be chosen and
a GDPR information request can be submitted. a GDPR information request can be submitted.
""", """,
@ -21,7 +23,8 @@
'website': "https://github.com/OCA/data-protection", 'website': "https://github.com/OCA/data-protection",
# Categories can be used to filter modules in modules listing # Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# Check https://github.com/odoo/odoo/blob/master/openerp/
# addons/base/module/module_data.xml
# for the full list # for the full list
'version': '11.0.1.0.0', 'version': '11.0.1.0.0',
'license': 'AGPL-3', 'license': 'AGPL-3',

82
website_contact_extend/controllers/myfilter.py

@ -8,10 +8,15 @@ import json
class VerifyController(http.Controller): class VerifyController(http.Controller):
@http.route('/verify_email', type='http', auth="public", methods=['GET'], website=True)
@http.route('/verify_email',
type='http',
auth="public",
methods=['GET'],
website=True)
def verify_email(self, **kwargs): def verify_email(self, **kwargs):
if kwargs: if kwargs:
link_data = base64.b64decode(kwargs.get("data")).decode("utf-8").split("####")
link_data = base64.b64decode(kwargs.get("data")).decode("utf-8")\
.split("####")
email = link_data[0] email = link_data[0]
contact_name = link_data[1] contact_name = link_data[1]
email_name = link_data[2] email_name = link_data[2]
@ -25,9 +30,10 @@ class VerifyController(http.Controller):
diff = today - link diff = today - link
if diff.days > 5 or diff.days < 0: if diff.days > 5 or diff.days < 0:
return "<center style='color:red'>Not valid!<br/>" \ return "<center style='color:red'>Not valid!<br/>" \
"The link you entered is either not valid or expired." \
"The link you entered is either not valid or expired."\
"<br/>Please request a new link.</center>" "<br/>Please request a new link.</center>"
partner = request.env['res.partner'].sudo().search([('email', '=', email), ('name', '=', contact_name)])
partner = request.env['res.partner'].sudo().search\
([('email', '=', email), ('name', '=', contact_name)])
if partner: if partner:
for part in partner: for part in partner:
part.is_verified = True part.is_verified = True
@ -44,20 +50,29 @@ class VerifyController(http.Controller):
part.letter_contact = True part.letter_contact = True
else: else:
part.letter_contact = False part.letter_contact = False
template = request.env.ref('website_contact_extend.confirmation_email_template').sudo().send_mail(part.id)
return "<center style='color:green'>Thank You! Your email address has been verified!</center>"
template = request.env.ref('website_contact_extend.'
'confirmation_email_template')\
.sudo().send_mail(part.id)
return "<center style='color:green'>" \
"Thank You! Your email address has been verified!" \
"</center>"
else: else:
return "<center style='color:red'>Not valid!<br/>" \ return "<center style='color:red'>Not valid!<br/>" \
"The link you entered is either not valid or expired." \
"The link you entered is either not valid or expired."\
"<br/>Please request a new link.</center>" "<br/>Please request a new link.</center>"
class MyFilter(parent_controller.WebsiteForm): class MyFilter(parent_controller.WebsiteForm):
@http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True)
@http.route('/website_form/<string:model_name>',
type='http',
auth="public",
methods=['POST'],
website=True)
def website_form(self, model_name, **kwargs): def website_form(self, model_name, **kwargs):
model_record = request.env['ir.model'].sudo().search([('model', '=', model_name),
('website_form_access', '=', True)])
model_record = request.env['ir.model'].sudo()\
.search([('model', '=', model_name),
('website_form_access', '=', True)])
if not model_record: if not model_record:
return json.dumps(False) return json.dumps(False)
# need_send_email = False # need_send_email = False
@ -74,28 +89,19 @@ class MyFilter(parent_controller.WebsiteForm):
contact_type = field_value contact_type = field_value
if field_name == "send_mail" and field_value == "send_mail": if field_name == "send_mail" and field_value == "send_mail":
send_mail = True send_mail = True
if field_name == "phone_contact" and field_value == "phone_contact":
if field_name == "phone_contact" \
and field_value == "phone_contact":
phone_contact = True phone_contact = True
if field_name == "letter_contact" and field_value == "letter_contact":
if field_name == "letter_contact" \
and field_value == "letter_contact":
letter_contact = True letter_contact = True
if field_name == "email_contact" and field_value == "email_contact":
if field_name == "email_contact" \
and field_value == "email_contact":
email_contact = True email_contact = True
index += 1 index += 1
contact_name = data.get("record").get("contact_name") contact_name = data.get("record").get("contact_name")
email_from = data.get("record").get("email_from") email_from = data.get("record").get("email_from")
# if data.get("record",False):
# partner_records = request.env['res.partner'].sudo().search([('name', '=', contact_name),
# ('email', '=', email_from)])
# for partner_record in partner_records:
# if partner_record:
# if partner_record.is_verified:
# partner_record.contact_type = contact_type
# partner_record.phone_contact = phone_contact
# partner_record.email_contact = email_contact
# partner_record.letter_contact = letter_contact
# if not partner_record.is_verified:
# need_send_email = True
# If we encounter an issue while extracting data # If we encounter an issue while extracting data
except ValidationError as e: except ValidationError as e:
@ -103,26 +109,38 @@ class MyFilter(parent_controller.WebsiteForm):
return json.dumps({'error_fields': e.args[0]}) return json.dumps({'error_fields': e.args[0]})
try: try:
id_record = self.insert_record(request, model_record, data['record'], data['custom'], data.get('meta'))
id_record = self.insert_record(request,
model_record,
data['record'],
data['custom'],
data.get('meta'))
if id_record: if id_record:
self.insert_attachment(model_record, id_record, data['attachments'])
self.insert_attachment(model_record,
id_record,
data['attachments'])
if id_record and send_mail and model_name == "crm.lead": if id_record and send_mail and model_name == "crm.lead":
crm_lead_obj = request.env['crm.lead'].sudo().search([('id', '=', id_record)])
crm_lead_obj = request.env['crm.lead'].sudo()\
.search([('id', '=', id_record)])
email_data = crm_lead_obj.email_from + "####" +\ email_data = crm_lead_obj.email_from + "####" +\
crm_lead_obj.contact_name + "####" +\ crm_lead_obj.contact_name + "####" +\
str(email_contact) + "####" +\ str(email_contact) + "####" +\
str(phone_contact) + "####" +\ str(phone_contact) + "####" +\
str(letter_contact)+"####" +\ str(letter_contact)+"####" +\
str(crm_lead_obj.create_date) str(crm_lead_obj.create_date)
ency_email = base64.b64encode(email_data.encode()).decode("utf-8")
ency_email = base64.b64encode(email_data.encode())\
.decode("utf-8")
action_url = '%s/verify_email/?data=%s' % ( action_url = '%s/verify_email/?data=%s' % (
request.env['ir.config_parameter'].sudo().get_param('web.base.url'),
request.env['ir.config_parameter'].
sudo().get_param('web.base.url'),
ency_email, ency_email,
) )
if crm_lead_obj: if crm_lead_obj:
crm_lead_obj.email_link = action_url crm_lead_obj.email_link = action_url
template = request.env.ref('website_contact_extend.verification_email_template').send_mail(id_record)
# Some fields have additional SQL constraints that we can't check generically
template = request.env.ref('website_contact_extend.'
'verification_email_template')\
.send_mail(id_record)
# Some fields have additional SQL constraints
# that we can't check generically
# Ex: crm.lead.probability which is a float between 0 and 1 # Ex: crm.lead.probability which is a float between 0 and 1
# TODO: How to get the name of the erroneous field ? # TODO: How to get the name of the erroneous field ?
except IntegrityError: except IntegrityError:

2
website_contact_extend/models/res_partner.py

@ -23,4 +23,4 @@ class ResContacts(models.Model):
class CrmLead(models.Model): class CrmLead(models.Model):
_inherit = "crm.lead" _inherit = "crm.lead"
email_link = fields.Char("Email verification link")
email_link = fields.Char("Email verification link")
Loading…
Cancel
Save