Exemplo n.º 1
0
    def mail_update_message(self, res_id, message, message_id, **post):

        res_model = 'slide.channel'  # keep this mecanism intern to slide
        message_body = plaintext2html(message)
        res_id = int(res_id)
        message_id = int(message_id)
        pid = int(post['pid']) if post.get('pid') else False

        if not _check_special_access(res_model,
                                     res_id,
                                     token=post.get('token'),
                                     _hash=post.get('hash'),
                                     pid=pid):
            raise Forbidden()

        # update mail.message
        domain = [('model', '=', res_model), ('res_id', '=', res_id),
                  ('website_published', '=', True),
                  ('author_id', '=', request.env.user.partner_id.id),
                  ('id', '=', message_id)]  # restrict to the given message_id
        message = request.env['mail.message'].search(domain, limit=1)
        if not message:
            raise NotFound()
        message.write({'body': message_body})

        # update rating
        if post.get('rating_value'):
            domain = [('res_model', '=', res_model), ('res_id', '=', res_id),
                      ('website_published', '=', True),
                      ('message_id', '=', message.id)]
            rating = request.env['rating.rating'].search(
                domain, order='write_date DESC', limit=1)
            rating.write({'rating': float(post['rating_value'])})

        return werkzeug.utils.redirect(request.httprequest.referrer, 302)
Exemplo n.º 2
0
    def mail_update_message(self, res_id, message, message_id, **post):

        res_model = 'slide.channel'  # keep this mecanism intern to slide
        message_body = plaintext2html(message)
        res_id = int(res_id)
        message_id = int(message_id)
        pid = int(post['pid']) if post.get('pid') else False

        if not _check_special_access(res_model, res_id, token=post.get('token'), _hash=post.get('hash'), pid=pid):
            raise Forbidden()

        # update mail.message
        domain = [
            ('model', '=', res_model),
            ('res_id', '=', res_id),
            ('website_published', '=', True),
            ('author_id', '=', request.env.user.partner_id.id),
            ('id', '=', message_id)
        ]  # restrict to the given message_id
        message = request.env['mail.message'].search(domain, limit=1)
        if not message:
            raise NotFound()
        message.write({
            'body': message_body
        })

        # update rating
        if post.get('rating_value'):
            domain = [('res_model', '=', res_model), ('res_id', '=', res_id), ('website_published', '=', True), ('message_id', '=', message.id)]
            rating = request.env['rating.rating'].search(domain, order='write_date DESC', limit=1)
            rating.write({
                'rating': float(post['rating_value'])
            })

        return werkzeug.utils.redirect(request.httprequest.referrer, 302)
Exemplo n.º 3
0
    def mail_update_message(self,
                            res_model,
                            res_id,
                            message,
                            message_id,
                            redirect=None,
                            attachment_ids='',
                            attachment_tokens='',
                            **post):
        # keep this mechanism intern to slide currently (saas 12.5) as it is
        # considered experimental
        if res_model != 'slide.channel':
            raise Forbidden()
        res_id = int(res_id)

        attachment_ids = [
            int(attachment_id) for attachment_id in attachment_ids.split(',')
            if attachment_id
        ]
        attachment_tokens = [
            attachment_token
            for attachment_token in attachment_tokens.split(',')
            if attachment_token
        ]
        self._portal_post_check_attachments(attachment_ids, attachment_tokens)

        pid = int(post['pid']) if post.get('pid') else False
        if not _check_special_access(res_model,
                                     res_id,
                                     token=post.get('token'),
                                     _hash=post.get('hash'),
                                     pid=pid):
            raise Forbidden()

        # fetch and update mail.message
        message_id = int(message_id)
        message_body = plaintext2html(message)
        domain = [('model', '=', res_model), ('res_id', '=', res_id),
                  ('is_internal', '=', False),
                  ('author_id', '=', request.env.user.partner_id.id),
                  ('message_type', '=', 'comment'),
                  ('id', '=', message_id)]  # restrict to the given message_id
        message = request.env['mail.message'].search(domain, limit=1)
        if not message:
            raise NotFound()
        message.sudo().write({
            'body':
            message_body,
            'attachment_ids': [(4, aid) for aid in attachment_ids],
        })

        # update rating
        if post.get('rating_value'):
            domain = [('res_model', '=', res_model), ('res_id', '=', res_id),
                      ('is_internal', '=', False),
                      ('message_id', '=', message.id)]
            rating = request.env['rating.rating'].sudo().search(
                domain, order='write_date DESC', limit=1)
            rating.write({
                'rating': float(post['rating_value']),
                'feedback': html2plaintext(message.body),
            })

        # redirect to specified or referrer or simply channel page as fallback
        redirect_url = redirect or (request.httprequest.referrer
                                    and request.httprequest.referrer +
                                    '#review') or '/slides/%s' % res_id
        return werkzeug.utils.redirect(redirect_url, 302)
Exemplo n.º 4
0
    def mail_update_message(self,
                            res_model,
                            res_id,
                            message,
                            message_id,
                            attachment_ids=None,
                            attachment_tokens=None,
                            **post):
        # keep this mechanism intern to slide currently (saas 12.5) as it is
        # considered experimental
        if res_model != 'slide.channel':
            raise Forbidden()
        res_id = int(res_id)

        self._portal_post_check_attachments(attachment_ids, attachment_tokens)

        pid = int(post['pid']) if post.get('pid') else False
        if not _check_special_access(res_model,
                                     res_id,
                                     token=post.get('token'),
                                     _hash=post.get('hash'),
                                     pid=pid):
            raise Forbidden()

        # fetch and update mail.message
        message_id = int(message_id)
        message_body = plaintext2html(message)
        domain = [('model', '=', res_model), ('res_id', '=', res_id),
                  ('is_internal', '=', False),
                  ('author_id', '=', request.env.user.partner_id.id),
                  ('message_type', '=', 'comment'),
                  ('id', '=', message_id)]  # restrict to the given message_id
        message = request.env['mail.message'].search(domain, limit=1)
        if not message:
            raise NotFound()
        message.sudo().write({
            'body':
            message_body,
            'attachment_ids': [(4, aid) for aid in attachment_ids],
        })

        # update rating
        if post.get('rating_value'):
            domain = [('res_model', '=', res_model), ('res_id', '=', res_id),
                      ('is_internal', '=', False),
                      ('message_id', '=', message.id)]
            rating = request.env['rating.rating'].sudo().search(
                domain, order='write_date DESC', limit=1)
            rating.write({
                'rating': float(post['rating_value']),
                'feedback': html2plaintext(message.body),
            })
        channel = request.env[res_model].browse(res_id)
        return {
            'default_message_id':
            message.id,
            'default_message':
            html2plaintext(message.body),
            'default_rating_value':
            message.rating_value,
            'rating_avg':
            channel.rating_avg,
            'rating_count':
            channel.rating_count,
            'default_attachment_ids':
            message.attachment_ids.sudo().read(
                ['id', 'name', 'mimetype', 'file_size', 'access_token']),
            'force_submit_url':
            '/slides/mail/update_comment',
        }