Compare commits

...

42 Commits
3 ... 4.2.0-rc1

Author SHA1 Message Date
github-actions e83099413b Merge branch '4.1' into 4 2024-02-07 11:15:06 +00:00
github-actions 7630307964 Merge branch '3' into 4.1 2024-02-07 11:15:06 +00:00
Guy Sartorelli ba9f5d868a
MNT Run module-standardiser (#110) 2024-02-02 14:07:44 +13:00
Guy Sartorelli 77aba75ffa
ENH Add generic types (#108) 2024-01-19 10:44:37 +13:00
Guy Sartorelli a5b2363e35
MNT Run module-standardiser (#107) 2023-12-21 16:30:45 +13:00
Guy Sartorelli 3079188625
Merge pull request #106 from wilr/pr/mnt
feat: code clean up
2023-09-15 09:40:29 +12:00
Will Rossiter 6f85c7e5ba
MNT: update linting 2023-09-15 06:17:06 +12:00
Will Rossiter 9d368b556f
MNT: remove unused namespace 2023-09-15 06:02:11 +12:00
Will Rossiter fa8366e706
MNT: use short array syntax 2023-09-13 06:50:09 +12:00
Will Rossiter 6d2ec29d32
MNT: move code from code/ to src as 2023-09-13 06:49:00 +12:00
Will Rossiter d10b6a1671
Merge pull request #104 from creative-commoners/pulls/4/revert-bad-commit
Revert "fix: if no spam protector set, fail sliently"
2023-09-12 09:59:29 +12:00
Guy Sartorelli 221089136f
Revert "fix: if no spam protector set, fail sliently"
This reverts commit 17106d8f30.
2023-09-12 09:45:39 +12:00
Will Rossiter 17106d8f30
fix: if no spam protector set, fail sliently 2023-09-11 11:42:09 +12:00
Guy Sartorelli 2d59501ef3
Merge branch '4.0' into 4 2023-08-30 12:00:05 +12:00
Guy Sartorelli 0879af9c99
Merge pull request #102 from creative-commoners/pulls/4.0/module-standardiser-1693279024
MNT Run module-standardiser
2023-08-29 17:12:18 +12:00
Steve Boyd a0ae7ef940 MNT Run module-standardiser 2023-08-29 15:17:04 +12:00
github-actions 7e1b433384 Merge branch '4.0' into 4 2023-08-23 11:14:48 +00:00
github-actions ac5f27d0b9 Merge branch '3' into 4.0 2023-08-23 11:14:46 +00:00
Guy Sartorelli a88640849e
Merge pull request #100 from creative-commoners/pulls/4/module-standardiser-1691550402
MNT Run module-standardiser
2023-08-15 12:27:03 +12:00
Steve Boyd 4f75f5253c MNT Run module-standardiser 2023-08-14 15:49:07 +12:00
Guy Sartorelli de3129fa92
Merge pull request #99 from blueo/patch-1
Add Cloudflare Turnstile captcha link
2023-07-17 11:18:24 +12:00
Bernard Hamlin a3586210e2
Add Cloudflare Turnstile captcha link 2023-07-11 13:36:10 +12:00
Steve Boyd 03eb0d42b9 Merge branch '4.0' into 4 2023-06-16 12:10:21 +12:00
Steve Boyd 4b3f5a2599 Merge branch '3' into 4.0 2023-06-16 12:10:02 +12:00
Guy Sartorelli 5cecb82116
Merge pull request #97 from creative-commoners/pulls/4/tx-1686703555
ENH Update translations
2023-06-14 15:17:51 +12:00
Steve Boyd e08ac10658 ENH Update translations 2023-06-14 12:45:55 +12:00
Steve Boyd 9ab49fadb6 Merge branch '4.0' into 4 2023-05-04 13:27:45 +12:00
Guy Sartorelli e1b4ea2807
Merge branch '3' into 4.0
# Conflicts:
#	_config.php
2023-04-27 14:31:23 +12:00
Sabina Talipova c08ec451bf
Merge pull request #96 from creative-commoners/pulls/4.0/cms5-readme
DOC Update README.md for CMS 5
2023-04-26 08:22:45 +12:00
Guy Sartorelli 00869b6755
DOC Update README.md for CMS 5 2023-04-24 16:31:47 +12:00
Steve Boyd 8efc022acd Merge branch '4.0' into 4 2023-03-30 12:58:48 +13:00
Steve Boyd cfcfa9352c Merge branch '3' into 4.0 2023-03-30 12:58:33 +13:00
Steve Boyd 5254e92d52 Merge branch '4.0' into 4 2023-03-08 12:02:43 +13:00
Steve Boyd 9e74d2749e Merge branch '3' into 4.0 2023-03-08 12:02:33 +13:00
Steve Boyd 04f6d63258 Merge branch '3' into 4 2023-02-03 10:30:15 +13:00
Maxime Rainville 41cd3190ee
Merge pull request #90 from creative-commoners/pulls/4/remove-legacy-upgrader
MNT Remove legacy upgrader config
2023-01-23 10:10:38 +13:00
Steve Boyd 20270caef8 MNT Remove legacy upgrader config 2023-01-20 16:49:42 +13:00
Sabina Talipova ad2dd60c77
Merge pull request #89 from creative-commoners/pulls/4/unit-test
MNT Explicitly test with default_spam_protector set to null
2023-01-18 16:00:21 +13:00
Steve Boyd f194344efe MNT Explicitly test with default_spam_protector set to null 2023-01-18 15:52:48 +13:00
Sabina Talipova 537b1b9290 Merge branch '3' into 4 2023-01-17 12:49:21 +13:00
Maxime Rainville d4df0bad4c
Merge pull request #86 from creative-commoners/pulls/4/upgrade-cms5
DEP PHP Support in CMS5
2023-01-13 13:44:24 +13:00
Sabina Talipova d669b42cc9 DEP PHP Support in CMS5 2023-01-13 11:35:58 +13:00
19 changed files with 221 additions and 66 deletions

1
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1 @@
<!-- Blank templates are for use by maintainers only! If you aren't a maintainer, please go back and pick one of the issue templates. -->

72
.github/ISSUE_TEMPLATE/1_bug_report.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: 🪳 Bug Report
description: Tell us if something isn't working the way it's supposed to
body:
- type: markdown
attributes:
value: |
We strongly encourage you to [submit a pull request](https://docs.silverstripe.org/en/contributing/code/) which fixes the issue.
Bug reports which are accompanied with a pull request are a lot more likely to be resolved quickly.
- type: input
id: affected-versions
attributes:
label: Module version(s) affected
description: |
What version of _this module_ have you reproduced this bug on?
Run `composer info` to see the specific version of each module installed in your project.
If you don't have access to that, check inside the help menu in the bottom left of the CMS.
placeholder: x.y.z
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: A clear and concise description of the problem
validations:
required: true
- type: textarea
id: how-to-reproduce
attributes:
label: How to reproduce
description: |
⚠️ This is the most important part of the report ⚠️
Without a way to easily reproduce your issue, there is little chance we will be able to help you and work on a fix.
- Please, take the time to show us some code and/or configuration that is needed for others to reproduce the problem easily.
- If the bug is too complex to reproduce with some short code samples, please reproduce it in a public repository and provide a link to the repository along with steps for setting up and reproducing the bug using that repository.
- If part of the bug includes an error or exception, please provide a full stack trace.
- If any user interaction is required to reproduce the bug, please add an ordered list of steps that are required to reproduce it.
- Be as clear as you can, but don't miss any steps out. Simply saying "create a page" is less useful than guiding us through the steps you're taking to create a page, for example.
placeholder: |
#### Code sample
```php
```
#### Reproduction steps
1.
validations:
required: true
- type: textarea
id: possible-solution
attributes:
label: Possible Solution
description: |
*Optional: only if you have suggestions on a fix/reason for the bug*
Please consider [submitting a pull request](https://docs.silverstripe.org/en/contributing/code/) with your solution! It helps get faster feedback and greatly increases the chance of the bug being fixed.
- type: textarea
id: additional-context
attributes:
label: Additional Context
description: "*Optional: any other context about the problem: log messages, screenshots, etc.*"
- type: checkboxes
id: validations
attributes:
label: Validations
description: "Before submitting the issue, please make sure you do the following:"
options:
- label: Check that there isn't already an issue that reports the same bug
required: true
- label: Double check that your reproduction steps work in a fresh installation of [`silverstripe/installer`](https://github.com/silverstripe/silverstripe-installer) (with any code examples you've provided)
required: true

View File

@ -0,0 +1,35 @@
name: 🚀 Feature Request
description: Submit a feature request (but only if you're planning on implementing it)
body:
- type: markdown
attributes:
value: |
Please only submit feature requests if you plan on implementing the feature yourself.
See the [contributing code documentation](https://docs.silverstripe.org/en/contributing/code/#make-or-find-a-github-issue) for more guidelines about submitting feature requests.
- type: textarea
id: description
attributes:
label: Description
description: A clear and concise description of the new feature, and why it belongs in core
validations:
required: true
- type: textarea
id: more-info
attributes:
label: Additional context or points of discussion
description: |
*Optional: Any additional context, points of discussion, etc that might help validate and refine your idea*
- type: checkboxes
id: validations
attributes:
label: Validations
description: "Before submitting the issue, please confirm the following:"
options:
- label: You intend to implement the feature yourself
required: true
- label: You have read the [contributing guide](https://docs.silverstripe.org/en/contributing/code/)
required: true
- label: You strongly believe this feature should be in core, rather than being its own community module
required: true
- label: You have checked for existing issues or pull requests related to this feature (and didn't find any)
required: true

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: Security Vulnerability
url: https://docs.silverstripe.org/en/contributing/issues_and_bugs/#reporting-security-issues
about: ⚠️ We do not use GitHub issues to track security vulnerability reports. Click "open" on the right to see how to report security vulnerabilities.
- name: Support Question
url: https://www.silverstripe.org/community/
about: We use GitHub issues only to discuss bugs and new features. For support questions, please use one of the support options available in our community channels.

39
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,39 @@
<!--
Thanks for contributing, you're awesome! ⭐
Please read https://docs.silverstripe.org/en/contributing/code/ if you haven't contributed to this project recently.
-->
## Description
<!--
Please describe expected and observed behaviour, and what you're fixing.
For visual fixes, please include tested browsers and screenshots.
-->
## Manual testing steps
<!--
Include any manual testing steps here which a reviewer can perform to validate your pull request works correctly.
Note that this DOES NOT replace unit or end-to-end tests.
-->
## Issues
<!--
List all issues here that this pull request fixes/resolves.
If there is no issue already, create a new one! You must link your pull request to at least one issue.
-->
- #
## Pull request checklist
<!--
PLEASE check each of these to ensure you have done everything you need to do!
If there's something in this list you need help with, please ask so that we can assist you.
-->
- [ ] The target branch is correct
- See [picking the right version](https://docs.silverstripe.org/en/contributing/code/#picking-the-right-version)
- [ ] All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
- Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
- [ ] The commit messages follow our [commit message guidelines](https://docs.silverstripe.org/en/contributing/code/#commit-messages)
- [ ] The PR follows our [contribution guidelines](https://docs.silverstripe.org/en/contributing/code/)
- [ ] Code changes follow our [coding conventions](https://docs.silverstripe.org/en/contributing/coding_conventions/)
- [ ] This change is covered with tests (or tests aren't necessary for this change)
- [ ] Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
- [ ] CI is green

View File

@ -1,10 +1,10 @@
name: Keepalive
on:
workflow_dispatch:
# The 4th of every month at 10:50am UTC
# At 8:40 AM UTC, on day 9 of the month
schedule:
- cron: '50 10 4 * *'
- cron: '40 8 9 * *'
workflow_dispatch:
jobs:
keepalive:

17
.github/workflows/merge-up.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Merge-up
on:
# At 11:10 AM UTC, only on Wednesday
schedule:
- cron: '10 11 * * 3'
workflow_dispatch:
jobs:
merge-up:
name: Merge-up
# 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: Merge-up
uses: silverstripe/gha-merge-up@v1

View File

@ -1,11 +0,0 @@
mappings:
SpamProtector: SilverStripe\SpamProtection\SpamProtector
CommentSpamProtection: SilverStripe\SpamProtection\Extension\CommentSpamProtection
EditableSpamProtectionField: SilverStripe\SpamProtection\EditableSpamProtectionField
FormSpamProtectionExtension: SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension
EditableSpamProtectionFieldTest: SilverStripe\SpamProtection\Tests\EditableSpamProtectionFieldTest
EditableSpamProtectionFieldTest_Protector: SilverStripe\SpamProtection\Tests\Stub\Protector
FormSpamProtectionExtensionTest: SilverStripe\SpamProtection\Tests\FormSpamProtectionExtensionTest
FormSpamProtectionExtensionTest_BarProtector: SilverStripe\SpamProtection\Tests\Stub\BarProtector
FormSpamProtectionExtensionTest_BazProtector: SilverStripe\SpamProtection\Tests\Stub\BazProtector
FormSpamProtectionExtensionTest_FooProtector: SilverStripe\SpamProtection\Tests\Stub\FooProtector

View File

@ -1,4 +1,4 @@
Copyright (c) 2017, SilverStripe Limited
Copyright (c) 2017, Silverstripe Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

View File

@ -3,6 +3,12 @@
[![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/)
## Installation
```sh
composer require silverstripe/spamprotection
```
## Maintainer Contact
* Saophalkun Ponlu
@ -11,16 +17,6 @@
* Will Rossiter
<will (at) fullscreen (dot) io>
## Requirements
Silverstripe 4.0+
**Note:** For Silverstripe 3.x, please use the [2.x release line](https://github.com/silverstripe/silverstripe-spamprotection/tree/2.0).
## Install
To install run `composer require silverstripe/spamprotection`.
## Documentation
This module provides a generic, consistent API for adding spam protection to
@ -32,6 +28,7 @@ implementations. Currently available options are:
* [MathSpamProtection](https://github.com/silverstripe/silverstripe-mathspamprotection)
* [Akismet](https://github.com/silverstripe/silverstripe-akismet)
* [Mollom](https://github.com/silverstripe-archive/silverstripe-mollom)
* [Cloudflare Turnstile](https://github.com/silverstripe-terraformers/turnstile-captcha/)
As a developer you can also provide your own protector by creating a class which
implements the `\SilverStripe\SpamProtection\SpamProtector` interface. More on that below.

View File

@ -17,14 +17,16 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/framework": "^4.10"
"php": "^8.1",
"silverstripe/framework": "^5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"silverstripe/versioned": "^1.0",
"squizlabs/php_codesniffer": "^3.0",
"silverstripe/userforms": "^5"
"phpunit/phpunit": "^9.6",
"silverstripe/versioned": "^2",
"squizlabs/php_codesniffer": "^3",
"silverstripe/userforms": "^6",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
},
"extra": {
"expose": [
@ -33,11 +35,11 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\SpamProtection\\": "code/",
"SilverStripe\\SpamProtection\\": "src/",
"SilverStripe\\SpamProtection\\Tests\\": "tests/"
}
},
"license": "BSD-3-Clause",
"minimum-stability": "dev",
"prefer-stable": true
}
}

View File

@ -1,6 +0,0 @@
---
Name: spamprotectionlegacy
---
SilverStripe\ORM\DatabaseAdmin:
classname_value_remapping:
EditableSpamProtectionField: 'SilverStripe\SpamProtection\EditableSpamProtectionField'

View File

@ -2,7 +2,7 @@
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<file>code</file>
<file>src</file>
<file>tests</file>
<rule ref="PSR2" >

3
phpstan.neon.dist Normal file
View File

@ -0,0 +1,3 @@
parameters:
paths:
- src

View File

@ -8,7 +8,7 @@
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">code/</directory>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>

View File

@ -3,7 +3,6 @@
namespace SilverStripe\SpamProtection;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldGroup;
@ -41,15 +40,15 @@ class EditableSpamProtectionField extends EditableFormField
* @var array
* @config
*/
private static $check_fields = array(
private static $check_fields = [
EditableEmailField::class,
EditableTextField::class,
EditableNumericField::class
);
];
private static $db = array(
private static $db = [
'SpamFieldSettings' => 'Text'
);
];
/**
* @var FormField
@ -69,7 +68,7 @@ class EditableSpamProtectionField extends EditableFormField
}
// Extract saved field mappings and update this field.
$fieldMapping = array();
$fieldMapping = [];
foreach ($this->getCandidateFields() as $otherField) {
$mapSetting = "Map-{$otherField->Name}";
$spamField = $this->spamMapValue($mapSetting);
@ -99,14 +98,14 @@ class EditableSpamProtectionField extends EditableFormField
/**
* Gets the list of all candidate spam detectable fields on this field's form
*
* @return DataList
* @return DataList<EditableFormField>
*/
protected function getCandidateFields()
{
// Get list of all configured classes available for spam detection
$types = $this->config()->get('check_fields');
$typesInherit = array();
$typesInherit = [];
foreach ($types as $type) {
$subTypes = ClassInfo::subclassesFor($type);
$typesInherit = array_merge($typesInherit, $subTypes);
@ -132,7 +131,7 @@ class EditableSpamProtectionField extends EditableFormField
{
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
if (empty($fieldMap)) {
$fieldMap = array();
$fieldMap = [];
}
foreach ($this->record as $key => $value) {
@ -152,7 +151,6 @@ class EditableSpamProtectionField extends EditableFormField
*/
public function getCMSFields()
{
/** @var FieldList $fields */
$fields = parent::getCMSFields();
// Get protector
@ -202,7 +200,7 @@ class EditableSpamProtectionField extends EditableFormField
{
$map = json_decode($this->SpamFieldSettings ?? '', true);
if (empty($map)) {
$map = array();
$map = [];
}
if (array_key_exists($mapSetting, $map ?? [])) {

View File

@ -2,31 +2,31 @@
namespace SilverStripe\SpamProtection\Extension;
use SilverStripe\Comments\Controllers\CommentingController;
use SilverStripe\Core\Extension;
/**
* Apply the spam protection to the comments module if it is installed.
*
* @package spamprotection
* @extends Extension<CommentingController>
*/
class CommentSpamProtection extends Extension
{
public function alterCommentForm(&$form)
{
$form->enableSpamProtection(array(
$form->enableSpamProtection([
'name' => 'IsSpam',
'mapping' => array(
'mapping' => [
'Name' => 'authorName',
'Email' => 'authorEmail',
'URL' => 'authorUrl',
'Comment' => 'body',
'ReturnURL' => 'contextUrl'
),
'checks' => array(
],
'checks' => [
'spam',
'profanity'
)
));
]
]);
}
}

View File

@ -6,14 +6,14 @@ use LogicException;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\Form;
/**
* An extension to the {@link Form} class which provides the method
* {@link enableSpamProtection()} helper.
*
* @package spamprotection
* @extends Extension<Form>
*/
class FormSpamProtectionExtension extends Extension
{
use Configurable;
@ -37,7 +37,7 @@ class FormSpamProtectionExtension extends Extension
*
* @var array $mappable_fields
*/
private static $mappable_fields = array(
private static $mappable_fields = [
'id',
'title',
'body',
@ -48,7 +48,7 @@ class FormSpamProtectionExtension extends Extension
'authorUrl',
'authorIp',
'authorId'
);
];
/**
* @config
@ -86,9 +86,9 @@ class FormSpamProtectionExtension extends Extension
*
* @param array $options
* @throws LogicException when get_protector method returns NULL.
* @return Object
* @return Form
*/
public function enableSpamProtection($options = array())
public function enableSpamProtection($options = [])
{
// captcha form field name (must be unique)