Skip to content

Commit

Permalink
Check whether rule is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Mar 4, 2024
1 parent 7514eec commit aa04fb4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/Automod/ModAction/BanUser/AbstractBanUserModAction.php
Expand Up @@ -123,7 +123,9 @@ private function findMatchingRegexRule(?string $content): ?InstanceBanRegex
return null;
}

$regexes = $this->banRegexRepository->findAll();
$regexes = $this->banRegexRepository->findBy([
'enabled' => true,
]);
foreach ($regexes as $regexEntity) {
$regex = str_replace('@', '\\@', $regexEntity->getRegex());
$regex = "@{$regex}@i";
Expand All @@ -143,7 +145,9 @@ private function findMatchingUsernameRule(?string $content): ?BannedUsername
return null;
}

$bannedUsernames = $this->usernameRepository->findAll();
$bannedUsernames = $this->usernameRepository->findBy([
'enabled' => true,
]);
foreach ($bannedUsernames as $bannedUsername) {
$regex = str_replace('@', '\\@', $bannedUsername->getUsername());
$regex = "@{$regex}@i";
Expand Down
2 changes: 1 addition & 1 deletion src/Automod/ModAction/BanUser/BanUserForEmailAction.php
Expand Up @@ -35,7 +35,7 @@ public function shouldRun(object $object): bool

private function findMatchingEmailRegex(string $email): ?BannedEmail
{
foreach ($this->bannedEmailRepository->findAll() as $regexEntity) {
foreach ($this->bannedEmailRepository->findBy(['enabled' => true]) as $regexEntity) {
$regex = str_replace('@', '\\@', $regexEntity->getRegex());
$regex = "@{$regex}@i";
if (!preg_match($regex, $email)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Automod/ModAction/BanUser/BanUserForImageAction.php
Expand Up @@ -49,7 +49,7 @@ public function shouldRun(object $object): bool
if (!preg_match($regex, $object->post->url)) {
return false;
}
if (!count($this->imageRepository->findAll())) {
if (!count($this->imageRepository->findBy(['enabled' => true]))) {
return false;
}

Expand All @@ -70,7 +70,7 @@ public function takeAction(object $object, Context $context = new Context()): Fu
if ($hash === null) {
return FurtherAction::CanContinue;
}
foreach ($this->imageRepository->findAll() as $image) {
foreach ($this->imageRepository->findBy(['enabled' => true]) as $image) {
$similarity = $this->imageComparator->compareHashStrings($hash, $image->getImageHash());
if ($similarity < $image->getSimilarityPercent()) {
continue;
Expand Down
Expand Up @@ -23,7 +23,7 @@ public function shouldRun(object $object): bool
if (!$object instanceof RegistrationApplicationView) {
return false;
}
$regexes = $this->autoApprovalRegexRepository->findAll();
$regexes = $this->autoApprovalRegexRepository->findBy(['enabled' => true]);
if (!count($regexes)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Automod/ModAction/Report/AbstractReportAction.php
Expand Up @@ -80,7 +80,7 @@ private function findMatchingRule(?string $content): ?ReportRegex
return null;
}

$regexes = $this->repository->findAll();
$regexes = $this->repository->findBy(['enabled' => true]);
foreach ($regexes as $regexEntity) {
$regex = str_replace('@', '\\@', $regexEntity->getRegex());
$regex = "@{$regex}@";
Expand Down
Expand Up @@ -53,7 +53,7 @@ public function shouldRun(object $object): bool
}

throw new LogicException('The user must either have an ID or username and instance');
}, $this->trustedUserRepository->findAll());
}, $this->trustedUserRepository->findBy(['enabled' => true]));

return in_array($object->creator->id, $trustedIds, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/IgnoredUserManager.php
Expand Up @@ -35,7 +35,7 @@ private function getIgnoredUserIds(): array
}

return $id;
}, $this->repository->findAll());
}, $this->repository->findBy(['enabled' => true]));
} finally {
$this->entityManager->flush();
}
Expand Down

0 comments on commit aa04fb4

Please sign in to comment.