using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace zero.Backoffice.Services; public class SectionService : ISectionService { protected IZeroOptions Options { get; set; } protected IBackofficeAssetFileSystem FileSystem { get; set; } protected ILogger Logger { get; set; } protected IEnumerable Sections { get; set; } protected IEnumerable SettingsGroups { get; set; } public SectionService(IZeroOptions options, IBackofficeAssetFileSystem fileSystem, ILogger logger, IEnumerable sections, IEnumerable settingsGroups) { Options = options; FileSystem = fileSystem; Logger = logger; Sections = sections; SettingsGroups = settingsGroups; } /// public Task> GetSections() { //bool isSuperUser = AuthenticationApi.IsSuper(); //IList permissions = AuthenticationApi.GetPermissions(Permissions.Sections.PREFIX); List sections = new(); foreach (IBackofficeSection section in Sections.OrderBy(x => x.Sort)) { //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 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>(sections); } /// public Task> GetSettingsAreas() { //bool isSuperUser = AuthenticationApi.IsSuper(); //IList permissions = AuthenticationApi.GetPermissions(Permissions.Settings.PREFIX); List groups = new(); bool hasIntegrations = Options.For().GetAll().Any(); foreach (SettingsGroup group in SettingsGroups) { List areas = new(); foreach (SettingsArea area in group.Areas) { //if (!isSuperUser && !Permission.CanReadKey(permissions, area.Alias, true)) //{ // continue; //} if (area.Alias == Constants.Settings.Integrations && !hasIntegrations) { continue; } //bool isPlugin = !(area is InternalSettingsArea); BackofficeSettingPresentation settingsArea = new() { Alias = area.Alias, Name = area.Name, Description = area.Description, Icon = area.Icon, Url = Constants.Sections.Settings.EnsureStartsWith('/') + area.CustomUrl.Or(Safenames.Alias(area.Alias)).EnsureStartsWith('/'), IsPlugin = true }; areas.Add(settingsArea); } if (areas.Count > 0) { groups.Add(new() { Name = group.Name, Items = areas }); } } return Task.FromResult>(groups); } } public interface ISectionService { /// /// Get all registered backoffice sections /// Task> GetSections(); /// /// Get all registered backoffice settings /// Task> GetSettingsAreas(); }