-
Notifications
You must be signed in to change notification settings - Fork 82
[FIX] *: replace all request.env by keywords to replace in the arch #1419
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
base: 18.0
Are you sure you want to change the base?
[FIX] *: replace all request.env by keywords to replace in the arch #1419
Conversation
frva-odoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @amas-odoo ! I left a few comments, don't hesitate to answer to any of them if you want to talk about it.
| <function name="button_choose_theme" model="ir.module.module" eval="[ref('base.module_theme_buzzy', raise_if_not_found=False) or ref('base.module_theme_default')]"/> | ||
|
|
||
| <function model="theme.utils" name="enable_view" eval="['website.template_header_hamburger']"/> | ||
| <!-- <function model="theme.utils" name="enable_view" eval="['website.template_header_hamburger']"/> --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing this line ? I don't see anything about it on the task or commit message, is this intended ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth investigating this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was investigating this issue and found a solution maybe I need to test that on multiple industries.
I will create a PR very soon .
Thanks 😇
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('micro_brewery.our-beers').arch.replace( | ||
| 'value="*lager_beer_bottle_product*"', 'value="%s"' % str(obj().env.ref('micro_brewery.product_product_13').id)).replace( | ||
| 'value="*blond_beer_bottle_product*"', 'value="%s"' % str(obj().env.ref('micro_brewery.product_product_2').id)).replace( | ||
| 'value="*brown_beer_bottle_product*"', 'value="%s"' % str(obj().env.ref('micro_brewery.product_product_14').id)).replace( | ||
| '"*lager_beer_bottle_product_variant*"', '"%s"' % str(obj().env.ref('micro_brewery.product_product_13').id)).replace( | ||
| '"*blond_beer_bottle_product_variant*"', '"%s"' % str(obj().env.ref('micro_brewery.product_product_2').id)).replace( | ||
| '"*brown_beer_bottle_product_variant*"', '"%s"' % str(obj().env.ref('micro_brewery.product_product_14').id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are the same products, shouldn't we use the same name for them so that it is less confusing ?
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('architects.contactus').arch.replace( | ||
| 'value="*base_user_admin*"', 'value="%s"' % str(obj().env.ref('base.user_admin').id) | ||
| )}"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why including 'value="..."' and not just put the keyword: '*base_user_admin*', is there a reason ? It would be simpler to read and quicker too.
| <function model="ir.ui.view" name="write"> | ||
| <value model="ir.ui.view" eval="obj().env.ref('tattoo_shop.ir_ui_view_2930').id"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('tattoo_shop.ir_ui_view_2930').arch.replace( | ||
| 'href="*flash_tattoo_appointment*"', 'href="/appointment/%s"' % str(obj().env.ref('tattoo_shop.appointment_type_1').id)) | ||
| }"/> | ||
| </function> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see 'href="flash_tattoo_appointment"' in that view, I think you can remove this.
tests/test_generic/tests/test_xml.py
Outdated
| if not value: | ||
| continue | ||
| if not (value.isdigit() and "request.env.ref" in value): | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could combine both conditions. I'm also not sure this is the intended condition we want: the only case where we don't enter 'if' here is when the value is a digit AND there is request.env.ref in value; We want to enter 'if' when both of them are false, so the correct way to do it would be
if not value or (not value.isdigit() and not "request.env.ref" in value): continue
or
if not value or not (value.isdigit() or "request.env.ref" in value): continue
tests/test_generic/tests/test_xml.py
Outdated
| continue | ||
| if href.startswith(("tel:", "mailto:", "javascript:", "#", "http://", "https://")): | ||
| continue | ||
| if href and re.search(r"-\d+$", href) or "request.env.ref" in href: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove first href in the last 'if' here as you already check above if it is null or not
6258b16 to
6abe35e
Compare
frva-odoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good ! Only one remaining comment but after that it's good for me 🙂
tests/test_generic/tests/test_xml.py
Outdated
| if href and re.search(r"-\d+$", href): | ||
| for tag in root.xpath("//input[@value] | //option[@value] | //input[@t-att-value] | //option[@t-att-value]"): | ||
| value = tag.get("value") or tag.get("t-att-value") | ||
| if not value or not (value.isdigit() and "request.env.ref" in value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to change the 'and' here by an 'or' as I explained in a past comment.
6abe35e to
a9f2457
Compare
| <value model="ir.ui.view" eval="obj().env['website'].with_context(website_id=obj().env.ref('website.default_website').id).viewref('website.contactus').id"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('headhunter.contact_us').arch}"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('headhunter.contact_us').arch.replace( | ||
| '*sales_team_team_sales_department*', str(obj().env.ref('sales_team.team_sales_department').id)).replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will break in no-demo mode, since the replacement is only done in demo
| <value model="ir.ui.view" eval="obj().env['website'].with_context(website_id=obj().env.ref('website.default_website').id).viewref('website.contactus').id"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('non_profit_organization.contactus').arch}"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('non_profit_organization.contactus').arch.replace( | ||
| '*sales_team_team_sales_department*', str(obj().env.ref('sales_team.team_sales_department').id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same demo / data issue
| <value model="ir.ui.view" eval="obj().env['website'].with_context(website_id=obj().env.ref('website.default_website').id).viewref('website.contactus').id"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('surveyor.contactus').arch}"/> | ||
| <value model="ir.ui.view" eval="{'arch': obj().env.ref('surveyor.contactus').arch.replace( | ||
| '*sales_team_team_sales_department*', str(obj().env.ref('sales_team.team_sales_department').id)).replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue data/demo
| <function name="button_choose_theme" model="ir.module.module" eval="[ref('base.module_theme_buzzy', raise_if_not_found=False) or ref('base.module_theme_default')]"/> | ||
|
|
||
| <function model="theme.utils" name="enable_view" eval="['website.template_header_hamburger']"/> | ||
| <!-- <function model="theme.utils" name="enable_view" eval="['website.template_header_hamburger']"/> --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth investigating this
Replaced direct `request.env.ref()` usage with static keywords and applied `replace()` on the view arch to insert the correct ID at runtime, restoring view editability.
Replaced direct `request.env.ref()` usage with static keywords and applied `replace()` on the view arch to insert the correct ID at runtime, restoring view editability.
- Disallow usage of `t-att-value`, `t-att-href`, and `t-attf-href` - Warn when `value` or `href` contains hardcoded digits or `request.env.ref(...)`
a9f2457 to
cc4112f
Compare


request.env.ref()usage with placeholder keywords and appliedreplace()on the view arch to dynamically insert correct IDs at runtime,restoring view editability.
• Disallow use of
t-att-value,t-att-href, andt-attf-href• Warn when
valueorhrefcontains hardcoded digits orrequest.env.ref(...)This improves maintainability, prevents hardcoded references, and ensures views
remain editable.
Task ID: 5355861