Skip to content

Commit 2d68e25

Browse files
new: Allow to repair links
1 parent b60e835 commit 2d68e25

File tree

17 files changed

+601
-38
lines changed

17 files changed

+601
-38
lines changed

locales/fr_FR/LC_MESSAGES/main.mo

646 Bytes
Binary file not shown.

locales/fr_FR/LC_MESSAGES/main.po

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: flusio\n"
4-
"POT-Creation-Date: 2022-08-10 17:38+0200\n"
5-
"PO-Revision-Date: 2022-08-10 17:38+0200\n"
4+
"POT-Creation-Date: 2022-08-11 12:06+0200\n"
5+
"PO-Revision-Date: 2022-08-11 12:06+0200\n"
66
"Last-Translator: Marien Fressinaud <dev@marienfressinaud.fr>\n"
77
"Language-Team: \n"
88
"Language: fr_FR\n"
@@ -57,10 +57,10 @@ msgstr "Afficher"
5757
#: controllers/collections/Images.php:113 controllers/collections/Links.php:104
5858
#: controllers/collections/Shares.php:107
5959
#: controllers/collections/Shares.php:230 controllers/links/Messages.php:71
60-
#: controllers/links/Searches.php:106 controllers/my/Account.php:103
61-
#: controllers/my/Profile.php:76 controllers/my/Security.php:79
62-
#: controllers/my/Security.php:150 controllers/my/Subscription.php:74
63-
#: controllers/my/Validation.php:132
60+
#: controllers/links/Repairing.php:106 controllers/links/Searches.php:106
61+
#: controllers/my/Account.php:103 controllers/my/Profile.php:76
62+
#: controllers/my/Security.php:79 controllers/my/Security.php:150
63+
#: controllers/my/Subscription.php:74 controllers/my/Validation.php:132
6464
msgid "A security verification failed: you should retry to submit the form."
6565
msgstr ""
6666
"Une vérification de sécurité a échoué : vous devriez essayer de resoumettre "
@@ -692,10 +692,11 @@ msgstr "Suivant"
692692
#: views/links/collections/index_adding.phtml:29
693693
#: views/links/collections/index_news.phtml:32 views/links/edit.phtml:43
694694
#: views/links/edit.phtml:72 views/links/new.phtml:41 views/links/new.phtml:58
695-
#: views/links/searches/show.phtml:55 views/links/show.phtml:184
696-
#: views/messages/edit.phtml:37 views/my/account/deletion.phtml:63
697-
#: views/my/profile/edit.phtml:55 views/my/profile/edit.phtml:91
698-
#: views/my/profile/edit.phtml:118 views/my/security/show_confirmed.phtml:41
695+
#: views/links/repairing/_new.phtml:37 views/links/searches/show.phtml:55
696+
#: views/links/show.phtml:184 views/messages/edit.phtml:37
697+
#: views/my/account/deletion.phtml:63 views/my/profile/edit.phtml:55
698+
#: views/my/profile/edit.phtml:91 views/my/profile/edit.phtml:118
699+
#: views/my/security/show_confirmed.phtml:41
699700
#: views/my/security/show_confirmed.phtml:81
700701
#: views/my/security/show_to_confirm.phtml:55 views/passwords/edit.phtml:58
701702
#: views/passwords/forgot.phtml:48 views/registrations/new.phtml:50
@@ -939,11 +940,12 @@ msgid "New link"
939940
msgstr "Nouveau lien"
940941

941942
#: views/collections/links/new.phtml:22 views/links/new.phtml:23
943+
#: views/links/repairing/_new.phtml:19
942944
msgid "What’s the address of the link?"
943945
msgstr "Quelle est l’adresse du lien ?"
944946

945947
#: views/collections/links/new.phtml:46 views/feeds/_new.phtml:39
946-
#: views/links/new.phtml:47
948+
#: views/links/new.phtml:47 views/links/repairing/_new.phtml:43
947949
msgid ""
948950
"It can be copy-paste from the <abbr>URL</abbr> bar, at the top of your "
949951
"browser."
@@ -1074,13 +1076,13 @@ msgid "Published by %s"
10741076
msgstr "Publiée par %s"
10751077

10761078
#: views/collections/show.phtml:74 views/collections/show_public.phtml:112
1077-
#: views/links/_link.phtml:120 views/links/_link.phtml:124
1079+
#: views/links/_link.phtml:121 views/links/_link.phtml:125
10781080
#: views/links/show.phtml:106 views/links/show.phtml:110
10791081
msgid "Actions"
10801082
msgstr "Actions"
10811083

10821084
#: views/collections/show.phtml:104 views/groups/_group.phtml:23
1083-
#: views/groups/_group.phtml:37 views/links/_link.phtml:141
1085+
#: views/groups/_group.phtml:37 views/links/_link.phtml:184
10841086
#: views/links/searches/show.phtml:124 views/links/show.phtml:126
10851087
#: views/profiles/show.phtml:55
10861088
msgid "Edit"
@@ -1395,24 +1397,24 @@ msgstr "Quelque chose s’est mal passé"
13951397
msgid "An error occurred during the processing of your request."
13961398
msgstr "Une erreur est survenue pendant le traitement de votre requête."
13971399

1398-
#: views/links/_link.phtml:54 views/links/searches/show.phtml:100
1400+
#: views/links/_link.phtml:55 views/links/searches/show.phtml:100
13991401
#: views/links/searches/show.phtml:157 views/links/show.phtml:47
14001402
msgid "ongoing synchronisation…"
14011403
msgstr "synchronisation en cours…"
14021404

1403-
#: views/links/_link.phtml:61
1405+
#: views/links/_link.phtml:62
14041406
msgid "You read this link."
14051407
msgstr "Vous avez lu ce lien."
14061408

1407-
#: views/links/_link.phtml:68
1409+
#: views/links/_link.phtml:69
14081410
#, php-format
14091411
msgid ""
14101412
"via your <strong><a class=\"anchor--hidden\" href=\"%s\">bookmarks</a></"
14111413
"strong>"
14121414
msgstr ""
14131415
"via vos <strong><a class=\"anchor--hidden\" href=\"%s\">signets</a></strong>"
14141416

1415-
#: views/links/_link.phtml:73
1417+
#: views/links/_link.phtml:74
14161418
#, php-format
14171419
msgid ""
14181420
"via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong> by <a "
@@ -1421,67 +1423,71 @@ msgstr ""
14211423
"via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong> de <a "
14221424
"class=\"anchor--hidden\" href=\"%s\">%s</a>"
14231425

1424-
#: views/links/_link.phtml:81 views/links/_link.phtml:88
1426+
#: views/links/_link.phtml:82 views/links/_link.phtml:89
14251427
#, php-format
14261428
msgid "via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong>"
14271429
msgstr "via <strong><a class=\"anchor--hidden\" href=\"%s\">%s</a></strong>"
14281430

1429-
#: views/links/_link.phtml:100 views/links/searches/show.phtml:110
1431+
#: views/links/_link.phtml:101 views/links/searches/show.phtml:110
14301432
#, php-format
14311433
msgid "%s comment"
14321434
msgid_plural "%s comments"
14331435
msgstr[0] "%s commentaire"
14341436
msgstr[1] "%s commentaires"
14351437

1436-
#: views/links/_link.phtml:105
1438+
#: views/links/_link.phtml:106
14371439
msgid "hidden"
14381440
msgstr "masqué"
14391441

1440-
#: views/links/_link.phtml:155
1442+
#: views/links/_link.phtml:141
14411443
msgid "Copy the external link"
14421444
msgstr "Copier le lien externe"
14431445

1444-
#: views/links/_link.phtml:165
1446+
#: views/links/_link.phtml:151
14451447
msgid "Mark as read"
14461448
msgstr "Marquer comme lu"
14471449

1448-
#: views/links/_link.phtml:178
1450+
#: views/links/_link.phtml:164
14491451
msgid "Remove from read list"
14501452
msgstr "Retirer des liens lus"
14511453

1452-
#: views/links/_link.phtml:190 views/links/_link.phtml:194
1454+
#: views/links/_link.phtml:199
1455+
msgid "Repair"
1456+
msgstr "Réparer"
1457+
1458+
#: views/links/_link.phtml:210 views/links/_link.phtml:214
14531459
msgid "Remove from the news page"
14541460
msgstr "Retirer du journal"
14551461

1456-
#: views/links/_link.phtml:201
1462+
#: views/links/_link.phtml:221
14571463
msgid "Remove from the news…"
14581464
msgstr "Retirer du journal…"
14591465

1460-
#: views/links/_link.phtml:209
1466+
#: views/links/_link.phtml:229
14611467
msgid "and mark as read"
14621468
msgstr "et marquer comme lu"
14631469

1464-
#: views/links/_link.phtml:218
1470+
#: views/links/_link.phtml:238
14651471
msgid "and read later"
14661472
msgstr "et lire plus tard"
14671473

1468-
#: views/links/_link.phtml:229
1474+
#: views/links/_link.phtml:249
14691475
msgid "and never see again"
14701476
msgstr "et ne plus revoir"
14711477

1472-
#: views/links/_link.phtml:244 views/links/_link.phtml:249
1478+
#: views/links/_link.phtml:264 views/links/_link.phtml:269
14731479
msgid "Manage collections"
14741480
msgstr "Gérer les collections"
14751481

1476-
#: views/links/_link.phtml:244 views/links/_link.phtml:254
1482+
#: views/links/_link.phtml:264 views/links/_link.phtml:274
14771483
msgid "Add to collections"
14781484
msgstr "Ajouter aux collections"
14791485

1480-
#: views/links/_link.phtml:268 views/links/show.phtml:69
1486+
#: views/links/_link.phtml:288 views/links/show.phtml:69
14811487
msgid "read"
14821488
msgstr "lire"
14831489

1484-
#: views/links/_link.phtml:270 views/links/show.phtml:71
1490+
#: views/links/_link.phtml:290 views/links/show.phtml:71
14851491
msgid "(open a new window)"
14861492
msgstr "(ouvre une nouvelle fenêtre)"
14871493

@@ -1562,6 +1568,33 @@ msgstr "Simplifiez-vous la vie en utilisant l’extension navigateur sur"
15621568
msgid "or"
15631569
msgstr "ou"
15641570

1571+
#: views/links/repairing/_new.phtml:4 views/links/repairing/new.phtml:3
1572+
msgid "Repairing a link"
1573+
msgstr "Réparation d’un lien"
1574+
1575+
#: views/links/repairing/_new.phtml:8
1576+
msgid ""
1577+
"You can change the <abbr>URL</abbr> of a link if it’s broken, or if you made "
1578+
"a mistake in it."
1579+
msgstr ""
1580+
"Vous pouvez modifier l’<abbr>URL</abbr> d’un lien s’il est cassé, ou si vous "
1581+
"avez fait une erreur."
1582+
1583+
#: views/links/repairing/_new.phtml:58
1584+
msgid "Ask for a new synchronization"
1585+
msgstr "Demander une nouvelle synchronisation"
1586+
1587+
#: views/links/repairing/_new.phtml:62
1588+
msgid ""
1589+
"This will check the status of the page and possibly update the illustration."
1590+
msgstr ""
1591+
"Cela vérifiera le statut de la page et mettra éventuellement à jour "
1592+
"l’illustration."
1593+
1594+
#: views/links/repairing/_new.phtml:68
1595+
msgid "Repair the link"
1596+
msgstr "Réparer le lien"
1597+
15651598
#: views/links/search.phtml:8 views/links/search.phtml:20
15661599
msgid "Results of the search"
15671600
msgstr "Résultats de la recherche"
@@ -2293,7 +2326,7 @@ msgstr "Voici votre profil public !"
22932326
msgid "Last shared links"
22942327
msgstr "Derniers liens partagés"
22952328

2296-
#: views/profiles/show.phtml:80
2329+
#: views/profiles/show.phtml:81
22972330
#, php-format
22982331
msgid ""
22992332
"You didn’t share any links yet. Start by <a href=\"%s\">creating a public "
@@ -2302,15 +2335,15 @@ msgstr ""
23022335
"Vous n’avez pas encore partagé de lien. Commencez par <a href=\"%s\">créer "
23032336
"une collection publique</a>."
23042337

2305-
#: views/profiles/show.phtml:84
2338+
#: views/profiles/show.phtml:85
23062339
msgid "This user didn’t share any links yet."
23072340
msgstr "Cet·te utilisateur·ice n’a pas encore partagé de lien."
23082341

2309-
#: views/profiles/show.phtml:90
2342+
#: views/profiles/show.phtml:91
23102343
msgid "Published collections"
23112344
msgstr "Collections publiées"
23122345

2313-
#: views/profiles/show.phtml:107
2346+
#: views/profiles/show.phtml:108
23142347
msgid "Collections shared with you"
23152348
msgstr "Collections partagées avec vous"
23162349

src/Router.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public static function load()
147147
$router->addRoute('get', '/links/:id/feed', 'links/Feeds#alias');
148148
$router->addRoute('get', '/links/:id/edit', 'Links#edit', 'edit link');
149149
$router->addRoute('post', '/links/:id/edit', 'Links#update', 'update link');
150+
$router->addRoute('get', '/links/:id/repair', 'links/Repairing#new', 'repairing link');
151+
$router->addRoute('post', '/links/:id/repair', 'links/Repairing#create', 'repair link');
150152
$router->addRoute('post', '/links/:id/delete', 'Links#delete', 'delete link');
151153
$router->addRoute('post', '/links/:id/fetch', 'Links#fetch', 'fetch link');
152154
$router->addRoute('post', '/links/:id/read', 'links/Read#create', 'mark link as read');

src/assets/icons/wrench.svg

Lines changed: 1 addition & 0 deletions
Loading

src/controllers/links/Repairing.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
namespace flusio\controllers\links;
4+
5+
use Minz\Response;
6+
use flusio\auth;
7+
use flusio\models;
8+
use flusio\services;
9+
10+
/**
11+
* @author Marien Fressinaud <dev@marienfressinaud.fr>
12+
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
13+
*/
14+
class Repairing
15+
{
16+
/**
17+
* Show the page to repair a link (change URL and resynchronize it).
18+
*
19+
* @request_param string id
20+
* @request_param string from
21+
*
22+
* @response 302 /login?redirect_to=:from
23+
* If the user is not connected.
24+
* @response 404
25+
* If the link doesn't exist or not accessible by the current user.
26+
* @response 200
27+
* On success.
28+
*/
29+
public function new($request)
30+
{
31+
$user = auth\CurrentUser::get();
32+
$link_id = $request->param('id');
33+
$from = $request->param('from');
34+
35+
if (!$user) {
36+
return Response::redirect('login', ['redirect_to' => $from]);
37+
}
38+
39+
$link = models\Link::find($link_id);
40+
$can_update = auth\LinksAccess::canUpdate($user, $link);
41+
if (!$can_update) {
42+
return Response::notFound('not_found.phtml');
43+
}
44+
45+
return Response::ok('links/repairing/new.phtml', [
46+
'link' => $link,
47+
'url' => $link->url,
48+
'ask_sync' => false,
49+
'from' => $from,
50+
]);
51+
}
52+
53+
/**
54+
* Repair a link (change URL and resynchronize it).
55+
*
56+
* @request_param string id
57+
* @request_param string url
58+
* @request_param boolean ask_sync
59+
* @request_param string from
60+
* @request_param string csrf
61+
*
62+
* @response 302 /login?redirect_to=:from
63+
* If the user is not connected.
64+
* @response 404
65+
* If the link doesn't exist or not accessible by the current user.
66+
* @response 400
67+
* If the csrf or url is invalid.
68+
* @response 302 :from
69+
* On success.
70+
*/
71+
public function create($request)
72+
{
73+
$user = auth\CurrentUser::get();
74+
$link_id = $request->param('id');
75+
$url = $request->param('url', '');
76+
$ask_sync = $request->paramBoolean('ask_sync', false);
77+
$csrf = $request->param('csrf');
78+
$from = $request->param('from');
79+
80+
if (!$user) {
81+
return Response::redirect('login', ['redirect_to' => $from]);
82+
}
83+
84+
$link = models\Link::find($link_id);
85+
$can_update = auth\LinksAccess::canUpdate($user, $link);
86+
if (!$can_update) {
87+
return Response::notFound('not_found.phtml');
88+
}
89+
90+
if ($request->isAccepting('text/vnd.turbo-stream.html')) {
91+
// This allows to display the errors within the modal instead of
92+
// sending a whole new page. This is a bit hacky so I'm going
93+
// to use this method only where absolutely needed.
94+
// @see https://github.com/hotwired/turbo/issues/138#issuecomment-847699281
95+
$view_file = 'links/repairing/new.turbo_stream.phtml';
96+
} else {
97+
$view_file = 'links/repairing/new.phtml';
98+
}
99+
100+
if (!\Minz\CSRF::validate($csrf)) {
101+
return Response::badRequest($view_file, [
102+
'link' => $link,
103+
'url' => $url,
104+
'ask_sync' => $ask_sync,
105+
'from' => $from,
106+
'error' => _('A security verification failed: you should retry to submit the form.'),
107+
]);
108+
}
109+
110+
$link->url = \SpiderBits\Url::sanitize($url);
111+
$errors = $link->validate();
112+
if ($errors) {
113+
return Response::badRequest($view_file, [
114+
'link' => $link,
115+
'url' => $url,
116+
'ask_sync' => $ask_sync,
117+
'from' => $from,
118+
'errors' => $errors,
119+
]);
120+
}
121+
122+
123+
if ($ask_sync) {
124+
$link_fetcher_service = new services\LinkFetcher([
125+
'timeout' => 10,
126+
'rate_limit' => false,
127+
]);
128+
$link_fetcher_service->fetch($link);
129+
} else {
130+
$link->save();
131+
}
132+
133+
return Response::found($from);
134+
}
135+
}

0 commit comments

Comments
 (0)