Skip to content

Conversation

@walidsahli
Copy link
Contributor

@walidsahli walidsahli commented Nov 25, 2024

Problem:

  1. Ctrl+click on a link in the editor does not open the link in a new tab.
  2. Internal links with the format odoo/<model>/<record_id> do not display a proper preview. Instead, a warning toaster appears: "Action <model> not found, link preview is not available. Please check your URL is correct."

Solution:

  1. Implement the same code as version 17.0 to handle ctrl+click for opening links in a new tab: 981290e
  2. For internal links (odoo/<model>/<record_id>), validate the action_name as a model name. If valid, treat action_name as the model name for the link preview.

Steps to reproduce:

  1. Open the editor.
  2. Add a link with the path odoo/project.task/59.
  3. Try Ctrl+click:
    • Issue: The link does not open in a new tab.
  4. Observe the warning toaster: "Action project.task not found, link preview is not available. Please check your URL is correct."

opw-4353235


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Nov 25, 2024

Pull request status dashboard

@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch from dd25f68 to 768b514 Compare November 25, 2024 13:29
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Nov 25, 2024
@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch 4 times, most recently from ee21b04 to adfd795 Compare November 25, 2024 14:10
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if we want to add this here to be able to access the model directly when the model name is given because it will may access some other models like ir.http, bus.bus.... We need to check the spec here if we want to support this or not .
cc @Jinjiu96 , @dmo-odoo

Copy link
Contributor

@Jinjiu96 Jinjiu96 Nov 25, 2024

Choose a reason for hiding this comment

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

Hello @walidsahli Thanks for the PR! I think @Mtaylorr has a very good point, we should only process the preview when it's not an abstract model. To do this I suggest to add other conditions in the if check:

Suggested change
if action_name in request.env:
if (action_name.startswith('m-') or '.' in action_name) and action_name in request.env and not request.env[action_name]._abstract:

By doing this, we ensure we don't access abstract models and also we restrict the action_name in this case to be a model name
cc @dmo-odoo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @Mtaylorr Thanks for the catch, indeed we should restrict that.
Thanks for the suggestion @Jinjiu96 , i was not sure how to handle it in a safe way. i updated the commit please let me know if i missed anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here since it's actually a model's name we are using, it better to use model_name instead. Also, we cover another possibility of model name in the URL which starts with m-

Suggested change
model = request.env[action_name].with_context(context)
model_name = action_name.removeprefix('m-')
model = request.env[model_name].with_context(context)

@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch 2 times, most recently from 243015b to 7aacef6 Compare November 26, 2024 14:13
Copy link
Contributor

Choose a reason for hiding this comment

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

@walidsahli , can you add a test for abstract model here to make sure he can't access it

@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch from 7aacef6 to dbfa998 Compare November 26, 2024 14:41
@walidsahli walidsahli marked this pull request as ready for review November 26, 2024 17:21
@C3POdoo C3POdoo requested a review from a team November 26, 2024 17:22
Copy link
Contributor

@dmo-odoo dmo-odoo left a comment

Choose a reason for hiding this comment

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

Thanks for your work! I wrote a few comments.

Comment on lines +192 to +194
Copy link
Contributor

Choose a reason for hiding this comment

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

Since both the issues and their respective fixes are completely unrelated from each other, they should be fixed in separated commits. It is ok to keep them in a single PR.

In the commit message for the _blank fix, it is better to link to the actual commit introducing the fix rather than on an arbitrary line of code in 17.0.

Copy link
Contributor

Choose a reason for hiding this comment

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

As you can see from this red sign on GitHub, the file is missing the empty line at the end.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be a comment? Because right now, it's a string that just floats there in the middle of the code... ^^' I looked in Odoo's codebase (I haven't worked in Python for years) and it seems this kind of triple quoted strings are only used as comments for the docstring of functions (as per PEP 257), that is right after the function definition, but never in the middle of the code itself. Classical Python comments use #.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, i'm sorry yea it should be a comment not a string.

@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch 3 times, most recently from dd0404f to 2d1e9a6 Compare December 5, 2024 08:36
**Problem**:
Internal links with the format `odoo/<model>/<record_id>` do not display a proper preview. Instead, a warning toaster appears:
   _"Action `<model>` not found, link preview is not available. Please check your URL is correct."_

**Solution**:
For internal links (`odoo/<model>/<record_id>`), validate the `action_name` as a model name. If valid, treat `action_name` as the model name for the link preview.

**Steps to reproduce**:
1. Open the editor.
2. Add a link with the path `odoo/project.task/59`.
3. Press `Ctrl+click`.
4. Observe the warning toaster:
   _"Action project.task not found, link preview is not available. Please check your URL is correct."_

opw-4353235
**Problem**:
`Ctrl+click` on a link in the editor does not open the link in a new tab.

**Solution**:
Implement the same code as version 17.0 to handle `ctrl+click` for opening links in a new tab: odoo@981290e

**Steps to reproduce**:
1. Open the editor.
2. Add a link with the path `odoo/project.task/59`.
3. Try `Ctrl+click`:
   - **Issue**: The link does not open in a new tab.

opw-4353235
@walidsahli walidsahli force-pushed the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch from 2d1e9a6 to d854987 Compare December 9, 2024 09:49
@dmo-odoo
Copy link
Contributor

@robodoo rebase-ff r+

@robodoo
Copy link
Contributor

robodoo commented Dec 18, 2024

Merge method set to rebase and fast-forward.

robodoo pushed a commit that referenced this pull request Dec 18, 2024
**Problem**:
Internal links with the format `odoo/<model>/<record_id>` do not display a proper preview. Instead, a warning toaster appears:
   _"Action `<model>` not found, link preview is not available. Please check your URL is correct."_

**Solution**:
For internal links (`odoo/<model>/<record_id>`), validate the `action_name` as a model name. If valid, treat `action_name` as the model name for the link preview.

**Steps to reproduce**:
1. Open the editor.
2. Add a link with the path `odoo/project.task/59`.
3. Press `Ctrl+click`.
4. Observe the warning toaster:
   _"Action project.task not found, link preview is not available. Please check your URL is correct."_

opw-4353235

Part-of: #188455
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
@robodoo robodoo closed this in 1ff4129 Dec 18, 2024
@fw-bot fw-bot deleted the 18.0-opw-4353235-fix_link_preview_and_open_link_editor-wasa branch January 1, 2025 14:19
gamarino pushed a commit to numaes/numa-public-odoo that referenced this pull request Jan 24, 2025
**Problem**:
Internal links with the format `odoo/<model>/<record_id>` do not display a proper preview. Instead, a warning toaster appears:
   _"Action `<model>` not found, link preview is not available. Please check your URL is correct."_

**Solution**:
For internal links (`odoo/<model>/<record_id>`), validate the `action_name` as a model name. If valid, treat `action_name` as the model name for the link preview.

**Steps to reproduce**:
1. Open the editor.
2. Add a link with the path `odoo/project.task/59`.
3. Press `Ctrl+click`.
4. Observe the warning toaster:
   _"Action project.task not found, link preview is not available. Please check your URL is correct."_

opw-4353235

Part-of: odoo/odoo#188455
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
gamarino pushed a commit to numaes/numa-public-odoo that referenced this pull request Jan 24, 2025
**Problem**:
`Ctrl+click` on a link in the editor does not open the link in a new tab.

**Solution**:
Implement the same code as version 17.0 to handle `ctrl+click` for opening links in a new tab: odoo/odoo@981290e

**Steps to reproduce**:
1. Open the editor.
2. Add a link with the path `odoo/project.task/59`.
3. Try `Ctrl+click`:
   - **Issue**: The link does not open in a new tab.

opw-4353235

closes odoo/odoo#188455

Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OE the report is linked to a support ticket (opw-...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants