add support for public content folders

This commit is contained in:
Shaun Walker
2021-05-26 12:01:35 -04:00
parent 1d171d2e56
commit c07e766e57
23 changed files with 281 additions and 123 deletions

View File

@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Oqtane.Extensions;
using Oqtane.Infrastructure;
using Oqtane.Models;
using Oqtane.Shared;
using File = Oqtane.Models.File;
@ -14,21 +15,25 @@ namespace Oqtane.Repository
private TenantDBContext _db;
private readonly IPermissionRepository _permissions;
private readonly IFolderRepository _folderRepository;
private readonly ITenantManager _tenants;
public FileRepository(TenantDBContext context, IPermissionRepository permissions, IFolderRepository folderRepository)
public FileRepository(TenantDBContext context, IPermissionRepository permissions, IFolderRepository folderRepository, ITenantManager tenants)
{
_db = context;
_permissions = permissions;
_folderRepository = folderRepository;
_tenants = tenants;
}
public IEnumerable<File> GetFiles(int folderId)
{
IEnumerable<Permission> permissions = _permissions.GetPermissions(EntityNames.Folder, folderId).ToList();
IEnumerable<File> files = _db.File.Where(item => item.FolderId == folderId).Include(item => item.Folder);
var alias = _tenants.GetAlias();
foreach (File file in files)
{
file.Folder.Permissions = permissions.EncodePermissions();
file.Url = GetFileUrl(file, alias);
}
return files;
}
@ -49,7 +54,9 @@ namespace Oqtane.Repository
public File GetFile(int fileId)
{
return GetFile(fileId, true);
File file = GetFile(fileId, true);
file.Url = GetFileUrl(file, _tenants.GetAlias());
return file;
}
public File GetFile(int fileId, bool tracking)
@ -68,6 +75,7 @@ namespace Oqtane.Repository
{
IEnumerable<Permission> permissions = _permissions.GetPermissions(EntityNames.Folder, file.FolderId).ToList();
file.Folder.Permissions = permissions.EncodePermissions();
file.Url = GetFileUrl(file, _tenants.GetAlias());
}
return file;
}
@ -92,5 +100,20 @@ namespace Oqtane.Repository
var filepath = Path.Combine(_folderRepository.GetFolderPath(folder), file.Name);
return filepath;
}
private string GetFileUrl(File file, Alias alias)
{
string url = "";
switch (file.Folder.Type)
{
case FolderTypes.Private:
url = Utilities.ContentUrl(alias, file.FileId);
break;
case FolderTypes.Public:
url = "/" + Utilities.UrlCombine("Content", "Tenants", alias.TenantId.ToString(), "Sites", file.Folder.SiteId.ToString(), file.Folder.Path) + file.Name;
break;
}
return url;
}
}
}

View File

@ -3,6 +3,7 @@ using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Oqtane.Extensions;
using Oqtane.Infrastructure;
using Oqtane.Models;
using Oqtane.Shared;
@ -13,9 +14,9 @@ namespace Oqtane.Repository
private TenantDBContext _db;
private readonly IPermissionRepository _permissions;
private readonly IWebHostEnvironment _environment;
private readonly ITenantResolver _tenants;
private readonly ITenantManager _tenants;
public FolderRepository(TenantDBContext context, IPermissionRepository permissions,IWebHostEnvironment environment, ITenantResolver tenants)
public FolderRepository(TenantDBContext context, IPermissionRepository permissions,IWebHostEnvironment environment, ITenantManager tenants)
{
_db = context;
_permissions = permissions;
@ -99,7 +100,17 @@ namespace Oqtane.Repository
public string GetFolderPath(Folder folder)
{
return Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
string path = "";
switch (folder.Type)
{
case FolderTypes.Private:
path = Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
break;
case FolderTypes.Public:
path = Utilities.PathCombine(_environment.WebRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
break;
}
return path;
}
}

View File

@ -648,25 +648,25 @@ namespace Oqtane.Repository
_roleRepository.AddRole(new Role {SiteId = site.SiteId, Name = RoleNames.Admin, Description = "Site Administrators", IsAutoAssigned = false, IsSystem = true});
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "FirstName", Title = "First Name", Description = "Your First Or Given Name", Category = "Name", ViewOrder = 1, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "FirstName", Title = "First Name", Description = "Your First Or Given Name", Category = "Name", ViewOrder = 1, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = ""});
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "LastName", Title = "Last Name", Description = "Your Last Or Family Name", Category = "Name", ViewOrder = 2, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "LastName", Title = "Last Name", Description = "Your Last Or Family Name", Category = "Name", ViewOrder = 2, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "Street", Title = "Street", Description = "Street Or Building Address", Category = "Address", ViewOrder = 3, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "Street", Title = "Street", Description = "Street Or Building Address", Category = "Address", ViewOrder = 3, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(
new Profile {SiteId = site.SiteId, Name = "City", Title = "City", Description = "City", Category = "Address", ViewOrder = 4, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
new Profile {SiteId = site.SiteId, Name = "City", Title = "City", Description = "City", Category = "Address", ViewOrder = 4, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "Region", Title = "Region", Description = "State Or Province", Category = "Address", ViewOrder = 5, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "Region", Title = "Region", Description = "State Or Province", Category = "Address", ViewOrder = 5, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "Country", Title = "Country", Description = "Country", Category = "Address", ViewOrder = 6, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "Country", Title = "Country", Description = "Country", Category = "Address", ViewOrder = 6, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "PostalCode", Title = "Postal Code", Description = "Postal Code Or Zip Code", Category = "Address", ViewOrder = 7, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "PostalCode", Title = "Postal Code", Description = "Postal Code Or Zip Code", Category = "Address", ViewOrder = 7, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
_profileRepository.AddProfile(new Profile
{SiteId = site.SiteId, Name = "Phone", Title = "Phone Number", Description = "Phone Number", Category = "Contact", ViewOrder = 8, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false});
{SiteId = site.SiteId, Name = "Phone", Title = "Phone Number", Description = "Phone Number", Category = "Contact", ViewOrder = 8, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false, Options = "" });
Folder folder = _folderRepository.AddFolder(new Folder
{
SiteId = site.SiteId, ParentId = null, Name = "Root", Path = "", Order = 1, IsSystem = true,
SiteId = site.SiteId, ParentId = null, Name = "Root", Type = FolderTypes.Private, Path = "", Order = 1, IsSystem = true,
Permissions = new List<Permission>
{
new Permission(PermissionNames.Browse, RoleNames.Admin, true),
@ -676,7 +676,7 @@ namespace Oqtane.Repository
});
_folderRepository.AddFolder(new Folder
{
SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = Utilities.PathCombine("Users",Path.DirectorySeparatorChar.ToString()), Order = 1, IsSystem = true,
SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Type = FolderTypes.Private, Path = Utilities.PathCombine("Users",Path.DirectorySeparatorChar.ToString()), Order = 1, IsSystem = true,
Permissions = new List<Permission>
{
new Permission(PermissionNames.Browse, RoleNames.Admin, true),