Skip to content

Commit 685855b

Browse files
api: Add support for links origins
1 parent d64d679 commit 685855b

11 files changed

Lines changed: 75 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog of Flus
22

3+
## unreleased
4+
5+
### Migration notes
6+
7+
The `source` field has been deprecated in the API.
8+
You must use the new `origin` field instead.
9+
310
## 2026-04-22 - v2.4.0
411

512
### Features

docs/api/journal.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ $ curl -H "Content-Type: application/json" \
3030
"reading_time": 3,
3131
"tags": [],
3232
"source": "collection#<id>",
33+
"origin": {
34+
"value": "https://app.flus.fr/collections/<id>",
35+
"label": "<collection's name>",
36+
"url": "https://app.flus.fr/collections/<id>"
37+
},
3338
"is_read": false,
3439
"is_read_later": false,
3540
"collections": [],
@@ -50,6 +55,7 @@ $ curl -H "Content-Type: application/json" \
5055
### Changelog
5156

5257
- 2.0.0: added
58+
- 2.5.0: `source` is deprecated, use `origin` instead
5359

5460
## Refresh the journal
5561

@@ -97,7 +103,8 @@ POST /api/v1/journal/read
97103
### JSON Parameters
98104

99105
- `date` (string, optional, format: `YYYY-MM-DD`): a date to filter the links to mark as read
100-
- `source` (string, optional): a source to filter the links to mark as read
106+
- `origin` (string, optional): an origin to filter the links to mark as read
107+
- `source` (**deprecated,** string, optional): a source to filter the links to mark as read
101108

102109
### Example
103110

@@ -128,6 +135,7 @@ $ curl -H "Content-Type: application/json" \
128135
### Changelog
129136

130137
- 2.0.0: added
138+
- 2.5.0: `source` is deprecated, use `origin` instead
131139

132140
## Mark the links of the journal to read later
133141

@@ -138,7 +146,8 @@ POST /api/v1/journal/later
138146
### JSON Parameters
139147

140148
- `date` (string, optional, format: `YYYY-MM-DD`): a date to filter the links to mark to read later
141-
- `source` (string, optional): a source to filter the links to mark to read later
149+
- `origin` (string, optional): an origin to filter the links to mark to read later
150+
- `source` (**deprecated,** string, optional): a source to filter the links to mark to read later
142151

143152
### Example
144153

@@ -169,6 +178,7 @@ $ curl -H "Content-Type: application/json" \
169178
### Changelog
170179

171180
- 2.0.0: added
181+
- 2.5.0: `source` is deprecated, use `origin` instead
172182

173183
## Remove the links from the journal
174184

@@ -179,7 +189,8 @@ DELETE /api/v1/journal/links
179189
### JSON Parameters
180190

181191
- `date` (string, optional, format: `YYYY-MM-DD`): a date to filter the links to remove
182-
- `source` (string, optional): a source to filter the links to remove
192+
- `origin` (string, optional): an origin to filter the links to remove
193+
- `source` (**deprecated,** string, optional): a source to filter the links to remove
183194

184195
### Example
185196

@@ -210,6 +221,7 @@ $ curl -H "Content-Type: application/json" \
210221
### Changelog
211222

212223
- 2.0.0: added
224+
- 2.5.0: `source` is deprecated, use `origin` instead
213225

214226
## Remove a single link from the journal
215227

docs/api/links.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ $ curl -H "Content-Type: application/json" \
3636
"reading_time": 3,
3737
"tags": [],
3838
"source": null,
39+
"origin": null,
3940
"is_read": false,
4041
"is_read_later": false,
4142
"collections": [],
@@ -80,6 +81,7 @@ $ curl -H "Content-Type: application/json" \
8081
### Changelog
8182

8283
- 2.0.0: added
84+
- 2.5.0: `source` is deprecated, use `origin` instead
8385

8486
## Get a link
8587

@@ -110,6 +112,7 @@ $ curl -H "Content-Type: application/json" \
110112
"reading_time": 3,
111113
"tags": [],
112114
"source": null,
115+
"origin": null,
113116
"is_read": false,
114117
"is_read_later": false,
115118
"collections": [],
@@ -145,6 +148,7 @@ $ curl -H "Content-Type: application/json" \
145148
### Changelog
146149

147150
- 2.0.0: added
151+
- 2.5.0: `source` is deprecated, use `origin` instead
148152

149153
## Update a link
150154

@@ -163,7 +167,7 @@ PATCH /api/v1/links/:id
163167
$ curl -H "Content-Type: application/json" \
164168
-H "Authorization: Bearer <token>" \
165169
-X PATCH \
166-
-d '{"title": "Flus homepage", "reading_time": 10}' \
170+
-d '{"title": "Flus homepage", "reading_time": 10, "origin": "https://example.org", "origin_is_public": true}' \
167171
"https://app.flus.fr/api/v1/links/<id>"
168172
```
169173

@@ -181,6 +185,11 @@ $ curl -H "Content-Type: application/json" \
181185
"reading_time": 10,
182186
"tags": [],
183187
"source": null,
188+
"origin": {
189+
"value": "https://example.org",
190+
"label": "example.org",
191+
"url": "https://example.org"
192+
},
184193
"is_read": false,
185194
"is_read_later": false,
186195
"collections": [],
@@ -240,6 +249,8 @@ $ curl -H "Content-Type: application/json" \
240249
### Changelog
241250

242251
- 2.0.0: added
252+
- 2.5.0: `origin` and `origin_is_public` can be updated
253+
- 2.5.0: `source` is deprecated, use `origin` instead
243254

244255
## Delete a link
245256

docs/api/search.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ $ curl -H "Content-Type: application/json" \
3636
"reading_time": 3,
3737
"tags": [],
3838
"source": null,
39+
"origin": null,
3940
"is_read": false,
4041
"is_read_later": false,
4142
"collections": [],
@@ -89,3 +90,4 @@ Thus, you can follow feeds using the same endpoint as for the collections.
8990
- 2.0.0: added
9091
- 2.0.5: add missing `created_at`, `is_hidden`, `source`, `published_at`, `number_notes`
9192
- 2.0.5: `feeds` entry added
93+
- 2.5.0: `source` is deprecated, use `origin` instead

src/forms/api/EmptyJournal.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class EmptyJournal extends Form
1414
#[Form\Field(format: 'Y-m-d')]
1515
public ?\DateTimeImmutable $date = null;
1616

17+
#[Form\Field]
18+
public ?string $origin = null;
19+
1720
#[Form\Field]
1821
public ?string $source = null;
1922

@@ -42,6 +45,10 @@ public function links(): array
4245
$options['origin'] = $source_origin;
4346
}
4447

48+
if ($this->origin) {
49+
$options['origin'] = $this->origin;
50+
}
51+
4552
$news = $this->user->news();
4653
return $news->links(options: $options);
4754
}

src/forms/api/Link.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ class Link extends Form
1818

1919
#[Form\Field]
2020
public int $reading_time;
21+
22+
#[Form\Field(bind: 'setOrigin')]
23+
public string $origin;
24+
25+
#[Form\Field]
26+
public bool $origin_is_public;
2127
}

src/models/Link.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\models;
44

5+
use App\auth;
56
use App\utils;
67
use Minz\Database;
78
use Minz\Translatable;
@@ -549,9 +550,16 @@ public static function hashUrl(string $url): string
549550
public function toJson(User $context_user): array
550551
{
551552
$origin_model = $this->origin();
553+
$origin = null;
552554
$source = null;
553555

554-
if ($context_user->id === $this->user_id && $origin_model) {
556+
if ($origin_model && auth\Access::can($context_user, 'viewOrigin', $this)) {
557+
$origin = [
558+
'value' => $origin_model->value,
559+
'label' => $origin_model->label,
560+
'url' => $origin_model->url,
561+
];
562+
555563
$source = $this->source();
556564
}
557565

@@ -564,6 +572,7 @@ public function toJson(User $context_user): array
564572
'reading_time' => $this->reading_time,
565573
'tags' => $this->tags,
566574
'source' => $source, // @deprecated Can be removed in version 3.0.0.
575+
'origin' => $origin,
567576
'is_read' => $this->isReadBy($context_user),
568577
'is_read_later' => $this->isInBookmarksOf($context_user),
569578
'collections' => array_column($this->collections(), 'id'),

tests/controllers/api/v1/LinksTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,31 @@ public function testUpdateUpdatesTheLink(): void
321321
$old_reading_time = 21;
322322
$new_title = 'The link';
323323
$new_reading_time = 42;
324+
$old_origin = 'Internet';
325+
$new_origin = 'The Web';
326+
$old_origin_is_public = false;
327+
$new_origin_is_public = true;
324328
$link = LinkFactory::create([
325329
'user_id' => $user->id,
326330
'title' => $old_title,
327331
'reading_time' => $old_reading_time,
332+
'origin' => $old_origin,
333+
'origin_is_public' => $old_origin_is_public,
328334
]);
329335

330336
$response = $this->apiRun('PATCH', "/api/v1/links/{$link->id}", [
331337
'title' => $new_title,
332338
'reading_time' => $new_reading_time,
339+
'origin' => $new_origin,
340+
'origin_is_public' => $new_origin_is_public,
333341
]);
334342

335343
$this->assertResponseCode($response, 200);
336344
$link = $link->reload();
337345
$this->assertSame($new_title, $link->title);
338346
$this->assertSame($new_reading_time, $link->reading_time);
347+
$this->assertSame($new_origin, $link->origin);
348+
$this->assertSame($new_origin_is_public, $link->origin_is_public);
339349
$this->assertApiResponse($response, $link->toJson($user));
340350
}
341351

tests/controllers/api/v1/journal/LaterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testCreateCanMakAsReadLaterByDate(): void
5959
$this->assertFalse($link2->isInBookmarksOf($user));
6060
}
6161

62-
public function testCreateCanMakAsReadLaterBySource(): void
62+
public function testCreateCanMakAsReadLaterByOrigin(): void
6363
{
6464
$user = $this->login();
6565
$news = $user->news();
@@ -79,7 +79,7 @@ public function testCreateCanMakAsReadLaterBySource(): void
7979
$this->assertFalse($link2->isInBookmarksOf($user));
8080

8181
$response = $this->apiRun('POST', '/api/v1/journal/later', [
82-
'source' => "collection#{$collection->id}",
82+
'origin' => $origin,
8383
]);
8484

8585
$this->assertResponseCode($response, 200);

tests/controllers/api/v1/journal/LinksTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testDeleteAllCanRemoveLinksByDate(): void
5959
$this->assertFalse($link2->isInNeverList($user));
6060
}
6161

62-
public function testDeleteAllCanRemoveLinksBySource(): void
62+
public function testDeleteAllCanRemoveLinksByOrigin(): void
6363
{
6464
$user = $this->login();
6565
$news = $user->news();
@@ -79,7 +79,7 @@ public function testDeleteAllCanRemoveLinksBySource(): void
7979
$this->assertFalse($link2->isInNeverList($user));
8080

8181
$response = $this->apiRun('DELETE', '/api/v1/journal/links', [
82-
'source' => "collection#{$collection->id}",
82+
'origin' => $origin,
8383
]);
8484

8585
$this->assertResponseCode($response, 200);

0 commit comments

Comments
 (0)