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

[15.0][IMP] resource_booking: Add search to partner_id field to prevent "wrong" results #134

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions resource_booking/migrations/15.0.1.4.0/noupdate_changes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='utf-8' ?>
<odoo>
<record id="rule_resource_booking_portal" model="ir.rule">
<field
name="domain_force"
>['|', ('partner_ids', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids)]</field>
</record>
<record id="rule_resource_booking_user" model="ir.rule">
<field
name="domain_force"
>['|', '|', ('partner_ids', 'child_of', user.partner_id.ids), ('message_partner_ids', 'child_of', user.partner_id.ids), ('combination_id.resource_ids.user_id', 'in', user.ids)]</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions resource_booking/migrations/15.0.1.4.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ def convert_resource_booking_partners(env):
def migrate(env, version):
"""Put partner_id in partner_ids"""
convert_resource_booking_partners(env)
openupgrade.load_data(
env.cr, "resource_booking", "migrations/15.0.1.4.0/noupdate_changes.xml"
)
9 changes: 9 additions & 0 deletions resource_booking/models/resource_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
comodel_name="res.partner",
compute="_compute_partner_id",
inverse="_inverse_partner_id",
search="_search_partner_id",
readonly=False,
string="Requester",
)
Expand Down Expand Up @@ -228,6 +229,14 @@
for one in self:
one.partner_ids = one.partner_id

@api.model
def _search_partner_id(self, operator, value):
"""Overwrite this for security, partner_id field is not stored and if we search
for it by mistake (or out of ignorance) we will get all the records.
To avoid this behavior, we search for the correct field: partner_ids
"""
return [("partner_ids", operator, value)]

Check warning on line 238 in resource_booking/models/resource_booking.py

View check run for this annotation

Codecov / codecov/patch

resource_booking/models/resource_booking.py#L238

Added line #L238 was not covered by tests

@api.model
def _default_user_id(self):
return self.env.user
Expand Down
Loading