public async Task <IActionResult> Enable(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants))
            {
                return(Unauthorized());
            }

            if (!IsDefaultShell())
            {
                return(Unauthorized());
            }

            var shellContext = (await _orchardHost.ListShellContextsAsync())
                               .OrderBy(x => x.Settings.Name)
                               .Where(x => string.Equals(x.Settings.Name, id, StringComparison.OrdinalIgnoreCase))
                               .FirstOrDefault();

            if (shellContext == null)
            {
                return(NotFound());
            }

            var shellSettings = shellContext.Settings;

            if (shellSettings.State != TenantState.Disabled)
            {
                _notifier.Error(H["You can only enable a Disabled tenant."]);
            }

            shellSettings.State = TenantState.Running;
            await _orchardHost.UpdateShellSettingsAsync(shellSettings);

            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
        public override async Task <IDisplayResult> EditAsync(OpenIdValidationSettings settings, BuildEditorContext context)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageValidationSettings))
            {
                return(null);
            }

            return(Initialize <OpenIdValidationSettingsViewModel>("OpenIdValidationSettings_Edit", async model =>
            {
                model.Authority = settings.Authority;
                model.Audience = settings.Audience;
                model.Tenant = settings.Tenant;

                var availableTenants = new List <string>();
                var tenants = _shellSettingsManager.LoadSettings().Where(s => s.State == TenantState.Running);

                foreach (var shellContext in await _shellHost.ListShellContextsAsync())
                {
                    using (var scope = shellContext.CreateScope())
                    {
                        var descriptor = scope.ServiceProvider.GetRequiredService <ShellDescriptor>();
                        if (descriptor.Features.Any(feature => feature.Id == OpenIdConstants.Features.Server))
                        {
                            availableTenants.Add(shellContext.Settings.Name);
                        }
                    }
                }

                model.AvailableTenants = availableTenants;
            }).Location("Content:2").OnGroup(SettingsGroupId));
        }
Example #3
0
        public IList <RouteDescriptor> GetRoutes()
        {
            var runningShells = _shellHost.ListShellContextsAsync().Result
                                .Where(sc => sc.Settings.State == TenantState.Running);

            var activeFeatures = runningShells.SelectMany(r => r.Blueprint.Descriptor.Features);


            return(activeFeatures.Select(f =>
            {
                var areaName = AreaTemplate.GetAreaKey(new AreaOption()
                {
                    AreaName = f.Id, FunctionType = "Views"
                });
                return new RouteDescriptor
                {
                    Name = areaName + "Route",
                    AreaName = areaName,
                    Priority = -10,
                    RouteTemplate = areaName + "/{controller}/{action}/{id?}",
                    Defaults = new { area = areaName, controller = "home", action = "index" }
                };
            }).ToList());
        }
 private async Task <IEnumerable <ShellContext> > GetRunningShells()
 {
     return((await _shellHost.ListShellContextsAsync()).Where(s => s.Settings.State == TenantState.Running && s.Pipeline != null).ToArray());
 }
 private async Task <IEnumerable <ShellContext> > GetShellsAsync()
 {
     return((await _shellHost.ListShellContextsAsync()).OrderBy(x => x.Settings.Name));
 }