Compare commits

...

43 Commits
3.1.1 ... 3

Author SHA1 Message Date
github-actions 26936f33e4 Merge branch '3.4' into 3 2024-02-07 11:15:05 +00:00
Guy Sartorelli 5badc345de
TLN Update translations (#111) 2024-02-07 16:12:33 +13:00
github-actions eb858ca76e Merge branch '3.4' into 3 2023-08-23 11:14:45 +00:00
Guy Sartorelli 19603c31bc
ENH Update translations (#101) 2023-08-21 13:16:40 +12:00
Steve Boyd 17411fbb95 Merge branch '3.4' into 3 2023-06-16 12:09:40 +12:00
Guy Sartorelli 404ae173d0
Merge pull request #98 from creative-commoners/pulls/3.4/tx-1686724855
ENH Update translations
2023-06-15 10:06:13 +12:00
Steve Boyd afbcf59ec4 ENH Update translations 2023-06-14 18:40:55 +12:00
Guy Sartorelli 5742971245
Merge branch '3.4' into 3 2023-04-26 12:46:05 +12:00
Guy Sartorelli 23843cd97f
MNT Revert erroneous dependency changes (#95) 2023-03-28 17:02:59 +13:00
Maxime Rainville 6ef3acd518
Merge pull request #94 from creative-commoners/pulls/3.4/no-deprecations
FIX Don't use deprecated API
2023-03-28 11:18:04 +13:00
Guy Sartorelli 3f62dfd4a4
FIX Don't use deprecated API 2023-03-28 10:23:53 +13:00
Maxime Rainville 7c81d075d6
Merge pull request #93 from creative-commoners/pulls/3/dispatch-ci
MNT Use gha-dispatch-ci
2023-03-23 14:19:24 +13:00
Steve Boyd 04aefedeef MNT Use gha-dispatch-ci 2023-03-21 13:41:47 +13:00
Guy Sartorelli 754bcee5da
MNT Update development dependencies 2023-03-10 16:32:56 +13:00
Guy Sartorelli 4971ddf3cb
MNT Update release dependencies 2023-03-10 16:32:52 +13:00
Guy Sartorelli 9fd768d5ad
MNT Update development dependencies 2023-03-10 12:21:29 +13:00
Guy Sartorelli 4e3f68cdb1
Merge pull request #92 from creative-commoners/pulls/3/tx-1678080129
ENH Update translations
2023-03-08 10:32:21 +13:00
Steve Boyd c5d644eb71 ENH Update translations 2023-03-06 18:22:09 +13:00
Maxime Rainville 9a7ed5f091
Merge pull request #91 from creative-commoners/pulls/3/broken-build-cms4
MNT Explicitly test with default_spam_protector set to null
2023-01-26 17:01:35 +13:00
Steve Boyd ed1d210f0d MNT Explicitly test with default_spam_protector set to null 2023-01-24 10:34:16 +13:00
Maxime Rainville 1c99bc8b92
Merge pull request #88 from creative-commoners/pulls/3/fix-invoke-method-on-null
FIX Check  value is not NULL
2023-01-17 10:25:18 +13:00
Sabina Talipova 2a55708ae8 FIX Check value is not NULL 2023-01-17 08:30:17 +13:00
Sabina Talipova 2c8fc03f2f
Merge pull request #85 from creative-commoners/pulls/3/stop-using-depr
API Stop using deprecated API
2022-12-05 16:40:37 +13:00
Steve Boyd 688b438e88 API Stop using deprecated API 2022-11-24 17:36:45 +13:00
Steve Boyd fc36247598 Merge branch '3.3' into 3 2022-08-02 18:58:04 +12:00
Steve Boyd 0d7a57cedf Merge branch '3.2' into 3.3 2022-08-02 18:58:00 +12:00
Guy Sartorelli 0e5a2dc66d
Merge pull request #84 from creative-commoners/pulls/3.2/standardise-modules
MNT Standardise modules
2022-08-02 15:41:11 +12:00
Steve Boyd 3b0d8d08ed MNT Standardise modules 2022-08-01 16:23:11 +12:00
Steve Boyd e028d76a34 Merge branch '3.3' into 3 2022-07-25 11:38:54 +12:00
Steve Boyd 4b7d18fe0e Merge branch '3.2' into 3.3 2022-07-25 11:38:51 +12:00
Guy Sartorelli 8eb3e05f76
Merge pull request #83 from creative-commoners/pulls/3.2/module-standards
MNT Use GitHub Actions CI
2022-07-15 17:20:32 +12:00
Steve Boyd 63fbae7413 MNT Use GitHub Actions CI 2022-07-05 19:07:16 +12:00
Steve Boyd 3e9f292082 Merge branch '3.3' into 3 2022-05-10 22:10:54 +12:00
Steve Boyd af01b0ad01 Update translations 2022-05-04 13:29:41 +12:00
Guy Sartorelli ed7dc6e38e
Merge pull request #82 from creative-commoners/pulls/3/php81
ENH PHP 8.1 compatibility
2022-04-26 17:57:43 +12:00
Steve Boyd d452367262 ENH PHP 8.1 compatibility 2022-04-13 13:47:43 +12:00
Maxime Rainville a2a21988ed Merge branch '3.2' into 3 2022-03-19 22:58:09 +13:00
Maxime Rainville 228f2a3058 Merge branch '3.1' into 3.2 2022-03-17 15:20:37 +13:00
Maxime Rainville 514b6d7a17
Merge pull request #81 from creative-commoners/pulls/3/php74
DEP Set PHP 7.4 as the minimum version
2022-02-18 22:08:44 +13:00
Steve Boyd f7febc1e98 DEP Set PHP 7.4 as the minimum version 2022-02-10 17:37:49 +13:00
Maxime Rainville 04eb8df284
Merge pull request #80 from creative-commoners/pulls/3/sapphire-test-nine
API phpunit 9 support
2021-11-01 22:24:02 +13:00
Steve Boyd 46169f71a0 API phpunit 9 support 2021-10-27 18:14:42 +13:00
Steve Boyd 9c9900f75a Merge branch '3.1' into 3 2021-05-21 14:03:17 +12:00
18 changed files with 108 additions and 54 deletions

11
.github/workflows/ci.yml vendored Normal file
View File

@ -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

16
.github/workflows/dispatch-ci.yml vendored Normal file
View File

@ -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

17
.github/workflows/keepalive.yml vendored Normal file
View File

@ -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

View File

@ -1,9 +0,0 @@
inherit: true
checks:
php:
code_rating: true
duplication: true
filter:
paths: [code/*, tests/*]

View File

@ -1,4 +0,0 @@
version: ~> 1.0
import:
- silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml

View File

@ -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

View File

@ -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:

View File

@ -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');

View File

@ -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) {

View File

@ -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

View File

@ -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
}
}

View File

@ -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'

View File

@ -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'

10
lang/it.yml Normal file
View File

@ -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'

View File

@ -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'

View File

@ -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">

View File

@ -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()

View File

@ -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(