Reworked new users login, improved share feature, enabled track downloads
Build and Publish / Build and Publish Docker Image (push) Failing after 4m21s

This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-18 14:40:16 +00:00
1 parent 2b7117a4f6
commit 939fc00e4c
24 files changed
+1018 -970

No files matched your search

+18 -6
View File
@@ -28,7 +28,18 @@ pub(super) async fn manage_user(
Ok(u) => u,
Err(r) => return Ok(r),
};
if body.action == "delete" {
if body.action == "approve" {
let Some(id) = body.id.filter(|id| *id > 0) else {
return Ok(json_error(StatusCode::BAD_REQUEST, "Invalid user"));
};
if Role::from_code(&body.role).is_none() || (id == admin.id && body.role != "admin") {
return Ok(json_error(StatusCode::BAD_REQUEST, "Invalid role"));
}
let Some(mut user) = User::get_by_id(&db, id).await? else {
return Ok(json_error(StatusCode::NOT_FOUND, "User not found"));
};
user.approve(&db, &body.role, admin.id).await?;
} else if body.action == "delete" {
let Some(id) = body.id.filter(|id| *id > 0) else {
return Ok(json_error(StatusCode::BAD_REQUEST, "Invalid user"));
};
@@ -43,7 +54,8 @@ pub(super) async fn manage_user(
if !["create", "update"].contains(&body.action.as_str())
|| body.username.trim().is_empty()
|| body.username.chars().count() > 255
|| Role::from_code(&body.role).is_none()
|| (Role::from_code(&body.role).is_none()
&& !(body.action == "update" && body.role.is_empty()))
|| (body.action == "create" && body.password.is_empty())
{
return Ok(json_error(
@@ -74,15 +86,15 @@ pub(super) async fn manage_user(
let Some(id) = body.id.filter(|id| *id > 0) else {
return Ok(json_error(StatusCode::BAD_REQUEST, "Invalid user"));
};
if id == admin.id && body.role != "admin" {
let Some(mut user) = User::get_by_id(&db, id).await? else {
return Ok(json_error(StatusCode::NOT_FOUND, "User not found"));
};
if id == admin.id && body.role != "admin" && !user.has_sso_admin_role() {
return Ok(json_error(
StatusCode::BAD_REQUEST,
"You cannot remove your own administrator role",
));
}
let Some(mut user) = User::get_by_id(&db, id).await? else {
return Ok(json_error(StatusCode::NOT_FOUND, "User not found"));
};
if User::get_by_username(&db, body.username.trim())
.await?
.is_some_and(|u| u.id_val() != id)
+9 -3
View File
@@ -230,6 +230,8 @@ struct AdminUserRowDto {
email: Option<String>,
role: String,
is_active: bool,
local_role: Option<String>,
sso_role: Option<String>,
is_online: bool,
last_seen_ms: Option<i64>,
plays: i64,
@@ -2667,6 +2669,8 @@ struct AdminUserSqlRow {
email: Option<String>,
role: String,
is_active: bool,
local_role: Option<String>,
sso_role: Option<String>,
plays: i64,
listened_seconds: i64,
last_play_ms: Option<i64>,
@@ -2700,7 +2704,7 @@ async fn load_admin_users_page(
let total: i64 = count_qb.build_query_scalar().fetch_one(pool).await?;
let mut qb = QueryBuilder::<Postgres>::new(
"SELECT id, username::text, display_name, email, role::text, is_active, \
"SELECT id, username::text, display_name, email, role::text, is_active, local_role, sso_role, \
(SELECT COUNT(*) FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id AND qualified) AS plays, \
(SELECT (COALESCE(SUM(listened_ms), 0) / 1000)::bigint FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id) AS listened_seconds, \
(SELECT MAX(started_at_ms) FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id AND qualified) AS last_play_ms \
@@ -2715,7 +2719,7 @@ async fn load_admin_users_page(
qb.push_bind(pattern);
qb.push(")");
}
qb.push(" ORDER BY username ASC LIMIT ");
qb.push(" ORDER BY is_active ASC, username ASC LIMIT ");
qb.push_bind(limit);
qb.push(" OFFSET ");
qb.push_bind(offset);
@@ -2747,7 +2751,7 @@ async fn load_admin_user_detail(
user_id: i64,
) -> anyhow::Result<Option<AdminUserDetailDto>> {
let row = sqlx::query_as::<_, AdminUserSqlRow>(
"SELECT id, username::text, display_name, email, role::text, is_active, \
"SELECT id, username::text, display_name, email, role::text, is_active, local_role, sso_role, \
(SELECT COUNT(*) FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id AND qualified) AS plays, \
(SELECT (COALESCE(SUM(listened_ms), 0) / 1000)::bigint FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id) AS listened_seconds, \
(SELECT MAX(started_at_ms) FROM furumusic__listen_event le WHERE le.user_id = furumusic__user.id AND qualified) AS last_play_ms \
@@ -2939,6 +2943,8 @@ fn admin_user_row(
email: row.email,
role: row.role,
is_active: row.is_active,
local_role: row.local_role,
sso_role: row.sso_role,
plays: row.plays,
listened_seconds: row.listened_seconds,
last_play_ms: row.last_play_ms,