Labrinth ID cleanup (#3681)

* Put all ID types in the labrinth::models::ids, and reduce code duplication with them

* Rewrite labrinth::database::models::ids and rename most DB interface ID structs to be prefixed with DB

* Run sqlx prepare

---------

Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
This commit is contained in:
Josiah Glosson
2025-05-22 03:34:36 -05:00
committed by GitHub
parent c6022ad977
commit 9e527ff141
111 changed files with 1477 additions and 1965 deletions

View File

@@ -90,7 +90,7 @@ pub async fn filter_visible_project_ids(
user_option: &Option<User>,
pool: &PgPool,
hide_unlisted: bool,
) -> Result<Vec<crate::database::models::ProjectId>, ApiError> {
) -> Result<Vec<crate::database::models::DBProjectId>, ApiError> {
let mut return_projects = Vec::new();
let mut check_projects = Vec::new();
@@ -129,11 +129,11 @@ pub async fn filter_enlisted_projects_ids(
projects: Vec<&Project>,
user_option: &Option<User>,
pool: &PgPool,
) -> Result<Vec<crate::database::models::ProjectId>, ApiError> {
) -> Result<Vec<crate::database::models::DBProjectId>, ApiError> {
let mut return_projects = vec![];
if let Some(user) = user_option {
let user_id: models::ids::UserId = user.id.into();
let user_id: models::ids::DBUserId = user.id.into();
use futures::TryStreamExt;
@@ -154,7 +154,7 @@ pub async fn filter_enlisted_projects_ids(
.iter()
.filter_map(|x| x.organization_id.map(|x| x.0))
.collect::<Vec<_>>(),
user_id as database::models::ids::UserId,
user_id as database::models::ids::DBUserId,
)
.fetch(pool)
.map_ok(|row| {
@@ -236,7 +236,7 @@ pub async fn filter_visible_version_ids(
user_option: &Option<User>,
pool: &PgPool,
redis: &RedisPool,
) -> Result<Vec<crate::database::models::VersionId>, ApiError> {
) -> Result<Vec<crate::database::models::DBVersionId>, ApiError> {
let mut return_versions = Vec::new();
let mut check_versions = Vec::new();
@@ -291,7 +291,7 @@ pub async fn filter_enlisted_version_ids(
user_option: &Option<User>,
pool: &PgPool,
redis: &RedisPool,
) -> Result<Vec<crate::database::models::VersionId>, ApiError> {
) -> Result<Vec<crate::database::models::DBVersionId>, ApiError> {
let mut return_versions = Vec::new();
// Get project ids of versions

View File

@@ -116,7 +116,7 @@ pub enum OAuthErrorType {
AuthenticationError(#[from] AuthenticationError),
#[error("Client {} has no redirect URIs specified", .client_id.0)]
ClientMissingRedirectURI {
client_id: crate::database::models::OAuthClientId,
client_id: crate::database::models::DBOAuthClientId,
},
#[error(
"The provided redirect URI did not match any configured in the client"
@@ -133,7 +133,7 @@ pub enum OAuthErrorType {
#[error("The provided flow id was invalid")]
InvalidAcceptFlowId,
#[error("The provided client id was invalid")]
InvalidClientId(crate::database::models::OAuthClientId),
InvalidClientId(crate::database::models::DBOAuthClientId),
#[error("The provided ID could not be decoded: {0}")]
MalformedId(#[from] DecodingError),
#[error("Failed to authenticate client")]

View File

@@ -6,7 +6,7 @@ use crate::database::models::oauth_client_authorization_item::OAuthClientAuthori
use crate::database::models::oauth_client_item::OAuthClient as DBOAuthClient;
use crate::database::models::oauth_token_item::OAuthAccessToken;
use crate::database::models::{
OAuthClientAuthorizationId, generate_oauth_access_token_id,
DBOAuthClientAuthorizationId, generate_oauth_access_token_id,
generate_oauth_client_authorization_id,
};
use crate::database::redis::RedisPool;
@@ -417,9 +417,9 @@ fn generate_access_token() -> String {
}
async fn init_oauth_code_flow(
user_id: crate::database::models::UserId,
user_id: crate::database::models::DBUserId,
client_id: OAuthClientId,
authorization_id: OAuthClientAuthorizationId,
authorization_id: DBOAuthClientAuthorizationId,
scopes: Scopes,
redirect_uris: OAuthRedirectUris,
state: Option<String>,

View File

@@ -1,6 +1,6 @@
use super::errors::OAuthError;
use crate::auth::oauth::OAuthErrorType;
use crate::database::models::OAuthClientId;
use crate::database::models::DBOAuthClientId;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@@ -16,7 +16,7 @@ impl ValidatedRedirectUri {
pub fn validate<'a>(
to_validate: &Option<String>,
validate_against: impl IntoIterator<Item = &'a str> + Clone,
client_id: OAuthClientId,
client_id: DBOAuthClientId,
) -> Result<Self, OAuthError> {
if let Some(first_client_redirect_uri) =
validate_against.clone().into_iter().next()
@@ -61,7 +61,7 @@ mod tests {
let validated = ValidatedRedirectUri::validate(
&None,
validate_against.clone(),
OAuthClientId(0),
DBOAuthClientId(0),
)
.unwrap();
@@ -82,7 +82,7 @@ mod tests {
let validated = ValidatedRedirectUri::validate(
&Some(to_validate.clone()),
validate_against,
OAuthClientId(0),
DBOAuthClientId(0),
)
.unwrap();
@@ -97,7 +97,7 @@ mod tests {
let validated = ValidatedRedirectUri::validate(
&Some(to_validate),
validate_against,
OAuthClientId(0),
DBOAuthClientId(0),
);
assert!(validated.is_err_and(|e| matches!(