add support for public content folders
This commit is contained in:
@ -173,6 +173,7 @@ namespace Oqtane.Controllers
|
||||
SiteId = folder.SiteId,
|
||||
ParentId = folder.FolderId,
|
||||
Name = "My Folder",
|
||||
Type = FolderTypes.Private,
|
||||
Path = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(),Path.DirectorySeparatorChar.ToString()),
|
||||
Order = 1,
|
||||
IsSystem = true,
|
||||
|
@ -593,6 +593,7 @@ namespace Oqtane.Infrastructure
|
||||
SiteId = folder.SiteId,
|
||||
ParentId = folder.FolderId,
|
||||
Name = "My Folder",
|
||||
Type = FolderTypes.Private,
|
||||
Path = Utilities.PathCombine(folder.Path, user.UserId.ToString(), Path.DirectorySeparatorChar.ToString()),
|
||||
Order = 1,
|
||||
IsSystem = true,
|
||||
|
@ -231,7 +231,6 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
public void DeleteFromTable(string condition = "")
|
||||
{
|
||||
var deleteSql = $"DELETE FROM {RewriteName(EntityTableName)} ";
|
||||
|
||||
if(!string.IsNullOrEmpty(condition))
|
||||
{
|
||||
deleteSql += $"WHERE {condition}";
|
||||
@ -241,11 +240,8 @@ namespace Oqtane.Migrations.EntityBuilders
|
||||
|
||||
public void UpdateColumn(string columnName, string value, string condition = "")
|
||||
{
|
||||
var updateValue = value;
|
||||
|
||||
var updateSql = $"UPDATE {RewriteName(EntityTableName)} SET {RewriteName(columnName)} = {value} ";
|
||||
|
||||
if(!string.IsNullOrEmpty(condition))
|
||||
if (!string.IsNullOrEmpty(condition))
|
||||
{
|
||||
updateSql += $"WHERE {condition}";
|
||||
}
|
||||
|
34
Oqtane.Server/Migrations/Tenant/02010003_AddFolderType.cs
Normal file
34
Oqtane.Server/Migrations/Tenant/02010003_AddFolderType.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Migrations.Tenant
|
||||
{
|
||||
[DbContext(typeof(TenantDBContext))]
|
||||
[Migration("Tenant.02.01.00.03")]
|
||||
public class AddFolderType : MultiDatabaseMigration
|
||||
{
|
||||
public AddFolderType(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
|
||||
//Add Type column and initialize
|
||||
folderEntityBuilder.AddStringColumn("Type", 50, true, true);
|
||||
folderEntityBuilder.UpdateColumn("Type", "'" + FolderTypes.Private + "'");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
|
||||
folderEntityBuilder.DropColumn("Type");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -35,7 +35,7 @@ Oqtane.RichTextEditor = {
|
||||
enableQuillEditor: function (editorElement, mode) {
|
||||
editorElement.__quill.enable(mode);
|
||||
},
|
||||
insertQuillImage: function (quillElement, imageURL) {
|
||||
insertQuillImage: function (quillElement, imageURL, altText) {
|
||||
var Delta = Quill.import('delta');
|
||||
editorIndex = 0;
|
||||
|
||||
@ -47,6 +47,6 @@ Oqtane.RichTextEditor = {
|
||||
new Delta()
|
||||
.retain(editorIndex)
|
||||
.insert({ image: imageURL },
|
||||
{ alt: imageURL }));
|
||||
{ alt: altText }));
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user