2021-12-06 13:29:15 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace zero.Backoffice.Services;
|
|
|
|
|
|
|
|
|
|
public class SectionService : ISectionService
|
|
|
|
|
{
|
2021-12-23 09:07:34 +01:00
|
|
|
protected IZeroOptions Options { get; set; }
|
2021-12-06 13:29:15 +01:00
|
|
|
|
|
|
|
|
protected IBackofficeAssetFileSystem FileSystem { get; set; }
|
|
|
|
|
|
|
|
|
|
protected ILogger<ISectionService> Logger { get; set; }
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<IBackofficeSection> Sections { get; set; }
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<ISettingsGroup> SettingsGroups { get; set; }
|
|
|
|
|
|
|
|
|
|
|
2021-12-23 09:07:34 +01:00
|
|
|
public SectionService(IZeroOptions options, IBackofficeAssetFileSystem fileSystem, ILogger<ISectionService> logger, IEnumerable<IBackofficeSection> sections, IEnumerable<ISettingsGroup> settingsGroups)
|
2021-12-06 13:29:15 +01:00
|
|
|
{
|
|
|
|
|
Options = options;
|
|
|
|
|
FileSystem = fileSystem;
|
|
|
|
|
Logger = logger;
|
|
|
|
|
Sections = sections;
|
|
|
|
|
SettingsGroups = settingsGroups;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task<IEnumerable<BackofficeSectionPresentation>> GetSections()
|
|
|
|
|
{
|
|
|
|
|
//bool isSuperUser = AuthenticationApi.IsSuper();
|
|
|
|
|
//IList<Permission> permissions = AuthenticationApi.GetPermissions(Permissions.Sections.PREFIX);
|
|
|
|
|
|
|
|
|
|
List<BackofficeSectionPresentation> sections = new();
|
|
|
|
|
|
2021-12-29 01:25:35 +01:00
|
|
|
foreach (IBackofficeSection section in Sections.OrderBy(x => x.Sort))
|
2021-12-06 13:29:15 +01:00
|
|
|
{
|
|
|
|
|
//if (!isSuperUser && !Permission.CanReadKey(permissions, section.Alias, true))
|
|
|
|
|
//{
|
|
|
|
|
// continue;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
string url = Safenames.Alias(section.Alias).EnsureStartsWith('/');
|
|
|
|
|
|
|
|
|
|
if (section.Alias == Constants.Sections.Dashboard)
|
|
|
|
|
{
|
|
|
|
|
url = "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BackofficeSectionPresentation backofficeSection = new()
|
|
|
|
|
{
|
|
|
|
|
Alias = section.Alias,
|
|
|
|
|
Name = section.Name,
|
|
|
|
|
Icon = section.Icon,
|
|
|
|
|
Color = section.Color,
|
|
|
|
|
Url = url,
|
|
|
|
|
IsExternal = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
List<BackofficeSectionPresentation> children = new();
|
|
|
|
|
|
|
|
|
|
foreach (IBackofficeSection child in section.Children)
|
|
|
|
|
{
|
|
|
|
|
children.Add(new()
|
|
|
|
|
{
|
|
|
|
|
Alias = child.Alias,
|
|
|
|
|
Name = child.Name,
|
|
|
|
|
Url = backofficeSection.Url.EnsureEndsWith('/') + Safenames.Alias(child.Alias),
|
|
|
|
|
IsExternal = false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backofficeSection.Children = children;
|
|
|
|
|
|
|
|
|
|
sections.Add(backofficeSection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<IEnumerable<BackofficeSectionPresentation>>(sections);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task<IEnumerable<BackofficeSettingGroupPresentation>> GetSettingsAreas()
|
|
|
|
|
{
|
|
|
|
|
//bool isSuperUser = AuthenticationApi.IsSuper();
|
|
|
|
|
//IList<Permission> permissions = AuthenticationApi.GetPermissions(Permissions.Settings.PREFIX);
|
|
|
|
|
|
|
|
|
|
List<BackofficeSettingGroupPresentation> groups = new();
|
|
|
|
|
|
2021-12-23 09:07:34 +01:00
|
|
|
bool hasIntegrations = Options.For<FlavorOptions>().GetAll<Integration>().Any();
|
2021-12-06 13:29:15 +01:00
|
|
|
|
|
|
|
|
foreach (SettingsGroup group in SettingsGroups)
|
|
|
|
|
{
|
|
|
|
|
List<BackofficeSettingPresentation> areas = new();
|
|
|
|
|
|
|
|
|
|
foreach (SettingsArea area in group.Areas)
|
|
|
|
|
{
|
|
|
|
|
//if (!isSuperUser && !Permission.CanReadKey(permissions, area.Alias, true))
|
|
|
|
|
//{
|
|
|
|
|
// continue;
|
|
|
|
|
//}
|
2021-12-23 09:07:34 +01:00
|
|
|
|
|
|
|
|
if (area.Alias == Constants.Settings.Integrations && !hasIntegrations)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-12-06 13:29:15 +01:00
|
|
|
|
|
|
|
|
//bool isPlugin = !(area is InternalSettingsArea);
|
|
|
|
|
|
|
|
|
|
BackofficeSettingPresentation settingsArea = new()
|
|
|
|
|
{
|
|
|
|
|
Alias = area.Alias,
|
|
|
|
|
Name = area.Name,
|
|
|
|
|
Description = area.Description,
|
|
|
|
|
Icon = area.Icon,
|
2021-12-29 01:25:35 +01:00
|
|
|
Url = Constants.Sections.Settings.EnsureStartsWith('/') + area.CustomUrl.Or(Safenames.Alias(area.Alias)).EnsureStartsWith('/'),
|
2021-12-06 13:29:15 +01:00
|
|
|
IsPlugin = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
areas.Add(settingsArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (areas.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
groups.Add(new()
|
|
|
|
|
{
|
|
|
|
|
Name = group.Name,
|
|
|
|
|
Items = areas
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<IEnumerable<BackofficeSettingGroupPresentation>>(groups);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface ISectionService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get all registered backoffice sections
|
|
|
|
|
/// </summary>
|
|
|
|
|
Task<IEnumerable<BackofficeSectionPresentation>> GetSections();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get all registered backoffice settings
|
|
|
|
|
/// </summary>
|
|
|
|
|
Task<IEnumerable<BackofficeSettingGroupPresentation>> GetSettingsAreas();
|
|
|
|
|
}
|