mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Fixed: Tag deletion via api if tag is still in use
This commit is contained in:
parent
d41ae7b172
commit
a99ee41f38
4 changed files with 58 additions and 11 deletions
|
@ -24,26 +24,20 @@ namespace Lidarr.Http.ErrorManagement
|
||||||
{
|
{
|
||||||
_logger.Trace("Handling Exception");
|
_logger.Trace("Handling Exception");
|
||||||
|
|
||||||
var apiException = exception as ApiException;
|
if (exception is ApiException apiException)
|
||||||
|
|
||||||
if (apiException != null)
|
|
||||||
{
|
{
|
||||||
_logger.Warn(apiException, "API Error");
|
_logger.Warn(apiException, "API Error");
|
||||||
return apiException.ToErrorResponse(context);
|
return apiException.ToErrorResponse(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
var validationException = exception as ValidationException;
|
if (exception is ValidationException validationException)
|
||||||
|
|
||||||
if (validationException != null)
|
|
||||||
{
|
{
|
||||||
_logger.Warn("Invalid request {0}", validationException.Message);
|
_logger.Warn("Invalid request {0}", validationException.Message);
|
||||||
|
|
||||||
return validationException.Errors.AsResponse(context, HttpStatusCode.BadRequest);
|
return validationException.Errors.AsResponse(context, HttpStatusCode.BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientException = exception as NzbDroneClientException;
|
if (exception is NzbDroneClientException clientException)
|
||||||
|
|
||||||
if (clientException != null)
|
|
||||||
{
|
{
|
||||||
return new ErrorModel
|
return new ErrorModel
|
||||||
{
|
{
|
||||||
|
@ -52,9 +46,25 @@ namespace Lidarr.Http.ErrorManagement
|
||||||
}.AsResponse(context, (HttpStatusCode)clientException.StatusCode);
|
}.AsResponse(context, (HttpStatusCode)clientException.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqLiteException = exception as SQLiteException;
|
if (exception is ModelNotFoundException notFoundException)
|
||||||
|
{
|
||||||
|
return new ErrorModel
|
||||||
|
{
|
||||||
|
Message = exception.Message,
|
||||||
|
Description = exception.ToString()
|
||||||
|
}.AsResponse(context, HttpStatusCode.NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
if (sqLiteException != null)
|
if (exception is ModelConflictException conflictException)
|
||||||
|
{
|
||||||
|
return new ErrorModel
|
||||||
|
{
|
||||||
|
Message = exception.Message,
|
||||||
|
Description = exception.ToString()
|
||||||
|
}.AsResponse(context, HttpStatusCode.Conflict);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exception is SQLiteException sqLiteException)
|
||||||
{
|
{
|
||||||
if (context.Request.Method == "PUT" || context.Request.Method == "POST")
|
if (context.Request.Method == "PUT" || context.Request.Method == "POST")
|
||||||
{
|
{
|
||||||
|
|
20
src/NzbDrone.Core/Datastore/ModelConflictException.cs
Normal file
20
src/NzbDrone.Core/Datastore/ModelConflictException.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
using NzbDrone.Common.Exceptions;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore
|
||||||
|
{
|
||||||
|
public class ModelConflictException : NzbDroneException
|
||||||
|
{
|
||||||
|
public ModelConflictException(Type modelType, int modelId)
|
||||||
|
: base("{0} with ID {1} cannot be modified", modelType.Name, modelId)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelConflictException(Type modelType, int modelId, string message)
|
||||||
|
: base("{0} with ID {1} {2}", modelType.Name, modelId, message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Tags
|
namespace NzbDrone.Core.Tags
|
||||||
|
@ -11,5 +12,13 @@ namespace NzbDrone.Core.Tags
|
||||||
public List<int> RestrictionIds { get; set; }
|
public List<int> RestrictionIds { get; set; }
|
||||||
public List<int> DelayProfileIds { get; set; }
|
public List<int> DelayProfileIds { get; set; }
|
||||||
public List<int> ImportListIds { get; set; }
|
public List<int> ImportListIds { get; set; }
|
||||||
|
|
||||||
|
public bool InUse
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (ArtistIds.Any() || NotificationIds.Any() || RestrictionIds.Any() || DelayProfileIds.Any() || ImportListIds.Any());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Core.ImportLists;
|
using NzbDrone.Core.ImportLists;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Notifications;
|
using NzbDrone.Core.Notifications;
|
||||||
using NzbDrone.Core.Profiles.Delay;
|
using NzbDrone.Core.Profiles.Delay;
|
||||||
|
@ -149,6 +151,12 @@ namespace NzbDrone.Core.Tags
|
||||||
|
|
||||||
public void Delete(int tagId)
|
public void Delete(int tagId)
|
||||||
{
|
{
|
||||||
|
var details = Details(tagId);
|
||||||
|
if (details.InUse)
|
||||||
|
{
|
||||||
|
throw new ModelConflictException(typeof(Tag), tagId, $"'{details.Label}' cannot be deleted since it's still in use");
|
||||||
|
}
|
||||||
|
|
||||||
_repo.Delete(tagId);
|
_repo.Delete(tagId);
|
||||||
_eventAggregator.PublishEvent(new TagsUpdatedEvent());
|
_eventAggregator.PublishEvent(new TagsUpdatedEvent());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue