From dd16f408aebb2bc67a529fceb7523110032543d0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 16 May 2020 16:13:38 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/TagController.cs | 50 +++++++-------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index 033f46ab..dfd7fd6f 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -88,6 +88,8 @@ namespace AyaNova.Api.Controllers 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) @@ -128,6 +130,8 @@ namespace AyaNova.Api.Controllers 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()); @@ -167,6 +171,8 @@ namespace AyaNova.Api.Controllers 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) @@ -175,12 +181,12 @@ namespace AyaNova.Api.Controllers if (string.IsNullOrWhiteSpace(tag)) return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag")); - var JobName = $"BulkAdd tag \"{tag}\" to {ayaType} ({idList.Count} specified)"; + var JobName = $"BulkRemove tag \"{tag}\" from {ayaType} ({idList.Count} specified)"; JObject o = JObject.FromObject(new { ayaType = ayaType, idList = idList, - op = "bulk-add", + op = "bulk-remove", tag = tag }); @@ -207,20 +213,20 @@ namespace AyaNova.Api.Controllers 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")); + tag = TagUtil.NormalizeTag(tag); if (string.IsNullOrWhiteSpace(tag)) return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag")); - var JobName = $"BulkAdd tag {tag} to {ayaType} ({idList.Count} specified)"; + var JobName = $"BulkRemove tag \"{tag}\" to any {ayaType}"; JObject o = JObject.FromObject(new { ayaType = ayaType, - idList = idList, - op = "bulk-add", + op = "bulk-remove-any", tag = tag }); @@ -245,35 +251,7 @@ 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 (!Authorized.HasModifyRole(HttpContext.Items, ayaType)) - return StatusCode(403, new ApiNotAuthorizedResponse()); - if (idList.Count == 0) - return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "List of ids")); - tag = TagUtil.NormalizeTag(tag); - if (string.IsNullOrWhiteSpace(tag)) - return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "tag")); - var JobName = $"BulkAdd tag \"{tag}\" to {ayaType} ({idList.Count} specified)"; - JObject o = JObject.FromObject(new - { - ayaType = ayaType, - idList = idList, - op = "bulk-add", - tag = tag - }); - - 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 }); } /// @@ -290,6 +268,8 @@ namespace AyaNova.Api.Controllers 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());