Skip to content

Commit

Permalink
Use default yellow for annotations if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Sep 11, 2022
1 parent 689f9e9 commit da664b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions model/Item.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,11 @@ public function save($userID=false) {
);
}

// Default color to yellow if not specified
if (!$this->annotationColor) {
$this->annotationColor = Zotero_Items::$defaultAnnotationColor;
}

$color = $this->annotationColor;
if ($color) {
// Strip '#' from hex color
Expand Down
1 change: 1 addition & 0 deletions model/Items.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Zotero_Items {
public static $maxAnnotationTextLength = 25000;
public static $maxAnnotationPageLabelLength = 50;
public static $maxAnnotationPositionLength = 65535;
public static $defaultAnnotationColor = '#ffd400';

/**
*
Expand Down
27 changes: 27 additions & 0 deletions tests/remote/tests/API/3/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,33 @@ public function test_should_reject_invalid_sortIndex() {
}


public function test_should_use_default_yellow_if_color_not_specified() {
$json = [
'itemType' => 'annotation',
'parentItem' => self::$attachmentKey,
'annotationType' => 'highlight',
'annotationText' => '',
'annotationSortIndex' => '00015|002431|00000',
'annotationPosition' => json_encode([
'pageIndex' => 123,
'rects' => [
[314.4, 412.8, 556.2, 609.6]
]
])
];
$response = API::userPost(
self::$config['userID'],
"items",
json_encode([$json]),
["Content-Type: application/json"]
);
$this->assert200ForObject($response);
$json = API::getJSONFromResponse($response);
$jsonData = $json['successful'][0]['data'];
$this->assertEquals('#ffd400', $jsonData['annotationColor']);
}


public function test_should_reject_invalid_color_value() {
$json = [
'itemType' => 'annotation',
Expand Down

0 comments on commit da664b8

Please sign in to comment.