You've already forked AstralRinth
forked from didirus/AstralRinth
f0224dfff7
* initial elasticsearch impl * working elastic cluster * replace SearchError with ApiError for preparation of search backend * start factoring meili out to trait * move meili to backend * update routes to use search backend trait * wip * Update projects.rs * search backend is only init'd once in config * wip * wip: backend agnostic * change search internal routes to delegate to backend * initial elasticsearch impl * fix filtering * elastic impl * refactor indexing into its own module * clean up elastic code * fix ci * fix tests * fix elastic health check * fix up env rebase * fix compile * dummy commit to update github pr * Fix rebase * Elastic basic https auth * Fix duplicate projects showing up * Fix up tests * Replace search `ApiErrors` with `eyre::Reports`, propagate background task errors * clean up agents files * make index chunk size configurable * make `match_phrase` in elastic case-insensitive * use current/next indices and swap between them * test case for error body * Fix failing case * da merge * factor out common stuff from search backends * allow fetching hit metadata from search results * allow customising elasticsearch search config * bit of docs * add mappings to indices for elastic * Implement Typesense * wip * fix up some sort fields stuff * use different approach to filterable field sets * remove a bunch of search fields which weren't used for filtering * bucket text matches * Bucketing by text_match for typesense * fix tombi lint * fix some sentry errors and dont prioritise 2+ term matches * tweak ts query settings * expose some more search settings * query sort changes * small fixes * should fix pagination stuff * fix healthcheck maybe * ragebait ci * tests * tests * revert environment
133 lines
4.6 KiB
Rust
133 lines
4.6 KiB
Rust
pub mod checks;
|
|
pub mod oauth;
|
|
pub mod templates;
|
|
pub mod validate;
|
|
pub use checks::{
|
|
filter_enlisted_projects_ids, filter_enlisted_version_ids,
|
|
filter_visible_collections, filter_visible_project_ids,
|
|
filter_visible_projects,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
pub use validate::{check_is_moderator_from_headers, get_user_from_headers};
|
|
|
|
use crate::file_hosting::FileHostingError;
|
|
use crate::models::error::ApiError;
|
|
use actix_web::HttpResponse;
|
|
use actix_web::http::StatusCode;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AuthenticationError {
|
|
#[error(transparent)]
|
|
Internal(#[from] eyre::Report),
|
|
#[error("An unknown database error occurred: {0}")]
|
|
Sqlx(#[from] sqlx::Error),
|
|
#[error("Database Error: {0}")]
|
|
Database(#[from] crate::database::models::DatabaseError),
|
|
#[error("Error while parsing JSON: {0}")]
|
|
SerDe(#[from] serde_json::Error),
|
|
#[error("Error while communicating to external provider")]
|
|
Reqwest(#[from] reqwest::Error),
|
|
#[error("Error uploading user profile picture")]
|
|
FileHosting(#[from] FileHostingError),
|
|
#[error("Error while decoding PAT: {0}")]
|
|
Decoding(#[from] ariadne::ids::DecodingError),
|
|
#[error("{0}")]
|
|
Mail(#[from] crate::queue::email::MailError),
|
|
#[error("Invalid Authentication Credentials")]
|
|
InvalidCredentials,
|
|
#[error("Authentication method was not valid")]
|
|
InvalidAuthMethod,
|
|
#[error("GitHub Token from incorrect Client ID")]
|
|
InvalidClientId,
|
|
#[error(
|
|
"User email is already registered on Modrinth. Try 'Forgot password' to access your account."
|
|
)]
|
|
DuplicateUser,
|
|
#[error("Invalid state sent, you probably need to get a new websocket")]
|
|
SocketError,
|
|
#[error("Invalid callback URL specified")]
|
|
Url,
|
|
}
|
|
|
|
impl actix_web::ResponseError for AuthenticationError {
|
|
fn status_code(&self) -> StatusCode {
|
|
match self {
|
|
AuthenticationError::Internal(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::Sqlx(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AuthenticationError::Database(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::SerDe(..) => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::Reqwest(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::InvalidCredentials => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::Decoding(..) => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::Mail(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AuthenticationError::InvalidAuthMethod => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::InvalidClientId => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::Url => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::FileHosting(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::DuplicateUser => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::SocketError => StatusCode::BAD_REQUEST,
|
|
}
|
|
}
|
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
HttpResponse::build(self.status_code()).json(ApiError {
|
|
error: self.error_name(),
|
|
description: self.to_string(),
|
|
details: None,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl AuthenticationError {
|
|
pub fn error_name(&self) -> &'static str {
|
|
match self {
|
|
AuthenticationError::Internal(..) => "internal_error",
|
|
AuthenticationError::Sqlx(..) => "database_error",
|
|
AuthenticationError::Database(..) => "database_error",
|
|
AuthenticationError::SerDe(..) => "invalid_input",
|
|
AuthenticationError::Reqwest(..) => "network_error",
|
|
AuthenticationError::InvalidCredentials => "invalid_credentials",
|
|
AuthenticationError::Decoding(..) => "decoding_error",
|
|
AuthenticationError::Mail(..) => "mail_error",
|
|
AuthenticationError::InvalidAuthMethod => "invalid_auth_method",
|
|
AuthenticationError::InvalidClientId => "invalid_client_id",
|
|
AuthenticationError::Url => "url_error",
|
|
AuthenticationError::FileHosting(..) => "file_hosting",
|
|
AuthenticationError::DuplicateUser => "duplicate_user",
|
|
AuthenticationError::SocketError => "socket",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(
|
|
Debug,
|
|
Clone,
|
|
Copy,
|
|
PartialEq,
|
|
Eq,
|
|
Default,
|
|
Serialize,
|
|
Deserialize,
|
|
utoipa::ToSchema,
|
|
)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum AuthProvider {
|
|
#[default]
|
|
GitHub,
|
|
Discord,
|
|
Microsoft,
|
|
GitLab,
|
|
Google,
|
|
Steam,
|
|
PayPal,
|
|
}
|