Skip to content

Commit

Permalink
[PURR #1622] require email address for publication contact
Browse files Browse the repository at this point in the history
  • Loading branch information
kuang5 authored and nkissebe committed Oct 6, 2023
1 parent ee736c2 commit e42b6ed
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 2 deletions.
5 changes: 5 additions & 0 deletions core/components/com_publications/admin/controllers/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
135 changes: 135 additions & 0 deletions core/components/com_publications/models/blocks/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions core/components/com_publications/tables/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion core/plugins/projects/publications/assets/css/curation.css
Original file line number Diff line number Diff line change
Expand Up @@ -1248,4 +1248,13 @@ a.more-content {

#notice-form .form-group > label > textarea {
width: 80%;
}
}

/* Draft review page */
.item-msg {
padding-right: 6em;
margin-left: 0;
padding-left: 0;
color: red;
}
}
44 changes: 44 additions & 0 deletions core/plugins/projects/publications/assets/js/review.js
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
9 changes: 9 additions & 0 deletions core/plugins/projects/publications/publications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 13 additions & 1 deletion core/plugins/projects/publications/views/draft/tmpl/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
?>

<!-- Load content selection browser //-->
Expand Down Expand Up @@ -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);
?>
<li>
<span class="item-order"><input type="checkbox" name="contact[]" value="<?php echo $this->escape($author->id); ?>" <?php if ($author->repository_contact) { echo ' checked="checked"'; } ?>/></span>
<span class="item-title"><?php echo $name; ?> <span class="item-subtext"><?php echo $org ? ' - ' . $org : ''; ?></span></span>
<?php if(!empty($email)) { ?>
<span id=<?php echo $this->escape($author->id) . "_email" ?> class="item-title"><?php echo $email; ?></span>
<?php }?>
<?php if(empty($email)) { ?>
<span hidden id=<?php echo $this->escape($author->id) . "_msg" ?> class="item-msg"><?php echo "The contact is required to have a valid email address. Please " ?>
<a href="<?php echo Route::url( $this->pub->link('editversionid') . '&active=publications&action=editauthor&aid=' . $author->id . '&p=' . $props); ?>" class="showinbox item-edit"><?php echo "edit"; ?></a>
<?php echo "the author."; ?>
</span>
<?php }?>
</li>
<?php } ?>
</ul>
Expand Down

0 comments on commit e42b6ed

Please sign in to comment.