summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfja-odoo <fja@odoo.com>2019-09-10 16:30:45 +0000
committerfja-odoo <fja@odoo.com>2019-09-12 13:49:02 +0000
commit424adb63e3ecd9ce6888c3246633a6414215f34d (patch)
treea32eb4add8daff0caf8a8ae1aecc7c138c85a965
parent5a273e74f0fff18df5ab6cb240c9e260be4bb7ff (diff)
[IMP] gamification, *: remove KarmaError
* = stock, test_website, web, website_forum, website_slides, base Replace KarmaError with AccessError and remove the related override made on crash_manager and ir_http. task-2069890 closes odoo/odoo#36655 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
-rw-r--r--addons/gamification/models/gamification_karma_rank.py18
-rw-r--r--addons/gamification/static/src/js/crash_manager.js19
-rw-r--r--addons/gamification/views/gamification.xml6
-rw-r--r--addons/stock/controllers/main.py3
-rw-r--r--addons/test_website/__manifest__.py1
-rw-r--r--addons/test_website/controllers/main.py11
-rw-r--r--addons/test_website/data/test_website_data.xml2
-rw-r--r--addons/test_website/static/tests/tours/error_views.js25
-rw-r--r--addons/web/controllers/main.py6
-rw-r--r--addons/web/static/src/js/services/crash_manager.js24
-rw-r--r--addons/website_forum/models/forum.py49
-rw-r--r--addons/website_forum/tests/test_forum.py29
-rw-r--r--addons/website_slides/models/slide_channel.py4
-rw-r--r--addons/website_slides/models/slide_slide.py5
-rw-r--r--odoo/addons/base/models/ir_http.py31
-rw-r--r--odoo/http.py29
16 files changed, 87 insertions, 175 deletions
diff --git a/addons/gamification/models/gamification_karma_rank.py b/addons/gamification/models/gamification_karma_rank.py
index 65b0d8d2177..fc50218148e 100644
--- a/addons/gamification/models/gamification_karma_rank.py
+++ b/addons/gamification/models/gamification_karma_rank.py
@@ -3,24 +3,6 @@
from odoo import api, fields, models, exceptions
from odoo.tools.translate import html_translate
-
-class KarmaError(exceptions.except_orm):
- """ Karma-related error, used for forum and posts. """
- def __init__(self, msg):
- super(KarmaError, self).__init__(msg)
-
-
-class Http(models.AbstractModel):
- _inherit = 'ir.http'
-
- @classmethod
- def serialize_exception(self, e):
- res = super(Http, self).serialize_exception(e)
- if isinstance(e, KarmaError):
- res["exception_type"] = "karma_error"
- return res
-
-
class KarmaRank(models.Model):
_name = 'gamification.karma.rank'
_description = 'Rank based on karma'
diff --git a/addons/gamification/static/src/js/crash_manager.js b/addons/gamification/static/src/js/crash_manager.js
deleted file mode 100644
index 806132bc4cd..00000000000
--- a/addons/gamification/static/src/js/crash_manager.js
+++ /dev/null
@@ -1,19 +0,0 @@
-odoo.define('gamification.CrashManager', function (require) {
-"use strict";
-
-const core = require('web.core');
-const CrashManager = require('web.CrashManager').CrashManager;
-
-const _lt = core._lt;
-
-CrashManager.include({
- /**
- * @override
- */
- getMapTitle() {
- return Object.assign({}, this._super(...arguments), {
- karma_error: _lt("Karma Error"),
- });
- },
-});
-});
diff --git a/addons/gamification/views/gamification.xml b/addons/gamification/views/gamification.xml
index b9217e26d9a..08341ac83c0 100644
--- a/addons/gamification/views/gamification.xml
+++ b/addons/gamification/views/gamification.xml
@@ -4,10 +4,4 @@
<link rel="stylesheet" type="text/scss" href="/gamification/static/src/scss/gamification.scss"/>
</xpath>
</template>
-
- <template id="assets_common" inherit_id="web.assets_common">
- <xpath expr="script[last()]" position="after">
- <script type="text/javascript" src="/gamification/static/src/js/crash_manager.js"/>
- </xpath>
- </template>
</odoo>
diff --git a/addons/stock/controllers/main.py b/addons/stock/controllers/main.py
index 011005706ff..a54c3068fde 100644
--- a/addons/stock/controllers/main.py
+++ b/addons/stock/controllers/main.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request
+from odoo.addons.web.controllers.main import _serialize_exception
from odoo.tools import html_escape
import json
@@ -36,7 +37,7 @@ class StockReportController(http.Controller):
response.set_cookie('fileToken', token)
return response
except Exception as e:
- se = request.env['ir.http'].serialize_exception(e)
+ se = _serialize_exception(e)
error = {
'code': 200,
'message': 'Odoo Server Error',
diff --git a/addons/test_website/__manifest__.py b/addons/test_website/__manifest__.py
index e1bac638412..557722971d4 100644
--- a/addons/test_website/__manifest__.py
+++ b/addons/test_website/__manifest__.py
@@ -14,7 +14,6 @@ dependencies. Neither we want to add in website module some routes, views and
models which only purpose is to run tests.""",
'depends': [
'website',
- 'gamification',
],
'data': [
'views/templates.xml',
diff --git a/addons/test_website/controllers/main.py b/addons/test_website/controllers/main.py
index 0a8210881c7..ec94cbc3aee 100644
--- a/addons/test_website/controllers/main.py
+++ b/addons/test_website/controllers/main.py
@@ -7,8 +7,7 @@ import werkzeug
from odoo import http
from odoo.http import request
from odoo.addons.portal.controllers.web import Home
-from odoo.exceptions import UserError, ValidationError, AccessError, MissingError, AccessError, AccessDenied
-from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
+from odoo.exceptions import UserError, ValidationError, AccessError, MissingError, AccessDenied
class WebsiteTest(Home):
@@ -81,14 +80,6 @@ class WebsiteTest(Home):
def test_missing_error_http(self, **kwargs):
raise MissingError("This is a missing http test")
- @http.route('/test_karma_error_json', type='json', auth='public', website=True)
- def test_karma_error_rpc(self, **kwargs):
- raise KarmaError("This is a karma rpc test")
-
- @http.route('/test_karma_error_http', type='http', auth='public', website=True)
- def test_karma_error_http(self, **kwargs):
- raise KarmaError("This is a karma http test")
-
@http.route('/test_internal_error_json', type='json', auth='public', website=True)
def test_internal_error_json(self, **kwargs):
raise werkzeug.exceptions.InternalServerError()
diff --git a/addons/test_website/data/test_website_data.xml b/addons/test_website/data/test_website_data.xml
index 37a0949f0bb..4327bf597f8 100644
--- a/addons/test_website/data/test_website_data.xml
+++ b/addons/test_website/data/test_website_data.xml
@@ -45,7 +45,6 @@
<li class="list-group-item"><a href="/test_user_error_http">http UserError (400)</a></li>
<li class="list-group-item"><a href="/test_validation_error_http">http ValidationError (400)</a></li>
<li class="list-group-item"><a href="/test_missing_error_http">http MissingError (400)</a></li>
- <li class="list-group-item"><a href="/test_karma_error_http">http KarmaError (400)</a></li>
<li class="list-group-item"><a href="/test_access_error_http">http AccessError (403)</a></li>
<li class="list-group-item"><a href="/test_access_denied_http">http AccessDenied (403)</a></li>
<li class="list-group-item"><a href="/test_internal_error_http">http InternalServerError (500)</a></li>
@@ -56,7 +55,6 @@
<li class="list-group-item"><a href="/test_user_error_json">rpc UserError</a></li>
<li class="list-group-item"><a href="/test_validation_error_json">rpc ValidationError</a></li>
<li class="list-group-item"><a href="/test_missing_error_json">rpc MissingError</a></li>
- <li class="list-group-item"><a href="/test_karma_error_json">rpc KarmaError</a></li>
<li class="list-group-item"><a href="/test_access_error_json">rpc AccessError</a></li>
<li class="list-group-item"><a href="/test_access_denied_json">rpc AccessDenied</a></li>
<li class="list-group-item list-group-item-primary"><h2>rpc Errors</h2></li>
diff --git a/addons/test_website/static/tests/tours/error_views.js b/addons/test_website/static/tests/tours/error_views.js
index 8adb470d505..0d0d4961ea8 100644
--- a/addons/test_website/static/tests/tours/error_views.js
+++ b/addons/test_website/static/tests/tours/error_views.js
@@ -45,13 +45,6 @@ tour.register('test_error_website', {
extra_trigger: 'div.toast-body:contains("This is an access denied rpc test")',
trigger: 'button.o_notification_close',
}, {
- content: "trigger rpc missing error",
- trigger: 'a[href="/test_karma_error_json"]',
- }, {
- content: "rpc missing error modal has message",
- extra_trigger: 'div.toast-body:contains("This is a karma rpc test")',
- trigger: 'button.o_notification_close',
- }, {
content: "trigger rpc error 500",
trigger: 'a[href="/test_internal_error_json"]',
}, {
@@ -136,24 +129,6 @@ tour.register('test_error_website', {
content: "http missing error page debug has traceback closed",
trigger: 'body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)',
run: function () {
- window.location.href = window.location.origin + '/test_karma_error_http?debug=0';
- },
- }, {
- content: "http karma error page has title and message",
- extra_trigger: 'h1:contains("Something went wrong.")',
- trigger: 'div.container pre:contains("This is a karma http test")',
- run: function () {
- window.location.href = window.location.origin + '/test_karma_error_http?debug=1';
- },
- }, {
- content: "http karma error page debug has title and message open",
- extra_trigger: 'h1:contains("Something went wrong.")',
- trigger: 'div#error_main.collapse.show pre:contains("This is a karma http test")',
- run: function () {},
- }, {
- content: "http karma error page debug has traceback closed",
- trigger: 'body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)',
- run: function () {
window.location.href = window.location.origin + '/test_access_denied_http?debug=0';
},
}, {
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 5b7eeaad62b..3aa2c0e64d9 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -42,7 +42,7 @@ from odoo.tools.translate import _
from odoo.tools.misc import str2bool, xlsxwriter, file_open
from odoo.tools.safe_eval import safe_eval
from odoo import http, tools
-from odoo.http import content_disposition, dispatch_rpc, request, Response
+from odoo.http import content_disposition, dispatch_rpc, request, serialize_exception as _serialize_exception, Response
from odoo.exceptions import AccessError, UserError, AccessDenied
from odoo.models import check_method_name
from odoo.service import db, security
@@ -84,7 +84,7 @@ def serialize_exception(f):
return f(*args, **kwargs)
except Exception as e:
_logger.exception("An exception occured during an http request")
- se = request.registry['ir.http'].serialize_exception(e)
+ se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
@@ -1850,7 +1850,7 @@ class ReportController(http.Controller):
else:
return
except Exception as e:
- se = request.env['ir.http'].serialize_exception(e)
+ se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
diff --git a/addons/web/static/src/js/services/crash_manager.js b/addons/web/static/src/js/services/crash_manager.js
index a430dfa8ef3..5f78b6b84dc 100644
--- a/addons/web/static/src/js/services/crash_manager.js
+++ b/addons/web/static/src/js/services/crash_manager.js
@@ -146,20 +146,6 @@ var CrashManager = AbstractService.extend({
disable: function () {
active = false;
},
- /**
- * @return {Object}
- */
- getMapTitle() {
- return {
- access_denied: _lt("Access Denied"),
- access_error: _lt("Access Error"),
- except_orm: _lt("Global Business Error"),
- missing_error: _lt("Missing Record"),
- user_error: _lt("User Error"),
- validation_error: _lt("Validation Error"),
- warning: _lt("Warning"),
- };
- },
handleLostConnection: function () {
var self = this;
if (!this.isConnected) {
@@ -188,7 +174,15 @@ var CrashManager = AbstractService.extend({
if (!document.body) {
return;
}
- var map_title = this.getMapTitle();
+ var map_title = {
+ access_denied: _lt("Access Denied"),
+ access_error: _lt("Access Error"),
+ except_orm: _lt("Global Business Error"),
+ missing_error: _lt("Missing Record"),
+ user_error: _lt("User Error"),
+ validation_error: _lt("Validation Error"),
+ warning: _lt("Warning"),
+ };
if (!active) {
return;
}
diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py
index 02d74b4324e..62d21ea9b6d 100644
--- a/addons/website_forum/models/forum.py
+++ b/addons/website_forum/models/forum.py
@@ -6,10 +6,9 @@ import math
import re
from datetime import datetime
-from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
from odoo import api, fields, models, tools, SUPERUSER_ID, _
-from odoo.exceptions import UserError, ValidationError
+from odoo.exceptions import UserError, ValidationError, AccessError
from odoo.tools import misc
from odoo.tools.translate import html_translate
@@ -411,7 +410,7 @@ class Post(models.Model):
filter_regexp = r'(<img.*?>)|(<a[^>]*?href[^>]*?>)|(<[a-z|A-Z]+[^>]*style\s*=\s*[\'"][^\'"]*\s*background[^:]*:[^url;]*url)'
content_match = re.search(filter_regexp, content, re.I)
if content_match:
- raise KarmaError(_('%d karma required to post an image or link.') % forum.karma_editor)
+ raise AccessError(_('%d karma required to post an image or link.') % forum.karma_editor)
return content
def _default_website_meta(self):
@@ -439,9 +438,9 @@ class Post(models.Model):
raise UserError(_('Posting answer on a [Deleted] or [Closed] question is not possible.'))
# karma-based access
if not post.parent_id and not post.can_ask:
- raise KarmaError(_('%d karma required to create a new question.') % post.forum_id.karma_ask)
+ raise AccessError(_('%d karma required to create a new question.') % post.forum_id.karma_ask)
elif post.parent_id and not post.can_answer:
- raise KarmaError(_('%d karma required to answer a question.') % post.forum_id.karma_answer)
+ raise AccessError(_('%d karma required to answer a question.') % post.forum_id.karma_answer)
if not post.parent_id and not post.can_post:
post.sudo().state = 'pending'
@@ -458,7 +457,7 @@ class Post(models.Model):
# Make sure only author or moderator can edit/delete messages
for post in self.browse(res_ids):
if not post.can_edit:
- raise KarmaError(_('%d karma required to edit a post.') % post.karma_edit)
+ raise AccessError(_('%d karma required to edit a post.') % post.karma_edit)
return super(Post, self).get_mail_message_access(res_ids, operation, model_name=model_name)
def write(self, vals):
@@ -474,18 +473,18 @@ class Post(models.Model):
if 'state' in vals:
if vals['state'] in ['active', 'close']:
if not post.can_close:
- raise KarmaError(_('%d karma required to close or reopen a post.') % post.karma_close)
+ raise AccessError(_('%d karma required to close or reopen a post.') % post.karma_close)
trusted_keys += ['state', 'closed_uid', 'closed_date', 'closed_reason_id']
elif vals['state'] == 'flagged':
if not post.can_flag:
- raise KarmaError(_('%d karma required to flag a post.') % post.forum_id.karma_flag)
+ raise AccessError(_('%d karma required to flag a post.') % post.forum_id.karma_flag)
trusted_keys += ['state', 'flag_user_id']
if 'active' in vals:
if not post.can_unlink:
- raise KarmaError(_('%d karma required to delete or reactivate a post.') % post.karma_unlink)
+ raise AccessError(_('%d karma required to delete or reactivate a post.') % post.karma_unlink)
if 'is_correct' in vals:
if not post.can_accept:
- raise KarmaError(_('%d karma required to accept or refuse an answer.') % post.karma_accept)
+ raise AccessError(_('%d karma required to accept or refuse an answer.') % post.karma_accept)
# update karma except for self-acceptance
mult = 1 if vals['is_correct'] else -1
if vals['is_correct'] != post.is_correct and post.create_uid.id != self._uid:
@@ -493,9 +492,9 @@ class Post(models.Model):
self.env.user.sudo().add_karma(post.forum_id.karma_gen_answer_accept * mult)
if tag_ids:
if set(post.tag_ids.ids) != tag_ids and self.env.user.karma < post.forum_id.karma_edit_retag:
- raise KarmaError(_('%d karma required to retag.') % post.forum_id.karma_edit_retag)
+ raise AccessError(_('%d karma required to retag.') % post.forum_id.karma_edit_retag)
if any(key not in trusted_keys for key in vals) and not post.can_edit:
- raise KarmaError(_('%d karma required to edit a post.') % post.karma_edit)
+ raise AccessError(_('%d karma required to edit a post.') % post.karma_edit)
res = super(Post, self).write(vals)
@@ -594,7 +593,7 @@ class Post(models.Model):
def validate(self):
for post in self:
if not post.can_moderate:
- raise KarmaError(_('%d karma required to validate a post.') % post.forum_id.karma_moderate)
+ raise AccessError(_('%d karma required to validate a post.') % post.forum_id.karma_moderate)
# if state == pending, no karma previously added for the new question
if post.state == 'pending':
post.create_uid.sudo().add_karma(post.forum_id.karma_gen_question_new)
@@ -609,7 +608,7 @@ class Post(models.Model):
def refuse(self):
for post in self:
if not post.can_moderate:
- raise KarmaError(_('%d karma required to refuse a post.') % post.forum_id.karma_moderate)
+ raise AccessError(_('%d karma required to refuse a post.') % post.forum_id.karma_moderate)
post.moderator_id = self.env.user
return True
@@ -617,7 +616,7 @@ class Post(models.Model):
res = []
for post in self:
if not post.can_flag:
- raise KarmaError(_('%d karma required to flag a post.') % post.forum_id.karma_flag)
+ raise AccessError(_('%d karma required to flag a post.') % post.forum_id.karma_flag)
if post.state == 'flagged':
res.append({'error': 'post_already_flagged'})
elif post.state == 'active':
@@ -638,7 +637,7 @@ class Post(models.Model):
def mark_as_offensive(self, reason_id):
for post in self:
if not post.can_moderate:
- raise KarmaError(_('%d karma required to mark a post as offensive.') % post.forum_id.karma_moderate)
+ raise AccessError(_('%d karma required to mark a post as offensive.') % post.forum_id.karma_moderate)
# remove some karma
_logger.info('Downvoting user <%s> for posting spam/offensive contents', post.create_uid)
post.create_uid.sudo().add_karma(post.forum_id.karma_gen_answer_flagged)
@@ -668,7 +667,7 @@ class Post(models.Model):
def unlink(self):
for post in self:
if not post.can_unlink:
- raise KarmaError(_('%d karma required to unlink a post.') % post.karma_unlink)
+ raise AccessError(_('%d karma required to unlink a post.') % post.karma_unlink)
# if unlinking an answer with accepted answer: remove provided karma
for post in self:
if post.is_correct:
@@ -713,7 +712,7 @@ class Post(models.Model):
# karma-based action check: use the post field that computed own/all value
if not self.can_comment_convert:
- raise KarmaError(_('%d karma required to convert an answer to a comment.') % self.karma_comment_convert)
+ raise AccessError(_('%d karma required to convert an answer to a comment.') % self.karma_comment_convert)
# post the message
question = self.parent_id
@@ -752,9 +751,9 @@ class Post(models.Model):
can_convert = self.env.user.karma >= karma_convert
if not can_convert:
if is_author and karma_own < karma_all:
- raise KarmaError(_('%d karma required to convert your comment to an answer.') % karma_own)
+ raise AccessError(_('%d karma required to convert your comment to an answer.') % karma_own)
else:
- raise KarmaError(_('%d karma required to convert a comment to an answer.') % karma_all)
+ raise AccessError(_('%d karma required to convert a comment to an answer.') % karma_all)
# check the message's author has not already an answer
question = post.parent_id if post.parent_id else post
@@ -791,7 +790,7 @@ class Post(models.Model):
)
can_unlink = user.karma >= karma_unlink
if not can_unlink:
- raise KarmaError(_('%d karma required to unlink a comment.') % karma_unlink)
+ raise AccessError(_('%d karma required to unlink a comment.') % karma_unlink)
result.append(comment.unlink())
return result
@@ -837,7 +836,7 @@ class Post(models.Model):
self.ensure_one()
if not self.can_comment:
- raise KarmaError(_('%d karma required to comment.') % self.karma_comment)
+ raise AccessError(_('%d karma required to comment.') % self.karma_comment)
if not kwargs.get('record_name') and self.parent_id:
kwargs['record_name'] = self.parent_id.name
return super(Post, self).message_post(message_type=message_type, **kwargs)
@@ -934,9 +933,9 @@ class Vote(models.Model):
def _check_karma_rights(self, upvote=None):
# karma check
if upvote and not self.post_id.can_upvote:
- raise KarmaError(_('%d karma required to upvote.') % self.post_id.forum_id.karma_upvote)
+ raise AccessError(_('%d karma required to upvote.') % self.post_id.forum_id.karma_upvote)
elif not upvote and not self.post_id.can_downvote:
- raise KarmaError(_('%d karma required to downvote.') % self.post_id.forum_id.karma_downvote)
+ raise AccessError(_('%d karma required to downvote.') % self.post_id.forum_id.karma_downvote)
def _vote_update_karma(self, old_vote, new_vote):
if self.post_id.parent_id:
@@ -971,5 +970,5 @@ class Tags(models.Model):
def create(self, vals):
forum = self.env['forum.forum'].browse(vals.get('forum_id'))
if self.env.user.karma < forum.karma_tag_create:
- raise KarmaError(_('%d karma required to create a new Tag.') % forum.karma_tag_create)
+ raise AccessError(_('%d karma required to create a new Tag.') % forum.karma_tag_create)
return super(Tags, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(vals)
diff --git a/addons/website_forum/tests/test_forum.py b/addons/website_forum/tests/test_forum.py
index f52deea315a..b9d3bcdb94a 100644
--- a/addons/website_forum/tests/test_forum.py
+++ b/addons/website_forum/tests/test_forum.py
@@ -2,7 +2,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from .common import KARMA, TestForumCommon
-from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
from odoo.exceptions import UserError, AccessError
from odoo.tools import mute_logger
from psycopg2 import IntegrityError
@@ -135,7 +134,7 @@ class TestForum(TestForumCommon):
})
# Portal user asks a question with tags: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
Post.with_user(self.user_portal).create({
'name': " Q_0",
'forum_id': self.forum.id,
@@ -164,7 +163,7 @@ class TestForum(TestForumCommon):
Post = self.env['forum.post']
# Answers its own question: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
Post.with_user(self.user_employee).create({
'name': " A0",
'forum_id': self.forum.id,
@@ -194,7 +193,7 @@ class TestForum(TestForumCommon):
emp_answer.vote(upvote=True)
# not enough karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).vote(upvote=True)
def test_vote(self):
@@ -217,7 +216,7 @@ class TestForum(TestForumCommon):
emp_answer.vote(upvote=False)
# not enough karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).vote(upvote=False)
def test_downvote(self):
@@ -227,7 +226,7 @@ class TestForum(TestForumCommon):
self.assertEqual(self.post.create_uid.karma, 50 + KARMA['gen_que_dwv'], 'website_forum: wrong karma generation of downvoted question author')
def test_comment_crash(self):
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).message_post(body='Should crash', message_type='comment')
def test_comment(self):
@@ -245,7 +244,7 @@ class TestForum(TestForumCommon):
})
# portal user flags a post: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
post.with_user(self.user_portal).flag()
# portal user flags a post: ok if enough karma
@@ -263,7 +262,7 @@ class TestForum(TestForumCommon):
})
# portal user validate a post: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
post.with_user(self.user_portal).validate()
# portal user validate a pending post
@@ -296,7 +295,7 @@ class TestForum(TestForumCommon):
})
# portal user validate a post: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
post.with_user(self.user_portal).refuse()
# portal user validate a pending post
@@ -316,7 +315,7 @@ class TestForum(TestForumCommon):
})
# portal user mark a post as offensive: not allowed, unsufficient karma
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
post.with_user(self.user_portal).mark_as_offensive(12)
# portal user mark a post as offensive
@@ -335,7 +334,7 @@ class TestForum(TestForumCommon):
self.assertEqual(new_msg.id, False, 'website_forum: question to comment conversion failed')
self.assertEqual(Post.search([('name', '=', 'TestQuestion')])[0].forum_id.name, 'TestForum', 'website_forum: question to comment conversion failed')
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.answer.with_user(self.user_portal).convert_answer_to_comment()
def test_convert_answer_to_comment(self):
@@ -347,7 +346,7 @@ class TestForum(TestForumCommon):
self.assertIn('I am an anteater', new_msg.body, 'website_forum: wrong answer to comment conversion')
def test_edit_post_crash(self):
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).write({'name': 'I am not your father.'})
def test_edit_post(self):
@@ -357,7 +356,7 @@ class TestForum(TestForumCommon):
self.post.with_user(self.user_portal).write({'name': 'Actually I am your cat.'})
def test_close_post_crash(self):
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).close(None)
def test_close_post_own(self):
@@ -369,7 +368,7 @@ class TestForum(TestForumCommon):
self.post.with_user(self.user_portal).close(None)
def test_deactivate_post_crash(self):
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).write({'active': False})
def test_deactivate_post_own(self):
@@ -381,7 +380,7 @@ class TestForum(TestForumCommon):
self.post.with_user(self.user_portal).write({'active': False})
def test_unlink_post_crash(self):
- with self.assertRaises(KarmaError):
+ with self.assertRaises(AccessError):
self.post.with_user(self.user_portal).unlink()
def test_unlink_post_own(self):
diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py
index ce37f9e2ce4..ab63de20246 100644
--- a/addons/website_slides/models/slide_channel.py
+++ b/addons/website_slides/models/slide_channel.py
@@ -5,7 +5,7 @@ import uuid
from odoo import api, fields, models, tools, _
from odoo.addons.http_routing.models.ir_http import slug
-from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
+from odoo.exceptions import UserError, AccessError
from odoo.osv import expression
@@ -366,7 +366,7 @@ class Channel(models.Model):
note as we don't want all channel followers to be notified of this answer. """
self.ensure_one()
if kwargs.get('message_type') == 'comment' and not self.can_review:
- raise KarmaError(_('Not enough karma to review'))
+ raise AccessError(_('Not enough karma to review'))
if parent_id:
parent_message = self.env['mail.message'].sudo().browse(parent_id)
if parent_message.subtype_id and parent_message.subtype_id == self.env.ref('website_slides.mt_channel_slide_published'):
diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py
index 69206edd916..f62c6c09ce7 100644
--- a/addons/website_slides/models/slide_slide.py
+++ b/addons/website_slides/models/slide_slide.py
@@ -13,8 +13,7 @@ from werkzeug import urls
from odoo import api, fields, models, _
from odoo.addons.http_routing.models.ir_http import slug
-from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
-from odoo.exceptions import Warning, UserError
+from odoo.exceptions import Warning, UserError, AccessError
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import url_for
@@ -438,7 +437,7 @@ class Slide(models.Model):
def message_post(self, message_type='notification', **kwargs):
self.ensure_one()
if message_type == 'comment' and not self.channel_id.can_comment: # user comments have a restriction on karma
- raise KarmaError(_('Not enough karma to comment'))
+ raise AccessError(_('Not enough karma to comment'))
return super(Slide, self).message_post(message_type=message_type, **kwargs)
def get_access_action(self, access_uid=None):
diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py
index 5c59223c240..64ab86aea9b 100644
--- a/odoo/addons/base/models/ir_http.py
+++ b/odoo/addons/base/models/ir_http.py
@@ -21,7 +21,7 @@ import odoo
from odoo import api, http, models, tools, SUPERUSER_ID
from odoo.exceptions import AccessDenied, AccessError
from odoo.http import request, STATIC_CACHE, content_disposition
-from odoo.tools import consteq, pycompat, ustr
+from odoo.tools import consteq, pycompat
from odoo.tools.mimetypes import guess_mimetype
from odoo.modules.module import get_resource_path, get_module_path
@@ -180,33 +180,6 @@ class IrHttp(models.AbstractModel):
return False
@classmethod
- def serialize_exception(self, e):
- tmp = {
- "name": type(e).__module__ + "." + type(e).__name__ if type(e).__module__ else type(e).__name__,
- "debug": traceback.format_exc(),
- "message": ustr(e),
- "arguments": e.args,
- "exception_type": "internal_error"
- }
- if isinstance(e, odoo.exceptions.UserError):
- tmp["exception_type"] = "user_error"
- elif isinstance(e, odoo.exceptions.Warning):
- tmp["exception_type"] = "warning"
- elif isinstance(e, odoo.exceptions.RedirectWarning):
- tmp["exception_type"] = "warning"
- elif isinstance(e, odoo.exceptions.AccessError):
- tmp["exception_type"] = "access_error"
- elif isinstance(e, odoo.exceptions.MissingError):
- tmp["exception_type"] = "missing_error"
- elif isinstance(e, odoo.exceptions.AccessDenied):
- tmp["exception_type"] = "access_denied"
- elif isinstance(e, odoo.exceptions.ValidationError):
- tmp["exception_type"] = "validation_error"
- elif isinstance(e, odoo.exceptions.except_orm):
- tmp["exception_type"] = "except_orm"
- return tmp
-
- @classmethod
def _handle_exception(cls, exception):
# in case of Exception, e.g. 404, we don't step into _dispatch
cls._handle_debug()
@@ -321,7 +294,7 @@ class IrHttp(models.AbstractModel):
record = record_sudo
elif self.env.user.has_group('base.group_portal'):
# Check the read access on the record linked to the attachment
- # eg: Allow to download an attachment on a task from /my/task/task_id
+ # eg: Allow to download an attachment on a task from /my/task/task_id
record.check('read')
record = record_sudo
# We have prefetched some fields of record, among which the field
diff --git a/odoo/http.py b/odoo/http.py
index 146d79f6aa6..90acbbe7cf7 100644
--- a/odoo/http.py
+++ b/odoo/http.py
@@ -633,7 +633,7 @@ class JsonRequest(WebRequest):
error = {
'code': 200,
'message': "Odoo Server Error",
- 'data': request.registry['ir.http'].serialize_exception(exception),
+ 'data': serialize_exception(exception),
}
if isinstance(exception, werkzeug.exceptions.NotFound):
error['http_status'] = 404
@@ -684,6 +684,33 @@ class JsonRequest(WebRequest):
return self._handle_exception(e)
+def serialize_exception(e):
+ tmp = {
+ "name": type(e).__module__ + "." + type(e).__name__ if type(e).__module__ else type(e).__name__,
+ "debug": traceback.format_exc(),
+ "message": ustr(e),
+ "arguments": e.args,
+ "exception_type": "internal_error"
+ }
+ if isinstance(e, odoo.exceptions.UserError):
+ tmp["exception_type"] = "user_error"
+ elif isinstance(e, odoo.exceptions.Warning):
+ tmp["exception_type"] = "warning"
+ elif isinstance(e, odoo.exceptions.RedirectWarning):
+ tmp["exception_type"] = "warning"
+ elif isinstance(e, odoo.exceptions.AccessError):
+ tmp["exception_type"] = "access_error"
+ elif isinstance(e, odoo.exceptions.MissingError):
+ tmp["exception_type"] = "missing_error"
+ elif isinstance(e, odoo.exceptions.AccessDenied):
+ tmp["exception_type"] = "access_denied"
+ elif isinstance(e, odoo.exceptions.ValidationError):
+ tmp["exception_type"] = "validation_error"
+ elif isinstance(e, odoo.exceptions.except_orm):
+ tmp["exception_type"] = "except_orm"
+ return tmp
+
+
class HttpRequest(WebRequest):
""" Handler for the ``http`` request type.