Skip to content

Commit

Permalink
Merge pull request #316 from SlateFoundation/develop
Browse files Browse the repository at this point in the history
Release: v2.17.1
  • Loading branch information
themightychris authored Dec 17, 2021
2 parents fbf392e + b33efdc commit 8a12bc3
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 40 deletions.
96 changes: 56 additions & 40 deletions cypress/integration/SlateAdmin/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('SlateAdmin: Contacts', () => {

// edit and save address via form
cy.get('.contact-postal').eq(-2)
.contains('.contact-cell-value', '908 N 3rd St, Suite B, Philadelphia, PA 19123')
.find('.contact-cell-value .x-grid-cell-inner')
.should('have.text', '908 N 3rd St, Suite B, Philadelphia, PA 19123')
.click();

cy.focused()
Expand All @@ -72,7 +73,8 @@ describe('SlateAdmin: Contacts', () => {

// edit and save address via composite string
cy.get('.contact-postal').eq(-2)
.contains('.contact-cell-value', 'Localhost, 908 N 3rd St, Suite A, Philadelphia, PA 19123')
.find('.contact-cell-value .x-grid-cell-inner')
.should('have.text', 'Localhost, 908 N 3rd St, Suite A, Philadelphia, PA 19123')
.click();

cy.focused()
Expand All @@ -83,8 +85,11 @@ describe('SlateAdmin: Contacts', () => {
cy.get('@saveContactPoint.all').should('have.length', 3);

cy.get('.contact-postal').eq(-2)
.contains('.contact-cell-value', 'Localhost, 908 N 3rd St, Suite A, Philly')
.find('.contact-cell-value')
.within(() => {
cy.get('.x-grid-cell-inner')
.should('have.text', 'Localhost, 908 N 3rd St, Suite A, Philly');

cy.root()
.should('have.class', 'x-grid-dirty-cell')
.trigger('mouseover')
Expand All @@ -102,7 +107,8 @@ describe('SlateAdmin: Contacts', () => {
cy.get('@saveContactPoint.all').should('have.length', 4);

cy.get('.contact-postal').eq(-2)
.contains('.contact-cell-value', 'Localhost, 908 N 3rd St, Suite A, Philly, PA')
.find('.contact-cell-value .x-grid-cell-inner')
.should('have.text', 'Localhost, 908 N 3rd St, Suite A, Philly, PA');


// add a second address via form
Expand Down Expand Up @@ -165,7 +171,8 @@ describe('SlateAdmin: Contacts', () => {
cy.get('.x-grid-cell').eq(1)
.should('not.have.class', 'x-grid-dirty-cell');

cy.contains('.contact-cell-value', 'The White House, 1600 Pennsylvania Avenue NW, Washington, DC 20500');
cy.get('.contact-cell-value .x-grid-cell-inner')
.should('have.text', 'The White House, 1600 Pennsylvania Avenue NW, Washington, DC 20500');

cy.intercept('POST', '/people/save?*').as('savePerson');

Expand Down Expand Up @@ -208,7 +215,8 @@ describe('SlateAdmin: Contacts', () => {
cy.get('@saveContactPoint.all').should('have.length', 6);

cy.get('.contact-postal').eq(-2)
.contains('.contact-cell-value', 'The White House, 1600 Pennsylvania Avenue NW, Suite 123, Washington, DC 20500');
.find('.contact-cell-value .x-grid-cell-inner')
.should('have.text', 'The White House, 1600 Pennsylvania Avenue NW, Suite 123, Washington, DC 20500');


// save invalid via text field and then overwrite with form
Expand All @@ -224,47 +232,55 @@ describe('SlateAdmin: Contacts', () => {
cy.get('@saveContactPoint.all').should('have.length', 7);

cy.get('.contact-postal').eq(-3)
.contains('.contact-cell-value', 'Hello world')
.within(() => {
cy.root()
.should('have.class', 'x-grid-dirty-cell')
.trigger('mouseover')
.should('have.attr', 'data-errorqtip')
.and('match', /Street number is required/i)
.and('match', /Street name is required/i)
.and('match', /Postal code or city\+state is required/i);

cy.root()
.click();

cy.focused()
.closest('.x-form-trigger-wrap')
.find('.x-form-trigger')
.find('.contact-cell-value')
.within(() => {
cy.get('.x-grid-cell-inner')
.should('have.text', 'Hello world');

cy.root()
.should('have.class', 'x-grid-dirty-cell')
.trigger('mouseover')
.should('have.attr', 'data-errorqtip')
.and('match', /Street number is required/i)
.and('match', /Street name is required/i)
.and('match', /Postal code or city\+state is required/i);

cy.root()
.click();
});

cy.get('.contact-postal-picker-form').within(() => {
cy.get('input[name=city]')
.click()
.type('{selectall}{backspace}Philadelphia');
cy.focused()
.closest('.x-form-trigger-wrap')
.find('.x-form-trigger')
.click();
});

cy.get('input[name=postal]')
.click()
.type('19123');
cy.get('.contact-postal-picker-form').within(() => {
cy.get('input[name=city]')
.click()
.type('{selectall}{backspace}Philadelphia');

cy.contains('.x-btn-button', 'Save')
.click();
});
cy.get('input[name=postal]')
.click()
.type('19123');

cy.wait('@saveContactPoint');
cy.get('@saveContactPoint.all').should('have.length', 8);
cy.contains('.x-btn-button', 'Save')
.click();
});

cy.get('.contact-postal').eq(-3)
.contains('.contact-cell-value', 'Localhost, 908 N 3rd St, Suite A, Philadelphia, PA 19123')
.should('not.have.class', 'x-grid-dirty-cell')
.trigger('mouseover')
.should('have.attr', 'data-errorqtip', '');
cy.wait('@saveContactPoint');
cy.get('@saveContactPoint.all').should('have.length', 8);

cy.get('.contact-postal').eq(-3)
.find('.contact-cell-value')
.within(() => {
cy.get('.x-grid-cell-inner')
.should('have.text', 'Localhost, 908 N 3rd St, Suite A, Philadelphia, PA 19123');

cy.root()
.should('not.have.class', 'x-grid-dirty-cell')
.trigger('mouseover')
.should('have.attr', 'data-errorqtip', '');
});
});

});
164 changes: 164 additions & 0 deletions site-root/powertools/user-data-report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

use Emergence\People\IPerson;

// configure request/response
$GLOBALS['Session']->requireAccountLevel('Administrator');
set_time_limit(0);
header('Content-Type: text/html; charset=utf-8');

// get input scope
if (empty($_GET['person'])) {
$Person = null;
} elseif (!$Person = PeopleRequestHandler::getRecordByHandle($_GET['person'])) {
throw new OutOfBoundsException(sprintf('person "%s" not found', $_GET['person']));
}

?>

<form method="GET">
<fieldset>
<legend>Analyze a person record</legend>
<div>
<label>
Person: <input type="text" name="person" value="<?=!empty($_GET['person']) ? htmlspecialchars($_GET['person']) : ''; ?>">
</label>
</div>
<div>
<input type="submit" value="Prepare report">
</div>
</fieldset>
</form>

<?php

function getRecordsForTable($Person, $tableName, $field = 'PersonID') {

return DB::allRecords(
'SELECT * FROM `%s` WHERE %u IN (%s)',
[
$tableName,
$Person->ID,
join(',', is_array($field) ? $field : [$field]),
]
);
}

$reports = [
'Enrollments' => function (IPerson $Person) {
return getRecordsForTable($Person, Slate\Courses\SectionParticipant::$tableName);
},
'Comments' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\Comments\Comment::$tableName, 'CreatorID');
},
'Contact Points' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\People\ContactPoint\AbstractPoint::$tableName);
},
'Content Created/Authored' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\CMS\AbstractContent::$tableName, ['CreatorID', 'AuthorID']);
},
'Groups Assigned' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\People\Groups\GroupMember::$tableName);
},
'Invitations' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\People\Invitation::$tableName, 'RecipientID');
},
'Media Created' => function (IPerson $Person) {
return getRecordsForTable($Person, Media::$tableName, 'CreatorID');
},
'Media Context' => function (IPerson $Person) {
return DB::allRecords(
'SELECT * FROM `%s` WHERE ContextClass = "%s" AND ContextID = %u',
[
Media::$tableName,
DB::escape(Emergence\People\Person::class),
$Person->ID
]
);
},
'Messages Created/Authored' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\CRM\Message::$tableName, ['CreatorID', 'AuthorID']);
},
'Messages Received' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\CRM\MessageRecipient::$tableName);
},
'Relationships' => function (IPerson $Person) {
return getRecordsForTable($Person, Emergence\People\Relationship::$tableName, ['PersonID', 'RelatedPersonID']);
},
'Interim Reports' => function (IPerson $Person) {
return getRecordsForTable($Person, Slate\Progress\SectionInterimReport::$tableName, 'StudentID');
},
'Interim Reports Sent' => function (IPerson $Person) {
$emailContactPointIDs = DB::allValues(
'ID',
'SELECT ID FROM `%s` WHERE Class = "%s" AND PersonID = %u',
[
Emergence\People\ContactPoint\Email::$tableName,
DB::escape(Emergence\People\ContactPoint\Email::class),
$Person->ID
]
);

if (empty($emailContactPointIDs)) {
return [];
}

return DB::allRecords(
'SELECT * FROM `%s` WHERE EmailContactID IN (%s)',
[
Slate\Progress\SectionInterimReportRecipient::$tableName,
join(',', $emailContactPointIDs)
]
);
},
'Term Reports' => function (IPerson $Person) {
return getRecordsForTable($Person, Slate\Progress\SectionTermReport::$tableName, 'StudentID');
},
'Term Reports Sent' => function (IPerson $Person) {
$emailContactPointIDs = DB::allValues(
'ID',
'SELECT ID FROM `%s` WHERE Class = "%s" AND PersonID = %u',
[
Emergence\People\ContactPoint\Email::$tableName,
DB::escape(Emergence\People\ContactPoint\Email::class),
$Person->ID
]
);

if (empty($emailContactPointIDs)) {
return [];
}

return DB::allRecords(
'SELECT * FROM `%s` WHERE EmailContactID IN (%s)',
[
Slate\Progress\SectionTermReportRecipient::$tableName,
join(',', $emailContactPointIDs)
]
);
},
'Tags' => function (IPerson $Person) {
return DB::allRecords(
'SELECT * FROM `%s` WHERE ContextClass = "%s" AND ContextID = %u',
[
TagItem::$tableName,
DB::escape(Emergence\People\Person::class),
$Person->ID
]
);
},
];

?>

<h2>Data report for <?=htmlspecialchars($Person->FullName)?></h2>

<dl>
<?php foreach ($reports as $reportName => $reportFunction) : ?>
<?php $records = $reportFunction($Person) ?>

<dt><?=$reportName?></dt>
<dd><?=count($records)?></dd>

<?php endforeach ?>
</dl>

0 comments on commit 8a12bc3

Please sign in to comment.