Example #1
0
 def mail_attachment_upload(self,
                            ufile,
                            thread_id,
                            thread_model,
                            is_pending=False,
                            **kwargs):
     channel_partner = request.env['mail.channel.partner']
     if thread_model == 'mail.channel':
         channel_partner = request.env[
             'mail.channel.partner']._get_as_sudo_from_request_or_raise(
                 request=request, channel_id=int(thread_id))
     vals = {
         'name': ufile.filename,
         'raw': ufile.read(),
         'res_id': int(thread_id),
         'res_model': thread_model,
     }
     if is_pending and is_pending != 'false':
         # Add this point, the message related to the uploaded file does
         # not exist yet, so we use those placeholder values instead.
         vals.update({
             'res_id': 0,
             'res_model': 'mail.compose.message',
         })
     if channel_partner.env.user.share:
         # Only generate the access token if absolutely necessary (= not for internal user).
         vals['access_token'] = channel_partner.env[
             'ir.attachment']._generate_access_token()
     try:
         attachment = channel_partner.env['ir.attachment'].create(vals)
         attachment._post_add_create()
         attachmentData = {
             'filename': ufile.filename,
             'id': attachment.id,
             'mimetype': attachment.mimetype,
             'name': attachment.name,
             'size': attachment.file_size
         }
         if attachment.access_token:
             attachmentData['accessToken'] = attachment.access_token
     except AccessError:
         attachmentData = {
             'error': _("You are not allowed to upload an attachment here.")
         }
     return request.make_json_response(attachmentData)
Example #2
0
    def flutterwave_webhook(self):
        """ Process the notification data sent by Flutterwave to the webhook.

        :return: An empty string to acknowledge the notification.
        :rtype: str
        """
        data = request.get_json_data()
        _logger.info("Notification received from Flutterwave with data:\n%s", pprint.pformat(data))

        if data['event'] == 'charge.completed':
            try:
                # Check the origin of the notification.
                tx_sudo = request.env['payment.transaction'].sudo()._get_tx_from_notification_data(
                    'flutterwave', data['data']
                )
                signature = request.httprequest.headers.get('verif-hash')
                self._verify_notification_signature(signature, tx_sudo)

                # Handle the notification data.
                notification_data = data['data']
                tx_sudo._handle_notification_data('flutterwave', notification_data)
            except ValidationError:  # Acknowledge the notification to avoid getting spammed.
                _logger.exception("Unable to handle the notification data; skipping to acknowledge")
        return request.make_json_response('')
Example #3
0
 def make_response(self, data):
     if isinstance(data, Response):
         # The response has been build by the called method...
         return data
     # By default return result as json
     return request.make_json_response(data)
Example #4
0
 def echo_json_over_http(self):
     try:
         data = request.get_json_data()
     except ValueError as exc:
         raise werkzeug.exceptions.BadRequest("Invalid JSON data") from exc
     return request.make_json_response(data)
Example #5
0
 def _sign_out(self):
     return request.make_json_response({})
Example #6
0
 def _successfull_sign_in(self, partner_auth):
     data = self._prepare_sign_in_data(partner_auth)
     return request.make_json_response(data)