GetSiteSettings() public method

Retrieves the current site settings.
public GetSiteSettings ( ) : SiteSettings
return Roadkill.Core.Configuration.SiteSettings
Exemplo n.º 1
0
        public string Upload(string destination, HttpFileCollectionBase files)
        {
            try
            {
                CloudBlobContainer container = GetCloudBlobContainer();

                // Get the allowed files types
                string fileName = "";

                // For checking the setting to overwrite existing files
                SiteSettings         siteSettings      = _settingsService.GetSiteSettings();
                IEnumerable <string> allowedExtensions = siteSettings.AllowedFileTypesList
                                                         .Select(x => x.ToLower());

                for (int i = 0; i < files.Count; i++)
                {
                    // Find the file's extension
                    HttpPostedFileBase sourceFile = files[i];
                    string             extension  = Path.GetExtension(sourceFile.FileName).Replace(".", "");

                    if (!string.IsNullOrEmpty(extension))
                    {
                        extension = extension.ToLower();
                    }

                    // Check if it's an allowed extension
                    if (allowedExtensions.Contains(extension))
                    {
                        string         filePath = CleanPath(String.Format("/{0}/{1}", destination, sourceFile.FileName));
                        CloudBlockBlob blob     = container.GetBlockBlobReference(filePath);

                        // Check if it exists on disk already
                        if (!siteSettings.OverwriteExistingFiles)
                        {
                            if (blob.Exists())
                            {
                                string errorMessage = string.Format(SiteStrings.FileManager_Upload_FileAlreadyExists, sourceFile.FileName);
                                throw new FileException(errorMessage, null);
                            }
                        }

                        blob.UploadFromStream(sourceFile.InputStream);
                        fileName = sourceFile.FileName;
                    }
                    else
                    {
                        string allowedExtensionsCsv = string.Join(",", allowedExtensions);
                        string errorMessage         = string.Format(SiteStrings.FileManager_Extension_Not_Supported, allowedExtensionsCsv);
                        throw new FileException(errorMessage, null);
                    }
                }

                return(fileName);
            }
            catch (StorageException e)
            {
                throw new FileException(e.Message, e);
            }
        }
		public void Setup()
		{
			// WikiController setup (use WikiController as it's the one typically used by views)
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_pluginFactory = _container.PluginFactory;
			_settingsService = _container.SettingsService;
			_siteSettings = _settingsService.GetSiteSettings();
			_siteSettings.Theme = "Mediawiki";

			_userService = _container.UserService;
			_historyService = _container.HistoryService;
			_pageService = _container.PageService;

			_wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService);
			_wikiController.SetFakeControllerContext("~/wiki/index/1");
			_urlHelper = _wikiController.Url;
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="destinationPath">The relative path of the folder to store the file.</param>
        /// <param name="files"></param>
        /// <returns></returns>
        public string Upload(string destinationPath, HttpFileCollectionBase files)
        {
            //string destination = Request.Form["destination_folder"];
            string physicalPath = _attachmentPathUtil.ConvertUrlPathToPhysicalPath(destinationPath);

            if (!_attachmentPathUtil.IsAttachmentPathValid(physicalPath))
            {
                throw new SecurityException("Attachment path was invalid when uploading.", null);
            }

            try
            {
                // Get the allowed files types
                string fileName = "";

                // For checking the setting to overwrite existing files
                SiteSettings         siteSettings      = _settingsService.GetSiteSettings();
                IEnumerable <string> allowedExtensions = siteSettings.AllowedFileTypesList
                                                         .Select(x => x.ToLower());

                for (int i = 0; i < files.Count; i++)
                {
                    // Find the file's extension
                    HttpPostedFileBase sourceFile = files[i];
                    string             extension  = Path.GetExtension(sourceFile.FileName).Replace(".", "");

                    if (!string.IsNullOrEmpty(extension))
                    {
                        extension = extension.ToLower();
                    }

                    // Check if it's an allowed extension
                    if (allowedExtensions.Contains(extension))
                    {
                        string fullFilePath = Path.Combine(physicalPath, sourceFile.FileName);

                        // Check if it exists on disk already
                        if (!siteSettings.OverwriteExistingFiles)
                        {
                            if (System.IO.File.Exists(fullFilePath))
                            {
                                // Any files afterwards won't be uploaded...this behaviour could change so that a flag is set, but
                                // all other files are still uploaded sucessfully.
                                string errorMessage = string.Format(SiteStrings.FileManager_Upload_FileAlreadyExists, sourceFile.FileName);
                                throw new FileException(errorMessage, null);
                            }
                        }

                        sourceFile.SaveAs(fullFilePath);
                        fileName = sourceFile.FileName;
                    }
                    else
                    {
                        string allowedExtensionsCsv = string.Join(",", allowedExtensions);
                        string errorMessage         = string.Format(SiteStrings.FileManager_Extension_Not_Supported, allowedExtensionsCsv);
                        throw new FileException(errorMessage, null);
                    }
                }

                return(fileName);
            }
            catch (IOException e)
            {
                throw new FileException(e.Message, e);
            }
        }
Exemplo n.º 4
0
        public void SaveSiteSettings_Should_Persist_All_Values()
        {
            // Arrange
            ApplicationSettings appSettings = new ApplicationSettings();
            SiteSettings siteSettings = new SiteSettings()
            {
                AllowedFileTypes = "jpg, png, gif",
                AllowUserSignup = true,
                IsRecaptchaEnabled = true,
                MarkupType = "markuptype",
                RecaptchaPrivateKey = "privatekey",
                RecaptchaPublicKey = "publickey",
                SiteName = "sitename",
                SiteUrl = "siteurl",
                Theme = "theme",
            };
            SettingsViewModel validConfigSettings = new SettingsViewModel()
            {
                AllowedFileTypes = "jpg, png, gif",
                AllowUserSignup = true,
                IsRecaptchaEnabled = true,
                MarkupType = "markuptype",
                RecaptchaPrivateKey = "privatekey",
                RecaptchaPublicKey = "publickey",
                SiteName = "sitename",
                SiteUrl = "siteurl",
                Theme = "theme",
            };

            RepositoryMock repository = new RepositoryMock();

            DependencyManager iocSetup = new DependencyManager(appSettings, repository, new UserContext(null)); // context isn't used
            iocSetup.Configure();
            SettingsService settingsService = new SettingsService(appSettings, repository);

            // Act
            settingsService.SaveSiteSettings(validConfigSettings);

            // Assert
            SiteSettings actualSettings = settingsService.GetSiteSettings();

            Assert.That(actualSettings.AllowedFileTypes.Contains("jpg"), "AllowedFileTypes jpg");
            Assert.That(actualSettings.AllowedFileTypes.Contains("gif"), "AllowedFileTypes gif");
            Assert.That(actualSettings.AllowedFileTypes.Contains("png"), "AllowedFileTypes png");
            Assert.That(actualSettings.AllowUserSignup, Is.True, "AllowUserSignup");
            Assert.That(actualSettings.IsRecaptchaEnabled, Is.True, "IsRecaptchaEnabled");
            Assert.That(actualSettings.MarkupType, Is.EqualTo("markuptype"), "MarkupType");
            Assert.That(actualSettings.RecaptchaPrivateKey, Is.EqualTo("privatekey"), "RecaptchaPrivateKey");
            Assert.That(actualSettings.RecaptchaPublicKey, Is.EqualTo("publickey"), "RecaptchaPublicKey");
            Assert.That(actualSettings.SiteName, Is.EqualTo("sitename"), "SiteName");
            Assert.That(actualSettings.SiteUrl, Is.EqualTo("siteurl"), "SiteUrl");
            Assert.That(actualSettings.Theme, Is.EqualTo("theme"), "Theme");
        }
Exemplo n.º 5
0
		public void savesitesettings_should_persist_all_values()
		{
			// Arrange
			ApplicationSettings appSettings = new ApplicationSettings();
			SiteSettings siteSettings = new SiteSettings()
			{
				AllowedFileTypes = "jpg, png, gif",
				AllowUserSignup = true,
				IsRecaptchaEnabled = true,
				MarkupType = "markuptype",
				RecaptchaPrivateKey = "privatekey",
				RecaptchaPublicKey = "publickey",
				SiteName = "sitename",
				SiteUrl = "siteurl",
				Theme = "theme",
			};
			SettingsViewModel validConfigSettings = new SettingsViewModel()
			{
				AllowedFileTypes = "jpg, png, gif",
				AllowUserSignup = true,
				IsRecaptchaEnabled = true,
				MarkupType = "markuptype",
				RecaptchaPrivateKey = "privatekey",
				RecaptchaPublicKey = "publickey",
				SiteName = "sitename",
				SiteUrl = "siteurl",
				Theme = "theme",
			};

			SettingsService settingsService = new SettingsService(_repositoryFactory, appSettings);

			// Act
			settingsService.SaveSiteSettings(validConfigSettings);

			// Assert
			SiteSettings actualSettings = settingsService.GetSiteSettings();

			Assert.That(actualSettings.AllowedFileTypes.Contains("jpg"), "AllowedFileTypes jpg");
			Assert.That(actualSettings.AllowedFileTypes.Contains("gif"), "AllowedFileTypes gif");
			Assert.That(actualSettings.AllowedFileTypes.Contains("png"), "AllowedFileTypes png");
			Assert.That(actualSettings.AllowUserSignup, Is.True, "AllowUserSignup");
			Assert.That(actualSettings.IsRecaptchaEnabled, Is.True, "IsRecaptchaEnabled");
			Assert.That(actualSettings.MarkupType, Is.EqualTo("markuptype"), "MarkupType");
			Assert.That(actualSettings.RecaptchaPrivateKey, Is.EqualTo("privatekey"), "RecaptchaPrivateKey");
			Assert.That(actualSettings.RecaptchaPublicKey, Is.EqualTo("publickey"), "RecaptchaPublicKey");
			Assert.That(actualSettings.SiteName, Is.EqualTo("sitename"), "SiteName");
			Assert.That(actualSettings.SiteUrl, Is.EqualTo("siteurl"), "SiteUrl");
			Assert.That(actualSettings.Theme, Is.EqualTo("theme"), "Theme");
		}