This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
@@ -400,6 +401,64 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Post TagMap from group - Map a group of tags to an object / Id
|
||||
/// Required roles: Same roles as tagged object
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="inObj">TagMapGroupInfo</param>
|
||||
/// <returns><see cref="TagMap"/> object</returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostTagMap([FromBody] TagMapGroupInfo inObj)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
//If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner
|
||||
if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, AyaType.TagMap))
|
||||
{
|
||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//Rights to parent taggable object?
|
||||
if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, inObj.TagToObjectType))
|
||||
{
|
||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
//Create and return list
|
||||
List<NameIdItem> l = await biz.TagObject(inObj);
|
||||
|
||||
if (l == null)
|
||||
{
|
||||
//error return
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
else
|
||||
{
|
||||
//save and success return
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//BIZLOG: Not going to log this for now, it's too common an operation and would require bringing in more info. If decide to implement should log the parent object with text of tag instead
|
||||
//and don't forget about import from v7 as well
|
||||
|
||||
return Ok(new ApiOkResponse(l));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool TagGroupExists(long id)
|
||||
{
|
||||
return ct.TagGroup.Any(e => e.Id == id);
|
||||
|
||||
@@ -89,9 +89,9 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Post TagMap - Map a tag to an object / Id
|
||||
/// Post TagMap - Map a single Tag to an object / Id
|
||||
/// Required roles: Same roles as tagged object
|
||||
///
|
||||
/// Required roles: Same roles as tagged object
|
||||
/// </summary>
|
||||
/// <param name="inObj">TagMapInfo</param>
|
||||
/// <returns><see cref="TagMap"/> object</returns>
|
||||
|
||||
Reference in New Issue
Block a user