diff --git a/addons/rating/controllers/main.py b/addons/rating/controllers/main.py index a80d131baa361427e296e3cad341f1fd4463c15a..c90ce213ce53b7bac8814ac877f5beae3091e9ab 100644 --- a/addons/rating/controllers/main.py +++ b/addons/rating/controllers/main.py @@ -50,15 +50,16 @@ class Rating(http.Controller): 'rate_names': rate_names, 'rate': rate }) - @http.route(['/rate/<string:token>/submit_feedback'], type="http", auth="public", methods=['post'], website=True) + @http.route(['/rate/<string:token>/submit_feedback'], type="http", auth="public", methods=['post', 'get'], website=True) def action_submit_rating(self, token, **kwargs): - rate = int(kwargs.get('rate')) - assert rate in (1, 3, 5), "Incorrect rating" rating = request.env['rating.rating'].sudo().search([('access_token', '=', token)]) if not rating: return request.not_found() - record_sudo = request.env[rating.res_model].sudo().browse(rating.res_id) - record_sudo.rating_apply(rate, token=token, feedback=kwargs.get('feedback')) + if request.httprequest.method == "POST": + rate = int(kwargs.get('rate')) + assert rate in (1, 3, 5), "Incorrect rating" + record_sudo = request.env[rating.res_model].sudo().browse(rating.res_id) + record_sudo.rating_apply(rate, token=token, feedback=kwargs.get('feedback')) lang = rating.partner_id.lang or get_lang(request.env).code return request.env['ir.ui.view'].with_context(lang=lang)._render_template('rating.rating_external_page_view', { 'web_base_url': request.env['ir.config_parameter'].sudo().get_param('web.base.url'), diff --git a/addons/rating/tests/__init__.py b/addons/rating/tests/__init__.py index d7f854e017bdc0bc81084a96485683dabe70e0e4..79deba75d45ec5053c994f2fb226bd77c5ee1e96 100644 --- a/addons/rating/tests/__init__.py +++ b/addons/rating/tests/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_security +from . import test_controller diff --git a/addons/rating/tests/test_controller.py b/addons/rating/tests/test_controller.py new file mode 100644 index 0000000000000000000000000000000000000000..e35ab85f01a247afaaeaaaaf9ead68b4e68e23fd --- /dev/null +++ b/addons/rating/tests/test_controller.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests import HttpCase, tagged, new_test_user + +@tagged('post_install', '-at_install') +class TestControllersRoute(HttpCase): + + def setUp(self): + super(TestControllersRoute, self).setUp() + self.user = new_test_user(self.env, "test_user_1", email="test_user_1@nowhere.com", tz="UTC") + self.partner = self.user.partner_id + + def test_controller_rating(self): + + rating_test = self.env['rating.rating'].with_user(self.user).create({ + 'res_model_id': self.env['ir.model'].sudo().search([('model', '=', 'res.partner')], limit=1).id, + 'res_model': 'res.partner', + 'res_id': self.partner.id, + 'rating': 3 + }) + self.authenticate(None, None) + access_token = rating_test.access_token + url = '/rate/%s/submit_feedback' % access_token + req = self.url_open(url) + self.assertEqual(req.status_code, 200, "Response should = OK")