Skip to content

Commit

Permalink
ISSUE-217: Ensures info['uid'] to be present for both processing opti…
Browse files Browse the repository at this point in the history
…ons (#218)

* Ensures info['uid'] to be present for both CSV expander and direct processing

* Also for delete operation
  • Loading branch information
DiegoPino authored Sep 5, 2024
1 parent 567fea5 commit cf70fd9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/AmiUtilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,8 @@ public function createAmiSet(\stdClass $data) {
public function preprocessAmiSet(File $file, \stdClass $data, array &$invalid = [], $strict = FALSE): array {

// Use the AMI set user ID for checking access to entity operations.
$account = $data->info['uid'] == \Drupal::currentUser()->id() ? \Drupal::currentUser() : $this->entityTypeManager->getStorage('user')->load($data->info['uid']);
$uid = $data->info['uid'] ?? \Drupal::currentUser()->id();
$account = $uid == \Drupal::currentUser()->id() ? \Drupal::currentUser() : $this->entityTypeManager->getStorage('user')->load($uid);

$file_data_all = $this->csv_read($file);
// We want to validate here if the found Headers match at least the
Expand Down
1 change: 1 addition & 0 deletions src/Form/amiSetEntityDeleteProcessedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
if ($file && $data!== new \stdClass()) {
// Only UUIDs you can delete will be added.
$data->info['uid'] = $this->currentUser()->id();
$uuids = $this->AmiUtilityService->getProcessedAmiSetNodeUUids($file, $data, 'delete');
if (empty($uuids)) {
$form_state->setRebuild();
Expand Down
3 changes: 2 additions & 1 deletion src/Form/amiSetEntityProcessForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->createItem($data_csv);
}
else {
// Add 'uid' to $data->info to unify with new account loader at \Drupal\ami\AmiUtilityService::preprocessAmiSet
$data->info['uid'] = $this->currentUser()->id();
$info = $this->AmiUtilityService->preprocessAmiSet($file, $data, $invalid, FALSE);
// Means preprocess set
if (count($invalid)) {
Expand All @@ -195,7 +197,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
return;
}


foreach ($info as $item) {
// We set current User here since we want to be sure the final owner of
// the object is this and not the user that runs the queue
Expand Down

0 comments on commit cf70fd9

Please sign in to comment.