Skip to content

Commit

Permalink
Complete customization of instructions and sending after dropbox created
Browse files Browse the repository at this point in the history
connecting the dots between saving instructions and sending emails

the sending emails action now load and send custom instructions if they exists,
otherwise send instructions from template (that's the change in DatasetUpload)

#168 done.
  • Loading branch information
Rija Menage authored and rija committed Sep 15, 2020
1 parent 9535cda commit 4c0d7b0
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 29 deletions.
10 changes: 9 additions & 1 deletion fuw/app/common/tests/_support/Step/Acceptance/CuratorSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ public function iShouldSee($arg1)
$this->I->canSee($arg1);
}

/**
/**
* @Then I should not see a :arg1 link
*/
public function iShouldNotSeeALink($arg1)
{
$this->I->cantSeeLink($arg1);
}

/**
* @Then I am on :arg1
*/
public function iAmOn($arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Scenario: Triggering the creation of a drop box for a dataset with the appropria
When I press "Datasets"
And I press "New Dropbox for this dataset"
And I wait "2" seconds
Then I should see "A new drop box has been created for this dataset."
Then I should see "A new drop box has been created for the dataset 100006."
And I should see "UserUploadingData"

@ok
Expand All @@ -34,7 +34,7 @@ Scenario: The drop box is created, we can send email instructions
When I press "Datasets"
And I press "New Dropbox for this dataset"
And I wait "2" seconds
Then I should see "A new drop box has been created for this dataset."
Then I should see "A new drop box has been created for the dataset 100006."
And I should see a "Send instructions by email" link
And I should see a "Customize instructions" link
And I am on "/adminDataset/admin"
Expand All @@ -48,6 +48,7 @@ Scenario: send default email instructions
And I wait "2" seconds
And I press "Send instructions by email"
Then I should see "Instructions sent."
And I should not see a "Send instructions by email" link

@ok
Scenario: Popup composer for customizing and sending email instructions
Expand All @@ -62,7 +63,7 @@ Scenario: Popup composer for customizing and sending email instructions
And I should see a "Save changes" link


@wip
@ok
Scenario: Popup composer for customizing and sending email instructions
Given I sign in as an admin
And I go to "/site/admin"
Expand Down
23 changes: 13 additions & 10 deletions protected/components/DatasetUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,22 @@ public function renderUploadInstructions(array $filedropAccount): string
// Retrieve info about the dataset
$dataset_info = $this->_filedrop->dataset->getTitleAndStatus();

// prepare array of variables to be interpolated
$vars = array_merge($filedropAccount, $dataset_info, $this->_config);
$instructions = $filedropAccount['instructions']; //preferably use saved instructions
if (!$instructions) { // otherwise create from template and interpolate properties
// prepare array of variables to be interpolated
$vars = array_merge($filedropAccount, $dataset_info, $this->_config);

// create a template loader from specific directory in file system
$loader = new \Twig\Loader\FilesystemLoader(
$this->_config['template_path']
);
// create a template loader from specific directory in file system
$loader = new \Twig\Loader\FilesystemLoader(
$this->_config['template_path']
);

// instantiate template environment object for rendering to be called upon
$twig = new \Twig\Environment($loader);
// instantiate template environment object for rendering to be called upon
$twig = new \Twig\Environment($loader);

// render the email instructions from template
$instructions = $twig->render('emailInstructions.twig', $vars);
// render the email instructions from template
$instructions = $twig->render('emailInstructions.twig', $vars);
}

return $instructions;
}
Expand Down
6 changes: 1 addition & 5 deletions protected/controllers/adminDataset/AssignFTPBoxAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ public function run($id)
]);

$response = $filedropSrv->createAccount();
$message = "";
if (!$response) {
$message = "An error occured. Drop box not created";
Yii::app()->user->setFlash('error',$message);
Yii::app()->user->setFlash('error',"An error occured. Drop box not created");
$this->getController()->redirect("/adminDataset/admin/");
}

$message = "A new drop box has been created for this dataset.";
Yii::app()->user->setFlash('success',$message);
Yii::app()->session["filedrop_id_".Yii::app()->user->id] = array($id, $response['id']);

$this->getController()->redirect("/adminDataset/admin/");
Expand Down
47 changes: 47 additions & 0 deletions protected/tests/unit/DatasetUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,52 @@ public function testRenderUploadInstructions()
$this->assertTrue(0 == preg_match('/a97b3/', $renderedInstructions));
}

public function testRenderCustomizedInstructions()
{
$config = [
"ftpd_endpoint" => "localhost",
"ftpd_port" => "9021",
"template_path" => "/var/www/files/templates",
];

$filedrop_id = 1;

// set mocks and expected behaviour

$filedropAccountHash = array('upload_login' => 'uploader-232452',
'upload_token' => '9ad4sf',
'download_login' => 'downloader-286652',
'download_token' => 'a97b3',
'instructions' => 'custom instructions here');

$mockDatasetDAO = $this->createMock(DatasetDAO::class);
$mockFiledropSrv = $this->createMock(FiledropService::class);

$mockDatasetDAO->expects($this->once())
->method('getTitleAndStatus')
->willReturn(array('title' => 'foo', 'status' => 'bar'));

$mockFiledropSrv->dataset = $mockDatasetDAO;


$datasetUpload = new DatasetUpload($filedrop_id, $mockFiledropSrv, $config);

$renderedInstructions = $datasetUpload->renderUploadInstructions($filedropAccountHash);
$this->assertNotNull($renderedInstructions);

//veriyfing that Twig has NOT interpolated the template tags with the variables
$this->assertTrue(1 == preg_match('/custom instructions here/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/foo/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/bar/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/host: localhost/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/port: 9021/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/username: uploader-232452/', $renderedInstructions));
$this->assertFalse(1 == preg_match('/password: 9ad4sf/', $renderedInstructions));

// makes sure that unusued template tags don't get interpolated
$this->assertTrue(0 == preg_match('/downloader-286652/', $renderedInstructions));
$this->assertTrue(0 == preg_match('/a97b3/', $renderedInstructions));
}

}
?>
49 changes: 39 additions & 10 deletions protected/views/adminDataset/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
</div>
<?php } ?>

<?php if( Yii::app()->session["filedrop_id_".Yii::app()->user->id] ) { ?>
<?php if( Yii::app()->session["filedrop_id_".Yii::app()->user->id]) {
[$doi, $fid] = Yii::app()->session["filedrop_id_".Yii::app()->user->id];
?>
<div class="button-panel panel" role="alert">
<div class="panel-heading header alert-success">A filedrop account has been created</div>
<div class="panel-heading header alert-success">A new drop box has been created for the dataset <?php echo $doi ?>.</div>
<div class="panel-body controls">
<?php
[$doi, $fid] = Yii::app()->session["filedrop_id_".Yii::app()->user->id];

echo CHtml::link('Customize instructions','#', array('class' => 'btn btn-primary', 'data-toggle' => "modal", 'data-target' => "#editInstructions"));

Expand Down Expand Up @@ -108,26 +109,54 @@
),
)); ?>

<?php if( Yii::app()->session["filedrop_id_".Yii::app()->user->id]) { ?>

<div class="modal fade" id="editInstructions" tabindex="-1" role="dialog" aria-labelledby="Customize Instructions">
<div class="modal fade" id="editInstructions" tabindex="-1" role="dialog" aria-labelledby="customizeInstructions">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Customize</h4>
<h4 class="modal-title">Write custom upload instructions</h4>
</div>
<div class="modal-body">
<form>
<label for="instructions">Instructions</label>
<form id="instructionsForm">
<label for="instructions" class="control-label">Instructions</label>
<textarea id="instructions" name="instructions"
rows="5" cols="33">
class="form-control" rows="6" cols="120" tabindex="0">
</textarea>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a href="#" class="btn btn-primary" alt="Save changes">Save changes</a>
<a id="saveLink" href="#" class="btn btn-primary" alt="Save changes" >Save changes</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div><!-- /.modal -->
<script>
document.addEventListener("DOMContentLoaded", function(event) {//after deferred scripts loaded

// $('#editInstructions').on('hidden.bs.modal', function (e) {
// console.log("Hidden!");
// });
$('#editInstructions').on('shown.bs.modal', function (e) {
document.querySelector("#instructions").focus();
});
// document.querySelector("#editInstructions").addEventListener("shown.bs.modal", function (event) {
// console.log("Shown!");
// document.querySelector("#instructions").focus();
// });
document.querySelector("#saveLink").addEventListener("click", function(event) {
event.preventDefault();
<?php
echo 'var doi = "'.$doi.'";';
echo 'var fid = "'.$fid.'";';
?>
var myForm = document.getElementById('instructionsForm') ;
myForm.method = 'post';
myForm.action = "/adminDataset/saveInstructions/id/"+doi+"/fid/" +fid ;
myForm.submit();
});
});
</script>
<?php } ?>

0 comments on commit 4c0d7b0

Please sign in to comment.