Merge remote-tracking branch 'oqtane/dev' into dev

This commit is contained in:
Leigh Pointer 2023-07-10 17:41:35 +02:00
commit 9158e24295
7 changed files with 43 additions and 7 deletions

View File

@ -219,7 +219,14 @@
if (folder != null) if (folder != null)
{ {
_haseditpermission = UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, folder.PermissionList); _haseditpermission = UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, folder.PermissionList);
_files = await FileService.GetFilesAsync(FolderId); if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Browse, folder.PermissionList))
{
_files = await FileService.GetFilesAsync(FolderId);
}
else
{
_files = new List<File>();
}
} }
else else
{ {

View File

@ -46,6 +46,11 @@ namespace Oqtane.Services
return await GetJsonAsync<File>($"{Apiurl}/{fileId}"); return await GetJsonAsync<File>($"{Apiurl}/{fileId}");
} }
public async Task<File> GetFileAsync(int folderId, string name)
{
return await GetJsonAsync<File>($"{Apiurl}/name/{name}/{folderId}");
}
public async Task<File> AddFileAsync(File file) public async Task<File> AddFileAsync(File file)
{ {
return await PostJsonAsync<File>(Apiurl, file); return await PostJsonAsync<File>(Apiurl, file);

View File

@ -1,5 +1,6 @@
using Oqtane.Models; using Oqtane.Models;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Oqtane.Services namespace Oqtane.Services
@ -33,6 +34,15 @@ namespace Oqtane.Services
/// <returns></returns> /// <returns></returns>
Task<File> GetFileAsync(int fileId); Task<File> GetFileAsync(int fileId);
/// <summary>
/// Get a <see cref="File"/> based on the <see cref="Folder"/> and file name.
/// </summary>
/// <param name="folderId">Reference to the <see cref="Folder"/></param>
/// <param name="name">name of the file
/// </param>
/// <returns></returns>
Task<File> GetFileAsync(int folderId, string name);
/// <summary> /// <summary>
/// Add / store a <see cref="File"/> record. /// Add / store a <see cref="File"/> record.
/// This does not contain the file contents. /// This does not contain the file contents.

View File

@ -129,6 +129,22 @@ namespace Oqtane.Controllers
} }
} }
[HttpGet("name/{name}/{folderId}")]
public Models.File Get(string name, int folderId)
{
Models.File file = _files.GetFile(folderId, name);
if (file != null && file.Folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.PermissionList))
{
return file;
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Get Attempt {Name} For Folder {FolderId}", name, folderId);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}
}
// PUT api/<controller>/5 // PUT api/<controller>/5
[HttpPut("{id}")] [HttpPut("{id}")]
[Authorize(Roles = RoleNames.Registered)] [Authorize(Roles = RoleNames.Registered)]

View File

@ -43,7 +43,7 @@ namespace Oqtane.Controllers
{ {
foreach (Folder folder in _folders.GetFolders(SiteId)) foreach (Folder folder in _folders.GetFolders(SiteId))
{ {
if (_userPermissions.IsAuthorized(User, PermissionNames.Browse, folder.PermissionList)) if (_userPermissions.IsAuthorized(User, PermissionNames.View, folder.PermissionList))
{ {
folders.Add(folder); folders.Add(folder);
} }
@ -64,7 +64,7 @@ namespace Oqtane.Controllers
public Folder Get(int id) public Folder Get(int id)
{ {
Folder folder = _folders.GetFolder(id); Folder folder = _folders.GetFolder(id);
if (folder != null && folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.Browse, folder.PermissionList)) if (folder != null && folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, folder.PermissionList))
{ {
return folder; return folder;
} }
@ -85,7 +85,7 @@ namespace Oqtane.Controllers
folderPath += "/"; folderPath += "/";
} }
Folder folder = _folders.GetFolder(siteId, folderPath); Folder folder = _folders.GetFolder(siteId, folderPath);
if (folder != null && folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.Browse, folder.PermissionList)) if (folder != null && folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.View, folder.PermissionList))
{ {
return folder; return folder;
} }

View File

@ -19,7 +19,7 @@ namespace Oqtane.Migrations.Tenant
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
var notificationEntityBuilder = new NotificationEntityBuilder(migrationBuilder, ActiveDatabase); var notificationEntityBuilder = new NotificationEntityBuilder(migrationBuilder, ActiveDatabase);
notificationEntityBuilder.AddBooleanColumn("IsRead", false); notificationEntityBuilder.AddBooleanColumn("IsRead", true);
notificationEntityBuilder.UpdateColumn("IsRead", "1", "bool", ""); notificationEntityBuilder.UpdateColumn("IsRead", "1", "bool", "");
} }

View File

@ -16,9 +16,7 @@ Global
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AB6FCC9-EFEB-4C0E-A2CF-8103914C5196}.Release|Any CPU.Build.0 = Release|Any CPU
{AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA8E58A1-CD09-4208-BF66-A8BB341FD669}.Release|Any CPU.ActiveCfg = Release|Any CPU