<commit_before>﻿using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Data.Migration;
using Orchard.Localization;
using Orchard.Modules.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Packaging;
using Orchard.Packaging.Services;
using Orchard.Reports.Services;
using Orchard.UI.Notify;

namespace Orchard.Modules.Controllers {
    public class AdminController : Controller {
        private readonly IModuleService _moduleService;
        private readonly IDataMigrationManager _dataMigrationManager;
        private readonly IPackageManager _packageManager;
        private readonly IReportsCoordinator _reportsCoordinator;

        public AdminController(IOrchardServices services,
            IModuleService moduleService,
            IDataMigrationManager dataMigrationManager,
            IPackageManager packageManager,
            IReportsCoordinator reportsCoordinator) {

            Services = services;
            _moduleService = moduleService;
            _dataMigrationManager = dataMigrationManager;
            _packageManager = packageManager;
            _reportsCoordinator = reportsCoordinator;

            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }
        public IOrchardServices Services { get; set; }

        public ActionResult Index() {
            if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
                return new HttpUnauthorizedResult();

            var modules = _moduleService.GetInstalledModules().ToList();
            return View(new ModulesIndexViewModel { Modules = modules });
        }

        public ActionResult Add() {
            return View(new ModuleAddViewModel());
        }

        [HttpPost, ActionName("Add")]
        public ActionResult AddPOST() {
            // module not used for anything other than display (and that only to not have object in the view 'T')
            var viewModel = new ModuleAddViewModel();
            try {
                UpdateModel(viewModel);
                if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Couldn't upload module package.")))
                    return new HttpUnauthorizedResult();

                if (string.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
                    ModelState.AddModelError("File", T("Select a file to upload.").ToString());
                }

                if (!ModelState.IsValid)
                    return View("add", viewModel);

                foreach (string fileName in Request.Files) {
                    var file = Request.Files[fileName];

                    var info = _packageManager.Install(file.InputStream);
                    Services.Notifier.Information(T("Installed package \"{0}\", version {1} of type \"{2}\" at location \"{3}\"",
                        info.ExtensionName, info.ExtensionVersion, info.ExtensionType, info.ExtensionPath));
                }

                return RedirectToAction("index");
            }
            catch (Exception exception) {
                for (var scan = exception; scan != null; scan = scan.InnerException) {
                    Services.Notifier.Error(T("Uploading module package failed: {0}", exception.Message));
                }
                return View("add", viewModel);
            }
        }

        public ActionResult Features() {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
                return new HttpUnauthorizedResult();

            var features = _moduleService.GetAvailableFeatures().ToList();
            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            return View(new FeaturesViewModel { Features = features, FeaturesThatNeedUpdate = featuresThatNeedUpdate });
        }

        [HttpPost]
        public ActionResult Enable(string id, bool? force) {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
                return new HttpUnauthorizedResult();

            if (string.IsNullOrEmpty(id))
                return new NotFoundResult();<commit_msg>Themes no longer show up as features in the features admin<commit_after>﻿using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Data.Migration;
using Orchard.Localization;
using Orchard.Modules.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Packaging;
using Orchard.Packaging.Services;
using Orchard.Reports.Services;
using Orchard.UI.Notify;

namespace Orchard.Modules.Controllers {
    public class AdminController : Controller {
        private readonly IModuleService _moduleService;
        private readonly IDataMigrationManager _dataMigrationManager;
        private readonly IPackageManager _packageManager;
        private readonly IReportsCoordinator _reportsCoordinator;

        public AdminController(IOrchardServices services,
            IModuleService moduleService,
            IDataMigrationManager dataMigrationManager,
            IPackageManager packageManager,
            IReportsCoordinator reportsCoordinator) {

            Services = services;
            _moduleService = moduleService;
            _dataMigrationManager = dataMigrationManager;
            _packageManager = packageManager;
            _reportsCoordinator = reportsCoordinator;

            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }
        public IOrchardServices Services { get; set; }

        public ActionResult Index() {
            if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
                return new HttpUnauthorizedResult();

            var modules = _moduleService.GetInstalledModules().ToList();
            return View(new ModulesIndexViewModel { Modules = modules });
        }

        public ActionResult Add() {
            return View(new ModuleAddViewModel());
        }

        [HttpPost, ActionName("Add")]
        public ActionResult AddPOST() {
            // module not used for anything other than display (and that only to not have object in the view 'T')
            var viewModel = new ModuleAddViewModel();
            try {
                UpdateModel(viewModel);
                if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Couldn't upload module package.")))
                    return new HttpUnauthorizedResult();

                if (string.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
                    ModelState.AddModelError("File", T("Select a file to upload.").ToString());
                }

                if (!ModelState.IsValid)
                    return View("add", viewModel);

                foreach (string fileName in Request.Files) {
                    var file = Request.Files[fileName];

                    var info = _packageManager.Install(file.InputStream);
                    Services.Notifier.Information(T("Installed package \"{0}\", version {1} of type \"{2}\" at location \"{3}\"",
                        info.ExtensionName, info.ExtensionVersion, info.ExtensionType, info.ExtensionPath));
                }

                return RedirectToAction("index");
            }
            catch (Exception exception) {
                for (var scan = exception; scan != null; scan = scan.InnerException) {
                    Services.Notifier.Error(T("Uploading module package failed: {0}", exception.Message));
                }
                return View("add", viewModel);
            }
        }

        public ActionResult Features() {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
                return new HttpUnauthorizedResult();

            var features = _moduleService.GetAvailableFeatures().Where(f => !f.Descriptor.Extension.ExtensionType.Equals("Theme", StringComparison.OrdinalIgnoreCase)).ToList();
            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            return View(new FeaturesViewModel { Features = features, FeaturesThatNeedUpdate = featuresThatNeedUpdate });
        }

        [HttpPost]
        public ActionResult Enable(string id, bool? force) {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
                return new HttpUnauthorizedResult();

            if (string.IsNullOrEmpty(id))
                return new NotFoundResult();
{'fraction_non_alphanumeric': 0.08587808587808587, 'fraction_numerical': 0.001404001404001404, 'mean_word_length': 2.3627065302911094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615950', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1971, 'n_words': 515}