Skip to content

2.0.0

Compare
Choose a tag to compare
@nasrulhazim nasrulhazim released this 31 Oct 16:41
· 32 commits to main since this release

Version 2.0 marks a new major release of the ResourceAction class, introducing enhanced flexibility, field transformation, and constraint handling, along with improvements in naming and structure. This release requires some upgrade changes for existing implementations.

Full Changelog: 1.6.0...2.0.0


Major Changes

  • Class Rename from AbstractAction to ResourceAction:
    • The foundational abstract class has been renamed from AbstractAction to ResourceAction to better reflect its purpose and usage in handling resources.
    • Upgrade Note: Update all references in your codebase to ResourceAction:
      use CleaniqueCoders\LaravelAction\ResourceAction;
    • Example Upgrade:
      - use CleaniqueCoders\LaravelAction\AbstractAction;
      + use CleaniqueCoders\LaravelAction\ResourceAction;

New Features and Improvements

  • Flexible Property Setter:

    • Introduced a generic setProperty method to dynamically set properties like hashFields, encryptFields, and constrainedBy, reducing code duplication and improving maintainability.
    • Previous Usage:
      $action->setHashFields(['password']);
      $action->setEncryptFields(['ssn']);
      $action->setConstrainedBy(['email' => 'johndoe@example.com']);
    • New Usage:
      $action->setProperty('hashFields', ['password']);
      $action->setProperty('encryptFields', ['ssn']);
      $action->setProperty('constrainedBy', ['email' => 'johndoe@example.com']);
    • Benefits: This update allows developers to set class properties dynamically and flexibly, streamlining the syntax and reducing boilerplate code.
  • Field Transformation with Hashing and Encryption:

    • Added support for specifying fields that require hashing and encryption, with the ability to apply both transformations independently or in combination on selected fields.
    • Example Usage:
      $inputs = [
          'name' => 'Jane Doe',
          'email' => 'janedoe@example.com',
          'password' => 'securepassword',
          'ssn' => '123-45-6789',
      ];
      
      $action = new CreateUserAction($inputs);
      $action->setProperty('hashFields', ['password']);
      $action->setProperty('encryptFields', ['ssn']);
      $record = $action->execute();
      
      // Results:
      // - 'password' field will be hashed using bcrypt.
      // - 'ssn' field will be encrypted for security.
    • Benefits: This feature provides fine-grained control over sensitive data, allowing selective application of security measures for each field.
  • Enhanced Test Suite:

    • A comprehensive suite of tests now covers essential scenarios, including:
      • Basic data creation and required field validation.
      • Applying multiple transformations with hashing and encryption on specific fields.
      • Using constraints to test updateOrCreate functionality, supporting scenarios like identifying records by id for unique constraint tests.
      • Conditional transformation to skip optional fields when they’re missing from inputs.
      • Validating transaction usage to confirm atomicity during execution.
    • Example of updateOrCreate with Constraints:
      // Initial user creation with a unique constraint on 'email'.
      $existingUser = User::create([
          'name' => 'Old Name',
          'email' => 'uniqueemail@example.com',
          'password' => Hash::make('oldpassword'),
      ]);
      
      // Update the existing user by constraining on 'id'.
      $inputs = [
          'name' => 'John Doe Updated',
          'email' => 'uniqueemail@example.com',
          'password' => 'newpassword',
      ];
      
      $action = new CreateUserAction($inputs);
      $action->setProperty('constrainedBy', ['id' => $existingUser->id]); // Use ID as a constraint for updating
      
      $record = $action->execute();
      
      // Expected result:
      // - The existing user record with the specified 'id' will be updated with new data.
    • Benefits: The updated test suite ensures that key functionality is covered and validated, making the ResourceAction class highly reliable and secure in various scenarios.

Summary of Benefits

This release delivers major improvements in flexibility, maintainability, and security within the ResourceAction class. By supporting dynamic property setting, targeted data transformations, and reliable constraint handling, Version 2.0 is positioned for robust, secure applications.

Upgrade Notes

  • Update Class Name: Replace all references to AbstractAction with ResourceAction in your codebase.
  • Test and Verify: If you have custom implementations extending the AbstractAction class, ensure they are updated to use the new ResourceAction class and test thoroughly.