Compare commits
No commits in common. "2ca9dead1fd258410dc2fc5c97a2dd56ac6d9c0d" and "03959f9b3882267620e51bf577acbde16e5ff5f6" have entirely different histories.
2ca9dead1f
...
03959f9b38
@ -1,25 +0,0 @@
|
|||||||
using Marco.Pms.Model.ViewModels.Activities;
|
|
||||||
|
|
||||||
namespace Marco.Pms.Model.ViewModels.DocumentManager
|
|
||||||
{
|
|
||||||
public class DocumentAttachmentDetailsVM
|
|
||||||
{
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public string? DocumentId { get; set; }
|
|
||||||
public string? Description { get; set; }
|
|
||||||
public int Version { get; set; }
|
|
||||||
public bool IsCurrentVersion { get; set; }
|
|
||||||
public Guid ParentAttachmentId { get; set; }
|
|
||||||
public DateTime UploadedAt { get; set; }
|
|
||||||
public BasicEmployeeVM? UploadedBy { get; set; }
|
|
||||||
public DateTime? UpdatedAt { get; set; }
|
|
||||||
public BasicEmployeeVM? UpdatedBy { get; set; }
|
|
||||||
public DateTime? VerifiedAt { get; set; }
|
|
||||||
public bool? IsVerified { get; set; }
|
|
||||||
public BasicEmployeeVM? VerifiedBy { get; set; }
|
|
||||||
public Guid EntityId { get; set; }
|
|
||||||
public DocumentTypeVM? DocumentType { get; set; }
|
|
||||||
public bool IsActive { get; set; } = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -221,66 +221,20 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("get/details/{id}")]
|
// GET api/<DocumentController>/5
|
||||||
public async Task<IActionResult> GetDetailsAsync(Guid id)
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetDetails(int id)
|
||||||
{
|
{
|
||||||
_logger.LogInfo("Starting GetDetails API for AttachmentId: {AttachmentId}", id);
|
|
||||||
|
|
||||||
// Create a new DbContext instance to fetch data
|
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
// Create a new scoped service provider to resolve scoped dependencies
|
|
||||||
using var scope = _serviceScope.CreateScope();
|
using var scope = _serviceScope.CreateScope();
|
||||||
|
|
||||||
// Resolve the permission service from the scoped service provider
|
|
||||||
var _permission = scope.ServiceProvider.GetRequiredService<PermissionServices>();
|
|
||||||
|
|
||||||
// Get the currently logged-in employee
|
|
||||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
//if (versionMapping.ChildAttachment != null && versionMapping.ChildAttachment.Document != null)
|
||||||
_logger.LogDebug("Logged in employee id: {EmployeeId}", loggedInEmployee.Id);
|
//{
|
||||||
|
// var s3Service = scope.ServiceProvider.GetRequiredService<S3UploadService>();
|
||||||
// Fetch the AttachmentVersionMapping with all necessary related data loaded eagerly
|
// documentVM.PreSignedUrl = s3Service.GeneratePreSignedUrl(versionMapping.ChildAttachment.Document.S3Key);
|
||||||
var versionMapping = await _context.AttachmentVersionMappings
|
//}
|
||||||
.Include(av => av.ChildAttachment)
|
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Filters for documents fetched successfully", 200));
|
||||||
.ThenInclude(da => da!.UploadedBy)
|
|
||||||
.ThenInclude(e => e!.JobRole)
|
|
||||||
.Include(av => av.ChildAttachment)
|
|
||||||
.ThenInclude(da => da!.UpdatedBy)
|
|
||||||
.ThenInclude(e => e!.JobRole)
|
|
||||||
.Include(av => av.ChildAttachment)
|
|
||||||
.ThenInclude(da => da!.VerifiedBy)
|
|
||||||
.ThenInclude(e => e!.JobRole)
|
|
||||||
.Include(av => av.ChildAttachment)
|
|
||||||
.ThenInclude(da => da!.DocumentType)
|
|
||||||
.FirstOrDefaultAsync(av => av.ChildAttachmentId == id && av.TenantId == tenantId);
|
|
||||||
|
|
||||||
// If no mapping found, return 404
|
|
||||||
if (versionMapping == null || versionMapping.ChildAttachment == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("AttachmentVersionMapping not found for AttachmentId: {AttachmentId}, TenantId: {TenantId}",
|
|
||||||
id, tenantId);
|
|
||||||
return NotFound(ApiResponse<object>.ErrorResponse("Document Attachment not found", "Document Attachment not found in database", 404));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the logged in employee has permission to view the document OR is the owner of the attachment entity
|
|
||||||
var hasViewPermission = await _permission.HasPermission(PermissionsMaster.ViewDocument, loggedInEmployee.Id);
|
|
||||||
if (!hasViewPermission && loggedInEmployee.Id != versionMapping.ChildAttachment.EntityId)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Access Denied for Employee {EmployeeId} on EntityId {EntityId}",
|
|
||||||
loggedInEmployee.Id, versionMapping.ChildAttachment.EntityId);
|
|
||||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to view documents", 403));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map the domain entity to the view model
|
|
||||||
var documentAttachmentVM = _mapper.Map<DocumentAttachmentDetailsVM>(versionMapping.ChildAttachment);
|
|
||||||
documentAttachmentVM.Version = versionMapping.Version;
|
|
||||||
documentAttachmentVM.ParentAttachmentId = versionMapping.ParentAttachmentId;
|
|
||||||
|
|
||||||
_logger.LogInfo("Document details fetched successfully for AttachmentId: {AttachmentId}", id);
|
|
||||||
|
|
||||||
// Return success response with document details
|
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(documentAttachmentVM, "Document details fetched successfully", 200));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("get/filter/{entityTypeId}")]
|
[HttpGet("get/filter/{entityTypeId}")]
|
||||||
@ -379,9 +333,6 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
|
|
||||||
// Create a new DbContext instance asynchronously
|
// Create a new DbContext instance asynchronously
|
||||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||||
using var scope = _serviceScope.CreateScope();
|
|
||||||
|
|
||||||
var _permission = scope.ServiceProvider.GetRequiredService<PermissionServices>();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -402,16 +353,6 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
.Where(av => av.ParentAttachmentId == parentAttachmentId && av.TenantId == tenantId)
|
.Where(av => av.ParentAttachmentId == parentAttachmentId && av.TenantId == tenantId)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var entityId = versionMappings.Select(av => av.ChildAttachment?.EntityId).FirstOrDefault();
|
|
||||||
|
|
||||||
// Check global permission
|
|
||||||
var hasViewPermission = await _permission.HasPermission(PermissionsMaster.ViewDocument, loggedInEmployee.Id);
|
|
||||||
if (!hasViewPermission && loggedInEmployee.Id != entityId)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Access Denied for Employee {EmployeeId} on EntityId {EntityId}", loggedInEmployee.Id, entityId ?? Guid.Empty);
|
|
||||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to view documents", 403));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInfo("Found {Count} versions for ParentAttachmentId: {ParentAttachmentId}", versionMappings.Count, parentAttachmentId);
|
_logger.LogInfo("Found {Count} versions for ParentAttachmentId: {ParentAttachmentId}", versionMappings.Count, parentAttachmentId);
|
||||||
|
|
||||||
// Map the retrieved child attachments to view models with version info
|
// Map the retrieved child attachments to view models with version info
|
||||||
@ -474,6 +415,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
// Return the pre-signed URL with a success response
|
// Return the pre-signed URL with a success response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uploads a document attachment for an Employee or Project.
|
/// Uploads a document attachment for an Employee or Project.
|
||||||
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
||||||
|
|||||||
@ -311,11 +311,13 @@ namespace Marco.Pms.Services.MappingProfiles
|
|||||||
CreateMap<DocumentAttachmentDto, DocumentAttachment>();
|
CreateMap<DocumentAttachmentDto, DocumentAttachment>();
|
||||||
CreateMap<DocumentAttachment, DocumentListVM>();
|
CreateMap<DocumentAttachment, DocumentListVM>();
|
||||||
CreateMap<DocumentAttachment, AttachmentVersionVM>();
|
CreateMap<DocumentAttachment, AttachmentVersionVM>();
|
||||||
CreateMap<DocumentAttachment, DocumentAttachmentDetailsVM>();
|
CreateMap<DocumentAttachmentDto, DocumentAttachment>();
|
||||||
|
|
||||||
CreateMap<DocumentCategoryMaster, DocumentCategoryVM>();
|
CreateMap<DocumentCategoryMaster, DocumentCategoryVM>();
|
||||||
|
CreateMap<DocumentAttachmentDto, DocumentAttachment>();
|
||||||
|
|
||||||
CreateMap<DocumentTypeMaster, DocumentTypeVM>();
|
CreateMap<DocumentTypeMaster, DocumentTypeVM>();
|
||||||
|
CreateMap<DocumentAttachmentDto, DocumentAttachment>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user