registri dei piani in git (AI-OS#309)
Refs gitea:Adriano/AI-OS#310 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
# Review package: 22d72be..2bf6b3d
|
||||
|
||||
## Commits
|
||||
2bf6b3d feat(admin): nav per 3 ruoli, blog filtrato per autore + colonna autore
|
||||
|
||||
## Files changed
|
||||
src/layouts/Admin.astro | 13 +++++++++++--
|
||||
src/pages/admin/index.astro | 11 ++++++++---
|
||||
2 files changed, 19 insertions(+), 5 deletions(-)
|
||||
|
||||
## Diff
|
||||
diff --git a/src/layouts/Admin.astro b/src/layouts/Admin.astro
|
||||
index e61622f..ab98680 100644
|
||||
--- a/src/layouts/Admin.astro
|
||||
+++ b/src/layouts/Admin.astro
|
||||
@@ -24,17 +24,26 @@ const user = Astro.locals.user;
|
||||
.pill--draft { background: #f3d9a4; }
|
||||
.form-msg { font-size: .9rem; margin-top: 8px; }
|
||||
.form-msg--ok { color: #3c7a3c; }
|
||||
.form-msg--err { color: #b03030; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="abar">
|
||||
<strong>InsanityLab · Admin</strong>
|
||||
<span>
|
||||
- {user && user.role === 'editor' && <>{`Ciao, ${user.username}`} <a href="/admin/content">Contenuti</a> <a href="/admin/logout">Esci</a></>}
|
||||
- {user && user.role !== 'editor' && <>{`Ciao, ${user.username}`} <a href="/admin">Articoli</a> <a href="/admin/content">Contenuti</a> <a href="/admin/new">Nuovo</a> <a href="/admin/logout">Esci</a> <a href="/blog" target="_blank">Vedi sito ↗</a></>}
|
||||
+ {user && (
|
||||
+ <>
|
||||
+ {`Ciao, ${user.username}`}
|
||||
+ <a href="/admin">Articoli</a>
|
||||
+ {(user.role === 'superuser' || user.role === 'admin') && <a href="/admin/content">Contenuti</a>}
|
||||
+ {user.role === 'admin' && <a href="/admin/users">Utenti</a>}
|
||||
+ <a href="/admin/new">Nuovo</a>
|
||||
+ <a href="/admin/logout">Esci</a>
|
||||
+ <a href="/blog" target="_blank">Vedi sito ↗</a>
|
||||
+ </>
|
||||
+ )}
|
||||
</span>
|
||||
</div>
|
||||
<div class="awrap"><slot /></div>
|
||||
</body>
|
||||
</html>
|
||||
diff --git a/src/pages/admin/index.astro b/src/pages/admin/index.astro
|
||||
index a8e0cd3..24cb0ca 100644
|
||||
--- a/src/pages/admin/index.astro
|
||||
+++ b/src/pages/admin/index.astro
|
||||
@@ -1,28 +1,33 @@
|
||||
---
|
||||
import Admin from '../../layouts/Admin.astro';
|
||||
import { getDb } from '../../lib/db';
|
||||
-import { listAllPosts } from '../../lib/posts';
|
||||
+import { listAllPosts, listByAuthor } from '../../lib/posts';
|
||||
+import { listUsers } from '../../lib/auth';
|
||||
export const prerender = false;
|
||||
-const posts = listAllPosts(getDb());
|
||||
+const user = Astro.locals.user!;
|
||||
+const isManager = user.role === 'superuser' || user.role === 'admin';
|
||||
+const posts = isManager ? listAllPosts(getDb()) : listByAuthor(getDb(), user.id);
|
||||
+const nameById = new Map(listUsers(getDb()).map((u) => [u.id, u.username]));
|
||||
const fmt = new Intl.DateTimeFormat('it-IT', { dateStyle: 'short', timeStyle: 'short' });
|
||||
---
|
||||
<Admin title="Articoli">
|
||||
<h1>Articoli</h1>
|
||||
<p><a class="abtn" href="/admin/new">+ Nuovo articolo</a></p>
|
||||
<table>
|
||||
- <thead><tr><th>Titolo</th><th>Categoria</th><th>Stato</th><th>Aggiornato</th><th></th></tr></thead>
|
||||
+ <thead><tr><th>Titolo</th><th>Categoria</th>{isManager && <th>Autore</th>}<th>Stato</th><th>Aggiornato</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{posts.map((p) => (
|
||||
<tr>
|
||||
<td><a href={`/admin/edit/${p.id}`}>{p.title}</a></td>
|
||||
<td>{p.category}</td>
|
||||
+ {isManager && <td>{p.author_id ? (nameById.get(p.author_id) ?? 'Staff InsanityLab') : 'Staff InsanityLab'}</td>}
|
||||
<td><span class:list={['pill', { 'pill--draft': p.draft }]}>{p.draft ? 'Bozza' : 'Pubblicato'}</span></td>
|
||||
<td>{fmt.format(new Date(p.updated_at.replace(' ', 'T') + 'Z'))}</td>
|
||||
<td><button class="abtn abtn--danger" data-del={p.id}>Elimina</button></td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{posts.length === 0 && <p>Nessun articolo: creane uno nuovo.</p>}
|
||||
</Admin>
|
||||
|
||||
Reference in New Issue
Block a user