private IEnumerable <IFeatureInfo> GetFeaturesToDisable(IFeatureInfo featureInfo)
        {
            var affectedFeatures = _extensionManager
                                   .GetDependentFeatures(featureInfo.Id)
                                   .ToList();

            return(affectedFeatures);
        }
Esempio n. 2
0
        public void GetDependentFeaturesShouldReturnAllFeaturesThatHaveADependencyOnAFeature()
        {
            var features = ModuleScopedExtensionManager.GetDependentFeatures("Sample1");

            Assert.Equal(4, features.Count());
            Assert.Equal("Sample1", features.ElementAt(0).Id);
            Assert.Equal("Sample2", features.ElementAt(1).Id);
            Assert.Equal("Sample3", features.ElementAt(2).Id);
            Assert.Equal("Sample4", features.ElementAt(3).Id);
        }
Esempio n. 3
0
        public async Task <ActionResult> Integrations()
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Features.Permissions.ManageFeatures)) // , T["Not allowed to manage features."]
            {
                return(Unauthorized());
            }

            var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

            // var alwaysEnabledFeatures = await _shellFeaturesManager.GetAlwaysEnabledFeaturesAsync();
//           var integrationFeatures = enabledFeatures.Where(extensionDescriptor =>
//           {
//               var tags = extensionDescriptor.Extension.Manifest.Tags.ToArray();
//               var isIntegrationFeature =
//                   tags.Any(x => string.Equals(x, "integration", StringComparison.OrdinalIgnoreCase));
//
//               return isIntegrationFeature;
//           });

            var moduleFeatures = new List <ModuleFeature>();

            foreach (var moduleFeatureInfo in _extensionManager
                     .GetFeatures()
                     .Where(f => !f.Extension.IsTheme() && FeatureIsAllowed(f)))
            {
                var dependentFeatures    = _extensionManager.GetDependentFeatures(moduleFeatureInfo.Id);
                var featureDependencies  = _extensionManager.GetFeatureDependencies(moduleFeatureInfo.Id);
                var isIntegrationFeature = IsIntegrationFeature(moduleFeatureInfo.Extension.Manifest);

                if (isIntegrationFeature == true)
                {
                    var moduleFeature = new ModuleFeature
                    {
                        Descriptor = moduleFeatureInfo,
                        IsEnabled  = enabledFeatures.Contains(moduleFeatureInfo),
                        // IsAlwaysEnabled = alwaysEnabledFeatures.Contains(moduleFeatureInfo),
                        //IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                        //NeedsUpdate = featuresThatNeedUpdate.Contains(f.Id),
                        EnabledDependentFeatures = dependentFeatures.Where(x => x.Id != moduleFeatureInfo.Id).ToList(),
                        FeatureDependencies      = featureDependencies.Where(d => d.Id != moduleFeatureInfo.Id).ToList()
                    };

                    moduleFeatures.Add(moduleFeature);
                }
            }

            return(View(new FeaturesViewModel
            {
                Features = moduleFeatures,
                IsAllowed = FeatureIsAllowed
            }));
        }
        /// <summary>
        /// Disables a feature.
        /// </summary>
        /// <param name="featureInfo">The info of the feature to be disabled.</param>
        /// <param name="enabledFeatureIds">The list of feature ids which are currently enabled.</param>
        /// <param name="force">Boolean parameter indicating if the feature should disable it's dependents.</param>
        /// <returns>An enumeration of the features to enable, empty if 'force' = true and a dependent is enabled</returns>
        private IEnumerable <IFeatureInfo> GetFeaturesToDisable(IFeatureInfo featureInfo, IEnumerable <string> enabledFeatureIds, bool force)
        {
            var featuresToDisable = _extensionManager
                                    .GetDependentFeatures(featureInfo.Id)
                                    .Where(f => enabledFeatureIds.Contains(f.Id))
                                    .ToList();

            if (featuresToDisable.Count > 1 && !force)
            {
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning(" To disable '{FeatureId}', additional features need to be disabled.", featureInfo.Id);
                }

                return(Enumerable.Empty <IFeatureInfo>());
            }

            return(featuresToDisable);
        }
Esempio n. 5
0
        /// <summary>
        /// Disables a feature.
        /// </summary>
        /// <param name="featureId">The ID of the feature to be enabled.</param>
        /// <param name="force">Boolean parameter indicating if the feature should enable it's dependencies if required or fail otherwise.</param>
        /// <returns>An enumeration of the disabled features.</returns>
        private IEnumerable <IFeatureInfo> GetFeaturesToDisable(IFeatureInfo featureInfo, bool force)
        {
            var affectedFeatures = _extensionManager
                                   .GetDependentFeatures(featureInfo.Id)
                                   .ToList();

            if (affectedFeatures.Count > 1 && !force)
            {
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning("Additional features need to be disabled.");
                }
                if (FeatureDependencyNotification != null)
                {
                    FeatureDependencyNotification("If {0} is disabled, then you'll also need to disable {1}.", featureInfo, affectedFeatures.Where(f => f.Id != featureInfo.Id));
                }
            }

            return(affectedFeatures);
        }
Esempio n. 6
0
        public async Task <ActionResult> Features()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures))
            {
                return(Forbid());
            }

            var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

            var alwaysEnabledFeatures = await _shellFeaturesManager.GetAlwaysEnabledFeaturesAsync();

            var moduleFeatures = new List <ModuleFeature>();

            foreach (var moduleFeatureInfo in _extensionManager
                     .GetFeatures()
                     .Where(f => !f.Extension.IsTheme() && FeatureIsAllowed(f)))
            {
                var dependentFeatures   = _extensionManager.GetDependentFeatures(moduleFeatureInfo.Id);
                var featureDependencies = _extensionManager.GetFeatureDependencies(moduleFeatureInfo.Id);

                var moduleFeature = new ModuleFeature
                {
                    Descriptor      = moduleFeatureInfo,
                    IsEnabled       = enabledFeatures.Contains(moduleFeatureInfo),
                    IsAlwaysEnabled = alwaysEnabledFeatures.Contains(moduleFeatureInfo),
                    //IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                    //NeedsUpdate = featuresThatNeedUpdate.Contains(f.Id),
                    DependentFeatures   = dependentFeatures.Where(x => x.Id != moduleFeatureInfo.Id).ToList(),
                    FeatureDependencies = featureDependencies.Where(d => d.Id != moduleFeatureInfo.Id).ToList()
                };

                moduleFeatures.Add(moduleFeature);
            }

            return(View(new FeaturesViewModel
            {
                Features = moduleFeatures,
                IsAllowed = FeatureIsAllowed
            }));
        }
Esempio n. 7
0
        public async Task <ActionResult> Features()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures)) // , T["Not allowed to manage features."]
            {
                return(Unauthorized());
            }

            var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

            var moduleFeatures = new List <ModuleFeature>();

            foreach (var moduleFeatureInfo in _extensionManager
                     .GetExtensions()
                     .Features
                     .Where(f => !f.Extension.Manifest.IsTheme()))
            {
                var dependentFeatures = _extensionManager.GetDependentFeatures(moduleFeatureInfo.Id, enabledFeatures.ToArray());

                var moduleFeature = new ModuleFeature
                {
                    Descriptor = moduleFeatureInfo,
                    IsEnabled  = enabledFeatures.Contains(moduleFeatureInfo),
                    //IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                    //NeedsUpdate = featuresThatNeedUpdate.Contains(f.Id),
                    DependentFeatures = dependentFeatures.Where(x => x.Id != moduleFeatureInfo.Id).ToList()
                };

                moduleFeatures.Add(moduleFeature);
            }

            return(View(new FeaturesViewModel
            {
                Features = moduleFeatures,
                IsAllowed = ExtensionIsAllowed
            }));
        }
Esempio n. 8
0
        public async Task UpdateAsync(string featureId)
        {
            if (_processedFeatures.Contains(featureId))
            {
                return;
            }

            _processedFeatures.Add(featureId);

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Updating feature: {0}", featureId);
            }

            // proceed with dependent features first, whatever the module it's in
            var dependencies = _extensionManager
                               .GetDependentFeatures(
                featureId)
                               .Where(x => x.Id != featureId)
                               .Select(x => x.Id);

            await UpdateAsync(dependencies);

            var migrations = GetDataMigrations(featureId);

            // apply update methods to each migration class for the module
            foreach (var migration in migrations)
            {
                var schemaBuilder = new SchemaBuilder(_session);
                migration.SchemaBuilder = schemaBuilder;

                // copy the object for the Linq query
                var tempMigration = migration;

                // get current version for this migration
                var dataMigrationRecord = GetDataMigrationRecordAsync(tempMigration).Result;

                var current = 0;
                if (dataMigrationRecord != null)
                {
                    current = dataMigrationRecord.Version.Value;
                }
                else
                {
                    dataMigrationRecord = new Records.DataMigration {
                        DataMigrationClass = migration.GetType().FullName
                    };
                    _dataMigrationRecord.DataMigrations.Add(dataMigrationRecord);
                }

                try
                {
                    // do we need to call Create() ?
                    if (current == 0)
                    {
                        // try to resolve a Create method

                        var createMethod = GetCreateMethod(migration);
                        if (createMethod != null)
                        {
                            current = (int)createMethod.Invoke(migration, new object[0]);
                        }
                    }

                    var lookupTable = CreateUpgradeLookupTable(migration);

                    while (lookupTable.ContainsKey(current))
                    {
                        try
                        {
                            if (_logger.IsEnabled(LogLevel.Information))
                            {
                                _logger.LogInformation("Applying migration for {0} from version {1}.", featureId, current);
                            }
                            current = (int)lookupTable[current].Invoke(migration, new object[0]);
                        }
                        catch (Exception ex)
                        {
                            if (ex.IsFatal())
                            {
                                throw;
                            }
                            _logger.LogError(0, "An unexpected error occurred while applying migration on {0} from version {1}.", featureId, current);
                            throw;
                        }
                    }

                    // if current is 0, it means no upgrade/create method was found or succeeded
                    if (current == 0)
                    {
                        return;
                    }

                    dataMigrationRecord.Version = current;
                }
                catch (Exception ex)
                {
                    if (ex.IsFatal())
                    {
                        throw;
                    }
                    _logger.LogError(0, "Error while running migration version {0} for {1}.", current, featureId);
                    _session.Cancel();
                    throw new Exception(T["Error while running migration version {0} for {1}.", current, featureId], ex);
                }
                finally
                {
                    // Persist data migrations
                    _session.Save(_dataMigrationRecord);
                }
            }
        }