Merge lp:~openerp-dev/openobject-server/trunk-bug-802976-nch into lp:openobject-server

Proposed by Naresh(OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-bug-802976-nch
Merge into: lp:openobject-server
Diff against target: 27 lines (+7/-7)
1 file modified
openerp/addons/base/ir/ir_filters.py (+7/-7)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-bug-802976-nch
Reviewer Review Type Date Requested Status
Vo Minh Thu (community) Needs Fixing
Review via email: mp+66246@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :
Revision history for this message
Vo Minh Thu (thu) wrote :

As you modified get_filters, please make sure it doesn't break any calling functions (in the server or the clients).

In the server, it is called by create_or_replace, which is now broken.

review: Needs Fixing
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

I dont think it should break ! I just added the missing domain.

can you give me a case where it breaks ?

Note: you need to merge the client branch too lp:~openerp-dev/openobject-client/trunk-bug-802976-nch
to get the desired results.

Thanks,

Revision history for this message
Vo Minh Thu (thu) wrote :

create_or_replace will modify the first filter among the filters returned by get_filters. You changed get_filters so it returns both (when available) user-specific and global filters. This means that when you save a filter for a specific user, you might write the global one instead.

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

it will only update if the old and the new name matches

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

see the variable "matching_filters"

Revision history for this message
Vo Minh Thu (thu) wrote :

A filter is uniquely identified by a name, user id, and model. This means matching_filter can contain two filters with the same name but one for a specific user (user id not null) and one global (user id is null).

Then create_or_update writes the first one, but you don't know which one.

Revision history for this message
Vo Minh Thu (thu) wrote :

(Actually, it can contain more than two filters: many filters with a null user id will be considered to be different by postgres.)

3486. By Naresh(OpenERP)

[FIX/IMP]:removed the call to get_filters and refactored the code using search with order by user_id, so the not null user id will be first

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

removed the call to get_filters and re-factored the code using search with order by user_id, so the not null user id will be first.

3487. By Naresh(OpenERP)

[REF]: removed unused variable

Revision history for this message
Vo Minh Thu (thu) wrote :

I thought it was good but it is not...

If you have a global filter, when you create a user-specific filter with the same name, the global one is overwritten, making it user-specific. So after that there is no more the global filter.

Probably leaving out the case

  or ('user_id','=',False)

in the domain should do the trick.

review: Needs Fixing
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

> I thought it was good but it is not...
>
> If you have a global filter, when you create a user-specific filter with the
> same name, the global one is overwritten, making it user-specific. So after
> that there is no more the global filter.
>
> Probably leaving out the case
>
> or ('user_id','=',False)
>
> in the domain should do the trick.

Hello,

If we do so then we are back to the position from where we begin.... :)

instead we can just Only the user_specific filters.if any !

nch@nch-laptop:~/workspace/OpenERP2011/rdtools/server/trunk-bug-802976-nch$ bzr diff
=== modified file 'openerp/addons/base/ir/ir_filters.py'
--- openerp/addons/base/ir/ir_filters.py 2011-06-29 11:36:36 +0000
+++ openerp/addons/base/ir/ir_filters.py 2011-06-30 06:29:45 +0000
@@ -39,13 +39,19 @@
         return my_acts

     def create_or_replace(self, cr, uid, vals, context=None):
+ ## Search all filters i.e global and user_specific matching the
+ ## new filter name order by user_id so that not null values
+ ## will be at first.
         filter_domain = [('name', '=', vals['name'].lower()),
                          ('model_id','=', vals['model_id']),
                          '|',('user_id','=',uid),('user_id','=',False)]
         filter_ids = self.search(cr, uid, filter_domain, order='user_id', context=context)
+ ## Only update the user_specific filters.
         if filter_ids:
- self.write(cr, uid, filter_ids[0], vals, context)
- return False
+ filter_rec = self.browse(cr, uid, filter_ids[0], context)
+ if filter_rec.user_id:
+ self.write(cr, uid, filter_ids[0], vals, context)
+ return False
         return self.create(cr, uid, vals, context)

     def _auto_init(self, cr, context={}):

3488. By Vo Minh Thu

[MERGE] merged trunk.

Revision history for this message
Vo Minh Thu (thu) wrote :

We have to go a bit further in the changes.

We agree to let users see both their own filters and the so-called global ones, i.e. where the user_id is null.

We want a constraint: for all filters selected on some user_id or null, model id, filter name, we must have at most one filter.

We use a ir rule to restrict access (for regular user) to unlink/write/create, so they can only create non-global filters.

For the above constraint to be user friendly, we might add some manual warnings instead of relying on the ORM to throw (unfriendly) errors.

review: Needs Fixing
Revision history for this message
Vo Minh Thu (thu) wrote :

The above changes mean that some addons which create global filters (knowing they would be hidden) will have to create user-specific filters instead.

3489. By Naresh(OpenERP)

[MERGE FROM TRUNK]

3490. By Naresh(OpenERP)

[MERGE FROM TRUNK]

3491. By Naresh(OpenERP)

[MERGE FROM TRUNK]

Unmerged revisions

3491. By Naresh(OpenERP)

[MERGE FROM TRUNK]

3490. By Naresh(OpenERP)

[MERGE FROM TRUNK]

3489. By Naresh(OpenERP)

[MERGE FROM TRUNK]

3488. By Vo Minh Thu

[MERGE] merged trunk.

3487. By Naresh(OpenERP)

[REF]: removed unused variable

3486. By Naresh(OpenERP)

[FIX/IMP]:removed the call to get_filters and refactored the code using search with order by user_id, so the not null user id will be first

3485. By Naresh(OpenERP)

[FIX]:ir_filters: filters created with user_id as False should show that filter to all user

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_filters.py'
2--- openerp/addons/base/ir/ir_filters.py 2011-08-06 00:50:46 +0000
3+++ openerp/addons/base/ir/ir_filters.py 2011-11-09 07:19:24 +0000
4@@ -39,17 +39,17 @@
5 return super(ir_filters, self).copy(cr, uid, id, default, context)
6
7 def get_filters(self, cr, uid, model):
8- act_ids = self.search(cr,uid,[('model_id','=',model),('user_id','=',uid)])
9+ act_ids = self.search(cr,uid,[('model_id','=',model),'|',('user_id','=',uid),('user_id','=',False)])
10 my_acts = self.read(cr, uid, act_ids, ['name', 'domain','context'])
11 return my_acts
12
13 def create_or_replace(self, cr, uid, vals, context=None):
14- filter_id = None
15- lower_name = vals['name'].lower()
16- matching_filters = [x for x in self.get_filters(cr, uid, vals['model_id'])
17- if x['name'].lower() == lower_name]
18- if matching_filters:
19- self.write(cr, uid, matching_filters[0]['id'], vals, context)
20+ filter_domain = [('name', '=', vals['name'].lower()),
21+ ('model_id','=', vals['model_id']),
22+ '|',('user_id','=',uid),('user_id','=',False)]
23+ filter_ids = self.search(cr, uid, filter_domain, order='user_id', context=context)
24+ if filter_ids:
25+ self.write(cr, uid, filter_ids[0], vals, context)
26 return False
27 return self.create(cr, uid, vals, context)
28