Ejemplo n.º 1
0
        public ActionResult FeaturesPOST(FeaturesBulkAction bulkAction, IList <string> featureIds, bool?force)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (featureIds == null || !featureIds.Any())
            {
                ModelState.AddModelError("featureIds", T("Please select one or more features."));
            }

            if (ModelState.IsValid)
            {
                var availableFeatures = _moduleService.GetAvailableFeatures().Where(feature => ModuleIsAllowed(feature.Descriptor.Extension)).ToList();
                var selectedFeatures  = availableFeatures.Where(x => featureIds.Contains(x.Descriptor.Id)).ToList();
                var enabledFeatures   = availableFeatures.Where(x => x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();
                var disabledFeatures  = availableFeatures.Where(x => !x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();

                switch (bulkAction)
                {
                case FeaturesBulkAction.None:
                    break;

                case FeaturesBulkAction.Enable:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Disable:
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Toggle:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Update:
                    foreach (var feature in selectedFeatures.Where(x => x.NeedsUpdate))
                    {
                        var id = feature.Descriptor.Id;
                        try {
                            _reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
                            _dataMigrationManager.Update(id);
                            Services.Notifier.Information(T("The feature {0} was updated successfully", id));
                        }
                        catch (Exception exception) {
                            Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, exception.Message));
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RedirectToAction("Features"));
        }
        public void DisableFeature(string featureId)
        {
            var features = _moduleService.GetAvailableFeatures().ToDictionary(m => m.Descriptor.Id, m => m);

            if (features.ContainsKey(featureId) && features[featureId].IsEnabled)
            {
                _moduleService.DisableFeatures(new string[] { featureId });
            }
        }
Ejemplo n.º 3
0
        public ActionResult Disable(string id, bool?force)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            _moduleService.DisableFeatures(new[] { id }, force != null && (bool)force);

            return(RedirectToAction("Features"));
        }
 public void Disable(params string[] featureNames)
 {
     Context.Output.WriteLine(T("Disabling features {0}", string.Join(",", featureNames)));
     _moduleService.DisableFeatures(featureNames, true);
     Context.Output.WriteLine(T("Disabled features  {0}", string.Join(",", featureNames)));
 }