This commit is contained in:
@@ -242,6 +242,7 @@ namespace AyaNova.Api.Controllers
|
||||
string AttachToObjectId = string.Empty;
|
||||
string errorMessage = string.Empty;
|
||||
string Notes = string.Empty;
|
||||
long? OverrideUserId = null;
|
||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||
|
||||
var uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||
@@ -262,6 +263,10 @@ namespace AyaNova.Api.Controllers
|
||||
if (!badRequest)
|
||||
{
|
||||
AttachToAType = uploadFormData.FormFieldData["AttachToAType"].ToString();
|
||||
//for v8 migrate purposes
|
||||
if (uploadFormData.FormFieldData.ContainsKey("OverrideUserId"))
|
||||
OverrideUserId = long.Parse(uploadFormData.FormFieldData["AttachToAType"].ToString());
|
||||
|
||||
AttachToObjectId = uploadFormData.FormFieldData["AttachToObjectId"].ToString();
|
||||
if (uploadFormData.FormFieldData.ContainsKey("Notes"))
|
||||
Notes = uploadFormData.FormFieldData["Notes"].ToString();
|
||||
@@ -365,7 +370,7 @@ namespace AyaNova.Api.Controllers
|
||||
if (theDate == DateTime.MinValue)
|
||||
theDate = DateTime.UtcNow;
|
||||
|
||||
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, theDate, attachToObject, Notes, ct);
|
||||
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, theDate, attachToObject, Notes, OverrideUserId ?? UserId, ct);
|
||||
|
||||
//EVENT LOG
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, attachToObject.ObjectId, attachToObject.AType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
|
||||
@@ -561,7 +566,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//is this allowed?
|
||||
//Is this a customer user attempting to view a wo attachments??
|
||||
|
||||
|
||||
if (dbObject.AttachToAType == AyaType.WorkOrder && (DownloadUser.UserType == UserType.Customer || DownloadUser.UserType == UserType.HeadOffice))
|
||||
{
|
||||
//check if allowed
|
||||
@@ -606,14 +611,46 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
async private Task<object> GetFileListForObjectAsync(AyaType ayaType, long ayaId)
|
||||
{
|
||||
return await ct.FileAttachment.AsNoTracking().Where(z => z.AttachToObjectId == ayaId && z.AttachToAType == ayaType).OrderBy(z => z.DisplayFileName)
|
||||
.Select(z => new { z.Id, z.Concurrency, z.ContentType, z.DisplayFileName, z.LastModified, z.Notes })
|
||||
.ToArrayAsync();
|
||||
// var v = l.OrderBy(z => z.DisplayFileName);
|
||||
// return v;
|
||||
var retList = new List<FileAttachmentListItem>();
|
||||
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
await ct.Database.OpenConnectionAsync();
|
||||
cmd.CommandText = $@"select afileattachment.id, displayfilename,contenttype,lastmodified, afileattachment.notes, size, auser.name as attachedbyuser from afileattachment
|
||||
left join auser on (afileattachment.attachtoobjectid=auser.id)
|
||||
where attachtoatype={ayaType} and attachtoobjectid={ayaId}
|
||||
order by displayfilename";
|
||||
|
||||
using (var dr = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
retList.Add(new FileAttachmentListItem() {
|
||||
Id = dr.GetInt64(0),
|
||||
DisplayFileName = dr.GetString(1),
|
||||
ContentType = dr.GetString(2),
|
||||
LastModified = dr.GetDateTime(3),
|
||||
Notes = dr.GetString(4),
|
||||
AttachedByUser = dr.GetString(5),
|
||||
Size = dr.GetInt64(6)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
|
||||
private class FileAttachmentListItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
// public uint Concurrency { get; set; }
|
||||
public string DisplayFileName { get; set; }
|
||||
public string ContentType { get; set; }//mime type
|
||||
public DateTime LastModified { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string AttachedByUser { get; set; }
|
||||
public long Size { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trigger immediate AttachmentMaintenanceJob
|
||||
|
||||
@@ -14,13 +14,8 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
|
||||
internal class UserBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, IImportAbleObject, INotifiableObject
|
||||
{
|
||||
|
||||
|
||||
|
||||
internal UserBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
@@ -1000,6 +995,8 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", pmtext + " - " + await Translate("WorkOrderItemTravel"));
|
||||
if (await ct.CustomerServiceRequest.AnyAsync(m => m.RequestedByUserId == inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("CustomerServiceRequest"));
|
||||
if (await ct.FileAttachment.AnyAsync(m => m.AttachedByUserId == inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "generalerror", await Translate("FileAttachment"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ namespace AyaNova.Models
|
||||
public DateTime LastModified { get; set; }
|
||||
public string Notes { get; set; }
|
||||
|
||||
[Required]
|
||||
public long AttachedByUserId { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool Exists { get; set; }//was on disk last sync check
|
||||
|
||||
|
||||
@@ -508,7 +508,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
await ExecQueryAsync("CREATE TABLE alicense (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, licenseagree BOOL NOT NULL, dbid TEXT, key TEXT NOT NULL)");
|
||||
|
||||
await ExecQueryAsync("CREATE TABLE afileattachment (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
|
||||
+ "attachtoobjectid BIGINT NOT NULL, attachtoatype INTEGER NOT NULL, "
|
||||
+ "attachtoobjectid BIGINT NOT NULL, attachtoatype INTEGER NOT NULL, attachedbyuserid BIGINT NOT NULL REFERENCES auser (id), "
|
||||
+ "storedfilename TEXT NOT NULL, displayfilename TEXT NOT NULL, contenttype TEXT, lastmodified TIMESTAMPTZ NOT NULL, notes TEXT, exists BOOL NOT NULL, size BIGINT NOT NULL)");
|
||||
|
||||
//index required for ops that need to check if file already in db (delete, count refs etc)
|
||||
|
||||
@@ -436,8 +436,15 @@ namespace AyaNova.Util
|
||||
/// Store a file attachment
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static async Task<FileAttachment> StoreFileAttachmentAsync(string tempFilePath, string contentType, string fileName, DateTime lastModified,
|
||||
AyaTypeId attachToObject, string notes, AyContext ct)
|
||||
internal static async Task<FileAttachment> StoreFileAttachmentAsync(
|
||||
string tempFilePath,
|
||||
string contentType,
|
||||
string fileName,
|
||||
DateTime lastModified,
|
||||
AyaTypeId attachToObject,
|
||||
string notes,
|
||||
long attachedByUserId,
|
||||
AyContext ct)
|
||||
{
|
||||
//calculate hash
|
||||
var hash = FileHash.GetChecksum(tempFilePath);
|
||||
@@ -473,7 +480,8 @@ namespace AyaNova.Util
|
||||
AttachToObjectId = attachToObject.ObjectId,
|
||||
AttachToAType = attachToObject.AType,
|
||||
LastModified = lastModified,
|
||||
Size = FileSize
|
||||
Size = FileSize,
|
||||
AttachedByUserId=attachedByUserId
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user