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

fix: Fix missing @defaults theme folder in composer installation #14425

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

driskell
Copy link
Contributor

@driskell driskell commented Jan 2, 2025

Q A
Bug fix? (use the a.b branch) 🟢
New feature/enhancement? (use the a.x branch) 🔴
Deprecations? 🔴
BC breaks? (use the c.x branch) 🔴
Automated tests included? 🔴
Issue(s) addressed Fixes #14423

Description

Add missing scaffold for the themes/@default

I don't know how to easily test this so need some help to test it


📋 Steps to test this PR:

Not sure as it relates to scaffold files

Copy link
Contributor

@andersonjeccel andersonjeccel left a comment

Choose a reason for hiding this comment

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

I'm wondering if there's a way to avoid having to maintain 2 duplicate locations for the same stuff

This PR means that updating these defaults will also require that all changes made to /themes/@defaults/... will also have to be copied to /app/assets/scaffold/...

Do you have any idea?

@driskell
Copy link
Contributor Author

driskell commented Jan 3, 2025

@andersonjeccel That’s currently how the scaffold files work. So changing that is a separate change best in another PR.

My suggestion though would be perhaps to “build” the assets/scaffold folder during package release - I am not familiar with that process though and only say this as I found what I thought was some file list builders in the packages folder - so it felt there’s already some automation there that could be expanded.

@andersonjeccel
Copy link
Contributor

@driskell The most efficient solution I can think at this moment would be to move the defaults folder into one of the bundles, changing the path from each theme to point to the new location

We probably could move forward without a duplicate instance of it, what do you think?

@driskell
Copy link
Contributor Author

driskell commented Jan 3, 2025

@andersonjeccel I thought about that but the app folder has a .htaccess to deny all access. So it would, I think, need a brand new package for example mautic/theme-defaults.

https://github.com/mautic/mautic/blob/6.x/app/.htaccess

I think as well this only solves it for the theme defaults - not for any other duplicated files in the scaffold area. So I don't think not doing work here is going to cause more work later. Ideally the solution for @defaults would work for the others too so that's why I thought it better to just keep the status quo and then work on that separately at some point if indeed it becomes an issue. The likelihood of these files changing seems fairly slim though I think much like the other scaffold files. And indeed the current approach has some advantages in that an installation could override and replace these files as they see fit to change the defaults - where bundling them in with core/lib would be a bit harder and require a patch file rather than a simple entry in composer.json (and patch files aren't gonna work well for binary images). So there's likely some larger things to think about

@andersonjeccel
Copy link
Contributor

@driskell Got it, makes sense. Let's proceed this way then

Do you have any clue why the PHPUnit test is failing?

@driskell
Copy link
Contributor Author

driskell commented Jan 3, 2025

@driskell Got it, makes sense. Let's proceed this way then

Do you have any clue why the PHPUnit test is failing?

Sorry I don't - it seems relating to asset download so I thought maybe a randomly failure but unfortunately I don't have access to re-run the tests. But I can try force push a change and see if it works.

@driskell driskell force-pushed the fix-missing-defaults branch from f93fb10 to 6d968b4 Compare January 3, 2025 12:27
@driskell
Copy link
Contributor Author

driskell commented Jan 3, 2025

@andersonjeccel Yeh it was a random test failure. All pass now!

Copy link
Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

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

This doesn't seem right. But I also don't fully understand this Composer magic. Shouldn't this theme be mentioned on the same places as other themes? For example this is where the Skyline theme is mentioned but the @defaults theme is not:

@driskell
Copy link
Contributor Author

driskell commented Jan 14, 2025

This doesn't seem right. But I also don't fully understand this Composer magic. Shouldn't this theme be mentioned on the same places as other themes? For example this is where the Skyline theme is mentioned but the @defaults theme is not:

It felt like these were not a theme but shared assets so I went the asset right but you could be right it be better to be its own bundle and added to the dependencies of each core theme so updates bring it in. Happy to close in that case but I think it might be beyond my contribution to create that theme as I not familiar with the working of that split stuff and not sure how I would test it. I could try tho as you outlined the files but it would probably be an untested PR 😬

@escopecz
Copy link
Member

@mollux do you think you could advise here?

@matbcvo
Copy link
Contributor

matbcvo commented Jan 14, 2025

I find that it would be better to create @defaults as its own theme repository like the other themes, since the files are located in the themes folder. This approach would help avoid maintaining duplicate files.

@escopecz has already listed the files that need to be updated or created to set up the @defaults theme. It should be named something like theme-defaults, not theme-@defaults, as the repository name can't contain @. There’s no need to test this.

@trianity
Copy link

I put manually these files and patched already existing files into Mautic 5.2.1 instance, recreated assets, cleared cache but the issue was not resolved.
@escopecz The @default theme where should be there?

@matbcvo
Copy link
Contributor

matbcvo commented Jan 14, 2025

@trianity This @defaults folder from https://github.com/mautic/mautic/tree/5.2.1/themes has to be copied to the <Mautic root>/docroot/themes/ folder.

@trianity
Copy link

trianity commented Jan 14, 2025

@trianity This @defaults folder from https://github.com/mautic/mautic/tree/5.2.1/themes has to be copied to the <Mautic root>/docroot/themes/ folder.

Thanks, I can confirm: copying the @defaults folder content to the <Mautic root>/docroot/themes/ folder, the error 500 issue was resolved in the unsubscribe link click.

@jos0405 jos0405 added the themes Anything related to themes label Jan 15, 2025
@andersonjeccel andersonjeccel requested review from andersonjeccel and removed request for andersonjeccel January 15, 2025 16:30
@vinzent
Copy link
Contributor

vinzent commented Jan 17, 2025

@trianity This @defaults folder from https://github.com/mautic/mautic/tree/5.2.1/themes has to be copied to the <Mautic root>/docroot/themes/ folder.

also Landing page builder (with blank theme) is working again after copying @defaults to docroot/themes

@escopecz
Copy link
Member

Or can we move the default theme twig files here? https://github.com/mautic/mautic/tree/6.x/app/bundles/CoreBundle/Resources/views/Theme

@matbcvo
Copy link
Contributor

matbcvo commented Jan 17, 2025

Yes, it's possible to move these files to app/bundles/CoreBundle/Resources/views/Theme and then replace with:

-{% extends "@themes/@defaults/html/base.html.twig" %}
+{% extends "@MauticCore/Theme/base.html.twig" %}

I just tested it, and this would be an even better option.

@andersonjeccel
Copy link
Contributor

@escopecz @matbcvo I'm wondering if, when the Preference center is enabled in Configuration, if contacts will have permission to access

If you can confirm, this would be nice

@driskell
Copy link
Contributor Author

driskell commented Jan 17, 2025

@andersonjeccel @escopecz @matbcvo On our platforms we block all app access as nothing needs it. All assets are outside of it in the media folder and I don't recall anything ever needing to access in there. So editors wouldn't see the images if they were referenced from CoreBundle. Granted, templates likely would work. But it's then where to put the images.

@driskell
Copy link
Contributor Author

driskell commented Jan 17, 2025

In Mautic app is blocked by Apache: https://github.com/mautic/mautic/blob/6.x/app/.htaccess

@escopecz
Copy link
Member

@driskell I was talking more about the twig files. You are right, the images should be moved to the media directory.

@driskell
Copy link
Contributor Author

@driskell I was talking more about the twig files. You are right, the images should be moved to the media directory.

Yeh sorry, quick to jump to reply! I will see if I can work on splitting the base templates to CoreBundle then and look at treating these images like the current images are treated.

@driskell driskell force-pushed the fix-missing-defaults branch from 6d968b4 to 91342dc Compare January 17, 2025 15:01
@driskell
Copy link
Contributor Author

driskell commented Jan 17, 2025

OK @escopecz @andersonjeccel I've done an initial draft - just gonna convert this to a GitHub Draft though so it's clear as I need to get some testing time which will need to be next week. Let me know if it looks like what you intended though and I'll get the testing done to make sure it all works OK. 👍

Thanks everyone for the feedback so far! In the meantime if anyone reaches here the workaround is to make sure you have @defaults theme in your theme folder if you're running a composer installation. Once this PR is done that won't be needed anymore so just need to remember to remove it but it should be harmless either way.

@driskell driskell marked this pull request as draft January 17, 2025 15:06
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.45%. Comparing base (3df5f9e) to head (91342dc).
Report is 62 commits behind head on 5.2.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                5.2   #14425   +/-   ##
=========================================
  Coverage     63.44%   63.45%           
- Complexity    34630    34636    +6     
=========================================
  Files          2273     2273           
  Lines        103594   103603    +9     
=========================================
+ Hits          65728    65741   +13     
+ Misses        37866    37862    -4     

see 7 files with indirect coverage changes

@matbcvo
Copy link
Contributor

matbcvo commented Jan 17, 2025

I just tested your PR (emails, forms, landing pages, unsubscribe page). No issues found so far, it works as expected. Placeholder images are present and publicly accessible.

@andersonjeccel
Copy link
Contributor

@driskell Why getOverridableUrl to retrieve the placeholders?

@driskell
Copy link
Contributor Author

@driskell Why getOverridableUrl to retrieve the placeholders?

I copied how it was done for the other images in the assets folder - which allow a copy to be made into the media folder to override them. I just went and used the same loading method as the other assets in that folder so I didn’t need to find the right API myself, but I didn’t think too much about it 😬 I can adjust if someone drops a review with what to use instead though. Might be ok though as it still should work and just has added bonus of behaving like the others and allowing overrides

@andersonjeccel
Copy link
Contributor

andersonjeccel commented Jan 17, 2025

@driskell From what I got, the solution will lead to only one place for managing these placeholders and using this function automatically solves technical things related to security, to get the theme working as expected for end users

Is it right? (I'm really not a PHP dev)

@driskell
Copy link
Contributor Author

@driskell From what I got, the solution will lead to only one place for managing these placeholders and using this function automatically solves technical things related to security, to get the theme working as expected for end users

Is it right? (I'm really not a PHP dev)

Correct - maintenance of the Mautic product wise - only one location for both the base templates and shared assets. And users can override the templates as per normal I expect and also user can override the assets in their media folders.

The function is used elsewhere so yes I would expect it to be safe and vetted already 😊 If not - one fix will fix it for all usages including existing usages.

@andersonjeccel
Copy link
Contributor

@driskell Got it! Thank you for explaining:)

@driskell
Copy link
Contributor Author

driskell commented Jan 20, 2025

I've just realised the entire assets folder that is now outside of app is also missing from composer installation, which explains some dodgy workarounds on my end. I'll try get some testing done myself on this soon but I will move out of draft since we had one test done already.

I'll then try look separately at the missing assets folder as perhaps that's a scaffold thing - I'll raise an issue for discussion though on best way to resolve as perhaps it needs a new composer package mautic/mautic-core-assets?

Issue on my side, sorry, ignore this

@driskell driskell marked this pull request as ready for review January 20, 2025 13:24
@matbcvo
Copy link
Contributor

matbcvo commented Jan 20, 2025

I'm not sure what you meant by assets being outside the app folder. The assets are still located within the app folder and will be included in the Composer-based installation.

@driskell
Copy link
Contributor Author

driskell commented Jan 20, 2025

I'm not sure what you meant by assets being outside the app folder. The assets are still located within the app folder and will be included in the Composer-based installation.

Sorry. I realise now there is no issue. So I will strike through this. Sorry for the confusion. I'm using Nginx and it looks like we missed allowing access to app/assets - in my head I thought it was in public and meant to be outside app but no it's just an issue on my side!

@escopecz escopecz added code-review-passed PRs which have passed code review and removed code-review-needed PR's that require a code review before merging labels Jan 20, 2025
@escopecz escopecz merged commit 43a0062 into mautic:5.2 Jan 20, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs code-review-passed PRs which have passed code review composer Any bugs or PRs relating to composer T1 Low difficulty to fix (issue) or test (PR) themes Anything related to themes user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Archived in project
9 participants