Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] base: remove groups_id from ir.ui.view #98551

Conversation

beledouxdenis
Copy link
Contributor

The goal of this revision is to get rid of the groups_id field of the model ir.ui.view.

  • This feature wasn't really known or used by most developers,
    and not straight-forward to understand.
    Removing it allows one less complicated thing to learn for developers.
    Besides, thanks to [IMP] base: uniform "groups" in back-end view #95729,
    changing the behavior of the groups= attribute,
    we can easily get rid of this groups_id feature
    by simply adding groups= in the elements of the views
    using the groups_id field, it will have the same effect:
    adding the elements in the view only for the users part of the specified group.

  • By getting rid of the groups_id many2many field on ir.ui.view,
    it makes possible to cache the view architecture without
    requiring to use the groups in the cache key.
    Currently, if we want to cache the view architecture,
    it would be required to use the intersection of the user
    groups with the groups_id groups of the view,
    making it costly to compute the cache key,
    therefore altering the performance point to cache the view
    architectures.

@robodoo
Copy link
Contributor

robodoo commented Aug 22, 2022

@C3POdoo C3POdoo added the RD research & development, internal work label Aug 22, 2022
@beledouxdenis beledouxdenis force-pushed the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch 5 times, most recently from 7c7f3b8 to 1d7ddaf Compare August 24, 2022 10:05
@beledouxdenis beledouxdenis force-pushed the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch from 1d7ddaf to 73dc30f Compare August 24, 2022 13:03
@beledouxdenis beledouxdenis marked this pull request as ready for review August 24, 2022 13:28
@C3POdoo C3POdoo requested review from a team August 24, 2022 13:29
@@ -44,12 +44,6 @@
<field string="Opportunities" name="opportunity_count" widget="statinfo"/>
</button>
</div>
<field name="parent_id" position="before">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed ^^

Comment on lines 190 to 191
return self.env['hr.attendance'].sudo().create(vals)
attendance = self.env['hr.attendance'].sudo().search([('employee_id', '=', self.id), ('check_out', '=', False)], limit=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why the extra sudo are needed here, considering that the only calls are already on a sudo'ed employee env?
https://github.com/odoo/odoo/blob/master/addons/hr_attendance/models/hr_employee.py#L158-L169

Perhaps the tests could be fixed instead to call _attendance_action()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why the extra sudo are needed here, considering that the only calls are already on a sudo'ed employee env? https://github.com/odoo/odoo/blob/master/addons/hr_attendance/models/hr_employee.py#L158-L169

Perhaps the tests could be fixed instead to call _attendance_action()?

It looks like the problem doesn't come from the test using _attendance_action_change but from the with_user within the method _attendance_action, which looses the sudo:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/addons/hr_attendance/tests/test_hr_attendance_process.py", line 47, in test_checkin_self_without_pin
    employee.with_user(self.user).attendance_manual({}, entered_pin=None)
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/addons/hr_attendance/models/hr_employee.py", line 147, in attendance_manual
    return self._attendance_action(next_action)
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/addons/hr_attendance/models/hr_employee.py", line 167, in _attendance_action
    modified_attendance = employee.with_user(employee.user_id)._attendance_action_change()
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/addons/hr_attendance/models/hr_employee.py", line 190, in _attendance_action_change
    return self.env['hr.attendance'].create(vals)
  File "<decorator-gen-278>", line 2, in create
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/api.py", line 409, in _model_create_multi
    return create(self, [arg])
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/addons/hr_attendance/models/hr_attendance.py", line 275, in create
    res = super().create(vals_list)
  File "<decorator-gen-67>", line 2, in create
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/api.py", line 410, in _model_create_multi
    return create(self, arg)
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/addons/base/models/ir_fields.py", line 613, in create
    recs = super().create(vals_list)
  File "<decorator-gen-16>", line 2, in create
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/api.py", line 410, in _model_create_multi
    return create(self, arg)
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/models.py", line 4120, in create
    self.check_access_rights('create')
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/models.py", line 3683, in check_access_rights
    return self.env['ir.model.access'].check(self._name, operation, raise_exception)
  File "<decorator-gen-35>", line 2, in check
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/tools/cache.py", line 90, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/home/odoo/src/odoo/master-ir-ui-view-remove-groups-id-for-backend-views-dle/odoo/addons/base/models/ir_model.py", line 1821, in check
    raise AccessError(msg)
odoo.exceptions.AccessError: You are not allowed to create 'Attendance' (hr.attendance) records.

This operation is allowed for the following groups:
        - Attendances/Officer : Manage all attendances
        - Attendances/User

Contact your administrator to request access if necessary.

I therefore moved the sudo that I put to this with_user, so the sudo are all kept within the method _attendance_action

@beledouxdenis beledouxdenis force-pushed the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch 2 times, most recently from 2b5edd6 to 6060430 Compare August 26, 2022 08:52
Copy link
Contributor

@Feyensv Feyensv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements and simplification 👍

@beledouxdenis beledouxdenis force-pushed the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch from 6060430 to 10b0f46 Compare August 26, 2022 10:35
@beledouxdenis beledouxdenis force-pushed the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch 2 times, most recently from 877d705 to 9ceefb3 Compare August 27, 2022 10:10
robodoo pushed a commit that referenced this pull request Sep 5, 2022
The master plan finally comes to an end.

Thanks to:
- #87522 refactoring `load_views`,
- #94337 refactoring `common.Form` to prevent changing
    invisible fields in unit tests using `Form` instances,
- #95729 refactoring the behavior of `groups=` in views,
- #98551 removing the need of the `groups_id` many2many field
    on back-end views.

The result returned by `get_view`/`get_views` can now finally be easily
and efficiently cached, in order to cache back-end views.

The goal of this revision is to cache the model views and fields
already post-processed for the web client
(with the modifiers, etc., already computed)
without group restriction.
Then, from this cached version, post-process group related features,
such as removing nodes restricted with a `groups=` attribute,
set the create/write button according to the user access rights to models, ...

Not including the groups in the cache key allows:
- to have less cached versions,
  (otherwise it would be one cached version per different group combination)
- to not have to fetch the user groups to compute the key
  (with the current cache key,
  there is nothing to fetch from the database to compute the key)

Besides, post-processing the groups features
after taking the view from the cache of the view doesn't take a tremendous time:
 - parsing arch from/to string with etree is fast,
 - removing the `groups=` nodes using etree is fast,
 - adding the `create="False"`, `write="False"`, `delete="False"` on the view
   root node according to the access right of the user on the model is fast.

This allows way faster calls to `get_views` by the web client,
as the server no longer need, for each call, to fetch the views in database,
combine the inherited views, post-process the modifiers attributes, etc.

Timing tests are available on the pull request of this revision.

Part-of: #99417
@fw-bot fw-bot deleted the master-ir-ui-view-remove-groups-id-for-backend-views-dle branch September 12, 2022 21:46
Feyensv added a commit to odoo-dev/odoo that referenced this pull request Oct 18, 2022
Since odoo#98551, groups have been moved from views fields to xml content
to harmonize the behavior of xml and view groups.

Nevertheless, this reduced the coverage of the test verifying settings user
are always able to open the settings view.

This commit brings back part of that coverage, by relying on a 'semi magic' hack
to find application administration groups, according to their xml_id.
Feyensv added a commit to odoo-dev/odoo that referenced this pull request Oct 24, 2022
Since odoo#98551, groups have been moved from views fields to xml content
to harmonize the behavior of xml and view groups.

Nevertheless, this reduced the coverage of the test verifying settings user
are always able to open the settings view.

This commit brings back part of that coverage, by relying on a 'semi magic' hack
to find application administration groups, according to their xml_id.
robodoo pushed a commit that referenced this pull request Oct 24, 2022
Since #98551, groups have been moved from views fields to xml content to harmonize the behavior of xml and view groups.

Nevertheless, this reduced the coverage of the test verifying settings user are always able to open the settings view.

This commit brings back part of that coverage, checking for each application manager group that the settings view can be opened and saved correctly.

closes #103441

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Feyensv added a commit to odoo-dev/odoo that referenced this pull request Oct 25, 2022
Since odoo#98551, groups have been moved from views fields to xml content
to harmonize the behavior of xml and view groups.

Nevertheless, this reduced the coverage of the test verifying settings user
are always able to open the settings view.

This commit brings back part of that coverage, checking for each application manager
group that the settings view can be opened and saved correctly.

X-original-commit: bb067f8
robodoo pushed a commit that referenced this pull request Oct 25, 2022
Since #98551, groups have been moved from views fields to xml content
to harmonize the behavior of xml and view groups.

Nevertheless, this reduced the coverage of the test verifying settings user
are always able to open the settings view.

This commit brings back part of that coverage, checking for each application manager
group that the settings view can be opened and saved correctly.

closes #103989

X-original-commit: bb067f8
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
15.5 RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants