Compare commits

...

2 commits

Author SHA1 Message Date
61cabf1f05 Add library list per user 2025-04-22 21:27:34 -05:00
c85d539dc1 Update readme 2025-04-21 11:42:32 -05:00
6 changed files with 30 additions and 11 deletions

View file

@ -61,9 +61,10 @@ Rough roadmap in a rough order of priority
* [ ] Individual email actions
* [ ] SSO Support (openid)
* [x] Basic implementation
* [ ] User mapping
* [ ] User creation
* [x] User mapping
* [x] User creation
* [ ] User logout
* [ ] Normal user registration (email/username+pass)
* [ ] S3 backend support
* [ ] Administration panel
* [ ] Add storage backends

View file

@ -131,6 +131,7 @@ async fn rocket() -> _ {
.manage(libraries_manager)
.manage(settings)
.manage(sso)
.manage(users)
.attach(store.fairing())
.attach(Template::custom(|engines| {

View file

@ -1,9 +1,10 @@
use std::collections::HashMap;
use sqlx::{Pool, Postgres};
use sqlx::{query_as, Pool, Postgres};
use tokio::sync::RwLock;
use crate::objs::library::Library;
use crate::managers::repos::{RepoContainer, RepoManager};
use crate::models;
use crate::models::library::LibraryModel;
use crate::util::{JsonErrorResponse, ResponseError};
pub struct LibraryManager {
@ -19,6 +20,13 @@ impl LibraryManager {
}
}
pub async fn list(&self, user_id: &str) -> Result<Vec<LibraryModel>, anyhow::Error> {
// TODO: check for access from library_permissions
let libraries = query_as!(LibraryModel, "SELECT * FROM storage.libraries WHERE owner_id = $1", user_id)
.fetch_all(&self.pool)
.await.map_err(anyhow::Error::from)?;
Ok(libraries)
}
pub async fn get(&self, library_id: &str) -> Result<Library, ResponseError> {
let Some(library) = models::library::get_library(&self.pool, library_id).await
.map_err(|e| ResponseError::GenericError)? else {

View file

@ -26,6 +26,12 @@ pub struct LibraryWithRepoModel {
pub storage_type: String,
}
pub enum PermissionLevel {
ReadOnly = 0,
ReadWrite = 1,
Admin = 2
}
pub async fn get_library(pool: &DB, library_id: &str) -> Result<Option<LibraryModel>, anyhow::Error> {
let library_id = Uuid::from_str(library_id)?;
let library = query_as!(LibraryModel, "select * from storage.libraries where id = $1", library_id)

View file

@ -17,6 +17,7 @@ use tokio::sync::Mutex;
use crate::consts::FILE_CONSTANTS;
use crate::guards::{AuthUser};
use crate::managers::libraries::LibraryManager;
use crate::managers::user::UsersState;
use crate::objs::library::ListOptions;
use crate::routes::ui::auth;
use crate::util::{JsonErrorResponse, ResponseError};
@ -26,8 +27,10 @@ pub async fn user_settings(user: AuthUser, route: &Route) -> Template {
Template::render("settings", context! { session: user.session, route: route.uri.path() })
}
#[get("/")]
pub async fn index(user: AuthUser, route: &Route) -> Template {
Template::render("index", context! { session: user.session, route: route.uri.path(), test: "value" })
pub async fn index(user: AuthUser, libraries: &State<Arc<Mutex<LibraryManager>>>, route: &Route) -> Template {
let libraries = libraries.lock().await;
let list = libraries.list(&user.session.user.id).await.unwrap();
Template::render("index", context! { session: user.session, libraries: list, route: route.uri.path(), test: "value" })
}
#[get("/library/<library_id>")]

View file

@ -16,20 +16,20 @@
<thead>
<tr>
<td>Name </td>
<td>Size </td>
<td>Last Updated </td>
<td>Created </td>
<td>Owner </td>
</tr>
</thead>
<tbody>
{{#each libraries}}
<tr>
<td class="px-4 py-4">
<a href="/library/dbabbf7d-9b63-487b-9908-57c2df11b2d2/My Library/">My Library</a>
<a href="/library/{{id}}/{{name}}/">{{name}}</a>
</td>
<td></td>
<td></td>
<td>Me</td>
<td>{{ created_at }}</td>
<td>{{ owner_id }}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>