Skip to content

Conversation

@amas-odoo
Copy link
Contributor

  • Replaced direct request.env.ref() usage with placeholder keywords and applied
    replace() on the view arch to dynamically insert correct IDs at runtime,
    restoring view editability.
  • Updated validation logic to:
    • Disallow use of t-att-value, t-att-href, and t-attf-href
    • Warn when value or href contains hardcoded digits or request.env.ref(...)

This improves maintainability, prevents hardcoded references, and ensures views
remain editable.

Task ID: 5355861

@robodoo
Copy link
Collaborator

robodoo commented Nov 28, 2025

Pull request status dashboard

@vava-odoo vava-odoo requested a review from frva-odoo December 3, 2025 13:39
Copy link
Contributor

@frva-odoo frva-odoo left a 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']"/> -->
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to this line you will get Internal server error
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe worth investigating this

Copy link
Contributor

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 😇

Comment on lines 14 to 20
<value model="ir.ui.view" eval="{'arch': obj().env.ref('micro_brewery.our-beers').arch.replace(
'value=&quot;*lager_beer_bottle_product*&quot;', 'value=&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_13').id)).replace(
'value=&quot;*blond_beer_bottle_product*&quot;', 'value=&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_2').id)).replace(
'value=&quot;*brown_beer_bottle_product*&quot;', 'value=&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_14').id)).replace(
'&quot;*lager_beer_bottle_product_variant*&quot;', '&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_13').id)).replace(
'&quot;*blond_beer_bottle_product_variant*&quot;', '&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_2').id)).replace(
'&quot;*brown_beer_bottle_product_variant*&quot;', '&quot;%s&quot;' % str(obj().env.ref('micro_brewery.product_product_14').id))
Copy link
Contributor

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 ?

Comment on lines 5 to 7
<value model="ir.ui.view" eval="{'arch': obj().env.ref('architects.contactus').arch.replace(
'value=&quot;*base_user_admin*&quot;', 'value=&quot;%s&quot;' % str(obj().env.ref('base.user_admin').id)
)}"/>
Copy link
Contributor

@frva-odoo frva-odoo Dec 4, 2025

Choose a reason for hiding this comment

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

Why including 'value=&quot;...&quot;' and not just put the keyword: '*base_user_admin*', is there a reason ? It would be simpler to read and quicker too.

Comment on lines 34 to 39
<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=&quot;*flash_tattoo_appointment*&quot;', 'href=&quot;/appointment/%s&quot;' % str(obj().env.ref('tattoo_shop.appointment_type_1').id))
}"/>
</function>
Copy link
Contributor

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.

Comment on lines 503 to 506
if not value:
continue
if not (value.isdigit() and "request.env.ref" in value):
continue
Copy link
Contributor

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

continue
if href.startswith(("tel:", "mailto:", "javascript:", "#", "http://", "https://")):
continue
if href and re.search(r"-\d+$", href) or "request.env.ref" in href:
Copy link
Contributor

@frva-odoo frva-odoo Dec 4, 2025

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

@amas-odoo amas-odoo force-pushed the 18.0-replace-request-env-by-replace-keyword-in-arch-amas branch 4 times, most recently from 6258b16 to 6abe35e Compare December 5, 2025 09:23
Copy link
Contributor

@frva-odoo frva-odoo left a 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 🙂

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):
Copy link
Contributor

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.

@amas-odoo amas-odoo force-pushed the 18.0-replace-request-env-by-replace-keyword-in-arch-amas branch from 6abe35e to a9f2457 Compare December 8, 2025 10:07
<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(
Copy link
Collaborator

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)
Copy link
Collaborator

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(
Copy link
Collaborator

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']"/> -->
Copy link
Collaborator

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(...)`
@amas-odoo amas-odoo force-pushed the 18.0-replace-request-env-by-replace-keyword-in-arch-amas branch from a9f2457 to cc4112f Compare December 11, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants