[FIX] website_forum: when a user posting a new answer or question does not have a valid email address, redirect to the user's profile instead of crashing when trying to send notifications.
This commit is contained in:
parent
240e042363
commit
f274572c30
|
@ -3,6 +3,7 @@
|
|||
from datetime import datetime
|
||||
import werkzeug.urls
|
||||
import werkzeug.wrappers
|
||||
import re
|
||||
import simplejson
|
||||
|
||||
from openerp import tools
|
||||
|
@ -12,6 +13,7 @@ from openerp.addons.web.controllers.main import login_redirect
|
|||
from openerp.addons.web.http import request
|
||||
from openerp.addons.website.controllers.main import Website as controllers
|
||||
from openerp.addons.website.models.website import slug
|
||||
from openerp.tools.translate import _
|
||||
|
||||
controllers = controllers()
|
||||
|
||||
|
@ -276,6 +278,10 @@ class WebsiteForum(http.Controller):
|
|||
def post_new(self, forum, post, **kwargs):
|
||||
if not request.session.uid:
|
||||
return login_redirect()
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
if not user.email or not tools.single_email_re.match(user.email):
|
||||
return werkzeug.utils.redirect("/forum/%s/user/%s/edit?email_required=1" % (slug(forum), uid))
|
||||
request.registry['forum.post'].create(
|
||||
request.cr, request.uid, {
|
||||
'forum_id': forum.id,
|
||||
|
@ -517,6 +523,7 @@ class WebsiteForum(http.Controller):
|
|||
countries = country.browse(request.cr, SUPERUSER_ID, country_ids, context=request.context)
|
||||
values = self._prepare_forum_values(forum=forum, searches=kwargs)
|
||||
values.update({
|
||||
'email_required': kwargs.get('email_required'),
|
||||
'countries': countries,
|
||||
'notifications': self._get_notifications(),
|
||||
})
|
||||
|
|
|
@ -112,6 +112,14 @@ a.no-decoration {
|
|||
z-index: 9999;
|
||||
}
|
||||
|
||||
.oe_forum_email_required {
|
||||
position: absolute;
|
||||
margin-top: 155px;
|
||||
margin-left: 500px;
|
||||
margin-right: 100px;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
button.btn-link.text-muted {
|
||||
color: #999999;
|
||||
}
|
||||
|
|
|
@ -91,5 +91,12 @@ a.no-decoration
|
|||
width: 300px
|
||||
z-index: 9999
|
||||
|
||||
.oe_forum_email_required
|
||||
position: absolute
|
||||
margin-top: 155px
|
||||
margin-left: 500px
|
||||
margin-right: 100px
|
||||
z-index: 5
|
||||
|
||||
button.btn-link.text-muted
|
||||
color: #999
|
||||
|
|
|
@ -832,6 +832,10 @@
|
|||
<div class="col-md-7 mb16">
|
||||
<input type="text" class="form-control" name="website" t-attf-value="#{user.partner_id.website or ''}"/>
|
||||
</div>
|
||||
<div t-if="email_required" class="alert alert-danger alert-dismissable oe_forum_email_required">
|
||||
<button type="button" class="close" data-dismiss="alert">x</button>
|
||||
<p>Please enter a valid email address in order to receive notifications from answers or comments.</p>
|
||||
</div>
|
||||
<label class="col-md-4 control-label mb16" for="user.partner_id.email">Email</label>
|
||||
<div class="col-md-7 mb16">
|
||||
<input type="text" class="form-control" name="email" required="True" t-attf-value="#{user.partner_id.email}"/>
|
||||
|
|
Loading…
Reference in New Issue