public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!String.Equals(context.Name, "custom-settings", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model = context.Step;

            var customSettingsList = (from property in model.Properties()
                                      where property.Name != "name"
                                      select property).ToArray();

            var customSettingsNames = (from customSettings in customSettingsList
                                       select customSettings.Name).ToArray();

            var customSettingsTypes = _customSettingsService.GetSettingsTypes(customSettingsNames).ToArray();

            foreach (var customSettingsType in customSettingsTypes)
            {
                if (!await _customSettingsService.CanUserCreateSettingsAsync(customSettingsType))
                {
                    return;
                }
            }

            var siteSettings = await _siteService.LoadSiteSettingsAsync();

            foreach (var customSettings in customSettingsList)
            {
                siteSettings.Properties[customSettings.Name] = customSettings.Value;
            }

            await _siteService.UpdateSiteSettingsAsync(siteSettings);
        }
예제 #2
0
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var customSettingsStep = step as CustomSettingsDeploymentStep;

            if (customSettingsStep == null)
            {
                return;
            }

            var settingsList = new List <JProperty> {
                new JProperty("name", "custom-settings")
            };

            var settingsTypes = customSettingsStep.IncludeAll
                ? _customSettingsService.GetAllSettingsTypes().ToArray()
                : _customSettingsService.GetSettingsTypes(customSettingsStep.SettingsTypeNames).ToArray();

            foreach (var settingsType in settingsTypes)
            {
                if (!await _customSettingsService.CanUserCreateSettingsAsync(settingsType))
                {
                    return;
                }
            }

            foreach (var settingsType in settingsTypes)
            {
                var settings = await _customSettingsService.GetSettingsAsync(settingsType);

                settingsList.Add(new JProperty(settings.ContentType, JObject.FromObject(settings)));
            }

            // Adding custom settings
            result.Steps.Add(new JObject(settingsList.ToArray()));
        }
예제 #3
0
        public IEnumerable <Permission> GetPermissions()
        {
            var list = new List <Permission>();

            foreach (var type in _customSettingsService.GetSettingsTypes())
            {
                list.Add(CreatePermissionForType(type));
            }

            return(list);
        }
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var customSettingsStep = step as CustomSettingsDeploymentStep;

            if (customSettingsStep == null)
            {
                return;
            }

            var settingsList = new List <JProperty> {
                new JProperty("name", "custom-settings")
            };

            var settingsTypes = customSettingsStep.IncludeAll
                ? _customSettingsService.GetAllSettingsTypes().ToArray()
                : _customSettingsService.GetSettingsTypes(customSettingsStep.SettingsTypeNames).ToArray();

            var settingsPermissionsTasks =
                (from settingsType in settingsTypes
                 select _customSettingsService.CanUserCreateSettingsAsync(settingsType)).ToArray();

            await Task.WhenAll(settingsPermissionsTasks);

            if (settingsPermissionsTasks.Any(t => !t.Result))
            {
                return;
            }

            var settingsTasks =
                (from settingsType in settingsTypes
                 select _customSettingsService.GetSettingsAsync(settingsType)).ToArray();

            await Task.WhenAll(settingsTasks);

            settingsList.AddRange(
                from settingsTask in settingsTasks
                let settings = settingsTask.Result
                               select new JProperty(settings.ContentType, JObject.FromObject(settings)));

            // Adding custom settings
            result.Steps.Add(new JObject(settingsList.ToArray()));
        }
예제 #5
0
        public void BuildNavigation(string name, NavigationBuilder builder)
        {
            if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (var type in _customSettingsService.GetSettingsTypes())
            {
                builder
                .Add(T["Configuration"], configuration => configuration
                     .Add(T["Settings"], settings => settings
                          .Add(new LocalizedString(type.DisplayName, type.DisplayName), layers => layers
                               .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = type.Name })
                               .Permission(Permissions.CreatePermissionForType(type))
                               .Resource(type.Name)
                               .LocalNav()
                               )));
            }
        }
예제 #6
0
 public CustomSettingsDisplayDriver(
     CustomSettingsService customSettingsService,
     IContentManager contentManager,
     IContentItemDisplayManager contentItemDisplayManager)
 {
     _customSettingsService     = customSettingsService;
     _contentManager            = contentManager;
     _contentItemDisplayManager = contentItemDisplayManager;
     _contentTypeDefinitions    = new Lazy <IList <ContentTypeDefinition> >(() => _customSettingsService.GetSettingsTypes());
 }
예제 #7
0
 public CustomSettingsDisplayDriver(
     CustomSettingsService customSettingsService,
     IContentManager contentManager,
     IContentItemDisplayManager contentItemDisplayManager,
     IHttpContextAccessor httpContextAccessor,
     IAuthorizationService authorizationService)
 {
     _customSettingsService     = customSettingsService;
     _contentManager            = contentManager;
     _contentItemDisplayManager = contentItemDisplayManager;
     _httpContextAccessor       = httpContextAccessor;
     _authorizationService      = authorizationService;
     _contentTypeDefinitions    = new Lazy <IList <ContentTypeDefinition> >(() => _customSettingsService.GetSettingsTypes());
 }