Skip to content

Commit 0920dcb

Browse files
committed
api: Document Item.author field and make it nullable
This raises API version, since previously the value would be an empty string when there was no author. Also update the database contents, replacing empty authors with `null`, so that clients can just rely on `null` author meaning ”no author”.
1 parent e153f2d commit 0920dcb

File tree

9 files changed

+37
-6
lines changed

9 files changed

+37
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
- `GET /login` endpoint, use `POST /login`. ([#1360](https://github.com/fossar/selfoss/pull/1360))
6060
- `GET /logout` was deprecated in favour of newly introduced (*API 4.1.0*) `DELETE /api/session/current`. ([#1360](https://github.com/fossar/selfoss/pull/1360))
6161
- `POST /source/delete/:id` in favour of `DELETE /source/:id`. ([#1360](https://github.com/fossar/selfoss/pull/1360))
62+
- *API 6.0.0*: Makes the `author` field `null` when an item author is not known ([#1367](https://github.com/fossar/selfoss/pull/1367))
6263

6364
### Customization changes
6465
- `selfoss.shares.register` was removed. Instead you should set `selfoss.customSharers` to an object of *sharer* objects. The `action` callback is now expected to open a window on its own, instead of returning a URL. A label and a HTML code of an icon (you can use a `<img>` tag, inline `<svg>`, emoji, etc.) are now expected.

assets/js/templates/Item.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
472472
<span className="entry-separator"></span>
473473

474474
{/* author */}
475-
{author.trim() !== '' ?
475+
{author !== null ?
476476
<React.Fragment>
477477
<span className="entry-author">{author}</span>
478478
<span className="entry-separator"></span>

docs/api-description.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"servers": [],
44
"info": {
55
"description": "You can access selfoss by using the same backend as selfoss user interface: The RESTful HTTP JSON API. There are a few urls where you can get information from selfoss and some for updating data. Assume you want all tags for rendering this in your own app. You have to make an HTTP GET call on the url /tags:\n\n```\nGET http://yourselfossurl.com/tags\n```\nThe result is following JSON formatted response (in this example two tags “blog” and “deviantart” are available:\n\n```\n[{\"tag\":\"blog\",\"color\":\"#251f10\",\"unread\":\"1\"},\n{\"tag\":\"deviantart\",\"color\":\"#e78e5c\",\"unread\":\"0\"}]\n```\n\nFollowing docs shows you which calls are possible and which response you can expect.",
6-
"version": "5.0.0",
6+
"version": "6.0.0",
77
"title": "selfoss"
88
},
99
"tags": [
@@ -954,6 +954,12 @@
954954
"type": "string",
955955
"example": "\n<p>Das 1-GBit/s-Angebot Google Fiber kommt nach Austin, die Hauptstadt des US-Bundesstaates Texas..."
956956
},
957+
"author": {
958+
"description": "Name/e-mail of the author of the item/article/tweet, when available.",
959+
"type": "string",
960+
"nullable": true,
961+
"example": "William Miller"
962+
},
957963
"unread": {
958964
"description": "true when the article is marked as unread, false when the article is marked as read",
959965
"type": "boolean",

docs/content/docs/customization/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Since selfoss 2.19, the API follows [semantic versioning](https://semver.org/) d
1111

1212
| selfoss | API |
1313
|---|---|
14-
| [2.19] | [5.0.0] |
14+
| [2.19] | [6.0.0] |
1515

1616
[2.19]: https://github.com/fossar/selfoss/releases/tag/2.19
17-
[5.0.0]: https://app.swaggerhub.com/apis-docs/jtojnar/selfoss/5.0.0
17+
[6.0.0]: https://app.swaggerhub.com/apis-docs/jtojnar/selfoss/6.0.0

src/constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
// independent of selfoss version
88
// needs to be bumped each time public API is changed (follows semver)
99
// keep in sync with docs/api-description.json
10-
const SELFOSS_API_VERSION = '5.0.0';
10+
const SELFOSS_API_VERSION = '6.0.0';

src/daos/mysql/Database.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ public function __construct(DatabaseConnection $connection, Logger $logger) {
287287
$this->exec('INSERT INTO ' . $this->connection->getTableNamePrefix() . 'version (version) VALUES (13)');
288288
$this->commit();
289289
}
290+
if ($version < 14) {
291+
$this->logger->debug('Upgrading database schema to version 14');
292+
293+
$this->beginTransaction();
294+
$this->exec('UPDATE ' . $this->connection->getTableNamePrefix() . "items SET author = NULL WHERE author = ''");
295+
$this->exec('INSERT INTO ' . $this->connection->getTableNamePrefix() . 'version (version) VALUES (14)');
296+
$this->commit();
297+
}
290298
}
291299

292300
/**

src/daos/pgsql/Database.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ public function __construct(DatabaseConnection $connection, Logger $logger) {
265265
$this->exec('INSERT INTO version (version) VALUES (13)');
266266
$this->commit();
267267
}
268+
if ($version < 14) {
269+
$this->logger->debug('Upgrading database schema to version 14');
270+
271+
$this->beginTransaction();
272+
$this->exec("UPDATE items SET author = NULL WHERE author = ''");
273+
$this->exec('INSERT INTO version (version) VALUES (14)');
274+
$this->commit();
275+
}
268276
}
269277

270278
/**

src/daos/sqlite/Database.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ public function __construct(DatabaseConnection $connection, Logger $logger) {
283283
$this->exec('INSERT INTO version (version) VALUES (13)');
284284
$this->commit();
285285
}
286+
if ($version < 14) {
287+
$this->logger->debug('Upgrading database schema to version 14');
288+
289+
$this->beginTransaction();
290+
$this->exec("UPDATE items SET author = NULL WHERE author = ''");
291+
$this->exec('INSERT INTO version (version) VALUES (14)');
292+
$this->commit();
293+
}
286294
}
287295

288296
/**

src/helpers/ContentLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function fetch($source) {
212212
'datetime' => $itemDate->format('Y-m-d H:i:s'),
213213
'uid' => $item->getId(),
214214
'link' => htmLawed($item->getLink(), ['deny_attribute' => '*', 'elements' => '-*']),
215-
'author' => $item->getAuthor() ?: '',
215+
'author' => $item->getAuthor(),
216216
'thumbnail' => null,
217217
'icon' => null,
218218
];

0 commit comments

Comments
 (0)