Compare commits

..

No commits in common. "61cabf1f05b6c90b3c4f1a151d610124f8ee5d54" and "3f222dfd3cf5c9fadb66debeb67afeacb458d8ba" have entirely different histories.

6 changed files with 11 additions and 30 deletions

View file

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

View file

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

View file

@ -1,10 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use sqlx::{query_as, Pool, Postgres}; use sqlx::{Pool, Postgres};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use crate::objs::library::Library; use crate::objs::library::Library;
use crate::managers::repos::{RepoContainer, RepoManager}; use crate::managers::repos::{RepoContainer, RepoManager};
use crate::models; use crate::models;
use crate::models::library::LibraryModel;
use crate::util::{JsonErrorResponse, ResponseError}; use crate::util::{JsonErrorResponse, ResponseError};
pub struct LibraryManager { pub struct LibraryManager {
@ -20,13 +19,6 @@ 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> { pub async fn get(&self, library_id: &str) -> Result<Library, ResponseError> {
let Some(library) = models::library::get_library(&self.pool, library_id).await let Some(library) = models::library::get_library(&self.pool, library_id).await
.map_err(|e| ResponseError::GenericError)? else { .map_err(|e| ResponseError::GenericError)? else {

View file

@ -26,12 +26,6 @@ pub struct LibraryWithRepoModel {
pub storage_type: String, 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> { 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_id = Uuid::from_str(library_id)?;
let library = query_as!(LibraryModel, "select * from storage.libraries where id = $1", library_id) let library = query_as!(LibraryModel, "select * from storage.libraries where id = $1", library_id)

View file

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

View file

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