Skip to content

Commit

Permalink
Merge branch 'externalAuthorsChanges-696' into 'main'
Browse files Browse the repository at this point in the history
Mudanças em relação a coleta de dados de autores externos

See merge request softwares-pkp/plugins_ojs/demographicData!11
  • Loading branch information
JhonathanLepidus committed Sep 18, 2024
2 parents 34a3c07 + dfed618 commit cd798bb
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 35 deletions.
67 changes: 67 additions & 0 deletions classes/DemographicDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,57 @@ public function registerExternalAuthorResponses(string $externalId, string $exte
}
}

public function getExternalAuthorResponses(int $contextId, string $externalId, string $externalType): array
{
$externalAuthorResponses = [];
$authorResponses = Repo::demographicResponse()->getCollector()
->filterByContextIds([$contextId])
->filterByExternalIds([$externalId])
->filterByExternalTypes([$externalType])
->getMany();

foreach ($authorResponses as $response) {
$question = Repo::demographicQuestion()->get($response->getDemographicQuestionId());
$responseValueForDisplay = $this->getResponseValueForDisplay($question, $response);
$externalAuthorResponses[$question->getId()] = $responseValueForDisplay;
}

return $externalAuthorResponses;
}

private function getResponseValueForDisplay($question, $response): string
{
if (in_array(
$question->getQuestionType(),
[DemographicQuestion::TYPE_SMALL_TEXT_FIELD, DemographicQuestion::TYPE_TEXT_FIELD, DemographicQuestion::TYPE_TEXTAREA]
)) {
return $response->getLocalizedData('responseValue');
}

if (
$question->getQuestionType() == DemographicQuestion::TYPE_CHECKBOXES
|| $question->getQuestionType() == DemographicQuestion::TYPE_RADIO_BUTTONS
) {
$possibleResponses = $question->getLocalizedPossibleResponses();
$selectedResponsesValues = [];

foreach ($response->getValue() as $selectedResponse) {
$selectedResponsesValues[] = $possibleResponses[$selectedResponse];
}

return implode(', ', $selectedResponsesValues);
}

if ($question->getQuestionType() == DemographicQuestion::TYPE_DROP_DOWN_BOX) {
$possibleResponses = $question->getLocalizedPossibleResponses();
$selectedResponse = $response->getValue();

return $possibleResponses[$selectedResponse];
}

return '';
}

public function deleteUserResponses(int $userId, int $contextId)
{
$userResponses = Repo::demographicResponse()->getCollector()
Expand All @@ -125,6 +176,19 @@ public function deleteUserResponses(int $userId, int $contextId)
}
}

public function deleteAuthorResponses(int $contextId, string $externalId, string $externalType)
{
$authorResponses = Repo::demographicResponse()->getCollector()
->filterByContextIds([$contextId])
->filterByExternalIds([$externalId])
->filterByExternalTypes([$externalType])
->getMany();

foreach ($authorResponses as $response) {
Repo::demographicResponse()->delete($response);
}
}

public function authorAlreadyAnsweredQuestionnaire($author, $authorOrcid = null): bool
{
$externalId = $author->getData('email');
Expand All @@ -133,6 +197,9 @@ public function authorAlreadyAnsweredQuestionnaire($author, $authorOrcid = null)
if (!is_null($authorOrcid)) {
$externalId = $authorOrcid;
$externalType = 'orcid';
} elseif (!is_null($author->getData('demographicOrcid'))) {
$externalId = $author->getData('demographicOrcid');
$externalType = 'orcid';
}

$countAuthorResponses = Repo::demographicResponse()
Expand Down
87 changes: 71 additions & 16 deletions cypress/tests/Test2_externalContributors.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import '../support/commands.js';

function assertDefaultQuestionsDisplay() {
function assertDefaultQuestionsDisplay(authorEmail) {
cy.contains('The demographic data from this questionnaire will be associated with the e-mail address: ' + authorEmail);

cy.contains('.questionTitle', 'Gender');
cy.contains('With which gender do you most identify?');

Expand Down Expand Up @@ -33,6 +35,8 @@ function assertDefaultQuestionsDisplay() {
cy.contains('option', 'One to three minimum wages');
cy.contains('option', 'Three to five minimum wages');
cy.contains('option', 'More than five minimum wages');

cy.contains('Demographic data is collected in accordance with this journal\'s privacy statement');
}

function answerDefaultQuestions() {
Expand All @@ -55,7 +59,22 @@ function answerDefaultQuestions() {
cy.contains('button', 'Save').click();
}

function assertResponsesToDefaultQuestions() {
function assertResponsesOfExternalAuthor(authorEmail) {
cy.contains('Showing demographic data associated with the e-mail address: ' + authorEmail);

cy.contains('Female');
cy.contains('Latin');
cy.contains('University of São Paulo');
cy.contains('University of Minas Gerais');
cy.contains('English, Spanish');
cy.contains('America');
cy.contains('Three to five minimum wages');

cy.contains('You can check you demographic data at any time by visiting this same address');
cy.contains('By creating a new account in the system with this same e-mail address, your demographic data will automatically be associated with the new account');
}

function assertResponsesOfRegisteredUser() {
cy.contains('a', 'Demographic Data').click();
cy.get('input[name="demographicDataConsent"][value=1]').should('be.checked');

Expand Down Expand Up @@ -208,7 +227,7 @@ describe('Demographic Data - External contributors data collecting', function()
});
});

assertDefaultQuestionsDisplay();
assertDefaultQuestionsDisplay('[email protected]');

cy.url().then(url => {
cy.visit(url + 'breakToken');
Expand All @@ -230,19 +249,9 @@ describe('Demographic Data - External contributors data collecting', function()
answerDefaultQuestions();

cy.contains('Thanks for answering our demographic questionnaire');
});
it('Contributor access questionnaire again', function () {
cy.visit('localhost:8025');
cy.get('b:contains("Request for demographic data collection")').click();
cy.contains('a', 'Check my answers').click();

cy.get('#nav-tab button:contains("Text")').click();
cy.get('.text-view').within(() => {
cy.get('a').eq(1).should('have.attr', 'href').then((href) => {
cy.visit(href);
});
});

cy.contains('You already answered the demographic questionnaire');
assertResponsesOfExternalAuthor('[email protected]');
});
it('New submission is created and accepted with same contributor', function () {
cy.login('ckwantes', null, 'publicknowledge');
Expand Down Expand Up @@ -287,6 +296,52 @@ describe('Demographic Data - External contributors data collecting', function()
cy.visit('localhost:8025');
cy.get('b:contains("Request for demographic data collection")').should('have.length', 1);
});
it('Contributor without registration deletes his own demographic data', function () {
cy.visit('localhost:8025');
cy.get('b:contains("Request for demographic data collection")').click();

cy.get('#nav-tab button:contains("Text")').click();
cy.get('.text-view').within(() => {
cy.get('a').eq(1).should('have.attr', 'href').then((href) => {
cy.visit(href);
});
});

cy.contains('a', 'Delete my demographic data').click();

cy.contains('Demographic data deletion');
cy.contains('Are you sure you want to delete your demographic data? This action cannot be undone.');
cy.contains('Delete my demographic data').click();

cy.contains('Your demographic data has been deleted');
});
it('Editor goes back and accepts submission again', function () {
cy.login('dbarnes', null, 'publicknowledge');
cy.findSubmission('myQueue', secondSubmissionData.title);

cy.get('#workflow-button').click();
cy.clickDecision('Cancel Copyediting');
cy.contains('button', 'Skip this email').click();
cy.contains('button', 'Record Decision').click();
cy.get('a.pkpButton').contains('View Submission').click();

cy.clickDecision('Accept Submission');
cy.recordDecisionAcceptSubmission(['Catherine Kwantes'], [], []);
});
it('Contributor answers demographic questionnaire on new submission', function () {
cy.visit('localhost:8025');
cy.get('b:contains("Request for demographic data collection")').eq(0).click();

cy.get('#nav-tab button:contains("Text")').click();
cy.get('.text-view').within(() => {
cy.get('a').eq(1).should('have.attr', 'href').then((href) => {
cy.visit(href);
});
});

answerDefaultQuestions();
cy.contains('Thanks for answering our demographic questionnaire');
});
it('Responses reference is migrated when author registers', function () {
cy.register({
'username': 'susyalmeida',
Expand All @@ -300,6 +355,6 @@ describe('Demographic Data - External contributors data collecting', function()
cy.contains('a', 'Edit My Profile').click();
cy.contains('a', 'Demographic Data').click();

assertResponsesToDefaultQuestions();
assertResponsesOfRegisteredUser();
});
});
50 changes: 48 additions & 2 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ msgstr "We request that you fill in the demographic data survey on the \"Demogra
msgid "plugins.generic.demographicData.questionnairePage.index.title"
msgstr "Demographic Questionnaire"

msgid "plugins.generic.demographicData.questionnairePage.externalId.email"
msgstr "The demographic data from this questionnaire will be associated with the e-mail address: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.externalId.orcid"
msgstr "The demographic data from this questionnaire will be associated with the ORCID: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.accessDenied"
msgstr "Only the author can access this page"

Expand All @@ -31,8 +37,8 @@ msgstr "Questionnaire saved successfully"
msgid "plugins.generic.demographicData.questionnairePage.saveSuccess.message"
msgstr "Thanks for answering our demographic questionnaire!"

msgid "plugins.generic.demographicData.questionnairePage.alreadyAnswered"
msgstr "You already answered the demographic questionnaire."
msgid "plugins.generic.demographicData.questionnairePage.saveSuccess.checkAnswers"
msgstr "Check my answers"

msgid "plugins.generic.demographicData.questionnairePage.orcidAccessDenied"
msgstr "You denied access to your ORCID record"
Expand All @@ -43,6 +49,46 @@ msgstr "An error occurred during your ORCID requesting. The message returned was
msgid "plugins.generic.demographicData.questionnairePage.userWithOrcidExists"
msgstr "There is a user registered with this ORCID in our system. Please fill in the demographic questionnaire using this user."

msgid "plugins.generic.demographicData.questionnairePage.privacyStatement"
msgstr ""
"Demographic data is collected in accordance with this journal's "
"<a href=\"{$privacyUrl}\" target=\"_blank\">privacy statement</a>"

msgid "plugins.generic.demographicData.questionnairePage.responses.title"
msgstr "Demographic Data"

msgid "plugins.generic.demographicData.questionnairePage.responsesFor.email"
msgstr "Showing demographic data associated with the e-mail address: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.responsesFor.orcid"
msgstr "Showing demographic data associated with the ORCID: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.checkAnswersAnytime"
msgstr "You can check you demographic data at any time by visiting this same address."

msgid "plugins.generic.demographicData.questionnairePage.dataMigration.email"
msgstr "By creating a new account in the system with this same e-mail address, "
"your demographic data will automatically be associated with the new account."

msgid "plugins.generic.demographicData.questionnairePage.dataMigration.orcid"
msgstr "By creating a new account in the system and add the same ORCID, "
"your demographic data will automatically be associated with the new account."

msgid "plugins.generic.demographicData.questionnairePage.deleteData.title"
msgstr "Demographic data deletion"

msgid "plugins.generic.demographicData.questionnairePage.deleteData.message"
msgstr "Are you sure you want to delete your demographic data? This action cannot be undone."

msgid "plugins.generic.demographicData.questionnairePage.deleteMyData"
msgstr "Delete my demographic data"

msgid "plugins.generic.demographicData.questionnairePage.deleteSuccess"
msgstr "Your demographic data has been deleted."

msgid "plugins.generic.demographicData.questionnairePage.onlyWhoAnsweredCanDelete"
msgstr "Only authors who have already completed the demographic questionnaire can delete demographic data."


msgid "plugins.generic.demographicData.settings.orcidAPIPathRequired"
msgstr "Please, inform which ORCID API should be used"
Expand Down
50 changes: 48 additions & 2 deletions locale/es/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ msgstr "Le pedimos que rellene el cuestionario de datos demográficos en la pest
msgid "plugins.generic.demographicData.questionnairePage.index.title"
msgstr "Cuestionario Demográfico"

msgid "plugins.generic.demographicData.questionnairePage.externalId.email"
msgstr "Los datos demográficos de este cuestionario se vincularán a la dirección de correo electrónico: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.externalId.orcid"
msgstr "Los datos demográficos de este cuestionario se vincularán a ORCID: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.accessDenied"
msgstr "Sólo el autor puede acceder a esta página"

Expand All @@ -31,8 +37,8 @@ msgstr "Cuestionario guardado correctamente"
msgid "plugins.generic.demographicData.questionnairePage.saveSuccess.message"
msgstr "¡Gracias por responder a nuestro cuestionario demográfico!"

msgid "plugins.generic.demographicData.questionnairePage.alreadyAnswered"
msgstr "Ya ha rellenado el cuestionario demográfico."
msgid "plugins.generic.demographicData.questionnairePage.saveSuccess.checkAnswers"
msgstr "Revisa mis respuestas"

msgid "plugins.generic.demographicData.questionnairePage.orcidAccessDenied"
msgstr "Ha denegado el acceso a su registro ORCID"
Expand All @@ -43,6 +49,46 @@ msgstr "Se ha producido un error al solicitar su ORCID. El mensaje devuelto fue:
msgid "plugins.generic.demographicData.questionnairePage.userWithOrcidExists"
msgstr "Hay un usuario registrado con este ORCID en nuestro sistema. Por favor, rellene el cuestionario demográfico utilizando este usuario."

msgid "plugins.generic.demographicData.questionnairePage.privacyStatement"
msgstr ""
"Los datos demográficos se recogen de acuerdo con la "
"<a href=\"{$privacyUrl}\" target=\"_blank\">declaración de privacidad</a> de esta revista"

msgid "plugins.generic.demographicData.questionnairePage.responses.title"
msgstr "Datos Demográficos"

msgid "plugins.generic.demographicData.questionnairePage.responsesFor.email"
msgstr "Mostrando datos demográficos asociados a la dirección de correo electrónico: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.responsesFor.orcid"
msgstr "Mostrando datos demográficos asociados a ORCID: <strong>{$externalId}</strong>"

msgid "plugins.generic.demographicData.questionnairePage.checkAnswersAnytime"
msgstr "Puede consultar sus datos demográficos en cualquier momento accediendo a esta misma dirección."

msgid "plugins.generic.demographicData.questionnairePage.dataMigration.email"
msgstr "Cuando cree una nueva cuenta en el sistema con esa misma dirección de correo electrónico, "
"sus datos demográficos se asociarán automáticamente a la nueva cuenta."

msgid "plugins.generic.demographicData.questionnairePage.dataMigration.orcid"
msgstr "Cuando cree una nueva cuenta en el sistema y añada ese mismo ORCID, "
"sus datos demográficos se asociarán automáticamente a la nueva cuenta."

msgid "plugins.generic.demographicData.questionnairePage.deleteData.title"
msgstr "Eliminación de datos demográficos"

msgid "plugins.generic.demographicData.questionnairePage.deleteData.message"
msgstr "¿Está seguro de que desea eliminar sus datos demográficos? Esta acción no se puede deshacer."

msgid "plugins.generic.demographicData.questionnairePage.deleteMyData"
msgstr "Eliminar mis datos demográficos"

msgid "plugins.generic.demographicData.questionnairePage.deleteSuccess"
msgstr "Tus datos demográficos han sido eliminados."

msgid "plugins.generic.demographicData.questionnairePage.onlyWhoAnsweredCanDelete"
msgstr "Sólo los autores que ya hayan respondido el cuestionario demográfico pueden eliminar datos demográficos."


msgid "plugins.generic.demographicData.settings.orcidAPIPathRequired"
msgstr "Indique qué API de ORCID se debe utilizar"
Expand Down
Loading

0 comments on commit cd798bb

Please sign in to comment.