/// <summary> /// Verifies that the album meets the prerequisites to be safely deleted but does not actually delete the album. Throws a /// <see cref="CannotDeleteAlbumException" /> when deleting it would violate a business rule. Throws a /// <see cref="GallerySecurityException" /> when the current user does not have permission to delete the album. /// </summary> /// <param name="albumToDelete">The album to delete.</param> /// <remarks>This function is automatically called when using the <see cref="DeleteAlbum(IAlbum, bool)"/> method, so it is not necessary to /// invoke when using that method. Typically you will call this method when there are several items to delete and you want to /// check all of them before deleting any of them, such as we have on the Delete Objects page.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="albumToDelete" /> is null.</exception> /// <exception cref="CannotDeleteAlbumException">Thrown when the album does not meet the /// requirements for safe deletion.</exception> /// <exception cref="GallerySecurityException">Thrown when the current user does not have permission to delete the album.</exception> public static void ValidateBeforeAlbumDelete(IAlbum albumToDelete) { if (albumToDelete == null) throw new ArgumentNullException("albumToDelete"); var userAlbum = UserController.GetUserAlbum(Utils.UserName, albumToDelete.GalleryId); var curUserDeletingOwnUserAlbum = (userAlbum != null && userAlbum.Id == albumToDelete.Id); // Skip security check when user is deleting their own user album. Normally this won't happen (the menu action for deleting will be // disabled), but it will happen when they delete their user album or their account on the account page, and this is one situation // where it is OK for them to delete their album. if (!curUserDeletingOwnUserAlbum) { SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.DeleteAlbum, RoleController.GetGalleryServerRolesForUser(), albumToDelete.Id, albumToDelete.GalleryId, Utils.IsAuthenticated, albumToDelete.IsPrivate, albumToDelete.IsVirtualAlbum); } if (Factory.LoadGallerySetting(albumToDelete.GalleryId).MediaObjectPathIsReadOnly) { throw new CannotDeleteAlbumException(Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_MediaPathIsReadOnly); } var validator = new AlbumDeleteValidator(albumToDelete); validator.Validate(); if (!validator.CanBeDeleted) { switch (validator.ValidationFailureReason) { case GalleryObjectDeleteValidationFailureReason.AlbumSpecifiedAsUserAlbumContainer: case GalleryObjectDeleteValidationFailureReason.AlbumContainsUserAlbumContainer: { string albumTitle = String.Concat("'", albumToDelete.Title, "' (ID# ", albumToDelete.Id, ")"); string msg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_User_Album_Parent_Ex_Msg, albumTitle); throw new CannotDeleteAlbumException(msg); } case GalleryObjectDeleteValidationFailureReason.AlbumSpecifiedAsDefaultGalleryObject: case GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectAlbum: case GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectMediaObject: { string albumTitle = String.Concat("'", albumToDelete.Title, "' (ID# ", albumToDelete.Id, ")"); string msg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_Default_Gallery_Object_Ex_Msg, albumTitle); throw new CannotDeleteAlbumException(msg); } default: throw new InvalidEnumArgumentException(String.Format(CultureInfo.CurrentCulture, "The function ValidateBeforeAlbumDelete is not designed to handle the enumeration value {0}. The function must be updated.", validator.ValidationFailureReason)); } } }
/// <summary> /// Verifies that the album meets the prerequisites to be safely deleted but does not actually delete the album. Throws a /// CannotDeleteAlbumException when it cannot be deleted. /// </summary> /// <param name="albumToDelete">The album to delete.</param> /// <remarks>This function is automatically called when using the <see cref="DeleteAlbum"/> method, so it is not necessary to /// invoke when using that method. Typically you will call this method when there are several items to delete and you want to /// check all of them before deleting any of them, such as we have on the Delete Objects page.</remarks> /// <exception cref="ErrorHandler.CustomExceptions.CannotDeleteAlbumException">Thrown when the album does not meet the /// requirements for safe deletion.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="albumToDelete" /> is null.</exception> public static void ValidateBeforeAlbumDelete(IAlbum albumToDelete) { if (albumToDelete == null) throw new ArgumentNullException("albumToDelete"); AlbumDeleteValidator validator = new AlbumDeleteValidator(albumToDelete); validator.Validate(); if (!validator.CanBeDeleted) { switch (validator.ValidationFailureReason) { case GalleryObjectDeleteValidationFailureReason.AlbumSpecifiedAsUserAlbumContainer: case GalleryObjectDeleteValidationFailureReason.AlbumContainsUserAlbumContainer: { string albumTitle = String.Concat("'", albumToDelete.Title, "' (ID# ", albumToDelete.Id, ")"); string msg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_User_Album_Parent_Ex_Msg, albumTitle); throw new CannotDeleteAlbumException(msg); } case GalleryObjectDeleteValidationFailureReason.AlbumSpecifiedAsDefaultGalleryObject: case GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectAlbum: case GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectMediaObject: { string albumTitle = String.Concat("'", albumToDelete.Title, "' (ID# ", albumToDelete.Id, ")"); string msg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Task_Delete_Album_Cannot_Delete_Contains_Default_Gallery_Object_Ex_Msg, albumTitle); throw new CannotDeleteAlbumException(msg); } default: throw new InvalidEnumArgumentException(String.Format(CultureInfo.CurrentCulture, "The function ValidateBeforeAlbumDelete is not designed to handle the enumeration value {0}. The function must be updated.", validator.ValidationFailureReason)); } } }