Skip to content

Commit

Permalink
pkp#9456 Allowing user private editorial notes
Browse files Browse the repository at this point in the history
  • Loading branch information
nibou230 committed Nov 30, 2023
1 parent c6a9c9b commit 90f4b47
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 15 deletions.
17 changes: 15 additions & 2 deletions classes/components/listPanels/PKPSelectReviewerListPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ public function getConfig()
];

if (!empty($this->lastRoundReviewers)) {
$config['lastRoundReviewers'] = Repo::user()
$reviewers = Repo::user()
->getSchemaMap()
->summarizeManyReviewers($this->lastRoundReviewers)
->values()
->toArray();
$contextId = $this->getParams['contextId'];
$privateNotesDAO = DAORegistry::getDAO('PrivateNotesDAO');
foreach ($reviewers as $key => $reviewer) {
$privateNote = $privateNotesDAO->getPrivateNote($contextId, $reviewer['id']);
$reviewers[$key]['privateNotes'] = $privateNote ? $privateNote->getNote() : null;
}
$config['lastRoundReviewers'] = $reviewers;
}

if (!empty($this->getParams)) {
Expand All @@ -147,6 +154,7 @@ public function getConfig()
$config['declinedReviewsLabel'] = __('reviewer.list.declinedReviews');
$config['emptyLabel'] = __('reviewer.list.empty');
$config['gossipLabel'] = __('user.gossip');
$config['privateNotesLabel'] = __('user.private.notes');
$config['neverAssignedLabel'] = __('reviewer.list.neverAssigned');
$config['reassignLabel'] = __('reviewer.list.reassign');
$config['reassignWithNameLabel'] = __('reviewer.list.reassign.withName');
Expand All @@ -172,8 +180,13 @@ public function getItems($request)
$reviewers = $this->_getCollector()->getMany();
$items = [];
$map = Repo::user()->getSchemaMap();
$contextId = $request->getContext()->getId();
$privateNotesDAO = DAORegistry::getDAO('PrivateNotesDAO');
foreach ($reviewers as $reviewer) {
$items[] = $map->summarizeReviewer($reviewer);
$item = $map->summarizeReviewer($reviewer);
$privateNote = $privateNotesDAO->getPrivateNote($contextId, $reviewer->getId());
$item['privateNotes'] = $privateNote ? $privateNote->getNote() : null;
$items[] = $item;
}

return $items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,17 @@ public function gossip($args, $request)
return new JSONMessage(false, __('user.authorization.roleBasedAccessDenied'));
}

$privateNotesDAO = DAORegistry::getDAO('PrivateNotesDAO');
$privateNote = $privateNotesDAO->getPrivateNote($request->getContext()->getId(), $user->getId());
if (!$privateNote) {
$privateNote = $privateNotesDAO->newDataObject();
$privateNote->setContextId($request->getContext()->getId());
$privateNote->setUserId($user->getId());
$privateNote->setNote('');
}

$requestArgs = array_merge($this->getRequestArgs(), ['reviewAssignmentId' => $reviewAssignment->getId()]);
$reviewerGossipForm = new ReviewerGossipForm($user, $requestArgs);
$reviewerGossipForm = new ReviewerGossipForm($user, $privateNote, $requestArgs);

// View form
if (!$request->isPost()) {
Expand Down
1 change: 1 addition & 0 deletions classes/core/PKPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ public function getDAOMap()
'NotificationSubscriptionSettingsDAO' => 'PKP\notification\NotificationSubscriptionSettingsDAO',
'PluginGalleryDAO' => 'PKP\plugins\PluginGalleryDAO',
'PluginSettingsDAO' => 'PKP\plugins\PluginSettingsDAO',
'PrivateNotesDAO' => 'PKP\user\PrivateNotesDAO',
'PublicationDAO' => 'APP\publication\PublicationDAO',
'QueuedPaymentDAO' => 'PKP\payment\QueuedPaymentDAO',
'ReviewFilesDAO' => 'PKP\submission\ReviewFilesDAO',
Expand Down
1 change: 1 addition & 0 deletions classes/migration/install/CommonMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace PKP\migration\install;

use APP\core\Application;
use APP\facades\Repo;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
Expand Down
54 changes: 54 additions & 0 deletions classes/migration/upgrade/v3_5_0/I9456_PrivateNotes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9456_PrivateNotes.php
*
* Copyright (c) 2014-2023 Simon Fraser University
* Copyright (c) 2000-2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9456_PrivateNotes
*/

namespace PKP\migration\upgrade\v3_5_0;

use APP\core\Application;
use APP\facades\Repo;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;

class I9456_PrivateNotes extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user_private_notes', function (Blueprint $table) {
$table->comment('User private notes are an addition to the gossip, but this one is private to each context.');
$table->bigInteger('private_note_id')->autoIncrement();

$table->bigInteger('context_id');
$contextDao = Application::getContextDAO();
$table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade');

$table->bigInteger('user_id');
$userDao = Repo::user()->dao;
$table->foreign('user_id')->references($userDao->primaryKeyColumn)->on($userDao->table)->onDelete('cascade');

$table->unique(['context_id', 'user_id'], 'user_private_notes_unique');
$table->index(['context_id'], 'user_private_notes_context_id_foreign');

$table->string('note')->default('');
});
}

/**
* Reverse the migration.
*/
public function down(): void
{
Schema::drop('user_private_notes');
}
}
109 changes: 109 additions & 0 deletions classes/user/PrivateNote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

/**
* @file classes/user/PrivateNote.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PrivateNote
*
* @ingroup user
*
* @see PrivateNotesDAO
*
* @brief Basic class describing user private note existing in the system.
*/

namespace PKP\user;

use PKP\core\DataObject;

class PrivateNote extends DataObject
{
/**
* Get private note ID.
*
* @return int
*/
public function getId(): int
{
return $this->getData('id');
}

/**
* Set private note ID.
*
* @param $id int
*/
public function setId($id): void
{
$this->setData('id', $id);
}

/**
* Get private note context ID.
*
* @return int
*/
public function getContextId(): int
{
return $this->getData('contextId');
}

/**
* Set private note context ID.
*
* @param $contextId int
*/
public function setContextId(int $contextId): void
{
$this->setData('contextId', $contextId);
}

/**
* Get private note user ID.
*
* @return int
*/
public function getUserId(): int
{
return $this->getData('userId');
}

/**
* Set private note user ID.
*
* @param $userId int
*/
public function setUserId(int $userId): void
{
$this->setData('userId', $userId);
}


/**
* Get private note value.
*
* @return string
*/
public function getNote(): string
{
return $this->getData('note');
}

/**
* Set private note value.
*
* @param $note string
*/
public function setNote(string $note): void
{
$this->setData('note', $note);
}
}

if (!PKP_STRICT_MODE) {
class_alias('\PKP\user\PrivateNote', '\PrivateNote');
}
108 changes: 108 additions & 0 deletions classes/user/PrivateNotesDAO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

/**
* @file classes/user/PrivateNotesDAO.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PrivateNotesDAO
*
* @ingroup user
*
* @see PrivateNote
*
* @brief Operations for retrieving and modifying user private notes.
*/

namespace PKP\user;

use PKP\db\DAO;
use PKP\db\DAOResultFactory;

class PrivateNotesDAO extends DAO
{
/**
* Construct a new PrivateNote object.
*
* @return PrivateNote
*/
public function newDataObject(): PrivateNote
{
return new PrivateNote();
}

/**
* Retrieve a user private note value.
*
* @param int $journalId
* @param int $userId
*
* @return PrivateNote|null
*/
public function getPrivateNote(int $journalId, int $userId): PrivateNote|null
{
$params = [
$journalId,
$userId
];
$result = $this->retrieve(
'SELECT * FROM user_private_notes WHERE context_id = ? AND user_id = ?',
$params
);
$factory = new DAOResultFactory($result, $this, '_fromRow');
return $factory->toIterator()->current();
}

/**
* Set a user private note value.
*
* @param int $journalId
* @param int $userId
* @param string $note
*/
public function setPrivateNote(int $journalId, int $userId, string $note): void
{
$params = [
$note,
$journalId,
$userId
];
$dbPrivateNote = $this->getPrivateNote($journalId, $userId);
if ($dbPrivateNote) {
$this->update(
'UPDATE user_private_notes SET note = ? WHERE context_id = ? AND user_id = ?',
$params
);
} else {
$this->update(
'INSERT INTO user_private_notes (note, context_id, user_id) VALUES (?, ?, ?)',
$params
);
}
}

/**
* Internal function to return a PrivateNote object from a row.
*
* @param array $row
*
* @return PrivateNote
*/
function _fromRow(array $row): PrivateNote
{
$privateNote = $this->newDataObject();

$privateNote->setId($row['private_note_id']);
$privateNote->setContextId($row['context_id']);
$privateNote->setUserId($row['user_id']);
$privateNote->setNote($row['note']);

return $privateNote;
}
}

if (!PKP_STRICT_MODE) {
class_alias('\PKP\user\PrivateNotesDAO', '\PrivateNotesDAO');
}
13 changes: 12 additions & 1 deletion controllers/grid/settings/user/form/UserDetailsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public function initData()
$data['canCurrentUserGossip'] = Repo::user()->canCurrentUserGossip($user->getId());
if ($data['canCurrentUserGossip']) {
$data['gossip'] = $user->getGossip();
$privateNotesDAO = DAORegistry::getDAO('PrivateNotesDAO');
$privateNote = $privateNotesDAO->getPrivateNote($request->getContext()->getId(), $user->getId());
$data['privateNote'] = $privateNote ? $privateNote->getNote() : '';
}
} elseif (isset($this->author)) {
$author = $this->author;
Expand Down Expand Up @@ -268,6 +271,7 @@ public function readInputData()
'country',
'biography',
'gossip',
'privateNote',
'interests',
'locales',
'generatePassword',
Expand Down Expand Up @@ -359,6 +363,7 @@ public function execute(...$functionParams)
}

Repo::user()->edit($this->user);
$userId = $this->user->getId();
} else {
$this->user->setUsername($this->getData('username'));
if ($this->getData('generatePassword')) {
Expand All @@ -372,7 +377,7 @@ public function execute(...$functionParams)
$this->user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));

$this->user->setDateRegistered(Core::getCurrentDate());
Repo::user()->add($this->user);
$userId = Repo::user()->add($this->user);

if ($sendNotify) {
// Send welcome email to user
Expand All @@ -398,6 +403,12 @@ public function execute(...$functionParams)
}
}

// Users can never view/edit their own private notes fields
if (Repo::user()->canCurrentUserGossip($userId)) {
$privateNotesDAO = DAORegistry::getDAO('PrivateNotesDAO');
$privateNotesDAO->setPrivateNote($context->getId(), $userId, $this->getData('privateNote'));
}

$interestManager = new InterestManager();
$interestManager->setInterestsForUser($this->user, $this->getData('interests'));

Expand Down
Loading

0 comments on commit 90f4b47

Please sign in to comment.