[IMP] website_slide: use classical chatter

Slide provided a chatter where you can post message as
public user. We decided to drop that feature in order
to avoid spamming.
Like for all other document, you must at least, be portal
user to post a comment.
Reusing the standart chatter highly simplify the code.
This commit is contained in:
Jérome Maes
2017-06-30 11:07:01 +02:00
parent 760c677d5c
commit 870b51134d
3 changed files with 4 additions and 89 deletions
-46
View File
@@ -168,52 +168,6 @@ class WebsiteSlides(http.Controller):
response.mimetype = 'application/pdf'
return response
@http.route('''/slides/slide/<model("slide.slide", "[('channel_id.can_see', '=', True)]"):slide>/comment''', type='http', auth="public", methods=['POST'], website=True)
def slide_comment(self, slide, **post):
""" Controller for message_post. Public user can post; their name and
email is used to find or create a partner and post as admin with the
right partner. Their comments are unpublished by default. Logged
users can post as usual. """
# TDE TODO :
# - subscribe partner instead of user writing the message ?
# - public user -> cannot create mail.message ?
if not post.get('comment'):
return werkzeug.utils.redirect(request.httprequest.referrer + "#discuss")
# public user: check or find author based on email, do not subscribe public user
# and do not publish their comments by default to avoid direct spam
if request.uid == request.website.user_id.id:
if not post.get('email'):
return werkzeug.utils.redirect(request.httprequest.referrer + "#discuss")
# TDE FIXME: public user has no right to create mail.message, should
# be investigated - using SUPERUSER_ID meanwhile
contextual_slide = slide.sudo().with_context(mail_create_nosubcribe=True)
# TDE FIXME: check in mail_thread, find partner from emails should maybe work as public user
partner_id = slide.sudo()._find_partner_from_emails([post.get('email')])[0]
if partner_id:
partner = request.env['res.partner'].sudo().browse(partner_id)
else:
partner = request.env['res.partner'].sudo().create({
'name': post.get('name', post['email']),
'email': post['email']
})
post_kwargs = {
'author_id': partner.id,
'website_published': False,
'email_from': partner.email,
}
# logged user: as usual, published by default
else:
contextual_slide = slide
post_kwargs = {}
contextual_slide.message_post(
body=post['comment'],
message_type='comment',
subtype='mt_comment',
**post_kwargs
)
return werkzeug.utils.redirect(request.httprequest.referrer + "#discuss")
@http.route('''/slides/slide/<model("slide.slide", "[('channel_id.can_see', '=', True), ('download_security', '=', 'public')]"):slide>/download''', type='http', auth="public", website=True)
def slide_download(self, slide):
if slide.download_security == 'public' or (slide.download_security == 'user' and request.session.uid):
+1
View File
@@ -261,6 +261,7 @@ class Slide(models.Model):
_name = 'slide.slide'
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.mixin']
_description = 'Slides'
_mail_post_access = 'read'
_PROMOTIONAL_FIELDS = [
'__last_update', 'name', 'image_thumb', 'image_medium', 'slide_type', 'total_views', 'category_id',
+3 -43
View File
@@ -543,49 +543,9 @@
</h4>
</div>
<div t-att-class="comments and 'tab-pane fade active in' or 'tab-pane fade'" id="discuss">
<form id="comment" class="js_website_submit_form" t-attf-action="/slides/slide/#{slide.id}/comment" method="POST">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<div class="media">
<span class="pull-left" t-if="not is_public_user">
<img class="img img-circle media-object"
t-att-src="'/web/image?model=res.partner&amp;field=image_small&amp;id='+str(user_id.partner_id.id)"
style="width: 30px"/>
</span>
<div class="media-body">
<div t-if="is_public_user" class="col-md-6">
<input type="name" class="form-control mb8" required="true" name="name" placeholder="Your Name"/>
<input type="email" class="form-control mb8" required="true" name="email" placeholder="Email Address"/>
</div>
<div t-if="is_public_user" class="col-md-6">
<p class="text-muted small">
Post comment with email address (confirmation of email is required in order to publish comment on website) or please
<a t-attf-href="/web?redirect=#{request.httprequest.url}">login</a>
to post comment
</p>
</div>
<div class="col-md-12">
<textarea rows="3" name="comment" class="o_slides_comment form-control" required="true" placeholder="Write a comment..."></textarea>
<button type="submit" class="btn btn-primary mt8">Post</button>
</div>
</div>
</div>
</form>
<ul class="media-list mt8">
<li t-foreach="comments" t-as="message" class="media">
<span class="pull-left">
<img class="media-object img img-circle"
t-att-src="'/web/image?model=mail.message&amp;field=author_avatar&amp;id='+str(message.id)" style="width: 30px"/>
</span>
<div class="media-body">
<t t-call="website.publish_short">
<t t-set="object" t-value="message"/>
</t>
<span t-field="message.author_id" style="display: inline-block;" t-options='{"widget": "contact", "fields": ["name"]}'/>
<span class="text-muted">on<span t-field="message.date"/></span>
<div t-field="message.body" class="discussion_scroll_post"></div>
</div>
</li>
</ul>
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="slide"/>
</t>
</div>
<div class="tab-pane fade oe_slides_transcript" id="transcript">
<t t-if="slide.index_content">