Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/src/routes/todo_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub async fn delete_todo_list(todo_list_id: i32) -> Result<NoContent, ServerFnEr
}

/// Kicks a user from a `TodoList`. Can only be performed by the owner or an admin of the `TodoList`.
/// If the owner was kicked, the ownership will be transferred to the user which kicked the owner.
/// An admin can only be removed when there is at least one other admin remaining in the `TodoList`.
#[post("/api/todolists/{todo_list_id}/remove-user", state: Extension<server::AppState>, auth: Extension<server::AuthenticationState>)]
pub async fn remove_user_from_todo_list(
todo_list_id: i32,
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/routes/todo_list/invite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ pub async fn decline_todo_list_invite(todo_list_id: i32) -> Result<NoContent, Se
Ok(NoContent)
}

/// Allows the authenticated user to leave a `TodoList` that they are a member of.
/// If the user is the only member of the `TodoList`, then the `TodoList` will be deleted.
/// If the user is an admin, they can only leave if there is at least one other admin remaining in the `TodoList` to avoid leaving the `TodoList` without any admins.
#[post("/api/todolists/{todo_list_id}/invite/leave", state: Extension<server::AppState>, auth: Extension<server::AuthenticationState> )]
pub async fn leave_todo_list(todo_list_id: i32) -> Result<NoContent, ServerFnError> {
use entity::todo_list_invitation::Column as InviteColum;
Expand Down
20 changes: 9 additions & 11 deletions packages/api/src/routes/todos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,27 @@ pub async fn list_todos(
use sea_orm::QueryFilter;
use sea_orm::QueryOrder;
use sea_orm::QuerySelect;
use sea_orm::QueryTrait;
use sea_orm::RelationTrait;

let user = auth.user.as_ref().or_unauthorized("Not authenticated")?;

let mut todos = Todo::find()
let todos = Todo::find()
.join(JoinType::InnerJoin, entity::todo::Relation::TodoList.def())
.join(
JoinType::InnerJoin,
entity::todo_list::Relation::TodoListInvitation.def(),
)
.filter(entity::todo_list_invitation::Column::ReceivingUserId.eq(user.id))
.filter(entity::todo_list_invitation::Column::IsAccepted.eq(true))
.apply_if(completed, |query, v| {
query.filter(entity::todo::Column::Completed.eq(v))
})
.apply_if(favorite, |query, v| {
query.filter(entity::todo_list_invitation::Column::IsFavorite.eq(v))
})
.order_by_asc(entity::todo::Column::Completed)
.order_by_asc(entity::todo::Column::Title);

if let Some(completed) = completed {
todos = todos.filter(entity::todo::Column::Completed.eq(completed));
}
if let Some(favorite) = favorite {
todos = todos.filter(entity::todo_list_invitation::Column::IsFavorite.eq(favorite));
}

let todos = todos
.order_by_asc(entity::todo::Column::Title)
.into_partial_model()
.all(&state.database)
.await
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/views/todo/components/todo_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use dioxus_free_icons::Icon;
use dioxus_free_icons::icons::ld_icons::{LdCircle, LdCircleCheckBig, LdTrash};
use entity::todo::UpdateToDo;
use entity::todo_list_invitation::InvitationPermission;
use roommates::message_from_captured_error;

#[component]
pub fn TodoEntry(
Expand Down Expand Up @@ -114,7 +115,7 @@ pub fn TodoEntry(
.error(
&format!("Failed to delete {}!", title_clone),
ToastOptions::new().description(rsx! {
span { "{error.to_string()}" }
span { "{message_from_captured_error(&error)}" }
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/views/todo/todo_list_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn TodoListEntry(
.error(
&format!("Failed to delete {title_clone}!"),
ToastOptions::new().description(rsx! {
span { "{error.to_string()}" }
span { "{message_from_captured_error(&error)}" }
}),
);
}
Expand Down