tourze / user-agreement-bundle
用户协议管理,支持协议签署、撤销等功能的 Symfony Bundle
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/user-agreement-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- knplabs/knp-menu: ^3.7
- medz/gb-t-2260: ^2.0
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/event-dispatcher-contracts: ^2.5 | ^3
- symfony/http-kernel: ^6.4
- symfony/security-bundle: ^6.4
- symfony/security-core: ^6.4
- symfony/security-http: ^6.4
- symfony/serializer: ^6.4
- tourze/arrayable: 0.0.*
- tourze/bundle-dependency: 0.0.*
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-ip-bundle: 0.0.*
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-track-bundle: 0.1.*
- tourze/doctrine-upsert-bundle: 0.1.*
- tourze/doctrine-user-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/easy-admin-extra-bundle: 0.1.*
- tourze/easy-admin-menu-bundle: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/json-rpc-core: 0.0.*
- tourze/json-rpc-lock-bundle: 0.1.*
- tourze/json-rpc-log-bundle: 0.1.*
- tourze/symfony-aop-async-bundle: 0.0.*
- tourze/user-event-bundle: 0.0.*
- tourze/user-id-bundle: 0.1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-31 20:07:58 UTC
README
A Symfony bundle for managing user agreements, protocols, and consent records. This bundle provides comprehensive functionality for handling user terms of service, privacy policies, and user account deletion requests in compliance with data protection regulations.
Table of Contents
- Features
- Installation
- Configuration
- Quick Start
- Advanced Usage
- Protocol Types
- Revocation Types
- JSON-RPC API
- Admin Interface
- Compliance Features
- Requirements
- Contributing
- License
Features
- Protocol Management: Create and manage different types of user agreements (registration, usage, privacy, marketing)
- Consent Tracking: Record and track user agreement to protocols with IP tracking
- Account Deletion: Handle user account deletion requests with different revocation types
- Admin Interface: EasyAdmin integration for backend management
- JSON-RPC API: Programmatic access to agreement functionality
- GDPR Compliance: Built-in support for data protection requirements
Installation
composer require tourze/user-agreement-bundle
Add the bundle to your config/bundles.php:
return [ // ... UserAgreementBundle\UserAgreementBundle::class => ['all' => true], ];
Configuration
Basic Configuration
Create config/packages/user_agreement.yaml:
user_agreement: enabled: true ip_tracking: true retention_period: 365 # days
Database Setup
Run the migrations to create required database tables:
php bin/console doctrine:migrations:migrate
Admin Interface
Enable EasyAdmin integration in config/packages/easy_admin.yaml:
easy_admin: entities: ProtocolEntity: class: UserAgreementBundle\Entity\ProtocolEntity AgreeLog: class: UserAgreementBundle\Entity\AgreeLog RevokeRequest: class: UserAgreementBundle\Entity\RevokeRequest
Quick Start
1. Create Protocol Entities
use UserAgreementBundle\Entity\ProtocolEntity; use UserAgreementBundle\Enum\ProtocolType; $protocol = new ProtocolEntity(); $protocol->setType(ProtocolType::PRIVACY); $protocol->setTitle('Privacy Policy'); $protocol->setVersion('1.0'); $protocol->setContent('Your privacy policy content...'); $protocol->setRequired(true); $protocol->setEffectiveTime(new \DateTimeImmutable()); $entityManager->persist($protocol); $entityManager->flush();
2. Record User Agreement
use UserAgreementBundle\Entity\AgreeLog; $agreeLog = new AgreeLog(); $agreeLog->setMemberId($user->getId()); $agreeLog->setProtocolId($protocol->getId()); $agreeLog->setValid(true); $entityManager->persist($agreeLog); $entityManager->flush();
3. Handle Deletion Requests
use UserAgreementBundle\Entity\RevokeRequest; use UserAgreementBundle\Enum\RevokeType; $revokeRequest = new RevokeRequest(); $revokeRequest->setUser($user); $revokeRequest->setType(RevokeType::All); $revokeRequest->setRemark('User requested account deletion'); $entityManager->persist($revokeRequest); $entityManager->flush();
Advanced Usage
Custom Protocol Validation
use Symfony\Component\Validator\Constraints as Assert; #[Assert\Callback] public function validateProtocol(ExecutionContextInterface $context): void { if ($this->type === ProtocolType::PRIVACY && empty($this->content)) { $context->buildViolation('Privacy policy content is required') ->atPath('content') ->addViolation(); } }
Event-Driven Architecture
use UserAgreementBundle\Event\AgreeProtocolEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ProtocolSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(): array { return [ AgreeProtocolEvent::class => 'onProtocolAgreed', ]; } public function onProtocolAgreed(AgreeProtocolEvent $event): void { // Custom logic when user agrees to protocol $protocol = $event->getProtocol(); $user = $event->getUser(); // Send confirmation email, log activity, etc. } }
Service Integration
use UserAgreementBundle\Service\MemberService; class MyService { public function __construct( private MemberService $memberService, ) {} public function processUser(UserInterface $user): void { $memberId = $this->memberService->extractMemberId($user); // Process user agreement logic } }
Protocol Types
MEMBER_REGISTER: User registration agreementMEMBER_USAGE: User usage termsPRIVACY: Privacy policySALE_PUSH: Marketing communications consent
Revocation Types
All: Complete account deletionNO_NOTIFY: Keep profile but opt out of notificationsNOTIFY: Keep profile and allow notifications
JSON-RPC API
The bundle provides JSON-RPC procedures for external integration:
ApiAgreeSystemProtocol: Record user agreement to protocolsApiGetSystemProtocolContent: Retrieve protocol content
Admin Interface
Access the admin interface through EasyAdmin:
- Protocol management:
/admin/protocol - Agreement logs:
/admin/agree-log - Deletion requests:
/admin/revoke-request
Compliance Features
- IP Tracking: Automatically records IP addresses for audit trails
- Version Control: Protocol versioning for regulatory compliance
- Consent Records: Immutable logs of user agreements
- Data Retention: Proper handling of user data deletion requests
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.