forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#9965 Anonymize reviews for authors
- Loading branch information
Showing
4 changed files
with
99 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* @file api/v1/submissions/AnonymizeData.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class AnonymizeData | ||
* | ||
* @ingroup api_v1_submission | ||
* | ||
* @brief Trait for anonymizing sensitive submission data. | ||
* | ||
*/ | ||
|
||
namespace PKP\API\v1\submissions; | ||
|
||
use APP\facades\Repo; | ||
use APP\submission\Submission; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\LazyCollection; | ||
use PKP\core\PKPRequest; | ||
use PKP\security\Role; | ||
use PKP\stageAssignment\StageAssignment; | ||
use PKP\submission\reviewAssignment\ReviewAssignment; | ||
|
||
trait AnonymizeData | ||
{ | ||
abstract public function getRequest(): PKPRequest; | ||
|
||
/** | ||
* Checks if sensitive review assignment data should be anonymized for authors and reviewers | ||
* | ||
* @param LazyCollection<Submission>|Submission $submissions the list of submissions with IDs as keys or a single submission | ||
* @param ?LazyCollection<ReviewAssignment> $reviewAssignments | ||
* | ||
* @return false|Collection List of review IDs to anonymize or false; | ||
*/ | ||
public function anonymizeReviews(LazyCollection|Submission $submissions, ?LazyCollection $reviewAssignments = null): false|Collection | ||
{ | ||
$currentUser = $this->getRequest()->getUser(); | ||
$submissionIds = is_a($submissions, Submission::class) ? [$submissions->getId()] : $submissions->keys()->toArray(); | ||
$reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds($submissionIds)->getMany(); | ||
|
||
$currentUserReviewAssignment = Repo::reviewAssignment()->getCollector() | ||
->filterBySubmissionIds($submissionIds) | ||
->filterByReviewerIds([$currentUser->getId()]) | ||
->getMany(); | ||
|
||
$currentUserStageAssignments = StageAssignment::withSubmissionIds($submissionIds) | ||
->withUserId($currentUser->getId()) | ||
->get(); | ||
|
||
$isAuthor = $currentUserStageAssignments->contains( | ||
function (StageAssignment $stageAssignment) { | ||
$userGroup = Repo::userGroup()->get($stageAssignment->userGroupId); | ||
return $userGroup->getRoleId() == Role::ROLE_ID_AUTHOR; | ||
} | ||
); | ||
|
||
if ($currentUserReviewAssignment->isNotEmpty() || $isAuthor) { | ||
$anonymizeReviews = $reviewAssignments->map(function (ReviewAssignment $reviewAssignment, int $reviewId) use ($currentUserReviewAssignment) { | ||
if ($currentUserReviewAssignment->isNotEmpty() && $currentUserReviewAssignment->has($reviewId)) { | ||
return false; | ||
} | ||
return $reviewAssignment->getReviewMethod() !== ReviewAssignment::SUBMISSION_REVIEW_METHOD_OPEN; | ||
})->filter()->keys()->collect(); | ||
} | ||
|
||
return !isset($anonymizeReviews) || $anonymizeReviews->isEmpty() ? false : $anonymizeReviews; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters