From 18e976754885929db0ef16b095bcecdecd7e7d44 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 16 May 2020 16:16:15 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/TagController.cs | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index dfd7fd6f..e3f46ebd 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -200,6 +200,7 @@ namespace AyaNova.Api.Controllers return Accepted(new { JobId = j.GId }); } + /// /// Bulk remove tags to all objects of type specified /// @@ -240,6 +241,7 @@ namespace AyaNova.Api.Controllers return Accepted(new { JobId = j.GId }); } + /// /// Bulk replace tags to list of object id's specified /// @@ -251,7 +253,40 @@ namespace AyaNova.Api.Controllers [HttpPost("bulk-replace/{ayaType}/{tag}")] public async Task BulkReplace([FromRoute] AyaType ayaType, [FromRoute] string fromTag, [FromQuery] string toTag, [FromBody] List idList) { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + if (!ayaType.HasAttribute(typeof(CoreBizObjectAttribute))) + return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "ayaType", "Not a taggable object type")); + if (!Authorized.HasModifyRole(HttpContext.Items, ayaType)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + if (idList.Count == 0) + return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "List of ids")); + fromTag = TagUtil.NormalizeTag(fromTag); + if (string.IsNullOrWhiteSpace(fromTag)) + return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "fromTag")); + toTag = TagUtil.NormalizeTag(toTag); + if (string.IsNullOrWhiteSpace(toTag)) + return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "toTag")); + var JobName = $"BulkReplace tag \"{fromTag}\" with tag \"{toTag}\" to {ayaType} ({idList.Count} specified)"; + JObject o = JObject.FromObject(new + { + ayaType = ayaType, + idList = idList, + op = "bulk-replace", + fromTag = fromTag, + toTag = toTag + }); + OpsJob j = new OpsJob(); + j.Name = JobName; + j.JobType = JobType.BulkTag; + j.Exclusive = false; + j.JobInfo = o.ToString(); + await JobsBiz.AddJobAsync(j, ct); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct); + return Accepted(new { JobId = j.GId }); } ///