Artwork system: More options for reviewers submitting new artwork

This commit is contained in:
Alex Cabal 2024-01-07 14:01:41 -06:00
parent 8e955bf357
commit 017baef7d3
6 changed files with 66 additions and 37 deletions

View file

@ -309,6 +309,15 @@ class Artwork extends PropertiesBase{
$error->Add(new Exceptions\InvalidMimeTypeException()); $error->Add(new Exceptions\InvalidMimeTypeException());
} }
// Check the ebook www filesystem path.
// We don't check if it exists, because the book might not be published yet.
// But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry
if($this->EbookWwwFilesystemPath !== null){
if(mb_stripos($this->EbookWwwFilesystemPath, '_') === false){
$error->Add(new Exceptions\InvalidEbookException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.'));
}
}
// Check for existing Artwork objects with the same URL but different Artwork IDs. // Check for existing Artwork objects with the same URL but different Artwork IDs.
try{ try{
$existingArtwork = Artwork::GetByUrl($this->Artist->UrlName, $this->UrlName); $existingArtwork = Artwork::GetByUrl($this->Artist->UrlName, $this->UrlName);

View file

@ -273,7 +273,12 @@ class Library{
try{ try{
$results = apcu_fetch($variable); $results = apcu_fetch($variable);
} }
catch(Safe\Exceptions\ApcuException){ catch(Safe\Exceptions\ApcuException $ex){
try{
// If we can't fetch this variable, rebuild the whole cache.
apcu_fetch('is-cache-fresh');
}
catch(Safe\Exceptions\ApcuException $ex){
Library::RebuildCache(); Library::RebuildCache();
try{ try{
$results = apcu_fetch($variable); $results = apcu_fetch($variable);
@ -291,6 +296,7 @@ class Library{
} }
} }
} }
}
if(!is_array($results)){ if(!is_array($results)){
$results = [$results]; $results = [$results];
@ -686,6 +692,8 @@ class Library{
} }
apcu_delete($lockVar); apcu_delete($lockVar);
apcu_store('is-cache-fresh', true);
} }
/** /**

View file

@ -5,5 +5,5 @@ $artwork = $artwork ?? null;
<? if($artwork->Status === COVER_ARTWORK_STATUS_APPROVED){ ?>Approved<? } ?> <? if($artwork->Status === COVER_ARTWORK_STATUS_APPROVED){ ?>Approved<? } ?>
<? if($artwork->Status === COVER_ARTWORK_STATUS_DECLINED){ ?>Declined<? } ?> <? if($artwork->Status === COVER_ARTWORK_STATUS_DECLINED){ ?>Declined<? } ?>
<? if($artwork->Status === COVER_ARTWORK_STATUS_UNVERIFIED){ ?>Unverified<? } ?> <? if($artwork->Status === COVER_ARTWORK_STATUS_UNVERIFIED){ ?>Unverified<? } ?>
<? if($artwork->Status === COVER_ARTWORK_STATUS_IN_USE){ ?>In use<? if($artwork->Ebook !== null && $artwork->Ebook->Url !== null){ ?> for <i><a href="<?= $artwork->Ebook->Url ?>"><?= Formatter::ToPlainText($artwork->Ebook->Title) ?></a></i><? } ?><? } ?> <? if($artwork->Status === COVER_ARTWORK_STATUS_IN_USE){ ?>In use<? if($artwork->EbookWwwFilesystemPath !== null){ ?> for <? if($artwork->Ebook !== null && $artwork->Ebook->Url !== null){ ?><i><a href="<?= $artwork->Ebook->Url ?>"><?= Formatter::ToPlainText($artwork->Ebook->Title) ?></a></i><? }else{ ?><?= Formatter::ToPlainText($artwork->EbookWwwFilesystemPath) ?><? } ?><? } ?><? } ?>
<? } ?> <? } ?>

View file

@ -173,6 +173,15 @@ catch(Exceptions\InvalidPermissionsException){
value="<?= $artwork->PublicationYear ?>" value="<?= $artwork->PublicationYear ?>"
/> />
</label> </label>
<label>
<input
type="checkbox"
name="artwork-is-published-in-us"
value="true"
<? if($artwork->IsPublishedInUs){ ?> checked="checked"<? } ?> />
<span>This book was published in the U.S.</span>
<span>Yes, if a U.S. city appears anywhere near the publication year or rights statement.</span>
</label>
<label> <label>
<span>URL of page with year of publication</span> <span>URL of page with year of publication</span>
<span>Roman numerals on the page scan are OK.</span> <span>Roman numerals on the page scan are OK.</span>
@ -194,16 +203,8 @@ catch(Exceptions\InvalidPermissionsException){
/> />
</label> </label>
<label> <label>
<input <span>URL of page with artwork</span>
type="checkbox" <span>Review the many <a href="/manual/latest/10-art-and-images#10.3.3.7.1.1">gotchas you may encounter</a> when confirming the reproduction is the exact same painting.</span>
name="artwork-is-published-in-us"
value="true"
<? if($artwork->IsPublishedInUs){ ?> checked="checked"<? } ?> />
<span>This book was published in the U.S.</span>
<span>Yes, if a U.S. city appears anywhere near the publication year or rights statement.</span>
</label>
<label>
URL of page with artwork
<input <input
type="url" type="url"
name="artwork-artwork-page-url" name="artwork-artwork-page-url"
@ -224,13 +225,21 @@ catch(Exceptions\InvalidPermissionsException){
<? if($GLOBALS['User']->Benefits->CanReviewArtwork){ ?> <? if($GLOBALS['User']->Benefits->CanReviewArtwork){ ?>
<fieldset> <fieldset>
<legend>Reviewer options</legend> <legend>Reviewer options</legend>
<label class="select">
<span>Artwork approval status</span>
<span>
<select name="artwork-status">
<option value="<?= COVER_ARTWORK_STATUS_UNVERIFIED ?>"<? if($artwork->Status == COVER_ARTWORK_STATUS_UNVERIFIED){ ?> selected="selected"<? } ?>>Unverified</option>
<option value="<?= COVER_ARTWORK_STATUS_DECLINED ?>"<? if($artwork->Status == COVER_ARTWORK_STATUS_DECLINED){ ?> selected="selected"<? } ?>>Declined</option>
<option value="<?= COVER_ARTWORK_STATUS_APPROVED ?>"<? if($artwork->Status == COVER_ARTWORK_STATUS_APPROVED){ ?> selected="selected"<? } ?>>Approved</option>
<option value="<?= COVER_ARTWORK_STATUS_IN_USE ?>"<? if($artwork->Status == COVER_ARTWORK_STATUS_IN_USE){ ?> selected="selected"<? } ?>>In use</option>
</select>
</span>
</label>
<label> <label>
<input <span>In use by</span>
type="checkbox" <span>Ebook file system slug, like <code>c-s-lewis_poetry</code>. If not in use, leave this blank.</span>
name="artwork-status" <input type="text" name="artwork-ebook-www-filesystem-path" value="<?= Formatter::ToPlainText($artwork->EbookWwwFilesystemPath) ?>"/>
value="<?= COVER_ARTWORK_STATUS_APPROVED ?>"
<? if($artwork->Status == COVER_ARTWORK_STATUS_APPROVED){ ?> checked="checked"<? } ?> />
Approve this artwork immediately
</label> </label>
</fieldset> </fieldset>
<? } ?> <? } ?>

View file

@ -1,14 +1,9 @@
<? <?
use Exceptions\InvalidRequestException;
use function Safe\ini_get;
use function Safe\substr;
try{ try{
session_start(); session_start();
if(HttpInput::RequestMethod() != HTTP_POST){ if(HttpInput::RequestMethod() != HTTP_POST){
throw new InvalidRequestException('Only HTTP POST accepted.'); throw new Exceptions\InvalidRequestException('Only HTTP POST accepted.');
} }
if(HttpInput::IsRequestTooLarge()){ if(HttpInput::IsRequestTooLarge()){
@ -33,7 +28,8 @@ try{
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
$artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false); $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false);
$artwork->Tags = Artwork::ParseTags(HttpInput::Str(POST, 'artwork-tags', false)); $artwork->Tags = Artwork::ParseTags(HttpInput::Str(POST, 'artwork-tags', false));
$artwork->Status = HttpInput::Str(POST, 'artwork-status', false) ?? COVER_ARTWORK_STATUS_UNVERIFIED; $artwork->Status = HttpInput::Str(POST, 'artwork-status', false, COVER_ARTWORK_STATUS_UNVERIFIED);
$artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false);
$artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null; $artwork->SubmitterUserId = $GLOBALS['User']->UserId ?? null;
$artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us', false); $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us', false);
$artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year'); $artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year');
@ -49,6 +45,11 @@ try{
throw new Exceptions\InvalidPermissionsException(); throw new Exceptions\InvalidPermissionsException();
} }
// If the artwork is approved, set the reviewer
if($artwork->Status != COVER_ARTWORK_STATUS_UNVERIFIED){
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
}
$artwork->Create($_FILES['artwork-image'] ?? []); $artwork->Create($_FILES['artwork-image'] ?? []);
$_SESSION['artwork'] = $artwork; $_SESSION['artwork'] = $artwork;
@ -63,11 +64,8 @@ catch(Exceptions\LoginRequiredException){
catch(Exceptions\InvalidPermissionsException){ catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); Template::Emit403();
} }
catch(Exceptions\InvalidRequestException){
http_response_code(405);
}
catch(Exceptions\AppException $exception){ catch(Exceptions\AppException $exception){
$_SESSION['artwork'] = $artwork; $_SESSION['artwork'] = $artwork ?? null;
$_SESSION['exception'] = $exception; $_SESSION['exception'] = $exception;
http_response_code(303); http_response_code(303);

View file

@ -1756,6 +1756,10 @@ label span + span{
font-style: italic; font-style: italic;
} }
label span + span code{
font-style: normal;
}
label span + span i{ label span + span i{
font-style: normal; font-style: normal;
} }
@ -1798,6 +1802,7 @@ label.select > span + span{
label.select > span + span::after{ label.select > span + span::after{
display: block; display: block;
font-style: normal;
position: absolute; position: absolute;
top: calc((2rem + 1.4rem + 2px) / 2 - 10px); top: calc((2rem + 1.4rem + 2px) / 2 - 10px);
right: calc(1rem - 12px / 2); right: calc(1rem - 12px / 2);