This commit is contained in:
@@ -27,6 +27,8 @@ todo: add query fail logging to datalist just like done with picklist so in prod
|
||||
TODO: BizRoles.cs seems to get hammered on every single request, is it efficient?
|
||||
- Why is it not cached in some way?
|
||||
|
||||
todo: consider renaming ConcurrencyToken to a shorter string?
|
||||
|
||||
todo: Document that anyone who has made their own plugins for AyaNova will need to now directly code against the api their own apps and there will be no plugin ability in v8
|
||||
- DEV MANUAL API section regarding coming from v7?
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Util;
|
||||
@@ -51,9 +51,91 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
//TODO: list with : name, notes, id, mimetype, lastmodified date
|
||||
//TODO: Update notes / filename PUT route
|
||||
|
||||
public class UpdateAttachmentInfo
|
||||
{
|
||||
[Required]
|
||||
public uint ConcurrencyToken { get; set; }
|
||||
[Required]
|
||||
public string DisplayFileName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put (update) FileAttachment
|
||||
/// (FileName and notes only)
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="inObj"></param>
|
||||
/// <returns>list</returns>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutAttachment([FromRoute] long id, [FromBody] UpdateAttachmentInfo inObj)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var dbObj = await ct.FileAttachment.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (dbObj == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
long UserId = UserIdFromContext.Id(HttpContext.Items);
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, dbObj.AttachToObjectType))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string ChangeTextra = string.Empty;
|
||||
if (dbObj.DisplayFileName != inObj.DisplayFileName)
|
||||
{
|
||||
ChangeTextra = $"\"{dbObj.DisplayFileName}\" => \"{inObj.DisplayFileName}\"";
|
||||
}
|
||||
if (dbObj.Notes != inObj.Notes)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ChangeTextra))
|
||||
ChangeTextra += ", ";
|
||||
ChangeTextra += "Notes";
|
||||
}
|
||||
dbObj.DisplayFileName = inObj.DisplayFileName;
|
||||
dbObj.Notes = inObj.Notes;
|
||||
|
||||
|
||||
|
||||
//Set "original" value of concurrency token to input token
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
|
||||
//Log event and save context
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentModified, ChangeTextra), ct);
|
||||
|
||||
|
||||
|
||||
//SEARCH INDEXING
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationIdFromContext.Id(HttpContext.Items), id, AyaType.FileAttachment);
|
||||
SearchParams.AddText(inObj.Notes).AddText(inObj.DisplayFileName);
|
||||
await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
|
||||
|
||||
//--------------
|
||||
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
|
||||
//Normallyh wouldn't return a whole list but in this case the UI demands it because of reactivity issues
|
||||
var ret = await GetFileListForObjectAsync(dbObj.AttachToObjectType, dbObj.AttachToObjectId);
|
||||
return Ok(ApiOkResponse.Response(ret, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -207,7 +289,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//SEARCH INDEXING
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment);
|
||||
SearchParams.AddText(v.Notes).AddText(v.DisplayFileName).AddText(v.StoredFileName);
|
||||
SearchParams.AddText(v.Notes).AddText(v.DisplayFileName);
|
||||
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@ namespace AyaNova.Biz
|
||||
AttachmentCreate=4,
|
||||
AttachmentDelete=5,
|
||||
AttachmentDownload=6,
|
||||
|
||||
LicenseFetch=7,
|
||||
LicenseTrialRequest=8,
|
||||
ServerStateChange=9,
|
||||
SeedDatabase=10
|
||||
SeedDatabase=10,
|
||||
AttachmentModified=11
|
||||
|
||||
//NEW ITEMS REQUIRE translation KEYS and update CLIENT ay-history.vue code in eventypes list and translation fetcher
|
||||
|
||||
|
||||
Reference in New Issue
Block a user