Add check on list type when deleting list

[MAILPOET-4752]
This commit is contained in:
Jan Lysý
2022-10-31 15:16:56 +01:00
committed by Aschepikov
parent ad46d05c6b
commit 8161b83ded
3 changed files with 17 additions and 1 deletions

View File

@@ -4,7 +4,7 @@
## `bool deleteList(string $list_id)`
This method provides functionality for deleting a new list.
This method provides functionality for deleting a list that is of the type 'default'.
It returns a boolean value.
@@ -24,3 +24,4 @@ Codes description:
| 20 | List cannot be deleted because its used for an automatic email |
| 21 | List cannot be deleted because its used for a form |
| 22 | The list couldnt be deleted from the database |
| 23 | Only lists of the type 'default' can be deleted |

View File

@@ -84,6 +84,9 @@ class Segments {
public function deleteList(string $listId): bool {
$this->validateSegmentId($listId);
// delete is supported only for default segment type
$this->validateSegmentType($listId);
$activelyUsedNewslettersSubjects = $this->newsletterSegmentRepository->getSubjectsOfActivelyUsedEmailsForSegments([$listId]);
if (isset($activelyUsedNewslettersSubjects[$listId])) {
throw new APIException(

View File

@@ -229,6 +229,18 @@ class SegmentsTest extends \MailPoetTest {
}
}
public function testItDoesNotAllowDeletingWPSegment(): void {
$wpSegment = $this->segmentsRepository->getWPUsersSegment();
$this->assertInstanceOf(SegmentEntity::class, $wpSegment);
try {
$this->getApi()->deleteList((string)$wpSegment->getId());
$this->fail('WP list cannot be updated.');
} catch (\Exception $e) {
expect($e->getMessage())->equals('List of the type \'' . $wpSegment->getType() . '\' is not supported for this action.');
expect($e->getCode())->equals(APIException::LIST_TYPE_IS_NOT_SUPPORTED);
}
}
public function testItDeletesList(): void {
$segment = $this->createOrUpdateSegment('Test Segment');
$subscriber = (new Subscriber())