#399 basic pdf library controller
This commit is contained in:
parent
134fccd22a
commit
c4f7fa1d95
@ -1,12 +1,18 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.PDFLibrary;
|
||||
using RMuseum.Models.PDFLibrary.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using RSecurityBackend.Services;
|
||||
|
||||
namespace RMuseum.Controllers
|
||||
{
|
||||
@ -31,6 +37,129 @@ namespace RMuseum.Controllers
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// secure get a pdf book
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("secure/{id}")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PDFBook))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetUserVisible(int id)
|
||||
{
|
||||
RServiceResult<PublishStatus[]> v = await _GetUserVisibleArtifactStatusSet
|
||||
(
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value),
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value)
|
||||
);
|
||||
if (!string.IsNullOrEmpty(v.ExceptionString))
|
||||
return BadRequest(v.ExceptionString);
|
||||
PublishStatus[] visibleItems = v.Result;
|
||||
RServiceResult<PDFBook> bookRes = null;
|
||||
if (visibleItems.Length == 1 && visibleItems[0] == PublishStatus.Published)
|
||||
{
|
||||
bookRes = await _pdfService.GetPDFBookByIdAsync(id, new PublishStatus[] { PublishStatus.Published });
|
||||
if (!string.IsNullOrEmpty(bookRes.ExceptionString))
|
||||
{
|
||||
return BadRequest(bookRes.ExceptionString);
|
||||
}
|
||||
if (bookRes.Result == null)
|
||||
return NotFound();
|
||||
}
|
||||
if (bookRes == null)
|
||||
{
|
||||
bookRes = await _pdfService.GetPDFBookByIdAsync(id, visibleItems);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(bookRes.ExceptionString))
|
||||
{
|
||||
return BadRequest(bookRes.ExceptionString);
|
||||
}
|
||||
if (bookRes.Result == null)
|
||||
return NotFound();
|
||||
|
||||
Response.GetTypedHeaders().LastModified = bookRes.Result.LastModified;
|
||||
|
||||
var requestHeaders = Request.GetTypedHeaders();
|
||||
if (requestHeaders.IfModifiedSince.HasValue &&
|
||||
requestHeaders.IfModifiedSince.Value >= bookRes.Result.LastModified)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status304NotModified);
|
||||
}
|
||||
|
||||
|
||||
return Ok(bookRes.Result);
|
||||
}
|
||||
|
||||
private async Task<RServiceResult<PublishStatus[]>> _GetUserVisibleArtifactStatusSet(Guid loggedOnUserId, Guid sessionId)
|
||||
{
|
||||
RServiceResult<bool>
|
||||
canView =
|
||||
await _userPermissionChecker.Check
|
||||
(
|
||||
loggedOnUserId,
|
||||
sessionId,
|
||||
RMuseumSecurableItem.PDFLibraryEntityShortName,
|
||||
RMuseumSecurableItem.ViewDraftOperationShortName
|
||||
);
|
||||
if (!string.IsNullOrEmpty(canView.ExceptionString))
|
||||
return new RServiceResult<PublishStatus[]>(null, canView.ExceptionString);
|
||||
|
||||
PublishStatus[] visibleItems =
|
||||
canView.Result
|
||||
?
|
||||
new PublishStatus[]
|
||||
{
|
||||
PublishStatus.Published,
|
||||
PublishStatus.Restricted,
|
||||
PublishStatus.Draft,
|
||||
PublishStatus.Awaiting
|
||||
}
|
||||
:
|
||||
new PublishStatus[]
|
||||
{
|
||||
PublishStatus.Published
|
||||
};
|
||||
|
||||
return new RServiceResult<PublishStatus[]>(visibleItems);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get published PDF Book by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(PDFBook))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetPDFBookByIdAsync(int id)
|
||||
{
|
||||
var bookRes = await _pdfService.GetPDFBookByIdAsync(id, new PublishStatus[] { PublishStatus.Published });
|
||||
|
||||
if (!string.IsNullOrEmpty(bookRes.ExceptionString))
|
||||
{
|
||||
return BadRequest(bookRes.ExceptionString);
|
||||
}
|
||||
if (bookRes.Result == null)
|
||||
return NotFound();
|
||||
|
||||
Response.GetTypedHeaders().LastModified = bookRes.Result.LastModified;
|
||||
|
||||
var requestHeaders = Request.GetTypedHeaders();
|
||||
if (requestHeaders.IfModifiedSince.HasValue &&
|
||||
requestHeaders.IfModifiedSince.Value >= bookRes.Result.LastModified)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status304NotModified);
|
||||
}
|
||||
|
||||
|
||||
return Ok(bookRes.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add a new book
|
||||
/// </summary>
|
||||
@ -89,13 +218,20 @@ namespace RMuseum.Controllers
|
||||
/// </summary>
|
||||
protected readonly IPDFLibraryService _pdfService;
|
||||
|
||||
/// <summary>
|
||||
/// IUserPermissionChecker instance
|
||||
/// </summary>
|
||||
protected IUserPermissionChecker _userPermissionChecker;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="pdfService"></param>
|
||||
public PDFLibraryController(IPDFLibraryService pdfService)
|
||||
/// <param name="userPermissionChecker"></param>
|
||||
public PDFLibraryController(IPDFLibraryService pdfService, IUserPermissionChecker userPermissionChecker)
|
||||
{
|
||||
_pdfService = pdfService;
|
||||
_userPermissionChecker = userPermissionChecker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +206,7 @@ namespace RMuseum.Models.Auth.Memory
|
||||
Operations = new SecurableItemOperation[]
|
||||
{
|
||||
new SecurableItemOperation(ModifyOperationShortName, "ویرایش محتوا", false),
|
||||
new SecurableItemOperation(ViewDraftOperationShortName, "مشاهدهٔ پیشنویسها", false),
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -2343,16 +2343,64 @@
|
||||
<param name="numberingService"></param>
|
||||
<param name="configuration"></param>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.StartImportingLocalPDF(RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel)">
|
||||
<summary>
|
||||
start importing a local pdf file
|
||||
</summary>
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetUserVisible(System.Int32)">
|
||||
<summary>
|
||||
secure get a pdf book
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetPDFBookByIdAsync(System.Int32)">
|
||||
<summary>
|
||||
get published PDF Book by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.AddBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
add a new book
|
||||
</summary>
|
||||
<param name="book"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.AddAuthorAsync(RMuseum.Models.PDFLibrary.Author)">
|
||||
<summary>
|
||||
add a new author
|
||||
</summary>
|
||||
<param name="author"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.AddMultiVolumePDFCollection(RMuseum.Models.PDFLibrary.MultiVolumePDFCollection)">
|
||||
<summary>
|
||||
add a new mukti volume pdf collection
|
||||
</summary>
|
||||
<param name="volumes"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:RMuseum.Controllers.PDFLibraryController._pdfService">
|
||||
<summary>
|
||||
PDF Service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.#ctor(RMuseum.Services.IPDFLibraryService)">
|
||||
<member name="F:RMuseum.Controllers.PDFLibraryController._userPermissionChecker">
|
||||
<summary>
|
||||
IUserPermissionChecker instance
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.#ctor(RMuseum.Services.IPDFLibraryService,RSecurityBackend.Services.IUserPermissionChecker)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="pdfService"></param>
|
||||
<param name="userPermissionChecker"></param>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.RecitationController.GetPublished(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user