From e42b6ed3f5fcd483fc25ad615f95ff25146d2a29 Mon Sep 17 00:00:00 2001 From: Jerry Kuang Date: Fri, 6 Oct 2023 16:22:42 -0400 Subject: [PATCH] [PURR #1622] require email address for publication contact --- .../admin/controllers/items.php | 5 + .../com_publications/models/blocks/review.php | 135 ++++++++++++++++++ .../com_publications/tables/author.php | 1 + .../publications/assets/css/curation.css | 11 +- .../projects/publications/assets/js/review.js | 44 ++++++ .../en-GB/en-GB.plg_projects_publications.ini | 1 + .../projects/publications/publications.php | 9 ++ .../publications/views/draft/tmpl/review.php | 14 +- 8 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 core/plugins/projects/publications/assets/js/review.js diff --git a/core/components/com_publications/admin/controllers/items.php b/core/components/com_publications/admin/controllers/items.php index a012378d02c..5f1bfe5ef88 100644 --- a/core/components/com_publications/admin/controllers/items.php +++ b/core/components/com_publications/admin/controllers/items.php @@ -955,6 +955,11 @@ public function saveTask($redirect = false) $this->model->version->archived = Date::toSql(); } } + + if ($action == 'republish') + { + $this->model->version->accepted = Date::toSql(); + } if (!$this->getError()) { diff --git a/core/components/com_publications/models/blocks/review.php b/core/components/com_publications/models/blocks/review.php index 3550d56a3b7..e675a9755e4 100644 --- a/core/components/com_publications/models/blocks/review.php +++ b/core/components/com_publications/models/blocks/review.php @@ -185,4 +185,139 @@ public function getManifest($new = false) return $manifest; } + + /** + * Update author record + * + * @param object $manifest + * @param integer $blockId + * @param object $pub + * @param integer $actor + * @param integer $elementId + * @param integer $aid + * @return void + */ + public function saveItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0) + { + $aid = $aid ? $aid : Request::getInt('aid', 0); + + // Load classes + $row = new \Components\Publications\Tables\Author($this->_parent->_db); + $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); + + // We need attachment record + if (!$aid || !$row->load($aid) || $row->publication_version_id != $pub->version_id) + { + $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR')); + return false; + } + + // Instantiate a new registration object + include_once \Component::path('com_members') . DS . 'models' . DS . 'registration.php'; + $xregistration = new \Components\Members\Models\Registration(); + + // Get current owners + $owners = $objO->getIds($pub->_project->get('id'), 'all', 1); + + $config = Component::params('com_publications'); + + $emailConfig = $config->get('email'); + $email = Request::getString('email', '', 'post'); + $firstName = Request::getString('firstName', '', 'post'); + $lastName = Request::getString('lastName', '', 'post'); + $org = Request::getString('organization', '', 'post'); + $credit = Request::getString('credit', '', 'post'); + $sendInvite = 0; + $code = \Components\Projects\Helpers\Html::generateCode(); + $uid = Request::getInt('uid', 0, 'post'); + + $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; + $email = preg_match($regex, $email) ? $email : ''; + + if (!$firstName || !$lastName) + { + $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); + return false; + } + + $row->organization = $org; + $row->firstName = $firstName; + $row->lastName = $lastName; + $row->name = $row->firstName . ' ' . $row->lastName; + $row->credit = $credit; + $row->modified_by = $actor; + $row->modified = Date::toSql(); + + // Check that profile exists + if ($uid) + { + $profile = User::getInstance($uid); + $uid = $profile->get('id') ? $uid : 0; + } + + // Tying author to a user account? + if ($uid && !$row->user_id) + { + // Do we have an owner with this user id? + $owner = $objO->getOwnerId($pub->_project->get('id'), $uid); + + if ($owner) + { + // Update owner assoc + $row->project_owner_id = $owner; + } + else + { + // Update associated project owner account + if ($objO->load($row->project_owner_id) && !$objO->userid) + { + $objO->userid = $uid; + $objO->status = 1; + $objO->store(); + } + } + } + $row->user_id = $uid; + + if ($row->store()) + { + $this->set('_message', Lang::txt('Author record saved')); + + // Reflect the update in curation record + $this->_parent->set('_update', 1); + } + else + { + $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO')); + return false; + } + + // Update project owner (invited) + if ($email && !$row->user_id && $objO->load($row->project_owner_id)) + { + $invitee = $objO->checkInvited($pub->_project->get('id'), $email); + + // Do we have a registered user with this email? + $user = $xregistration->getEmailId($email); + + if ($invitee && $invitee != $row->project_owner_id) + { + // Stop, must have owner record + } + elseif (in_array($user, $owners)) + { + // Stop, already in team + } + elseif ($email != $objO->invited_email) + { + $objO->invited_email = $email; + $objO->invited_name = $row->name; + $objO->userid = $row->user_id; + $objO->invited_code = $code; + $objO->store(); + } + } + + return true; + } } diff --git a/core/components/com_publications/tables/author.php b/core/components/com_publications/tables/author.php index 59a1ac73239..043927b6eec 100644 --- a/core/components/com_publications/tables/author.php +++ b/core/components/com_publications/tables/author.php @@ -311,6 +311,7 @@ public function getAuthors($vid = null, $get_uids = 0, $active = 1, $return_uid_ $res->middleName = $user->get('middleName'); $res->surname = $user->get('surname'); $res->orcid = $user->get('orcid'); + $res->p_email = $user->get('email'); } if ($res->user_id) diff --git a/core/plugins/projects/publications/assets/css/curation.css b/core/plugins/projects/publications/assets/css/curation.css index d93f0c42643..203e9ee674b 100644 --- a/core/plugins/projects/publications/assets/css/curation.css +++ b/core/plugins/projects/publications/assets/css/curation.css @@ -1248,4 +1248,13 @@ a.more-content { #notice-form .form-group > label > textarea { width: 80%; -} \ No newline at end of file +} + +/* Draft review page */ + .item-msg { + padding-right: 6em; + margin-left: 0; + padding-left: 0; + color: red; + } +} diff --git a/core/plugins/projects/publications/assets/js/review.js b/core/plugins/projects/publications/assets/js/review.js new file mode 100644 index 00000000000..ed9f46c1637 --- /dev/null +++ b/core/plugins/projects/publications/assets/js/review.js @@ -0,0 +1,44 @@ +/** + * @package hubzero-cms + * @copyright Copyright (c) 2005-2023 The Regents of the University of California. + * @license http://opensource.org/licenses/MIT MIT + */ + +//----------------------------------------------------------- +// Ensure we have our namespace +//----------------------------------------------------------- +if (!HUB) { + var HUB = {}; +} + +//---------------------------------------------------------- +// Publication review page JS +//---------------------------------------------------------- +HUB.ProjectPublicationReview = { + contactEmailCheck: function() + { + $("input[name='contact[]']").change(function() { + var emailID = '#' + $(this).val() + '_email'; + var msgID = '#' + $(this).val() + '_msg'; + + if ($(this).prop('checked')) + { + if ($(this).parents().has(emailID).length == 0) + { + $(msgID).show(); + } + } + else + { + if ($(this).parents().has(emailID).length == 0) + { + $(msgID).hide(); + } + } + }); + } +} + +jQuery(document).ready(function($){ + HUB.ProjectPublicationReview.contactEmailCheck(); +}); diff --git a/core/plugins/projects/publications/language/en-GB/en-GB.plg_projects_publications.ini b/core/plugins/projects/publications/language/en-GB/en-GB.plg_projects_publications.ini index b229451f2bf..a07e3d88d6f 100644 --- a/core/plugins/projects/publications/language/en-GB/en-GB.plg_projects_publications.ini +++ b/core/plugins/projects/publications/language/en-GB/en-GB.plg_projects_publications.ini @@ -98,6 +98,7 @@ PLG_PROJECTS_PUBLICATIONS_PUB_REVIEW_PRIMARY_CONTACT_EXPLANATION="Trusted reposi PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_NOT_FOUND="Selected author not found" PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_NOT_SAVED="Error: Failed to store selected author information" PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_INFO_MISSING="No information found for point of contact." +PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_EMAIL_ADDRESS_MISSING="The contact is required to include valid email address" ; Handlers COM_PUBLICATIONS_HANDLER_CHOICE="Content Presentation Options:" diff --git a/core/plugins/projects/publications/publications.php b/core/plugins/projects/publications/publications.php index 0e30304f808..9dbf63d4155 100644 --- a/core/plugins/projects/publications/publications.php +++ b/core/plugins/projects/publications/publications.php @@ -2087,6 +2087,15 @@ public function publishDraft() $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_NOT_FOUND')); continue; } + + // Prompt error message if an author is chosen as contact but the email address is empty + $owner = $author->getAuthorByOwnerId($pub->version->id, $author->project_owner_id); + if (empty($owner->invited_email)) + { + Notify::error(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_EMAIL_ADDRESS_MISSING'), 'projects'); + App::redirect(Route::url($pub->link('editversion') . '&action=' . $this->_task)); + return; + } $author->repository_contact = 1; diff --git a/core/plugins/projects/publications/views/draft/tmpl/review.php b/core/plugins/projects/publications/views/draft/tmpl/review.php index 2a484a90c04..68b77f20d90 100644 --- a/core/plugins/projects/publications/views/draft/tmpl/review.php +++ b/core/plugins/projects/publications/views/draft/tmpl/review.php @@ -10,7 +10,8 @@ $this->css('jquery.datepicker.css', 'system') ->css('jquery.timepicker.css', 'system') - ->js('jquery.timepicker', 'system'); + ->js('jquery.timepicker', 'system') + ->js('review.js', 'projects', 'publications'); $complete = $this->pub->curation('complete'); $params = $this->pub->curation('params'); @@ -55,6 +56,7 @@ $requestReview = isset($this->pub->_curationModel->_manifest->params->request_review) ? $this->pub->_curationModel->_manifest->params->request_review : 0; $unsubmitted = $this->pub->version->get('state') == 3; +$props = $this->pub->curation('blocks', $this->step, 'props'); ?> @@ -167,10 +169,20 @@ $name = $author->name ? $author->name : $author->p_name; $name = trim($name) ? $name : $author->invited_name; $name = trim($name) ? $name : $author->invited_email; + $email = trim($author->p_email) ? $author->p_email : (trim($author->invited_email) ? trim($author->invited_email) : null); ?>
  • repository_contact) { echo ' checked="checked"'; } ?>/> + + escape($author->id) . "_email" ?> class="item-title"> + + + +