Skip to content

Commit

Permalink
Merge pull request #1542 from griidc/release/6.56.0
Browse files Browse the repository at this point in the history
Release/6.56.0
  • Loading branch information
mickel1138 authored Mar 5, 2024
2 parents a4a4887 + 07352bc commit 1602331
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 57 deletions.
2 changes: 1 addition & 1 deletion assets/static/js/datasetReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ $(document).ready(function(){
});
buildKeywordLists();

$("form :input").not("input.keywordinput").on('keydown', function(event) {
$("form :input").not("input.keywordinput,textarea").on('keydown', function(event) {
if (event.which == 13) {
return false;
}
Expand Down
23 changes: 23 additions & 0 deletions assets/static/js/submissionKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ $(() => {
gcmdKeywords = JSON.parse(xhr.responseText);
}

const toast = $('#toast').dxToast({}).dxToast('instance');

const treeList = $('#treelist').dxTreeView({
items: anzsrcKeywords,
dataStructure: 'plain',
Expand Down Expand Up @@ -140,6 +142,17 @@ $(() => {
searchPanel: { visible: true },
}).dxTreeView('instance');

function copyToClipboard(text)
{
navigator.clipboard.writeText(text);
toast.option({
message: "Keyword copied to clipboard!",
type: "info",
displayTime: 3000,
});
toast.show();
}

const keywordList = $('#selectedList').dxList({
dataSource: selectedAnzsrcKeywords,
allowItemDeleting: false,
Expand All @@ -157,6 +170,11 @@ $(() => {
keywordList.reload();
keywordList.repaint();
});
$(item.element).find('.dx-tag-remove-button[item=' + item.itemData.id + ']')
.parents('.dx-list-item')
.on('dblclick', (event) => {
copyToClipboard(item.itemData.displayPath);
});
},
onItemDeleted(item) {
var keywordListArray = [];
Expand Down Expand Up @@ -191,6 +209,11 @@ $(() => {
keywordListGcmd.reload();
keywordListGcmd.repaint();
});
$(item.element).find('.dx-tag-remove-button[item=' + item.itemData.id + ']')
.parents('.dx-list-item')
.on('dblclick', (event) => {
copyToClipboard(item.itemData.displayPath);
});
},
onItemDeleted(item) {
var keywordListArray = [];
Expand Down
72 changes: 43 additions & 29 deletions src/Command/GetGoMRIStatisticsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,47 @@
namespace App\Command;

use App\Entity\Dataset;
use App\Entity\DIF;
use App\Entity\DatasetSubmission;
use App\Entity\DIF;
use App\Repository\LogActionItemRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Messenger\MessageBusInterface;
use DateTime;

class GetGoMRIStatisticsCommand extends Command
{
protected static $defaultName = 'pelagos:get-gomri-statistics';
protected static $defaultDescription = 'Produce GoMRI report artifacts.';

/**
* A Doctrine ORM EntityManager instance.
*
* @var EntityManagerInterface $entityManager
*/
protected $entityManager;

/**
* Class constructor for dependency injection.
*
* @param EntityManagerInterface $entityManager A Doctrine EntityManager.
*/
public function __construct(
EntityManagerInterface $entityManager,
private EntityManagerInterface $entityManager,
private LogActionItemRepository $logActionItemRepository,
) {
$this->entityManager = $entityManager;
parent::__construct();
}

protected function configure(): void
{
$this
->setDescription(self::$defaultDescription)
->addArgument('start', InputArgument::OPTIONAL, 'Starting date for DL count')
->addArgument('end', InputArgument::OPTIONAL, 'Ending date for DL count')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$startEpoch = strtotime($input->getArgument('start'));
$endEpoch = strtotime($input->getArgument('end'));

$datasets = $this->entityManager->getRepository(Dataset::class)->findAll();

$datasetCount = 0;
Expand All @@ -61,21 +55,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$totalDatasetSubmittedSince2021Count = 0;

foreach ($datasets as $dataset) {
/** @var Dataset $dataset */
if ($dataset->getDif()->getStatus() === DIF::STATUS_UNSUBMITTED) {
if (DIF::STATUS_UNSUBMITTED === $dataset->getDif()->getStatus()) {
continue;
}
$datasetCount++;
++$datasetCount;
$udi = $dataset->getUdi();
$datasetSubmission = $dataset->getDatasetSubmission();
if ($dataset->getResearchGroup()->getFundingCycle()->getFundingOrganization()->getShortName() === 'GoMRI') {
$gomriDatasetCount++;
if ('GoMRI' === $dataset->getResearchGroup()->getFundingCycle()->getFundingOrganization()->getShortName()) {
++$gomriDatasetCount;
if ($datasetSubmission instanceof DatasetSubmission) {
if ($datasetSubmission->getSubmissionTimeStamp()->format('U') >= DateTime::createFromFormat('d/m/Y', '01/01/2021', new \DateTimeZone('America/Chicago'))->format('U')) {
$totalGomriDatasetSubmittedSince2021Count++;
if ($datasetSubmission->getSubmissionTimeStamp()->format('U') >= \DateTime::createFromFormat('d/m/Y', '01/01/2021', new \DateTimeZone('America/Chicago'))->format('U')) {
++$totalGomriDatasetSubmittedSince2021Count;
}
if ($datasetSubmission->isDatasetFileInColdStorage()) {
$gomriDatasetColdStorageCount++;
++$gomriDatasetColdStorageCount;
$gomriColdStorageDatasetTotalSize += $datasetSubmission->getColdStorageTotalUnpackedSize() ?? 0;
} else {
$gomriDatasetTotalSize += $datasetSubmission->getFileset()?->getFileSize() ?? 0;
Expand All @@ -84,19 +77,40 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($datasetSubmission instanceof DatasetSubmission) {
if ($datasetSubmission->getSubmissionTimeStamp()->format('U') >= DateTime::createFromFormat('d/m/Y', '01/01/2021', new \DateTimeZone('America/Chicago'))->format('U')) {
$totalDatasetSubmittedSince2021Count++;
if ($datasetSubmission->getSubmissionTimeStamp()->format('U') >= \DateTime::createFromFormat('d/m/Y', '01/01/2021', new \DateTimeZone('America/Chicago'))->format('U')) {
++$totalDatasetSubmittedSince2021Count;
}
}
}

$io->writeln("Total GRIIDC Dataset Count: $datasetCount");
$io->writeln("Total number of GoMRI Datasets: $gomriDatasetCount");
$io->writeln("Total Size of GoMRI Datasets: " . round(($gomriDatasetTotalSize + $gomriColdStorageDatasetTotalSize) / 1000000000000, 1) . ' TB');
$io->writeln('Total Size of GoMRI Datasets: ' . round(($gomriDatasetTotalSize + $gomriColdStorageDatasetTotalSize) / 1000000000000, 1) . ' TB');
$io->writeln("Number of GoMRI Datasets in cold storage: $gomriDatasetColdStorageCount");
$io->writeln("Total size of GoMRI Datasets in cold storage: " . round($gomriColdStorageDatasetTotalSize / 1000000000000, 1) . ' TB');
$io->writeln("Total number of GoMRI datasets submitted since 2021-01-01 until current date " . $totalGomriDatasetSubmittedSince2021Count);
$io->writeln("Total number of datasets (all data including GoMRI) submitted since 2021-01-01 until current date " . $totalDatasetSubmittedSince2021Count);
$io->writeln('Total size of GoMRI Datasets in cold storage: ' . round($gomriColdStorageDatasetTotalSize / 1000000000000, 1) . ' TB');
$io->writeln('Total number of GoMRI datasets submitted since 2021-01-01 until current date ' . $totalGomriDatasetSubmittedSince2021Count);
$io->writeln('Total number of datasets (all data including GoMRI) submitted since 2021-01-01 until current date ' . $totalDatasetSubmittedSince2021Count);

if (false != $startEpoch and false != $endEpoch) { // false on strtotime fail
$startDateTime = new \DateTime();
// will assume DST-aware central time if not specified.
$startDateTime->setTimezone(new \DateTimeZone('America/Chicago'));
$startDateTime->setTimestamp($startEpoch);
$dbFormatStartTime = $startDateTime->format('Y-m-d H:i:sO');

$endDateTime = new \DateTime();
$endDateTime->setTimezone(new \DateTimeZone('America/Chicago'));
$endDateTime->setTimestamp($endEpoch);
$dbFormatEndTime = $endDateTime->format('Y-m-d H:i:sO');

$io->writeln("Total GoMRI Downloads from $dbFormatStartTime to $dbFormatEndTime: "
. $this->logActionItemRepository->countDownloads(
$startDateTime,
$endDateTime
));
} else {
$io->writeln('Total GoMRI Downloads: ' . $this->logActionItemRepository->countDownloads());
}

return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,12 @@ public function getHashAlgorithm()
{
return $this->passwordHashAlgorithm;
}

/**
* Return base64 encoded salted password hash.
*/
public function getSSHAPassword(): string
{
return "{SSHA}" . base64_encode(pack('H*', bin2hex($this->getPasswordHash()) . bin2hex($this->getSalt())));
}
}
44 changes: 26 additions & 18 deletions src/Repository/LogActionItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace App\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\Query;
use App\Entity\Dataset;
use App\Entity\LogActionItem;
use App\Util\FundingOrgFilter;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;

/**
* LogActionItem Entity Repository class.
Expand All @@ -23,9 +23,6 @@ class LogActionItemRepository extends ServiceEntityRepository

/**
* Constructor.
*
* @param ManagerRegistry $registry The Registry Manager.
* @param FundingOrgFilter $fundingOrgFilter Utility to filter by funding organization.
*/
public function __construct(ManagerRegistry $registry, FundingOrgFilter $fundingOrgFilter)
{
Expand All @@ -35,20 +32,31 @@ public function __construct(ManagerRegistry $registry, FundingOrgFilter $funding
}

/**
* Sum of all dataset file sizes.
* Count of downloads, optional date range and also filter aware.
*
* @return integer Size of data in bytes.
* @return int the count of the datasets downloaded, per FAIR guidelines
*/
public function countDownloads(): int
public function countDownloads(\DateTime $start = null, \DateTime $stop = null): int
{
$qb = $this->createQueryBuilder('log')
->select('log.creationTimeStamp, log.subjectEntityId')
->where('log.subjectEntityName = ?1')
->andWhere('log.actionName = ?2')
->orderBy('log.subjectEntityId', 'ASC')
->addOrderBy('log.creationTimeStamp', 'ASC')
->setParameter(1, 'Pelagos\Entity\Dataset')
->setParameter(2, 'File Download');
->select('log.creationTimeStamp, log.subjectEntityId')
->where('log.subjectEntityName = :entityName')
->andWhere('log.actionName = :actionName')
->orderBy('log.subjectEntityId', 'ASC')
->addOrderBy('log.creationTimeStamp', 'ASC')
->setParameter('entityName', 'Pelagos\Entity\Dataset')
->setParameter('actionName', 'File Download');

if ($start instanceof \DateTime and $stop instanceof \DateTime) {
$dbFormatStartTime = $start->format('Y-m-d H:i:sO');
$dbFormatEndTime = $stop->format('Y-m-d H:i:sO');

$qb
->andWhere('log.creationTimeStamp >= :start')
->andWhere('log.creationTimeStamp <= :stop')
->setParameter('start', $dbFormatStartTime)
->setParameter('stop', $dbFormatEndTime);
}

if ($this->fundingOrgFilter->isActive()) {
$researchGroupIds = $this->fundingOrgFilter->getResearchGroupsIdArray();
Expand All @@ -72,9 +80,9 @@ public function countDownloads(): int
$dateTime = $timeStamp['creationTimeStamp'];
$epochTime = (int) $dateTime->format('U');

if ($key === array_key_first($downloads) or ($epochTime - $currentTimeStamp) > 30 or $currentId <> $id) {
if ($key === array_key_first($downloads) or ($epochTime - $currentTimeStamp) > 30 or $currentId != $id) {
$currentTimeStamp = $epochTime;
$downloadCount++;
++$downloadCount;
}

$currentId = $id;
Expand Down
13 changes: 8 additions & 5 deletions src/Util/Ldap/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public function addPerson(Person $person)
*
* @return void
*/
public function updatePerson(Person $person)
public function updatePerson(Person $person, bool $recreate = true)
{
$uidNumber = $person->getAccount()->getUidNumber();
if ($this->checkIfUidNumberAvailable($uidNumber, $person->getAccount()->getUserName())) {
$ldapPerson = $this->buildLdapPerson($person);
$this->ldapClient->modify($ldapPerson['dn'], $ldapPerson['entry']);
if ($recreate) {
$this->ldapClient->delete($ldapPerson['dn']);
$this->ldapClient->add($ldapPerson['dn'], $ldapPerson['entry']);
} else {
$this->ldapClient->modify($ldapPerson['dn'], $ldapPerson['entry']);
}
} else {
throw new UidNumberInUseInLDAPException("This UID number ($uidNumber) is already in use in LDAP .");
}
Expand Down Expand Up @@ -117,9 +122,7 @@ protected function buildLdapPerson(Person $person)
),
);

if ($person->getAccount()->getPasswordEntity()->getClearTextPassword() != null) {
$ldapPerson['entry']['userPassword'] = $person->getAccount()->getPasswordEntity()->getClearTextPassword();
}
$ldapPerson['entry']['userPassword'] = $person->getAccount()->getPasswordEntity()->getSSHAPassword();

$accessor = PropertyAccess::createPropertyAccessor();

Expand Down
1 change: 0 additions & 1 deletion src/Util/POSIXifyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function POSIXifyAccount(Account $account)

// Update LDAP with this modified Account (via Person).
$this->ldap->updatePerson($account->getPerson());

// Persist changes.
$this->entityHandler->update($account);
}
Expand Down
6 changes: 3 additions & 3 deletions templates/Dataland/v2/collection-period-card.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
</div>
<div class="card-body">
<div class="card-body">
<p class="card-text text-dark whitespace-nowrap text-nowrap">
{{ begin }}
<p class="card-text text-dark text-wrap">
<span class="whitespace-nowrap">{{ begin }}</span>
to
{{ end }}
<span class="whitespace-nowrap">{{ end }}</span>
</p>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions templates/DatasetSubmission/standard-keywords.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div id="toast"></div>

<div id="keyword-items">
{% set keywords = [] %}
{% for keyword in form.keywords %}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Entity/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ public function testGetHash()
$this->assertNotNull($this->password->getPasswordHash());
}

/**
* Test that the SSHA hash can be returned.
*
* @return void
*/
public function testGetSSHAHash()
{
$this->assertNotNull($this->password->getSSHAPassword());
}

/**
* Test that the hash alrorithm can be retrieved from the Password entity.
*
Expand Down

0 comments on commit 1602331

Please sign in to comment.