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

V11: Using IFileProvider to access assets added from packages #13141

Merged
merged 28 commits into from
Nov 2, 2022

Conversation

elit0451
Copy link
Member

@elit0451 elit0451 commented Oct 7, 2022

Details

  • In this PR tours, icons, package.manifest and grid.editors.config.js files are considered;
  • The changes include accessing the file system through File Providers (by using IFileProvider) and thus providing those ⬆️ files;
  • That way if a package adds those types of files, the physical files wouldn't clutter the Umbraco solution;
  • We will look in the web root, and then check in RCLs;
  • Check below for the folders, the files mentioned above should be located in, in order to be discovered (same location as stated in our docs);
  • In some places, magic strings are used to filter out and optimize the loops we will make through the file system until we find the folder where the specific files are located. If a better solution comes to mind, comment down below 😋.

Test

  • Tours
    • Add a new .json file in /App_Plugins/<YourTourPlugin>/backoffice/tours - ref: Backoffice Tours docs
      • You can use Umbraco.Cms.StaticAssets project for quick testing as it is an RCL -> ❗ create the App_Plugins folder inside wwwroot;
    • Create a tour object, like:
[
  {
    "name": "My Custom Backoffice tour",
    "alias": "myCustomBackofficeTour",
    "group": "Get things done!!!",
    "groupOrder": 1,
    "allowDisable": true,
    "culture": "en-US",
    "contentType": "",
    "requiredSections": [ "content", "media" ],
    "steps": [
      {
        "title": "Welcome",
        "content": "<p>In this tour . . .</p>",
        "type": "intro"
      }
    ]
  }
]
    • Verify that the new tour appears and that you can complete it;
    • Add another tour file in /App_Plugins folder at the root of Umbraco.Web.UI project and verify that this tour also appears -> that the old functionality still works;
      • ❗ Follow the same path structure as before;
  • Icons

    • Add an .svg file inside Umbraco.Cms.StaticAssets\wwwroot\App_Plugins\<YourTourPlugin>\backoffice\icons
    • It can be this one;
    • Create a new document type and change the default icon to the one you just added;
  • package.manifest

    • Add the following package.manifest file in /App_Plugins/{YourPackageName} as stated in the Package Manifest docs;
    • You can use the Umbraco.Cms.StaticAssets\wwwroot location again for the /App_Plugins folder;
{
    "name": "Sir Trevor",
    "version": "1.0.0 beta",
    "allowPackageTelemetry": true,
    "bundleOptions": "Default",
    "packageView": "/App_Plugins/SirTrevor/SirTrevor-config.html",
    "propertyEditors": [
        {
            "alias": "Sir.Trevor",
            "name": "Sir Trevor",
            "editor": {
                "view": "/App_Plugins/SirTrevor/SirTrevor.html",
                "hideLabel": true,
                "valueType": "JSON",
                "supportsReadOnly": true
            }
        }
    ],
    "javascript": [
        "/App_Plugins/SirTrevor/SirTrevor.controller.js"
    ]
}
    • On a document type, try to select a property editor and make sure you can find the Sir Trevor property editor we added through the package.manifest file;
  • grid.editors.config.js

    • Add the following file ⬇️ into /config/grid.editors.config.js (ref: Grid Editors docs) - You can use Umbraco.Cms.StaticAssets project: Umbraco.Cms.StaticAssets\wwwroot\config\grid.editors.config.js file location:
[
    {
        "name": "Rich text editor",
        "alias": "rte",
        "view": "rte",
        "icon": "icon-article"
    }
]
    • In a document type, add a property with a Grid layout - keep the default settings;
    • Create a content node and add a row for our grid: ex: Headline;
      • The rich text editor appears immediately, as it is the only option;
    • Click again "Add content" and verify that there is indeed just one option - the one we added in our grid.editors.config.js
    • Delete the file from the config folder and verify that the types that appear for the Headline content are the ones that Umbraco comes with - namely the ones listed in Umbraco.Core\EmbeddedResources\Grid\grid.editors.config.js
      • This shows that we will check if we have a custom grid.editors.config.js file, otherwise, we will default to the embedded file.

Update:

  • Nested package manifests are also discoverable both in RCLs and on disk - info in comment;
  • The flow of discovering grid.editors.config.js file is the following:
    • Try to get file on disk;
    • If no file, check in RCLs;
    • If still no file, get the embedded one from Umbraco.
  • For tours, in the case that the same tour (both file name and exact path match starting from App_Plugins folder) is found in both the website project and any RCL, RCL will be preferred. Check comment for explanation. If this is the case, we recommend changing the plugin folder name.

@elit0451 elit0451 marked this pull request as ready for review October 10, 2022 13:04
Fix merge conflict in src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilder.LocalizedText.cs
Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

@elit0451 I've been trying this out and the described test flows work just fine.

However it seems like the code favors RCL files over files on disk in scenarios where the same files exist in both places. That doesn't seem right? I would expect the files on disk to take precedence, but maybe that's just me? I have observed this for tours and packages (both for manifests and for the files referenced within), but not for icons - though it might be worth doing a double check here for good measure.

I am also unable to serve a grid.editors.config.js file from disk. The old code would allow that file to exist under /config and take precedence over the embedded file.

I haven't reviewed the code yet, these are just initial test observations. It may very well be me that is testing this all wrong, but could you please have a look?

@elit0451
Copy link
Member Author

Those are some valid concerns @kjac which we can definitely revisit, as at least my initial understanding of this task was that we would prefer the files from RCL which now that you mention it, might not make sense in all cases. I will make sure to clarify the intended workflow and I will check the rest of the things you mentioned 💪

@kjac
Copy link
Contributor

kjac commented Oct 24, 2022

@elit0451 one more behavioural thing to take into account: Nested package manifests. Although it is not clearly (or remotely) documented, Umbraco allows for package manifests to be nested in sub folders to the plugin root folders. This goes for language files as well, as they are usually shipped with the packages.

Consider this structure with nested package manifests and language files (also attached as a zip file here):

nested-plugins-file-structure

In v11/dev this yields:

nested-plugins

In this PR, the nested dashboards are missing - but as you can see, the nested localization files are read out correctly:

image

Here's an issue that mentions the use of nested plugins (from back when we added nested language files).

@elit0451
Copy link
Member Author

elit0451 commented Nov 1, 2022

Comment for @kjac: The PR is ready for review again! 💪

Comment for my future self: The reason why the said behaviour was observed - favouring "RCL files over files on disk in scenarios where the same files exist in both places" * - is because our custom file provider (one reading from the website project) is registered after the RCL/static assets one (.ConcatComposite()), therefore it's picking up the RCL file first.
The same behaviour is observed in aspnetcore.

Finally, there has also been a short discussion which outcome is also in agreement to what we saw that content from Razor Class Library (RCL) can't really be overridden. BUT again, the chances of the mentioned scenario* happening are very minimal. Overriding Umbraco files in relation to tours, lang files, grid.editors.config.js will be possible as those are embedded files.

@kjac
Copy link
Contributor

kjac commented Nov 1, 2022

@elit0451 the code looks great and tests out well👍 I have left a few small comments here and there for you to consider

@kjac kjac merged commit 897cf4c into v11/dev Nov 2, 2022
@kjac kjac deleted the v11/feature/use-IFileProvider branch November 2, 2022 14:26
@kjac
Copy link
Contributor

kjac commented Nov 2, 2022

Looks good to me 🎉

nikolajlauridsen pushed a commit that referenced this pull request Nov 3, 2022
* Creating a FileProviderFactory for getting the package.manifest and grid.editors.config.js files through a file provider

* Collecting the package.manifest-s from different sources

* Searching different sources for grid.editors.config.js

* Using an IFileProvider to collect all tours

* Refactoring IconService.cs

* Typo

* Optimizations when looping through the file system

* Moving WebRootFileProviderFactory to Umbraco.Web.Common proj

* Removes double registering

* pluginLangFileSources includes the localPluginFileSources

* Comments

* Remove linq from foreach

* Change workflow for grid.editors.config.js so we check first physical file, then RCL, then Embedded

* Clean up

* Check if config dir exists

* Discover nested package.manifest files

* Fix IFileInfo.PhysicalPath check

* Revert 712810e as that way files in content root are preferred over those in web root

* Adding comments

* Refactoring

* Remove PhysicalPath check

* Fix registration of WebRootFileProviderFactory
Zeegaan added a commit that referenced this pull request Nov 8, 2022
* Bump version

* Add IContextCache to deploy connectors (#13287)

* Add IContextCache and implementations

* Update connector interfaces to use IContextCache

* Minor cleanup

* Move DeployContextCache prefix to constant

* Move default implementations to obsolete methods

* Remove DeployContextCache and DictionaryCache

Co-authored-by: Andy Butland <abutland73@gmail.com>

* Add IContextCache to deploy connectors (#13287)

* Add IContextCache and implementations

* Update connector interfaces to use IContextCache

* Minor cleanup

* Move DeployContextCache prefix to constant

* Move default implementations to obsolete methods

* Remove DeployContextCache and DictionaryCache

Co-authored-by: Andy Butland <abutland73@gmail.com>

* Parse lockId as invariant (#13284)

Co-authored-by: Zeegaan <nge@umbraco.dk>

* Fix Sqlite database locking issue (#13246)

* Add locking for creating scope

* Lock the repository instead

* Add scope in action instead of locking in service

* Fix up post-merge

Co-authored-by: Zeegaan <nge@umbraco.dk>

* Bump version to next minor

* Fix for UseExceptionHandler no longer working since v10.3 RC (#13218)

* Fix for UseExceptionHandler no longer working since v10.3 RC

* Update the management api path to match the new one

Co-authored-by: Nikolaj <nikolajlauridsen@protonmail.ch>

* New backoffice: Cleanup management API routes (#13296)

* Rename ModelsBuilderDashboard folder to ModelsBuilder

* Fix modelsbuilder paths and related naming

* Rename analytics route to telemetry

* Fix controller bases - routes and tags

* Fix items route

* Fix more controllerbase routes

* Fix route

* Fix OpenApi file

* Merging DictionaryItem and Dictionary

* Fix TrackedReferences naming

* Update OpenApi file

* Rename Analytics* related types to Telemetry*

* New Backoffice: Return AnalyticsLevelViewModel from Telemetry/ (#13298)

* Return TelemetryLevelViewModel instead of TelemetryLevel

* Fix schema

* Change telemetry/current to telemetry/level

(cherry picked from commit f2b8494)

* Add contants for tree and recycle-bin subpaths

(cherry picked from commit 4449f56)

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Updated Smidge, Npoco and MailKit (#13310)

* Updated Smidge, Npoco and MailKit

* Added missing command (after breaking interface in npoco)

* OpenId Connect authentication for new management API (#13318)

* First attempt at OpenIddict

* Making headway and more TODOs

* Redo current policies for multiple schemas + clean up auth controller

* Fix bad merge

* Clean up some more test code

* Fix spacing

* Include AddAuthentication() in OpenIddict addition

* A little more clean-up

* Move application creation to its own implementation + prepare for middleware to handle valid callback URL

* Enable refresh token flow

* Fix bad merge from v11/dev

* Support auth for Swagger and Postman in non-production environments + use default login screen for back-office logins

* Add workaround to client side login handling so the OAuth return URL is not corrupted before redirection

* Add temporary configuration handling for new backoffice

* Restructure the code somewhat, move singular responsibility from management API project

* Add recurring task for cleaning up old tokens in the DB

* Fix bad merge + make auth controller align with the new management API structure

* Explicitly handle the new management API path as a backoffice path (NOTE: this is potentially behaviorally breaking!)

* Redo handle the new management API requests as backoffice requests, this time in a non-breaking way

* Add/update TODOs

* Revert duplication of current auth policies for OpenIddict (as it breaks everything for V11 without the new management APIs) and introduce a dedicated PoC policy setup for OpenIddict.

* Fix failing unit tests

* Update src/Umbraco.Cms.ManagementApi/Security/BackOfficeApplicationManager.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Update src/Umbraco.Cms.ManagementApi/Security/BackOfficeApplicationManager.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Update src/Umbraco.Cms.ManagementApi/Security/BackOfficeApplicationManager.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Update src/Umbraco.Core/Routing/UmbracoRequestPaths.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* V11: Using IFileProvider to access assets added from packages (#13141)

* Creating a FileProviderFactory for getting the package.manifest and grid.editors.config.js files through a file provider

* Collecting the package.manifest-s from different sources

* Searching different sources for grid.editors.config.js

* Using an IFileProvider to collect all tours

* Refactoring IconService.cs

* Typo

* Optimizations when looping through the file system

* Moving WebRootFileProviderFactory to Umbraco.Web.Common proj

* Removes double registering

* pluginLangFileSources includes the localPluginFileSources

* Comments

* Remove linq from foreach

* Change workflow for grid.editors.config.js so we check first physical file, then RCL, then Embedded

* Clean up

* Check if config dir exists

* Discover nested package.manifest files

* Fix IFileInfo.PhysicalPath check

* Revert 712810e as that way files in content root are preferred over those in web root

* Adding comments

* Refactoring

* Remove PhysicalPath check

* Fix registration of WebRootFileProviderFactory

* Use Swashbuckle instead of NSwag (#13350)

* First attempt at OpenIddict

* Making headway and more TODOs

* Redo current policies for multiple schemas + clean up auth controller

* Fix bad merge

* Clean up some more test code

* Fix spacing

* Include AddAuthentication() in OpenIddict addition

* A little more clean-up

* Move application creation to its own implementation + prepare for middleware to handle valid callback URL

* Enable refresh token flow

* Fix bad merge from v11/dev

* Support auth for Swagger and Postman in non-production environments + use default login screen for back-office logins

* Add workaround to client side login handling so the OAuth return URL is not corrupted before redirection

* Add temporary configuration handling for new backoffice

* Restructure the code somewhat, move singular responsibility from management API project

* Add recurring task for cleaning up old tokens in the DB

* Fix bad merge + make auth controller align with the new management API structure

* Explicitly handle the new management API path as a backoffice path (NOTE: this is potentially behaviorally breaking!)

* Redo handle the new management API requests as backoffice requests, this time in a non-breaking way

* Add/update TODOs

* Replace NSwag with Swashbuckle and clean up unnecessary client secret workaround

* Revert duplication of current auth policies for OpenIddict (as it breaks everything for V11 without the new management APIs) and introduce a dedicated PoC policy setup for OpenIddict.

* Fix failing unit tests

* A little niceness + export new OpenApi.json and fix path in contract unit test

* Redo after merge with v11/dev + filter out unwanted mime types

* Remove CreatedResult and NotFoundObjectResult where possible

* Custom schema IDs - no more "ViewModel" postfix and make generic lists look less clunky too

* A little more explanation for generic schema ID generation

* Force Swashbuckle to use enum string names

* Update OpenApi.json to match new enum string values

* Add clarifying comment about weird looking construct

* add workflow to schema (#13349)

* add workflow to schema

* add licenses to CMSDefinition - intentionally only adding to schema, not registered as options

Co-authored-by: Nikolaj <nikolajlauridsen@protonmail.ch>
Co-authored-by: Ronald Barendse <ronald@barend.se>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Zeegaan <nge@umbraco.dk>
Co-authored-by: Justin Neville <67802060+justin-nevitech@users.noreply.github.com>
Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
Co-authored-by: Nathan Woulfe <nathan@nathanw.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants