Compare commits
43 Commits
Author | SHA1 | Date |
---|---|---|
github-actions | 26936f33e4 | |
Guy Sartorelli | 5badc345de | |
github-actions | eb858ca76e | |
Guy Sartorelli | 19603c31bc | |
Steve Boyd | 17411fbb95 | |
Guy Sartorelli | 404ae173d0 | |
Steve Boyd | afbcf59ec4 | |
Guy Sartorelli | 5742971245 | |
Guy Sartorelli | 23843cd97f | |
Maxime Rainville | 6ef3acd518 | |
Guy Sartorelli | 3f62dfd4a4 | |
Maxime Rainville | 7c81d075d6 | |
Steve Boyd | 04aefedeef | |
Guy Sartorelli | 754bcee5da | |
Guy Sartorelli | 4971ddf3cb | |
Guy Sartorelli | 9fd768d5ad | |
Guy Sartorelli | 4e3f68cdb1 | |
Steve Boyd | c5d644eb71 | |
Maxime Rainville | 9a7ed5f091 | |
Steve Boyd | ed1d210f0d | |
Maxime Rainville | 1c99bc8b92 | |
Sabina Talipova | 2a55708ae8 | |
Sabina Talipova | 2c8fc03f2f | |
Steve Boyd | 688b438e88 | |
Steve Boyd | fc36247598 | |
Steve Boyd | 0d7a57cedf | |
Guy Sartorelli | 0e5a2dc66d | |
Steve Boyd | 3b0d8d08ed | |
Steve Boyd | e028d76a34 | |
Steve Boyd | 4b7d18fe0e | |
Guy Sartorelli | 8eb3e05f76 | |
Steve Boyd | 63fbae7413 | |
Steve Boyd | 3e9f292082 | |
Steve Boyd | af01b0ad01 | |
Guy Sartorelli | ed7dc6e38e | |
Steve Boyd | d452367262 | |
Maxime Rainville | a2a21988ed | |
Maxime Rainville | 228f2a3058 | |
Maxime Rainville | 514b6d7a17 | |
Steve Boyd | f7febc1e98 | |
Maxime Rainville | 04eb8df284 | |
Steve Boyd | 46169f71a0 | |
Steve Boyd | 9c9900f75a |
|
@ -0,0 +1,11 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
|
|
@ -0,0 +1,16 @@
|
|||
name: Dispatch CI
|
||||
|
||||
on:
|
||||
# At 11:10 AM UTC, only on Saturday and Sunday
|
||||
schedule:
|
||||
- cron: '10 11 * * 6,0'
|
||||
|
||||
jobs:
|
||||
dispatch-ci:
|
||||
name: Dispatch CI
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dispatch CI
|
||||
uses: silverstripe/gha-dispatch-ci@v1
|
|
@ -0,0 +1,17 @@
|
|||
name: Keepalive
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# The 4th of every month at 10:50am UTC
|
||||
schedule:
|
||||
- cron: '50 10 4 * *'
|
||||
|
||||
jobs:
|
||||
keepalive:
|
||||
name: Keepalive
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Keepalive
|
||||
uses: silverstripe/gha-keepalive@v1
|
|
@ -1,9 +0,0 @@
|
|||
inherit: true
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [code/*, tests/*]
|
|
@ -1,4 +0,0 @@
|
|||
version: ~> 1.0
|
||||
|
||||
import:
|
||||
- silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml
|
|
@ -1,8 +1,9 @@
|
|||
[main]
|
||||
host = https://www.transifex.com
|
||||
|
||||
[silverstripe-spamprotection.master]
|
||||
[o:silverstripe:p:silverstripe-spamprotection:r:master]
|
||||
file_filter = lang/<lang>.yml
|
||||
source_file = lang/en.yml
|
||||
source_lang = en
|
||||
type = YML
|
||||
type = YML
|
||||
|
||||
|
|
12
README.md
12
README.md
|
@ -1,9 +1,7 @@
|
|||
# SpamProtection Module
|
||||
|
||||
[![Build Status](https://api.travis-ci.com/silverstripe/silverstripe-spamprotection.svg?branch=3)](https://travis-ci.com/silverstripe/silverstripe-spamprotection)
|
||||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-spamprotection/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-spamprotection/?branch=master)
|
||||
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-spamprotection/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-spamprotection)
|
||||
[![CI](https://github.com/silverstripe/silverstripe-spamprotection/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-spamprotection/actions/workflows/ci.yml)
|
||||
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
|
||||
## Maintainer Contact
|
||||
|
||||
|
@ -15,9 +13,9 @@
|
|||
|
||||
## Requirements
|
||||
|
||||
SilverStripe 4.0+
|
||||
Silverstripe 4.0+
|
||||
|
||||
**Note:** For SilverStripe 3.x, please use the [2.x release line](https://github.com/silverstripe/silverstripe-spamprotection/tree/2.0).
|
||||
**Note:** For Silverstripe 3.x, please use the [2.x release line](https://github.com/silverstripe/silverstripe-spamprotection/tree/2.0).
|
||||
|
||||
## Install
|
||||
|
||||
|
@ -26,7 +24,7 @@ To install run `composer require silverstripe/spamprotection`.
|
|||
## Documentation
|
||||
|
||||
This module provides a generic, consistent API for adding spam protection to
|
||||
your SilverStripe Forms. This does not provide any spam protection out of the
|
||||
your Silverstripe Forms. This does not provide any spam protection out of the
|
||||
box. For that, you must also download one of the spam protection
|
||||
implementations. Currently available options are:
|
||||
|
||||
|
|
14
_config.php
14
_config.php
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Default configuration settings for the Spam Protection module.
|
||||
*
|
||||
* You should not put your own configuration in here rather use your
|
||||
* mysite/_config.php file
|
||||
*
|
||||
* @package spamprotection
|
||||
*/
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
Deprecation::notification_version('3.0', 'spamprotection');
|
|
@ -130,13 +130,13 @@ class EditableSpamProtectionField extends EditableFormField
|
|||
*/
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
$fieldMap = json_decode($this->SpamFieldSettings, true);
|
||||
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
|
||||
if (empty($fieldMap)) {
|
||||
$fieldMap = array();
|
||||
}
|
||||
|
||||
foreach ($this->record as $key => $value) {
|
||||
if (substr($key, 0, 8) === 'spammap-') {
|
||||
if (substr($key ?? '', 0, 8) === 'spammap-') {
|
||||
$fieldMap[substr($key, 8)] = $value;
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||
|
||||
// Generate field specific settings
|
||||
$mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields');
|
||||
$mappableFieldsMerged = array_combine($mappableFields, $mappableFields);
|
||||
$mappableFieldsMerged = array_combine($mappableFields ?? [], $mappableFields ?? []);
|
||||
foreach ($this->getCandidateFields() as $otherField) {
|
||||
$mapSetting = "Map-{$otherField->Name}";
|
||||
$fieldOption = DropdownField::create(
|
||||
|
@ -200,12 +200,12 @@ class EditableSpamProtectionField extends EditableFormField
|
|||
*/
|
||||
public function spamMapValue($mapSetting)
|
||||
{
|
||||
$map = json_decode($this->SpamFieldSettings, true);
|
||||
$map = json_decode($this->SpamFieldSettings ?? '', true);
|
||||
if (empty($map)) {
|
||||
$map = array();
|
||||
}
|
||||
|
||||
if (array_key_exists($mapSetting, $map)) {
|
||||
if (array_key_exists($mapSetting, $map ?? [])) {
|
||||
return $map[$mapSetting];
|
||||
}
|
||||
return '';
|
||||
|
@ -235,7 +235,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||
$foundError = false;
|
||||
|
||||
// field validate implementation may not add error to validator
|
||||
if (count($errors) > 0) {
|
||||
if (count($errors ?? []) > 0) {
|
||||
// check if error already added from fields' validate method
|
||||
foreach ($errors as $error) {
|
||||
if ($error['fieldName'] == $this->Name) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace SilverStripe\SpamProtection\Extension;
|
||||
|
||||
use LogicException;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
|
@ -73,7 +74,7 @@ class FormSpamProtectionExtension extends Extension
|
|||
$protector = self::config()->get('default_spam_protector');
|
||||
}
|
||||
|
||||
if ($protector && class_exists($protector)) {
|
||||
if ($protector && class_exists($protector ?? '')) {
|
||||
return Injector::inst()->create($protector);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -84,6 +85,7 @@ class FormSpamProtectionExtension extends Extension
|
|||
* Activates the spam protection module.
|
||||
*
|
||||
* @param array $options
|
||||
* @throws LogicException when get_protector method returns NULL.
|
||||
* @return Object
|
||||
*/
|
||||
public function enableSpamProtection($options = array())
|
||||
|
@ -106,7 +108,11 @@ class FormSpamProtectionExtension extends Extension
|
|||
// set custom mapping on this form
|
||||
$protector = self::get_protector($options);
|
||||
|
||||
if (isset($options['mapping'])) {
|
||||
if ($protector === null) {
|
||||
throw new LogicException('No spam protector has been set. Null is not valid value.');
|
||||
}
|
||||
|
||||
if ($protector && isset($options['mapping'])) {
|
||||
$protector->setFieldMapping($options['mapping']);
|
||||
}
|
||||
|
||||
|
@ -118,7 +124,7 @@ class FormSpamProtectionExtension extends Extension
|
|||
// Add before field specified by insertBefore
|
||||
$inserted = false;
|
||||
if (!empty($options['insertBefore'])) {
|
||||
$inserted = $this->owner->Fields()->insertBefore($field, $options['insertBefore']);
|
||||
$inserted = $this->owner->Fields()->insertBefore($options['insertBefore'], $field);
|
||||
}
|
||||
if (!$inserted) {
|
||||
// Add field to end if not added already
|
||||
|
|
|
@ -17,10 +17,11 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4.0"
|
||||
"php": "^7.4 || ^8.0",
|
||||
"silverstripe/framework": "^4.10"
|
||||
},
|
||||
"require-dev": {
|
||||
"sminnee/phpunit": "^5.7",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"silverstripe/versioned": "^1.0",
|
||||
"squizlabs/php_codesniffer": "^3.0",
|
||||
"silverstripe/userforms": "^5"
|
||||
|
@ -39,4 +40,4 @@
|
|||
"license": "BSD-3-Clause",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
}
|
|
@ -7,3 +7,4 @@ en:
|
|||
SINGULARNAME: 'Spam Protection Field'
|
||||
SPAMFIELDMAPPING: 'Spam Field Mapping'
|
||||
SPAMFIELDMAPPINGDESCRIPTION: 'Select the form fields that correspond to any relevant spam protection identifiers'
|
||||
db_SpamFieldSettings: 'Spam field settings'
|
||||
|
|
|
@ -7,3 +7,4 @@ eo:
|
|||
SINGULARNAME: 'Spamprotekta kampo'
|
||||
SPAMFIELDMAPPING: 'Spamkampa mapigo'
|
||||
SPAMFIELDMAPPINGDESCRIPTION: 'Elektu la kampojn kiuj rilatas al eventualaj rilataj spamprotektaj identigiloj'
|
||||
db_SpamFieldSettings: 'Spamkampaj agordoj'
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
it:
|
||||
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||
PLURALNAME: 'Campi di Prevenzione Spam'
|
||||
PLURALS:
|
||||
many: '{count} Campi di Prevenzione Spam'
|
||||
one: 'Un Campo di Prevenzione Spam'
|
||||
other: '{count} Campi di Prevenzione Spam'
|
||||
SINGULARNAME: 'Campo di Prevenzione Spam'
|
||||
SPAMFIELDMAPPING: 'Mappatura Campo Spam'
|
||||
SPAMFIELDMAPPINGDESCRIPTION: 'Selezionare i campi della form che forniscono una qualche protezione dallo spam'
|
|
@ -1,6 +1,12 @@
|
|||
sk:
|
||||
SilverStripe\SpamProtection\EditableSpamProtectionField:
|
||||
PLURALNAME: 'Polia ochrany proti spamu'
|
||||
PLURALS:
|
||||
few: '{count} polia ochrany proti spamu'
|
||||
many: '{count} polí ochrany proti spamu'
|
||||
one: 'Pole ochrany proti spamu'
|
||||
other: '{count} polí ochrany proti spamu'
|
||||
SINGULARNAME: 'Pole ochrany proti spamu'
|
||||
SPAMFIELDMAPPING: 'Mapovanie spamového poľa'
|
||||
SPAMFIELDMAPPINGDESCRIPTION: 'Vyberte polia formulára, ktoré zodpovedajú všetkým príslušným identifikátorom ochrany proti spamu'
|
||||
db_SpamFieldSettings: 'Nastavenia poľa spamu'
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
|
||||
<testsuite name="Default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
<testsuites>
|
||||
<testsuite name="Default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
|
|
|
@ -19,7 +19,7 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||
{
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -117,7 +117,7 @@ class EditableSpamProtectionFieldTest extends SapphireTest
|
|||
{
|
||||
$field = new EditableSpamProtectionField;
|
||||
|
||||
$this->assertContains('/images/editablespamprotectionfield.png', $field->getIcon());
|
||||
$this->assertStringContainsString('/images/editablespamprotectionfield.png', $field->getIcon());
|
||||
}
|
||||
|
||||
protected function getFormMock()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace SilverStripe\SpamProtection\Tests;
|
||||
|
||||
use LogicException;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
@ -25,7 +26,7 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||
*/
|
||||
protected $form = null;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -38,6 +39,15 @@ class FormSpamProtectionExtensionTest extends SapphireTest
|
|||
$this->form->disableSecurityToken();
|
||||
}
|
||||
|
||||
public function testEnableSpamProtectionThrowsException()
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
$this->expectExceptionMessage('No spam protector has been set. Null is not valid value.');
|
||||
|
||||
Config::modify()->set(FormSpamProtectionExtension::class, 'default_spam_protector', null);
|
||||
$this->form->enableSpamProtection();
|
||||
}
|
||||
|
||||
public function testEnableSpamProtection()
|
||||
{
|
||||
Config::modify()->set(
|
||||
|
|
Loading…
Reference in New Issue