OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.43k stars 2.4k forks source link

Issue having CMS as a module, can the Orchard CMS security being reused on Modules? #8980

Closed gabrielacosta closed 6 months ago

gabrielacosta commented 3 years ago

Hi,

I'm trying to use Orchard and have:

  1. Landing project using CMS
  2. Module Admin - using Module
  3. Module customer - using Module.

I create a solution with a working example of what I'm trying to achieve. https://github.com/gabrielacosta/WebApplication1

First, I created everything and it works fine. I added to the landing only the OrchardCore.Module.Targets Nuget.

Landing

image

Admin

image

Customer

image Until that point, everything works fine.

However, when I tried to add the CMS Nuget to the Landing Module.

image

And modify the startup on the landing to load OrchardCMS

image

The solution compiles without any issues.

However, when I run it I got this error.

image

I'm not sure how to fix it. Or if the model that I'm trying to build is correct.

Could you please review the solution and let me know.

Kind regards,

G

Skrypt commented 3 years ago

This is a bad idea to reference Orchard Core inside a module. It should be referenced only on your main website project like OrchardCore.Cms.Web for example in our templates.

If you need to reference a specific OrchardCore module in your project you can reference these instead.

If I look at your solution folders and project I'd say that OrchardCore.Cms.Web would be equivalent to your Main.csproj. This is the only place where you should reference OrchardCore.Application.Cms.Target.

Skrypt commented 3 years ago

Please explain what you are trying to achieve so that we can understand better and help you. Else the solution is to revert the changes that makes this fail to run.

gabrielacosta commented 3 years ago

Hi Skrypt, Thanks for replying. What I'm trying to achieve is having one website as landing using the Orchard CMS. Then I want to add to it more modules that will do other functionalities, but still use security model from the CMS. So, if have two specific roles such as admin and customer, those modules can have dashboards or other CRUD type of code not related with the content of the landing website.

Skrypt commented 3 years ago

Create 2 different tenants then.

Landing Website = host tenant Child Website = activate module 1 Child Website 2 = activate module 2 ...

Then these 2 websites/tenants are not going to use the same Content Types than the host one. And your modules can register a custom route for your "/dashboard" which will be secured by it's controller like we do in OrchardCore.Contents module AdminController. But instead of naming it AdminController you name it DashboardController.

And this way each tenants can have their own custom dashboard. But you should not activate both modules in the same tenant if they both register a /dashboard route.

gabrielacosta commented 3 years ago

Hi Skrypt,

I just tried.

image

And I got another error.

image

I checked other possible issues, but I'm quite sure I do not use AddMvc() in the startup of the landing.

image

Do you know, what could be the issue.

Kind regards, G

Skrypt commented 3 years ago

Look at the templates for examples :

https://github.com/OrchardCMS/OrchardCore/tree/dev/src/Templates/OrchardCore.ProjectTemplates/content

Your CMSLanding here will be probably needing the startup.cs and program.cs from this template module :

https://github.com/OrchardCMS/OrchardCore/tree/dev/src/Templates/OrchardCore.ProjectTemplates/content/OrchardCore.Templates.Cms.Web

gabrielacosta commented 3 years ago

I already the startup and the program as recommended from the templates.

https://github.com/OrchardCMS/OrchardCore/blob/dev/src/Templates/OrchardCore.ProjectTemplates/content/OrchardCore.Templates.Cms.Web/Program.cs

and https://github.com/OrchardCMS/OrchardCore/blob/dev/src/Templates/OrchardCore.ProjectTemplates/content/OrchardCore.Templates.Cms.Web/Startup.cs

However, the error still appearing...

image

I think another ticket was setup before https://github.com/OrchardCMS/OrchardCore/issues/3453

But, I do not use Sqlite, the landing CMS is using the blank template and SQL Server 2012.

I upload the solution to

https://github.com/gabrielacosta/CMSwithModules

deanmarcussen commented 3 years ago

Your module / startup definitions don't seem correct.

Suggest:

Create one Web project which calls .UseOrchardCore()

Create as many modules as you want after that. Do your code in those modules. Don't call .UseOrchardCore() again.

gabrielacosta commented 3 years ago

Hi Dean,

Thanks for the suggestion. I already try that and I know it works. However, I want to use the cms component. I don't get how your suggestion helps me to achieve that.

weirdyang commented 3 years ago

Hi Dean,

Thanks for the suggestion. I already try that and I know it works. However, I want to use the cms component. I don't get how your suggestion helps me to achieve that.

@gabrielacosta, The issue is you have not created the tenant, but your appsettings.json has configuration for it with the states set to running. but if you inspect the tenants.json in your App_Data folder, there is only the default tenant. Note; this is only an issue if you're using OrchardCMS

create a new occms first install the templates: dotnet new -i OrchardCore.ProjectTemplates::1.0.0-* then navigate to a folder: dotnet new occms -n MySite launch the site, select blog or saas navigate to features and activate tenants feature:

image

do the setup: image

click setup: image

navigate to the prefix you set: image

image

your App_Data folder should now have a new entry in tenants.json.

weirdyang commented 3 years ago

See https://github.com/OrchardCMS/OrchardCore/pull/5422 for how to preconfigure it:

So now, for the documentation

To provide preconfig values for a given tenant you need a tenant valid state as Uninitialized. This will automatically create a tenant at runtime using these values.

To only provide config values for a given tenant don't specify a tenant state. These values will be only used when the tenant is manually created.

here's a screenshot;

image

Hope that helps!

Here's the repo; https://github.com/weirdyang/orchardcore-demo