Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk Edit Tests and Tweaks #14707

Merged
merged 7 commits into from
May 15, 2024
Merged

Bulk Edit Tests and Tweaks #14707

merged 7 commits into from
May 15, 2024

Conversation

spencerrlongg
Copy link
Collaborator

Description

This introduces some bulk edit tests, includes some tweaks to factories, an extra gate, and the flipping of keys and values in an array.

The key value flip is because the array was originally
'id' => 'key'
but now is properly
'key' => 'id'

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

These are tests. 😄

Test Configuration:

  • PHP version: 8.1
  • MySQL version: 8.2

Copy link

what-the-diff bot commented May 9, 2024

PR Summary

  • Improving Security and Rights Management in BulkAssetsController
  • Security measures in the BulkAssetsController.php have been enhanced by adding new import statements, ensuring only administrators can modify certain sensitive data within the system.
  • The process of updating data has been optimized by using an existing array within the update method.
  • Removed redundant return comment.
  • The clarity of the code has been improved by changing variable names to be more descriptive.
  • New Method to Create Asset Models with Multiple Custom Fields
  • Methods named hasMultipleCustomFields have been added in AssetFactory.php, AssetModelFactory.php, and CustomFieldsetFactory.php, providing a way to easily create and manage different asset models with multiple custom fields, streamlining the modeling process and saving precious development time.
  • Improving Code Clarity in Hardware View
  • Changes in hardware/bulk.blade.php have been made to improve and simplify the code, making it easier to understand and maintain.
  • Enhancement of Asset Bulk Editing Tests
  • The AssetsBulkEditTest.php now includes additional tests ranging from access rights management to verifying the correct behavior of the bulk editing functionality.
  • There are tests added to check if encrypted and unencrypted custom fields can be updated accurately and appropriately.
  • Furthermore, the test coverage has enhanced to ensure that only admin users can update encrypted custom fields.

Each of these modifications contributes to improved system security, code quality, and test coverage, resulting in a more robust and reliable software.

Comment on lines -382 to -403
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});

/*
* Check if the decrypted existing value is different from one we just submitted
* and if not, pull it out of the object since it shouldn't really be updating at all.
* If we don't do this, it will try to re-encrypt it, and the same value encrypted two
* different times will have different values, so it will *look* like it was updated
* but it wasn't.
*/
if ($decrypted_old != $this->update_array[$field->db_column]) {
$asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]);
} else {
if (Gate::allows('admin')) {
$decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column});

/*
* Remove the encrypted custom field from the update_array, since nothing changed
* Check if the decrypted existing value is different from one we just submitted
* and if not, pull it out of the object since it shouldn't really be updating at all.
* If we don't do this, it will try to re-encrypt it, and the same value encrypted two
* different times will have different values, so it will *look* like it was updated
* but it wasn't.
*/
unset($this->update_array[$field->db_column]);
unset($asset->{$field->db_column});
}
if ($decrypted_old != $this->update_array[$field->db_column]) {
$asset->{$field->db_column} = Crypt::encrypt($this->update_array[$field->db_column]);
} else {
/*
* Remove the encrypted custom field from the update_array, since nothing changed
*/
unset($this->update_array[$field->db_column]);
unset($asset->{$field->db_column});
}

/*
* These custom fields aren't encrypted, just carry on as usual
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think this diff is so weird because of the added indentation 😢

@snipe
Copy link
Owner

snipe commented May 15, 2024

Nice work!

@snipe snipe merged commit eb09a99 into snipe:develop May 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants