diff options
| author | David Beguin <dbe@odoo.com> | 2019-02-20 16:54:36 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2019-03-15 14:58:28 +0000 |
| commit | fb40c6bf6018f7f208201e1d4a4d413fd2ce3080 (patch) | |
| tree | d6df1ec5f2e7aca08311a51fad7f2ab3162a6806 /addons/website_forum | |
| parent | bbedcdb19054527940fb040a0d4f22115d5be265 (diff) | |
[IMP] website(_profile,_forum,_slides): move validation email to profile and use in forum and elearning
Email validation was necessary on the forum to be able to begin to use the forum
(ask or answer questions, vote, etc..)
As the new elearning also uses karma since 705376a982d64fb41800f148a167ef0fc28ce4c6,
the email validation is now also necessary in the eLearning platform.
This is why this commit is moving the email validation process to website_profile
and extend website_slides (eLearning) and website_forum to use this feature.
In function of where the user asked to send him the validation email,
the user is redirected on the forum or on the elearning when he clicks on
'Validate my account' in the received 'email validation' email.
Task ID : 1943788
PR #31321
Diffstat (limited to 'addons/website_forum')
| -rw-r--r-- | addons/website_forum/controllers/main.py | 37 | ||||
| -rw-r--r-- | addons/website_forum/data/forum_data.xml | 102 | ||||
| -rw-r--r-- | addons/website_forum/models/forum.py | 10 | ||||
| -rw-r--r-- | addons/website_forum/models/res_users.py | 51 | ||||
| -rw-r--r-- | addons/website_forum/static/src/js/website_forum.js | 30 | ||||
| -rw-r--r-- | addons/website_forum/views/website_forum.xml | 22 |
6 files changed, 22 insertions, 230 deletions
diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index f31b59e430f..ed2cb30df2e 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -3,6 +3,7 @@ import json import lxml import requests +import logging import werkzeug.exceptions import werkzeug.urls import werkzeug.wrappers @@ -15,6 +16,8 @@ from odoo.addons.website.models.ir_http import sitemap_qs2dom from odoo.addons.website_profile.controllers.main import WebsiteProfile from odoo.http import request +_logger = logging.getLogger(__name__) + class WebsiteForum(WebsiteProfile): _post_per_page = 10 @@ -26,8 +29,6 @@ class WebsiteForum(WebsiteProfile): values.update({ 'header': kwargs.get('header', dict()), 'searches': kwargs.get('searches', dict()), - 'validation_email_sent': request.session.get('validation_email_sent', False), - 'validation_email_done': request.session.get('validation_email_done', False), }) if kwargs.get('forum'): values['forum'] = kwargs.get('forum') @@ -37,32 +38,21 @@ class WebsiteForum(WebsiteProfile): # User and validation # -------------------------------------------------- - + # TODO DBE : Those 3 are deprecated. To remove in v13. @http.route('/forum/send_validation_email', type='json', auth='user', website=True) - def send_validation_email(self, forum_id=None, **kwargs): - if request.env.uid != request.website.user_id.id: - request.env.user._send_forum_validation_email(forum_id=forum_id) - request.session['validation_email_sent'] = True - return True + def send_forum_validation_email(self, forum_id=None, **kwargs): + _logger.warning("The method send_forum_validation_email() is deprecated and should be removed in v13.") + return self.send_forum_validation_email(forum_id=forum_id, **kwargs) @http.route('/forum/validate_email', type='http', auth='public', website=True, sitemap=False) - def validate_email(self, token, id, email, forum_id=None, **kwargs): - if forum_id: - try: - forum_id = int(forum_id) - except ValueError: - forum_id = None - done = request.env['res.users'].sudo().browse(int(id)).process_forum_validation_token(token, email, forum_id=forum_id)[0] - if done: - request.session['validation_email_done'] = True - if forum_id: - return request.redirect("/forum/%s" % int(forum_id)) - return request.redirect('/forum') + def forum_validate_email(self, token, user_id, email, forum_id=None, **kwargs): + _logger.warning("The method forum_validate_email() is deprecated and should be removed in v13.") + return self.forum_validate_email(token=token, user_id=user_id, email=email, forum_id=forum_id, **kwargs) @http.route('/forum/validate_email/close', type='json', auth='public', website=True) - def validate_email_done(self): - request.session['validation_email_done'] = False - return True + def forum_validate_email_done(self, **kwargs): + _logger.warning("The method forum_validate_email_done() is deprecated and should be removed in v13.") + return self.validate_email_done(**kwargs) # Forum # -------------------------------------------------- @@ -550,6 +540,7 @@ class WebsiteForum(WebsiteProfile): # Profile # ----------------------------------- + @http.route(['/forum/<model("forum.forum"):forum>/user/<int:user_id>'], type='http', auth="public", website=True) def view_user_forum_profile(self, forum, user_id, **post): return werkzeug.utils.redirect('/profile/user/' + str(user_id) + '?forum_id=' + str(forum.id)) diff --git a/addons/website_forum/data/forum_data.xml b/addons/website_forum/data/forum_data.xml index fe5fb2b8ea2..4196804495a 100644 --- a/addons/website_forum/data/forum_data.xml +++ b/addons/website_forum/data/forum_data.xml @@ -129,107 +129,5 @@ <field name="reason_type">offensive</field> </record> - <!-- Email template for email validation (for karma purpose) --> - <record id="validation_email" model="mail.template"> - <field name="name">Forum: Email Verification</field> - <field name="model_id" ref="base.model_res_users"/> - <field name="subject">${object.company_id.name} Forums validation</field> - <field name="email_from">${('<%s>' % (object.env.user.company_id.email or user.email)) | safe}</field> - <field name="email_to">${object.email|safe}</field> - <field name="body_html" type="html"> -<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center"> -<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;"> -<tbody> - <!-- HEADER --> - <tr> - <td align="center" style="min-width: 590px;"> - <table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;"> - <tr> - <td valign="middle"> - <span style="font-size: 10px;">Your Forum</span><br/> - <span style="font-size: 20px; font-weight: bold;"> - ${object.company_id.name} Forum validation - </span> - </td> - <td valign="middle" align="right"> - <img src="/logo.png?company=${user.company_id.id}" style="padding: 0px; margin: 0px; height: auto; width: 80px;" alt="${user.company_id.name}"/> - </td> - </tr> - <tr> - <td colspan="2" style="text-align:center;"> - <hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin:16px 0px 16px 0px;"/> - </td> - </tr> - </table> - </td> - </tr> - <!-- CONTENT --> - <tr> - <td align="center" style="min-width: 590px;"> - <table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;"> - <tr> - <td valign="top" style="font-size: 13px;"> - <p style="margin: 0px; padding: 0px; font-size: 13px;"> - Hello ${object.name},<br /><br /> - You have been invited to validate your email in order to get access to "${object.company_id.name}" Q/A Forums. - To validate your email, please click on the following link: - <div style="margin: 16px 0px 16px 0px;"> - <a href="${ctx.get('token_url')}" - style="background-color: #875A7B; padding: 8px 16px 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;"> - Validate my account - </a> - </div> - Thanks for your participation! - </p> - </td> - </tr> - <tr> - <td style="text-align:center;"> - <hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"/> - </td> - </tr> - </table> - </td> - </tr> - <!-- FOOTER --> - <tr> - <td align="center" style="min-width: 590px;"> - <table border="0" cellpadding="0" cellspacing="0" width="590" style=" font-family: 'Verdana Regular'; color: #454748; min-width: 590px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;"> - <tr> - <td valign="middle" align="left"> - ${user.company_id.name} - </td> - <td valign="middle" align="right" style="opacity: 0.7;"> - ${user.company_id.phone} - % if user.company_id.email: - | <a href="'mailto:%s' % ${user.company_id.email}" style="text-decoration:none; color: #454748;"> - ${user.company_id.email} - </a> - % endif - % if user.company_id.website: - | <a href="${user.company_id.website}" style="text-decoration:none; color: #454748;"> - ${user.company_id.website} - </a> - % endif - </td> - </tr> - </table> - </td> - </tr> -</tbody> -</table> -</td></tr> -<!-- POWERED BY --> -<tr><td align="center" style="min-width: 590px;"> - <table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: #F1F1F1; color: #454748; padding: 8px; border-collapse:separate;"> - <tr><td style="text-align: center; font-size: 13px;"> - Powered by <a target="_blank" href="https://www.odoo.com?utm_source=db&utm_medium=forum" style="color: #875A7B;">Odoo</a> - </td></tr> - </table> -</td></tr> -</table> - </field> - </record> - </data> </odoo> diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 68d48b8534f..4dc172a90a0 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -4,7 +4,6 @@ import logging import math import re -import uuid from datetime import datetime from odoo.addons.gamification.models.gamification_karma_rank import KarmaError @@ -21,15 +20,6 @@ class Forum(models.Model): _description = 'Forum' _inherit = ['mail.thread', 'website.seo.metadata', 'website.multi.mixin'] - @api.model_cr - def init(self): - """ Add forum uuid for user email validation. - - TDE TODO: move me somewhere else, auto_init ? """ - forum_uuids = self.env['ir.config_parameter'].search([('key', '=', 'website_forum.uuid')]) - if not forum_uuids: - forum_uuids.set_param('website_forum.uuid', str(uuid.uuid4())) - @api.model def _get_default_faq(self): with misc.file_open('website_forum/data/forum_default_faq.html', 'r') as f: diff --git a/addons/website_forum/models/res_users.py b/addons/website_forum/models/res_users.py index 43791f3538c..67326175ac9 100644 --- a/addons/website_forum/models/res_users.py +++ b/addons/website_forum/models/res_users.py @@ -32,57 +32,6 @@ class Users(models.Model): domain = [('parent_id', '=', False), ('state', '=', 'pending'), ('create_uid', '=', user.id)] user.forum_waiting_posts_count = Post.search_count(domain) - @api.model - def _generate_forum_token(self, user_id, email): - """Return a token for email validation. This token is valid for the day - and is a hash based on a (secret) uuid generated by the forum module, - the user_id, the email and currently the day (to be updated if necessary). """ - forum_uuid = self.env['ir.config_parameter'].sudo().get_param('website_forum.uuid') - return hashlib.sha256((u'%s-%s-%s-%s' % ( - datetime.now().replace(hour=0, minute=0, second=0, microsecond=0), - forum_uuid, - user_id, - email - )).encode('utf-8')).hexdigest() - - @api.one - def _send_forum_validation_email(self, forum_id=None): - if not self.email: - return False - token = self._generate_forum_token(self.id, self.email) - activation_template = self.env.ref('website_forum.validation_email') - if activation_template: - params = { - 'token': token, - 'id': self.id, - 'email': self.email} - if forum_id: - params['forum_id'] = forum_id - base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') - token_url = base_url + '/forum/validate_email?%s' % urls.url_encode(params) - with self._cr.savepoint(): - activation_template.sudo().with_context(token_url=token_url).send_mail( - self.id, force_send=True, raise_exception=True) - return True - - @api.one - def process_forum_validation_token(self, token, email, forum_id=None, context=None): - validation_token = self._generate_forum_token(self.id, email) - if token == validation_token and self.karma == 0: - karma = 3 - forum = None - if forum_id: - forum = self.env['forum.forum'].browse(forum_id) - else: - forum_ids = self.env['forum.forum'].search([], limit=1) - if forum_ids: - forum = forum_ids[0] - if forum: - # karma gained: karma to ask a question and have 2 downvotes - karma = forum.karma_ask + (-2 * forum.karma_gen_question_downvote) - return self.write({'karma': karma}) - return False - # Wrapper for call_kw with inherits @api.multi def open_website_url(self): diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 613163a045a..cfca0be8454 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -6,6 +6,7 @@ var Wysiwyg = require('web_editor.wysiwyg.root'); var sAnimations = require('website.content.snippets.animation'); var session = require('web.session'); var qweb = core.qweb; +var WebsiteProfile = require('website_profile.website_profile'); var _t = core._t; @@ -29,8 +30,6 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({ 'click .favourite_question': '_onFavoriteQuestionClick', 'click .comment_delete': '_onDeleteCommentClick', 'click .notification_close': '_onCloseNotificationClick', - 'click .send_validation_email': '_onSendValidationEmailClick', - 'click .validated_email_close': '_onCloseValidatedEmailClick', 'click .js_close_intro': '_onCloseIntroClick', }, @@ -469,32 +468,6 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({ * @private * @param {Event} ev */ - _onSendValidationEmailClick: function (ev) { - ev.preventDefault(); - var $link = $(ev.currentTarget); - this._rpc({ - route: '/forum/send_validation_email', - params: { - forum_id: $link.attr('forum-id'), - }, - }).then(function (data) { - if (data) { - $('button.validation_email_close').click(); - } - }); - }, - /** - * @private - */ - _onCloseValidatedEmailClick: function () { - this._rpc({ - route: '/forum/validate_email/close', - }); - }, - /** - * @private - * @param {Event} ev - */ _onCloseIntroClick: function (ev) { ev.preventDefault(); document.cookie = 'forum_welcome_message = false'; @@ -579,4 +552,5 @@ sAnimations.registry.websiteForumSpam = sAnimations.Class.extend({ }); }, }); + }); diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 482a7d9541b..1c4755f7092 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -52,22 +52,12 @@ <div id="wrap" t-attf-class="container #{website_forum_action}"> <div class="row"> - <div class="col o_left_forum_container mb16 mt16"> - <div t-if="not validation_email_sent and not is_public_user and user.karma == 0" class="alert alert-danger alert-dismissable" role="alert"> - <button type="button" class="close validation_email_close" data-dismiss="alert" aria-label="Close">&times;</button> - <div> - <p> - It appears your email has not been verified. - <a class="send_validation_email" href="#" t-att-forum-id="forum.id">Click here to send a verification email allowing you to participate to the forum.</a> - </p> - </div> - </div> - <div t-if="validation_email_done" class="alert alert-success alert-dismissable" role="status"> - <button type="button" class="close validated_email_close" data-dismiss="alert" aria-label="Close">&times;</button> - <div> - <p>Congratulations! Your email has just been validated. You may now participate to our forums.</p> - </div> - </div> + <div class="o_wprofile_email_validation_container mb16 mt16"> + <t t-call="website_profile.email_validation_banner"> + <t t-set="redirect_url" t-value="'/forum/%s' % forum.id"/> + <t t-set="send_validation_email_message" t-value="'Click here to send a verification email allowing you to participate to the forum.'"/> + <t t-set="additional_validated_email_message" t-value="' You may now participate to our forums.'"/> + </t> <t t-raw="0"/> </div> <t t-if="not is_profile_page"> |
