Access rules on fields.related in osv.TransientModel

Bug #1123018 reported by Yann Papouin

This bug report was converted into a question: question #235513: Access rules on fields.related in osv.TransientModel.

6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Opinion
Undecided
Unassigned

Bug Description

I don't know if it's a bug or not but:

If you add a fields.related (to a Model like stock.move) in a transient model (like stock.partial.picking.line) that will be displayed in a wizard, all access rules on these fields are bypass by the uid automatically changed to SUPERUSER (==1) in _fnct_read from fields.py.

It is a normal behavior ?

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

I guess not :(

Regards,

Revision history for this message
Yann Papouin (yann-papouin) wrote :

Maybe an OpenERP framework expert could take a look on this !

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

Hi Yann,

No, this is not a bug, its done intentionally to behave like this. we allow the user to read the value even if it comes from a model to which they have no access. the idea of related fields is to delegate the storage of the content to another object, so it seems logical to act exactly as if it was a field owned by the current model

Thanks,
Naresh Soni,
Team Lead,
OpenERP Enterprise Services

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Yann Papouin (yann-papouin) wrote :

That's not what I reported, the behaviour is different between "osv.osv" and "osv.TransientModel".
Or maybe I miss something, fields.related bypass the user id by design for wizard (TransientModel) only ?

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

No, its not specific to TransientModel only. It's by design for all types of model in OpenERP(TransientModel and database-persisted models )

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

Can you elaborate a bit on this "the behaviour is different between "osv.osv" and "osv.TransientModel"." It will be good if you can have an example.

Changed in openobject-server:
status: Invalid → Incomplete
Revision history for this message
Yann Papouin (yann-papouin) wrote :

I just made a simple test and I can confirm the issue.

Following is a basic example that will display current user id in the related field display value.
To test it, you have to use admin and a another user (id=2 for example).

Create a MODEL_A (model.a) inherited from "osv.osv"
- Field A1 like fields.function(_get_field_a1, type="char", string='Field A1', readonly=True)

and define it like this:
    def _get_field_a1(self, cr, uid, ids, name, arg, context=None):
        return str(uid)

Create a MODEL_B (model.b) inherited from "osv.osv"
- Field MA like fields.many2one('model.a', "Model A"),
- Field B1 like fields.related('MA', 'A1', type='char', string='Related Field A1'),

Create a MODEL_C (model.c) inherited from "osv.TransientModel"
- Field MA like fields.many2one('model.a', "Model A"),
- Field C1 like fields.related('MA', 'A1', type='char', string='Related Field A1'),

You will see as output:

As admin
MODEL_B.MA == 1
MODEL_C.MA == 1

As user 2
MODEL_B.MA == 2
MODEL_C.MA == 1

Changed in openobject-server:
status: Incomplete → New
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello Yann,

Thanks for providing the test case . But I have a different result (As Expected) then yours.

I have :

*As admin(same results before and after save)*

MODEL_B.MA == 1
MODEL_C.MA == 1

(Related fied)MODEL_B.B1 == 1
(Related fied)MODEL_C.C1 ==1

*As user Demo(id 3)* :

While creating a new record and when the drop down menu is pressed. I have :

MODEL_B.MA == 3
MODEL_C.MA == 3
(Related fied) MODEL_B.B1 == False
(Related fied) MODEL_C.C1 == False

*As soon as I click save I have:*

MODEL_B.MA == 1
MODEL_C.MA == 1
(Related fied) MODEL_B.B1 == 1
(Related fied) MODEL_C.C1 == 1

 However I still don't think its a bug for the reason I already mentioned in my above comments, as when the
 related field is read it requires access to the third party models. Here in this case MODEL_A it may be possible that the MODEL_B, MODEL_C don't have rights on this MODEL_A. Here in the example above when you click save it will try to read the value of the related field with SUPERUSERID and as the related value is generated by a function field, it recalculates the value of the function field and hence you see the SUPER USER ID.

However, we can wait for some other experts inputs on this.

Thanks,
Naresh Soni
OpenERP Enterprise Services

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

Before going to any decision meanwhile, Let put this as a Opinion for more conversation. and suggestion from the OpenERP framework experts.

Thanks and more suggestions are welcomed!

Changed in openobject-server:
status: New → Opinion
Revision history for this message
Denis Karataev (dskarataev) wrote :

Hi everybody, we continue discussion on GitHub in related issue https://github.com/odoo/odoo/issues/6274

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.