Skip to content

Commit

Permalink
Merge pull request #111 from ONLYOFFICE/feature/plugins-cfg-refactoring
Browse files Browse the repository at this point in the history
Feature/plugins cfg refactoring
  • Loading branch information
andreysavihin authored Dec 13, 2023
2 parents 3e51ded + 313417e commit fdc02d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
10 changes: 9 additions & 1 deletion web/ASC.Web.Api/Api/Settings/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ public async Task<SettingsDto> GetSettingsAsync(bool? withpassword)
settings.Plugins.Enabled = pluginsEnabled;
}

settings.Plugins.Allow = _configuration.GetSection("plugins:allow").Get<List<string>>() ?? new List<string>();
if (bool.TryParse(_configuration["plugins:upload"], out var pluginsUpload))
{
settings.Plugins.Upload = pluginsUpload;
}

if (bool.TryParse(_configuration["plugins:delete"], out var pluginsDelete))
{
settings.Plugins.Delete = pluginsDelete;
}

var formGallerySettings = _configurationExtension.GetSetting<OFormSettings>("files:oform");
settings.FormGallery = _mapper.Map<FormGalleryDto>(formGallerySettings);
Expand Down
9 changes: 6 additions & 3 deletions web/ASC.Web.Api/ApiModels/ResponseDto/PluginsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public class PluginsDto
/// <type>System.Boolean, System</type>
public bool Enabled { get; set; }

/// <summary>The allowed actions with the plugins ("upload", "delete", etc.)</summary>
/// <type>System.Collections.Generic.IEnumerable{System.String}, System.Collections.Generic</type>
public IEnumerable<string> Allow { get; set; }
/// <summary>Specifies if the plugins can be uploaded or not</summary>
/// <type>System.Boolean, System</type>
public bool Upload { get; set; }

/// <summary>Specifies if the plugins can be deleted or not</summary>
/// <type>System.Boolean, System</type>
public bool Delete { get; set; }
}
8 changes: 4 additions & 4 deletions web/ASC.Web.Core/WebPluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ public WebPluginManager(
_log = log;
}

private void DemandWebPlugins(string action = null)
private void DemandWebPlugins(bool upload = false, bool delete = false)
{
if (!_webPluginConfigSettings.Enabled)
{
throw new SecurityException("Plugins disabled");
}

if (!string.IsNullOrWhiteSpace(action) && _webPluginConfigSettings.Allow.Any() && !_webPluginConfigSettings.Allow.Contains(action))
if ((upload && !_webPluginConfigSettings.Upload) || (delete && !_webPluginConfigSettings.Delete))
{
throw new SecurityException("Forbidden action");
}
Expand Down Expand Up @@ -160,7 +160,7 @@ private static async Task<string> GetPluginUrlTemplateAsync(IDataStore storage)

public async Task<WebPlugin> AddWebPluginFromFileAsync(int tenantId, IFormFile file, bool system)
{
DemandWebPlugins("upload");
DemandWebPlugins(upload: true);

if (system && !_coreBaseSettings.Standalone)
{
Expand Down Expand Up @@ -461,7 +461,7 @@ private async Task<WebPlugin> UpdateWebPluginAsync(int tenantId, WebPlugin webPl

public async Task<WebPlugin> DeleteWebPluginAsync(int tenantId, string name)
{
DemandWebPlugins("delete");
DemandWebPlugins(delete: true);

var webPlugin = await GetWebPluginByNameAsync(tenantId, name);

Expand Down
9 changes: 2 additions & 7 deletions web/ASC.Web.Core/WebPluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public WebPluginConfigSettings(ConfigurationExtension configuration)

private long _maxSize;
private string _extension;
private string[] _allow;
private string[] _assetExtensions;

public bool Enabled { get; set; }
public bool Upload { get; set; }
public bool Delete { get; set; }

public long MaxSize
{
Expand All @@ -53,12 +54,6 @@ public string Extension
set => _extension = value;
}

public string[] Allow
{
get => _allow ?? Array.Empty<string>();
set => _allow = value;
}

public string[] AssetExtensions
{
get => _assetExtensions ?? Array.Empty<string>();
Expand Down

0 comments on commit fdc02d9

Please sign in to comment.