Formatting and cleanup
This commit is contained in:
@@ -292,9 +292,6 @@ async fn do_oauth_callback(
|
||||
Ok(Redirect::temporary(&ui_redirect_uri).into_response())
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ //
|
||||
// LOGIN MODE: look up (or create) the local user for this Discord account
|
||||
// ------------------------------------------------------------------ //
|
||||
None => {
|
||||
// Find existing connection → local user_id
|
||||
let local_user_id: Option<(Uuid, String)> = sqlx::query_as(
|
||||
@@ -403,10 +400,6 @@ async fn do_oauth_callback(
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Return a username derived from `base` that does not yet exist in `users`.
|
||||
async fn generate_unique_username(pool: &sqlx::PgPool, base: &str) -> crate::error::Result<String> {
|
||||
// Truncate to 28 chars to leave room for the `_XXXX` suffix
|
||||
|
||||
@@ -41,10 +41,6 @@ pub fn get_routes() -> Router<Arc<AppState>> {
|
||||
.route("/connections/{provider}", delete(disconnect_provider))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Payloads
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RegisterPayload {
|
||||
username: String,
|
||||
@@ -71,10 +67,6 @@ struct ChangePasswordPayload {
|
||||
new_password: String,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Response types
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ConnectionInfo {
|
||||
pub provider: String,
|
||||
@@ -95,10 +87,6 @@ pub struct UserInfo {
|
||||
pub connections: Vec<ConnectionInfo>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DB row types
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct DbUser {
|
||||
id: Uuid,
|
||||
@@ -116,10 +104,6 @@ struct DbConnection {
|
||||
provider_avatar: Option<String>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Password helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Hash and salt a plaintext password with Argon2.
|
||||
pub fn hash_password(password: &str) -> Result<String> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
@@ -139,10 +123,6 @@ pub fn verify_password(password: &str, hash: &str) -> bool {
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Cookie / session helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Build the `siren_session` HttpOnly Secure cookie.
|
||||
pub fn build_session_cookie(token: String) -> Cookie<'static> {
|
||||
Cookie::build(("siren_session", token))
|
||||
@@ -192,10 +172,6 @@ pub async fn create_session_and_cookie(
|
||||
Ok((jar, ()))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper: load full UserInfo for a given user_id
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async fn load_user_info(user_id: Uuid) -> Result<UserInfo> {
|
||||
let pool = data::pool();
|
||||
|
||||
@@ -232,10 +208,6 @@ async fn load_user_info(user_id: Uuid) -> Result<UserInfo> {
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handlers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async fn register(
|
||||
headers: HeaderMap,
|
||||
jar: CookieJar,
|
||||
@@ -245,12 +217,6 @@ async fn register(
|
||||
if username.is_empty() || username.len() > 32 {
|
||||
return Err(Error::new(422, "Username must be 1–32 characters".into()));
|
||||
}
|
||||
if payload.password.len() < 8 {
|
||||
return Err(Error::new(
|
||||
422,
|
||||
"Password must be at least 8 characters".into(),
|
||||
));
|
||||
}
|
||||
|
||||
let pool = data::pool();
|
||||
|
||||
@@ -402,13 +368,6 @@ async fn change_password(
|
||||
) -> Result<StatusCode> {
|
||||
let session = session.ok_or_else(|| Error::from(StatusCode::UNAUTHORIZED))?;
|
||||
|
||||
if payload.new_password.len() < 8 {
|
||||
return Err(Error::new(
|
||||
422,
|
||||
"New password must be at least 8 characters".into(),
|
||||
));
|
||||
}
|
||||
|
||||
let pool = data::pool();
|
||||
|
||||
let existing_hash: Option<String> =
|
||||
|
||||
@@ -61,10 +61,6 @@ pub fn get_routes() -> Router<Arc<AppState>> {
|
||||
.route("/maps/{id}/ws", get(ws_handler))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Access helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Fetch the role of `user_id` on `map_id`, or `None` if no record exists.
|
||||
async fn get_user_role(map_id: &str, user_id: Uuid) -> Result<Option<MapRole>> {
|
||||
let pool = siren_core::data::pool();
|
||||
@@ -120,10 +116,6 @@ async fn is_owner(map: &GridMap, session: &Option<Session>) -> bool {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Map CRUD
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_maps(
|
||||
SessionAuthorization(session): SessionAuthorization,
|
||||
) -> Result<Json<Vec<ListedMap>>> {
|
||||
@@ -287,10 +279,6 @@ pub async fn delete_map(
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Permission management
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn list_permissions(
|
||||
SessionAuthorization(session): SessionAuthorization,
|
||||
Path(id): Path<String>,
|
||||
@@ -429,10 +417,6 @@ pub async fn unfavorite_map(
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Access Requests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn create_access_request(
|
||||
SessionAuthorization(session): SessionAuthorization,
|
||||
Path(id): Path<String>,
|
||||
@@ -572,10 +556,6 @@ pub async fn resolve_access_request(
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WebSocket handler
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
pub async fn ws_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
State(state): State<Arc<AppState>>,
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Map Role / Permission
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Deserialize, sqlx::Type, Clone, Debug, PartialEq, Eq)]
|
||||
#[sqlx(type_name = "text", rename_all = "lowercase")]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
@@ -36,10 +32,6 @@ pub struct PermissionWithUser {
|
||||
pub role: MapRole,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Grid Map
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Core map record as stored/returned by create, get, and update endpoints.
|
||||
#[derive(Serialize, Deserialize, sqlx::FromRow, Clone, Debug)]
|
||||
pub struct GridMap {
|
||||
@@ -49,8 +41,8 @@ pub struct GridMap {
|
||||
pub public_access: String,
|
||||
pub owner_id: Uuid,
|
||||
pub colors: Vec<String>,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Extended map record returned by the list endpoint.
|
||||
@@ -64,8 +56,8 @@ pub struct ListedMap {
|
||||
pub owner_id: Uuid,
|
||||
pub owner_username: String,
|
||||
pub colors: Vec<String>,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
/// The authenticated caller's role on this map, or NULL if they only have it
|
||||
/// via a favorite (no explicit permission).
|
||||
pub user_role: Option<MapRole>,
|
||||
@@ -98,10 +90,6 @@ pub struct UpdatePermissionPayload {
|
||||
pub role: Option<MapRole>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Map Access Requests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// An access-request row joined with the requesting user's username.
|
||||
#[derive(Serialize, sqlx::FromRow, Clone, Debug)]
|
||||
pub struct AccessRequestWithUser {
|
||||
@@ -111,8 +99,8 @@ pub struct AccessRequestWithUser {
|
||||
pub username: String,
|
||||
pub requested_role: MapRole,
|
||||
pub status: String,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
@@ -126,10 +114,6 @@ pub struct ResolveAccessRequestPayload {
|
||||
pub action: String,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Grid Cell (no id column — composite PK in DB)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Deserialize, sqlx::FromRow, Clone, Debug)]
|
||||
pub struct GridCell {
|
||||
pub map_id: String,
|
||||
@@ -146,10 +130,6 @@ pub struct CellPatch {
|
||||
pub color: String,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Grid Token
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Deserialize, sqlx::FromRow, Clone, Debug)]
|
||||
pub struct GridToken {
|
||||
pub id: String,
|
||||
@@ -160,10 +140,6 @@ pub struct GridToken {
|
||||
pub color: String,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Full map state (used on initial WS connect and REST GET)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct MapState {
|
||||
pub map: GridMap,
|
||||
@@ -171,10 +147,6 @@ pub struct MapState {
|
||||
pub tokens: Vec<GridToken>,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WebSocket message types
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum ClientMessage {
|
||||
|
||||
Reference in New Issue
Block a user