Merge lp:~openerp-dev/openobject-addons/7.0-opw-584224-rgo into lp:openobject-addons/7.0

Proposed by Ravi Gohil (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-584224-rgo
Merge into: lp:openobject-addons/7.0
Diff against target: 68 lines (+36/-0)
2 files modified
base_action_rule/base_action_rule.py (+34/-0)
base_action_rule/tests/base_action_rule_test.py (+2/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-584224-rgo
Reviewer Review Type Date Requested Status
nel Pending
Review via email: mp+144120@code.launchpad.net

Description of the change

This branch contains fix for below 2 issues:

Issue 1:
Example: User A has created and saved a filter on crm.lead object and shared with all users, hence, it will be available to all users.
Now, user B will log in and thinks that this filter doesn't belong to me, he will find the user who creates it and assign that user to that filter from menu Setting/Techincal/User Defined Filters or may be by some other way, So, the filter is not global anymore! This should not be done.

So, I fixed this issue by introducing a python constraint which will denied user to do so if the filter is used in action rules(as action rules can have filters which are global).

Issue 2:
One is able to assign a user by clicking on "Create and Edit" on filter fields(m2o fields at Setting/Techincal/Automated Actions/Automated Actions) and is able to save the record! which is wrong(as there is a domain on these fields which shows only global filters).

Here too, I introduce the python constraints which will restrict users to do so.

Kindly review the fix and share your views on this fix.

Thanks.

To post a comment you must log in.

Unmerged revisions

8594. By Ravi Gohil (OpenERP)

[FIX] base_action_rule: 'Automated Actions' should only select filters which are shared with all users (global filters only) in 'Before Update Filter/After Update Filter' fields and the filters which are used in 'Automated Actions' shouldn't be allowed to assign a user: (Maintenance Case: 584224)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_action_rule/base_action_rule.py'
2--- base_action_rule/base_action_rule.py 2012-12-21 14:49:34 +0000
3+++ base_action_rule/base_action_rule.py 2013-01-21 14:20:29 +0000
4@@ -92,6 +92,23 @@
5
6 _order = 'sequence'
7
8+ def _check_filter_pre(self, cr, uid, ids, context=None):
9+ for rule in self.browse(cr, uid, ids, context=context):
10+ if rule.filter_pre_id and rule.filter_pre_id.user_id:
11+ return False
12+ return True
13+
14+ def _check_filter(self, cr, uid, ids, context=None):
15+ for rule in self.browse(cr, uid, ids, context=context):
16+ if rule.filter_id and rule.filter_id.user_id:
17+ return False
18+ return True
19+
20+ _constraints = [
21+ (_check_filter_pre, '\n"Before Update Filter" can have filters which are shared with all users.', ['filter_pre_id']),
22+ (_check_filter, '\n"After Update Filter" can have filters which are shared with all users.', ['filter_id']),
23+ ]
24+
25 def _filter(self, cr, uid, action, action_filter, record_ids, context=None):
26 """ filter the list record_ids that satisfy the action filter """
27 if record_ids and action_filter:
28@@ -256,3 +273,20 @@
29 _logger.error(traceback.format_exc())
30
31 action.write({'last_run': now.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
32+
33+class ir_filters(osv.osv):
34+ _inherit = "ir.filters"
35+
36+ def _check_no_user(self, cr, uid, ids, context=None):
37+ base_action_rule_obj = self.pool.get('base.action.rule')
38+ all_rules = base_action_rule_obj.browse(cr, uid, base_action_rule_obj.search(cr, uid, []), context=context)
39+ for filter in self.browse(cr, uid, ids, context=context):
40+ if filter.user_id:
41+ for rule in all_rules:
42+ if filter.id == rule.filter_id.id or filter.id == rule.filter_pre_id.id:
43+ return False
44+ return True
45+
46+ _constraints = [
47+ (_check_no_user, '\nYou cannot assign a user to the filters which are used in "Automated Actions".', ['user_id']),
48+ ]
49
50=== modified file 'base_action_rule/tests/base_action_rule_test.py'
51--- base_action_rule/tests/base_action_rule_test.py 2012-12-21 11:39:57 +0000
52+++ base_action_rule/tests/base_action_rule_test.py 2013-01-21 14:20:29 +0000
53@@ -20,6 +20,7 @@
54 'is_default': False,
55 'model_id': 'base.action.rule.lead.test',
56 'domain' : "[('state','=','done')]",
57+ 'user_id': False
58 }, context=context)
59
60 def create_filter_draft(self, cr, uid, context=None):
61@@ -29,6 +30,7 @@
62 'is_default': False,
63 'model_id': "base.action.rule.lead.test",
64 'domain' : "[('state','=','draft')]",
65+ 'user_id': False
66 }, context=context)
67
68 def create_lead_test_1(self, cr, uid, context=None):