You've already forked AstralRinth
forked from didirus/AstralRinth
Commonize and distinguish a lot of struct names in labrinth::database::models (#3691)
This commit is contained in:
@@ -578,7 +578,7 @@ async fn filter_allowed_ids(
|
||||
// If no project_ids or version_ids are provided, we default to all projects the user has *public* access to
|
||||
if project_ids.is_none() && !remove_defaults.unwrap_or(false) {
|
||||
project_ids = Some(
|
||||
user_item::User::get_projects(user.id.into(), &***pool, redis)
|
||||
user_item::DBUser::get_projects(user.id.into(), &***pool, redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|x| ProjectId::from(x).to_string())
|
||||
@@ -589,7 +589,7 @@ async fn filter_allowed_ids(
|
||||
// Convert String list to list of ProjectIds or VersionIds
|
||||
// - Filter out unauthorized projects/versions
|
||||
let project_ids = if let Some(project_strings) = project_ids {
|
||||
let projects_data = database::models::Project::get_many(
|
||||
let projects_data = database::models::DBProject::get_many(
|
||||
&project_strings,
|
||||
&***pool,
|
||||
redis,
|
||||
@@ -601,7 +601,7 @@ async fn filter_allowed_ids(
|
||||
.map(|x| x.inner.team_id)
|
||||
.collect::<Vec<database::models::DBTeamId>>();
|
||||
let team_members =
|
||||
database::models::TeamMember::get_from_team_full_many(
|
||||
database::models::DBTeamMember::get_from_team_full_many(
|
||||
&team_ids, &***pool, redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -610,7 +610,7 @@ async fn filter_allowed_ids(
|
||||
.iter()
|
||||
.filter_map(|x| x.inner.organization_id)
|
||||
.collect::<Vec<database::models::DBOrganizationId>>();
|
||||
let organizations = database::models::Organization::get_many_ids(
|
||||
let organizations = database::models::DBOrganization::get_many_ids(
|
||||
&organization_ids,
|
||||
&***pool,
|
||||
redis,
|
||||
@@ -622,7 +622,7 @@ async fn filter_allowed_ids(
|
||||
.map(|x| x.team_id)
|
||||
.collect::<Vec<database::models::DBTeamId>>();
|
||||
let organization_team_members =
|
||||
database::models::TeamMember::get_from_team_full_many(
|
||||
database::models::DBTeamMember::get_from_team_full_many(
|
||||
&organization_team_ids,
|
||||
&***pool,
|
||||
redis,
|
||||
|
||||
@@ -85,7 +85,7 @@ pub async fn collection_create(
|
||||
let collection_id: CollectionId =
|
||||
generate_collection_id(&mut transaction).await?.into();
|
||||
|
||||
let initial_project_ids = project_item::Project::get_many(
|
||||
let initial_project_ids = project_item::DBProject::get_many(
|
||||
&collection_create_data.projects,
|
||||
&mut *transaction,
|
||||
&redis,
|
||||
@@ -149,7 +149,7 @@ pub async fn collections_get(
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let collections_data =
|
||||
database::models::Collection::get_many(&ids, &**pool, &redis).await?;
|
||||
database::models::DBCollection::get_many(&ids, &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -179,7 +179,7 @@ pub async fn collection_get(
|
||||
|
||||
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
|
||||
let collection_data =
|
||||
database::models::Collection::get(id, &**pool, &redis).await?;
|
||||
database::models::DBCollection::get(id, &**pool, &redis).await?;
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
@@ -242,7 +242,8 @@ pub async fn collection_edit(
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
|
||||
let result = database::models::Collection::get(id, &**pool, &redis).await?;
|
||||
let result =
|
||||
database::models::DBCollection::get(id, &**pool, &redis).await?;
|
||||
|
||||
if let Some(collection_item) = result {
|
||||
if !can_modify_collection(&collection_item, &user) {
|
||||
@@ -322,7 +323,7 @@ pub async fn collection_edit(
|
||||
.collect_vec();
|
||||
let mut validated_project_ids = Vec::new();
|
||||
for project_id in new_project_ids {
|
||||
let project = database::models::Project::get(
|
||||
let project = database::models::DBProject::get(
|
||||
project_id, &**pool, &redis,
|
||||
)
|
||||
.await?
|
||||
@@ -359,7 +360,7 @@ pub async fn collection_edit(
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Collection::clear_cache(collection_item.id, &redis)
|
||||
database::models::DBCollection::clear_cache(collection_item.id, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -397,7 +398,7 @@ pub async fn collection_icon_edit(
|
||||
let string = info.into_inner().0;
|
||||
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
|
||||
let collection_item =
|
||||
database::models::Collection::get(id, &**pool, &redis)
|
||||
database::models::DBCollection::get(id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -451,7 +452,7 @@ pub async fn collection_icon_edit(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Collection::clear_cache(collection_item.id, &redis)
|
||||
database::models::DBCollection::clear_cache(collection_item.id, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -478,7 +479,7 @@ pub async fn delete_collection_icon(
|
||||
let string = info.into_inner().0;
|
||||
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
|
||||
let collection_item =
|
||||
database::models::Collection::get(id, &**pool, &redis)
|
||||
database::models::DBCollection::get(id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -509,7 +510,7 @@ pub async fn delete_collection_icon(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Collection::clear_cache(collection_item.id, &redis)
|
||||
database::models::DBCollection::clear_cache(collection_item.id, &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -534,7 +535,7 @@ pub async fn collection_delete(
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
|
||||
let collection = database::models::Collection::get(id, &**pool, &redis)
|
||||
let collection = database::models::DBCollection::get(id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -546,7 +547,7 @@ pub async fn collection_delete(
|
||||
}
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let result = database::models::Collection::remove(
|
||||
let result = database::models::DBCollection::remove(
|
||||
collection.id,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
@@ -554,7 +555,7 @@ pub async fn collection_delete(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Collection::clear_cache(collection.id, &redis).await?;
|
||||
database::models::DBCollection::clear_cache(collection.id, &redis).await?;
|
||||
|
||||
if result.is_some() {
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -564,7 +565,7 @@ pub async fn collection_delete(
|
||||
}
|
||||
|
||||
fn can_modify_collection(
|
||||
collection: &database::models::Collection,
|
||||
collection: &database::models::DBCollection,
|
||||
user: &models::users::User,
|
||||
) -> bool {
|
||||
collection.user_id == user.id.into() || user.role.is_mod()
|
||||
|
||||
@@ -43,13 +43,13 @@ pub async fn add_friend(
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let friend =
|
||||
crate::database::models::User::get(&string, &**pool, &redis).await?;
|
||||
crate::database::models::DBUser::get(&string, &**pool, &redis).await?;
|
||||
|
||||
if let Some(friend) = friend {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
if let Some(friend) =
|
||||
crate::database::models::friend_item::FriendItem::get_friend(
|
||||
crate::database::models::friend_item::DBFriend::get_friend(
|
||||
user.id.into(),
|
||||
friend.id,
|
||||
&**pool,
|
||||
@@ -68,7 +68,7 @@ pub async fn add_friend(
|
||||
));
|
||||
}
|
||||
|
||||
crate::database::models::friend_item::FriendItem::update_friend(
|
||||
crate::database::models::friend_item::DBFriend::update_friend(
|
||||
friend.user_id,
|
||||
friend.friend_id,
|
||||
true,
|
||||
@@ -115,7 +115,7 @@ pub async fn add_friend(
|
||||
));
|
||||
}
|
||||
|
||||
crate::database::models::friend_item::FriendItem {
|
||||
crate::database::models::friend_item::DBFriend {
|
||||
user_id: user.id.into(),
|
||||
friend_id: friend.id,
|
||||
created: Utc::now(),
|
||||
@@ -161,12 +161,12 @@ pub async fn remove_friend(
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let friend =
|
||||
crate::database::models::User::get(&string, &**pool, &redis).await?;
|
||||
crate::database::models::DBUser::get(&string, &**pool, &redis).await?;
|
||||
|
||||
if let Some(friend) = friend {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
crate::database::models::friend_item::FriendItem::remove(
|
||||
crate::database::models::friend_item::DBFriend::remove(
|
||||
user.id.into(),
|
||||
friend.id,
|
||||
&mut transaction,
|
||||
@@ -206,7 +206,7 @@ pub async fn friends(
|
||||
.1;
|
||||
|
||||
let friends =
|
||||
crate::database::models::friend_item::FriendItem::get_user_friends(
|
||||
crate::database::models::friend_item::DBFriend::get_user_friends(
|
||||
user.id.into(),
|
||||
None,
|
||||
&**pool,
|
||||
|
||||
@@ -67,7 +67,7 @@ pub async fn images_add(
|
||||
ImageContext::Project { project_id } => {
|
||||
if let Some(id) = data.project_id {
|
||||
let project =
|
||||
project_item::Project::get(&id, &**pool, &redis).await?;
|
||||
project_item::DBProject::get(&id, &**pool, &redis).await?;
|
||||
if let Some(project) = project {
|
||||
if is_team_member_project(
|
||||
&project.inner,
|
||||
@@ -92,7 +92,7 @@ pub async fn images_add(
|
||||
ImageContext::Version { version_id } => {
|
||||
if let Some(id) = data.version_id {
|
||||
let version =
|
||||
version_item::Version::get(id.into(), &**pool, &redis)
|
||||
version_item::DBVersion::get(id.into(), &**pool, &redis)
|
||||
.await?;
|
||||
if let Some(version) = version {
|
||||
if is_team_member_version(
|
||||
@@ -119,7 +119,7 @@ pub async fn images_add(
|
||||
ImageContext::ThreadMessage { thread_message_id } => {
|
||||
if let Some(id) = data.thread_message_id {
|
||||
let thread_message =
|
||||
thread_item::ThreadMessage::get(id.into(), &**pool)
|
||||
thread_item::DBThreadMessage::get(id.into(), &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -127,7 +127,7 @@ pub async fn images_add(
|
||||
.to_string(),
|
||||
)
|
||||
})?;
|
||||
let thread = thread_item::Thread::get(thread_message.thread_id, &**pool)
|
||||
let thread = thread_item::DBThread::get(thread_message.thread_id, &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -147,14 +147,14 @@ pub async fn images_add(
|
||||
}
|
||||
ImageContext::Report { report_id } => {
|
||||
if let Some(id) = data.report_id {
|
||||
let report = report_item::Report::get(id.into(), &**pool)
|
||||
let report = report_item::DBReport::get(id.into(), &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The report could not be found.".to_string(),
|
||||
)
|
||||
})?;
|
||||
let thread = thread_item::Thread::get(report.thread_id, &**pool)
|
||||
let thread = thread_item::DBThread::get(report.thread_id, &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -198,7 +198,7 @@ pub async fn images_add(
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let db_image: database::models::Image = database::models::Image {
|
||||
let db_image: database::models::DBImage = database::models::DBImage {
|
||||
id: database::models::generate_image_id(&mut transaction).await?,
|
||||
url: upload_result.url,
|
||||
raw_url: upload_result.raw_url,
|
||||
|
||||
@@ -46,7 +46,7 @@ pub async fn notifications_get(
|
||||
.1;
|
||||
|
||||
use database::models::DBNotificationId;
|
||||
use database::models::notification_item::Notification as DBNotification;
|
||||
use database::models::notification_item::DBNotification;
|
||||
|
||||
let notification_ids: Vec<DBNotificationId> =
|
||||
serde_json::from_str::<Vec<NotificationId>>(ids.ids.as_str())?
|
||||
@@ -55,7 +55,7 @@ pub async fn notifications_get(
|
||||
.collect();
|
||||
|
||||
let notifications_data: Vec<DBNotification> =
|
||||
database::models::notification_item::Notification::get_many(
|
||||
database::models::notification_item::DBNotification::get_many(
|
||||
¬ification_ids,
|
||||
&**pool,
|
||||
)
|
||||
@@ -90,7 +90,7 @@ pub async fn notification_get(
|
||||
let id = info.into_inner().0;
|
||||
|
||||
let notification_data =
|
||||
database::models::notification_item::Notification::get(
|
||||
database::models::notification_item::DBNotification::get(
|
||||
id.into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -127,7 +127,7 @@ pub async fn notification_read(
|
||||
let id = info.into_inner().0;
|
||||
|
||||
let notification_data =
|
||||
database::models::notification_item::Notification::get(
|
||||
database::models::notification_item::DBNotification::get(
|
||||
id.into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -137,7 +137,7 @@ pub async fn notification_read(
|
||||
if data.user_id == user.id.into() || user.role.is_admin() {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
database::models::notification_item::Notification::read(
|
||||
database::models::notification_item::DBNotification::read(
|
||||
id.into(),
|
||||
&mut transaction,
|
||||
&redis,
|
||||
@@ -177,7 +177,7 @@ pub async fn notification_delete(
|
||||
let id = info.into_inner().0;
|
||||
|
||||
let notification_data =
|
||||
database::models::notification_item::Notification::get(
|
||||
database::models::notification_item::DBNotification::get(
|
||||
id.into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -187,7 +187,7 @@ pub async fn notification_delete(
|
||||
if data.user_id == user.id.into() || user.role.is_admin() {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
database::models::notification_item::Notification::remove(
|
||||
database::models::notification_item::DBNotification::remove(
|
||||
id.into(),
|
||||
&mut transaction,
|
||||
&redis,
|
||||
@@ -234,7 +234,7 @@ pub async fn notifications_read(
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let notifications_data =
|
||||
database::models::notification_item::Notification::get_many(
|
||||
database::models::notification_item::DBNotification::get_many(
|
||||
¬ification_ids,
|
||||
&**pool,
|
||||
)
|
||||
@@ -249,7 +249,7 @@ pub async fn notifications_read(
|
||||
}
|
||||
}
|
||||
|
||||
database::models::notification_item::Notification::read_many(
|
||||
database::models::notification_item::DBNotification::read_many(
|
||||
¬ifications,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
@@ -287,7 +287,7 @@ pub async fn notifications_delete(
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let notifications_data =
|
||||
database::models::notification_item::Notification::get_many(
|
||||
database::models::notification_item::DBNotification::get_many(
|
||||
¬ification_ids,
|
||||
&**pool,
|
||||
)
|
||||
@@ -302,7 +302,7 @@ pub async fn notifications_delete(
|
||||
}
|
||||
}
|
||||
|
||||
database::models::notification_item::Notification::remove_many(
|
||||
database::models::notification_item::DBNotification::remove_many(
|
||||
¬ifications,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
|
||||
@@ -5,10 +5,10 @@ use crate::{
|
||||
auth::{checks::ValidateAuthorized, get_user_from_headers},
|
||||
database::{
|
||||
models::{
|
||||
DBOAuthClientId, DatabaseError, User, generate_oauth_client_id,
|
||||
DBOAuthClientId, DBUser, DatabaseError, generate_oauth_client_id,
|
||||
generate_oauth_redirect_id,
|
||||
oauth_client_authorization_item::OAuthClientAuthorization,
|
||||
oauth_client_item::{OAuthClient, OAuthRedirectUri},
|
||||
oauth_client_authorization_item::DBOAuthClientAuthorization,
|
||||
oauth_client_item::{DBOAuthClient, DBOAuthRedirectUri},
|
||||
},
|
||||
redis::RedisPool,
|
||||
},
|
||||
@@ -38,7 +38,6 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::database::models::oauth_client_item::OAuthClient as DBOAuthClient;
|
||||
use crate::models::ids::OAuthClientId;
|
||||
use crate::util::img::{delete_old_images, upload_image_optimized};
|
||||
|
||||
@@ -75,7 +74,7 @@ pub async fn get_user_clients(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let target_user = User::get(&info.into_inner(), &**pool, &redis).await?;
|
||||
let target_user = DBUser::get(&info.into_inner(), &**pool, &redis).await?;
|
||||
|
||||
if let Some(target_user) = target_user {
|
||||
if target_user.id != current_user.id.into()
|
||||
@@ -87,7 +86,8 @@ pub async fn get_user_clients(
|
||||
}
|
||||
|
||||
let clients =
|
||||
OAuthClient::get_all_user_clients(target_user.id, &**pool).await?;
|
||||
DBOAuthClient::get_all_user_clients(target_user.id, &**pool)
|
||||
.await?;
|
||||
|
||||
let response = clients
|
||||
.into_iter()
|
||||
@@ -190,7 +190,7 @@ pub async fn oauth_client_create(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let client = OAuthClient {
|
||||
let client = DBOAuthClient {
|
||||
id: client_id,
|
||||
icon_url: None,
|
||||
raw_icon_url: None,
|
||||
@@ -234,10 +234,10 @@ pub async fn oauth_client_delete(
|
||||
.1;
|
||||
|
||||
let client =
|
||||
OAuthClient::get(client_id.into_inner().into(), &**pool).await?;
|
||||
DBOAuthClient::get(client_id.into_inner().into(), &**pool).await?;
|
||||
if let Some(client) = client {
|
||||
client.validate_authorized(Some(¤t_user))?;
|
||||
OAuthClient::remove(client.id, &**pool).await?;
|
||||
DBOAuthClient::remove(client.id, &**pool).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
@@ -295,7 +295,7 @@ pub async fn oauth_client_edit(
|
||||
})?;
|
||||
|
||||
if let Some(existing_client) =
|
||||
OAuthClient::get(client_id.into_inner().into(), &**pool).await?
|
||||
DBOAuthClient::get(client_id.into_inner().into(), &**pool).await?
|
||||
{
|
||||
existing_client.validate_authorized(Some(¤t_user))?;
|
||||
|
||||
@@ -368,7 +368,7 @@ pub async fn oauth_client_icon_edit(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let client = OAuthClient::get((*client_id).into(), &**pool)
|
||||
let client = DBOAuthClient::get((*client_id).into(), &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -435,7 +435,7 @@ pub async fn oauth_client_icon_delete(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let client = OAuthClient::get((*client_id).into(), &**pool)
|
||||
let client = DBOAuthClient::get((*client_id).into(), &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -482,7 +482,7 @@ pub async fn get_user_oauth_authorizations(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let authorizations = OAuthClientAuthorization::get_all_for_user(
|
||||
let authorizations = DBOAuthClientAuthorization::get_all_for_user(
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -512,7 +512,7 @@ pub async fn revoke_oauth_authorization(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
OAuthClientAuthorization::remove(
|
||||
DBOAuthClientAuthorization::remove(
|
||||
info.client_id.into(),
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -534,11 +534,11 @@ async fn create_redirect_uris(
|
||||
uri_strings: impl IntoIterator<Item = impl Display>,
|
||||
client_id: DBOAuthClientId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<Vec<OAuthRedirectUri>, DatabaseError> {
|
||||
) -> Result<Vec<DBOAuthRedirectUri>, DatabaseError> {
|
||||
let mut redirect_uris = vec![];
|
||||
for uri in uri_strings.into_iter() {
|
||||
let id = generate_oauth_redirect_id(transaction).await?;
|
||||
redirect_uris.push(OAuthRedirectUri {
|
||||
redirect_uris.push(DBOAuthRedirectUri {
|
||||
id,
|
||||
client_id,
|
||||
uri: uri.to_string(),
|
||||
@@ -550,7 +550,7 @@ async fn create_redirect_uris(
|
||||
|
||||
async fn edit_redirects(
|
||||
redirects: Vec<String>,
|
||||
existing_client: &OAuthClient,
|
||||
existing_client: &DBOAuthClient,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let updated_redirects: HashSet<String> = redirects.into_iter().collect();
|
||||
@@ -566,12 +566,12 @@ async fn edit_redirects(
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?;
|
||||
OAuthClient::insert_redirect_uris(&redirects_to_add, &mut **transaction)
|
||||
DBOAuthClient::insert_redirect_uris(&redirects_to_add, &mut **transaction)
|
||||
.await?;
|
||||
|
||||
let mut redirects_to_remove = existing_client.redirect_uris.clone();
|
||||
redirects_to_remove.retain(|r| !updated_redirects.contains(&r.uri));
|
||||
OAuthClient::remove_redirect_uris(
|
||||
DBOAuthClient::remove_redirect_uris(
|
||||
redirects_to_remove.iter().map(|r| r.id),
|
||||
&mut **transaction,
|
||||
)
|
||||
@@ -585,7 +585,7 @@ pub async fn get_clients_inner(
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<Vec<models::oauth_clients::OAuthClient>, ApiError> {
|
||||
let ids: Vec<DBOAuthClientId> = ids.iter().map(|i| (*i).into()).collect();
|
||||
let clients = OAuthClient::get_many(&ids, &**pool).await?;
|
||||
let clients = DBOAuthClient::get_many(&ids, &**pool).await?;
|
||||
|
||||
Ok(clients.into_iter().map(|c| c.into()).collect_vec())
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ use std::sync::Arc;
|
||||
|
||||
use super::ApiError;
|
||||
use crate::auth::{filter_visible_projects, get_user_from_headers};
|
||||
use crate::database::models::team_item::TeamMember;
|
||||
use crate::database::models::team_item::DBTeamMember;
|
||||
use crate::database::models::{
|
||||
Organization, generate_organization_id, team_item,
|
||||
DBOrganization, generate_organization_id, team_item,
|
||||
};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
@@ -69,7 +69,7 @@ pub async fn organization_projects_get(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let organization_data = Organization::get(&id, &**pool, &redis).await?;
|
||||
let organization_data = DBOrganization::get(&id, &**pool, &redis).await?;
|
||||
if let Some(organization) = organization_data {
|
||||
let project_ids = sqlx::query!(
|
||||
"
|
||||
@@ -84,7 +84,7 @@ pub async fn organization_projects_get(
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
let projects_data = crate::database::models::Project::get_many_ids(
|
||||
let projects_data = crate::database::models::DBProject::get_many_ids(
|
||||
&project_ids,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -146,7 +146,7 @@ pub async fn organization_create(
|
||||
organization_strings.push(name_organization_id.to_string());
|
||||
}
|
||||
organization_strings.push(new_organization.slug.clone());
|
||||
let results = Organization::get_many(
|
||||
let results = DBOrganization::get_many(
|
||||
&organization_strings,
|
||||
&mut *transaction,
|
||||
&redis,
|
||||
@@ -174,7 +174,7 @@ pub async fn organization_create(
|
||||
let team_id = team.insert(&mut transaction).await?;
|
||||
|
||||
// Create organization
|
||||
let organization = Organization {
|
||||
let organization = DBOrganization {
|
||||
id: organization_id,
|
||||
slug: new_organization.slug.clone(),
|
||||
name: new_organization.name.clone(),
|
||||
@@ -188,10 +188,11 @@ pub async fn organization_create(
|
||||
transaction.commit().await?;
|
||||
|
||||
// Only member is the owner, the logged in one
|
||||
let member_data = TeamMember::get_from_team_full(team_id, &**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.next();
|
||||
let member_data =
|
||||
DBTeamMember::get_from_team_full(team_id, &**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.next();
|
||||
let members_data = if let Some(member_data) = member_data {
|
||||
vec![crate::models::teams::TeamMember::from_model(
|
||||
member_data,
|
||||
@@ -230,13 +231,13 @@ pub async fn organization_get(
|
||||
.ok();
|
||||
let user_id = current_user.as_ref().map(|x| x.id.into());
|
||||
|
||||
let organization_data = Organization::get(&id, &**pool, &redis).await?;
|
||||
let organization_data = DBOrganization::get(&id, &**pool, &redis).await?;
|
||||
if let Some(data) = organization_data {
|
||||
let members_data =
|
||||
TeamMember::get_from_team_full(data.team_id, &**pool, &redis)
|
||||
DBTeamMember::get_from_team_full(data.team_id, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&members_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -293,15 +294,16 @@ pub async fn organizations_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let ids = serde_json::from_str::<Vec<&str>>(&ids.ids)?;
|
||||
let organizations_data =
|
||||
Organization::get_many(&ids, &**pool, &redis).await?;
|
||||
DBOrganization::get_many(&ids, &**pool, &redis).await?;
|
||||
let team_ids = organizations_data
|
||||
.iter()
|
||||
.map(|x| x.team_id)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let teams_data =
|
||||
TeamMember::get_from_team_full_many(&team_ids, &**pool, &redis).await?;
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
DBTeamMember::get_from_team_full_many(&team_ids, &**pool, &redis)
|
||||
.await?;
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&teams_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -405,11 +407,11 @@ pub async fn organizations_edit(
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let result =
|
||||
database::models::Organization::get(&string, &**pool, &redis).await?;
|
||||
database::models::DBOrganization::get(&string, &**pool, &redis).await?;
|
||||
if let Some(organization_item) = result {
|
||||
let id = organization_item.id;
|
||||
|
||||
let team_member = database::models::TeamMember::get_from_user_id(
|
||||
let team_member = database::models::DBTeamMember::get_from_user_id(
|
||||
organization_item.team_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -526,7 +528,7 @@ pub async fn organizations_edit(
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Organization::clear_cache(
|
||||
database::models::DBOrganization::clear_cache(
|
||||
organization_item.id,
|
||||
Some(organization_item.slug),
|
||||
&redis,
|
||||
@@ -564,7 +566,7 @@ pub async fn organization_delete(
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let organization =
|
||||
database::models::Organization::get(&string, &**pool, &redis)
|
||||
database::models::DBOrganization::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -574,7 +576,7 @@ pub async fn organization_delete(
|
||||
|
||||
if !user.role.is_admin() {
|
||||
let team_member =
|
||||
database::models::TeamMember::get_from_user_id_organization(
|
||||
database::models::DBTeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
user.id.into(),
|
||||
false,
|
||||
@@ -638,7 +640,7 @@ pub async fn organization_delete(
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
let member = TeamMember {
|
||||
let member = DBTeamMember {
|
||||
id: new_id,
|
||||
team_id: *organization_project_team,
|
||||
user_id: owner_id,
|
||||
@@ -653,7 +655,7 @@ pub async fn organization_delete(
|
||||
member.insert(&mut transaction).await?;
|
||||
}
|
||||
// Safely remove the organization
|
||||
let result = database::models::Organization::remove(
|
||||
let result = database::models::DBOrganization::remove(
|
||||
organization.id,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
@@ -662,7 +664,7 @@ pub async fn organization_delete(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
database::models::Organization::clear_cache(
|
||||
database::models::DBOrganization::clear_cache(
|
||||
organization.id,
|
||||
Some(organization.slug),
|
||||
&redis,
|
||||
@@ -670,7 +672,7 @@ pub async fn organization_delete(
|
||||
.await?;
|
||||
|
||||
for team_id in organization_project_teams {
|
||||
database::models::TeamMember::clear_cache(team_id, &redis).await?;
|
||||
database::models::DBTeamMember::clear_cache(team_id, &redis).await?;
|
||||
}
|
||||
|
||||
if result.is_some() {
|
||||
@@ -704,7 +706,7 @@ pub async fn organization_projects_add(
|
||||
.1;
|
||||
|
||||
let organization =
|
||||
database::models::Organization::get(&info, &**pool, &redis)
|
||||
database::models::DBOrganization::get(&info, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -712,7 +714,7 @@ pub async fn organization_projects_add(
|
||||
)
|
||||
})?;
|
||||
|
||||
let project_item = database::models::Project::get(
|
||||
let project_item = database::models::DBProject::get(
|
||||
&project_info.project_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -731,7 +733,7 @@ pub async fn organization_projects_add(
|
||||
}
|
||||
|
||||
let project_team_member =
|
||||
database::models::TeamMember::get_from_user_id_project(
|
||||
database::models::DBTeamMember::get_from_user_id_project(
|
||||
project_item.inner.id,
|
||||
current_user.id.into(),
|
||||
false,
|
||||
@@ -744,7 +746,7 @@ pub async fn organization_projects_add(
|
||||
)
|
||||
})?;
|
||||
let organization_team_member =
|
||||
database::models::TeamMember::get_from_user_id_organization(
|
||||
database::models::DBTeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
current_user.id.into(),
|
||||
false,
|
||||
@@ -814,17 +816,17 @@ pub async fn organization_projects_add(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
database::models::User::clear_project_cache(
|
||||
database::models::DBUser::clear_project_cache(
|
||||
&[current_user.id.into()],
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
database::models::TeamMember::clear_cache(
|
||||
database::models::DBTeamMember::clear_cache(
|
||||
project_item.inner.team_id,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
database::models::Project::clear_cache(
|
||||
database::models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -866,17 +868,20 @@ pub async fn organization_projects_remove(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let organization =
|
||||
database::models::Organization::get(&organization_id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The specified organization does not exist!".to_string(),
|
||||
)
|
||||
})?;
|
||||
let organization = database::models::DBOrganization::get(
|
||||
&organization_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The specified organization does not exist!".to_string(),
|
||||
)
|
||||
})?;
|
||||
|
||||
let project_item =
|
||||
database::models::Project::get(&project_id, &**pool, &redis)
|
||||
database::models::DBProject::get(&project_id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -896,7 +901,7 @@ pub async fn organization_projects_remove(
|
||||
}
|
||||
|
||||
let organization_team_member =
|
||||
database::models::TeamMember::get_from_user_id_organization(
|
||||
database::models::DBTeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
current_user.id.into(),
|
||||
false,
|
||||
@@ -916,7 +921,7 @@ pub async fn organization_projects_remove(
|
||||
.unwrap_or_default();
|
||||
if permissions.contains(OrganizationPermissions::REMOVE_PROJECT) {
|
||||
// Now that permissions are confirmed, we confirm the veracity of the new user as an org member
|
||||
database::models::TeamMember::get_from_user_id_organization(
|
||||
database::models::DBTeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
data.new_owner.into(),
|
||||
false,
|
||||
@@ -932,13 +937,14 @@ pub async fn organization_projects_remove(
|
||||
|
||||
// Then, we get the team member of the project and that user (if it exists)
|
||||
// We use the team member get directly
|
||||
let new_owner = database::models::TeamMember::get_from_user_id_project(
|
||||
project_item.inner.id,
|
||||
data.new_owner.into(),
|
||||
true,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
let new_owner =
|
||||
database::models::DBTeamMember::get_from_user_id_project(
|
||||
project_item.inner.id,
|
||||
data.new_owner.into(),
|
||||
true,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
@@ -951,7 +957,7 @@ pub async fn organization_projects_remove(
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
let member = TeamMember {
|
||||
let member = DBTeamMember {
|
||||
id: new_id,
|
||||
team_id: project_item.inner.team_id,
|
||||
user_id: data.new_owner.into(),
|
||||
@@ -998,17 +1004,17 @@ pub async fn organization_projects_remove(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::User::clear_project_cache(
|
||||
database::models::DBUser::clear_project_cache(
|
||||
&[current_user.id.into()],
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
database::models::TeamMember::clear_cache(
|
||||
database::models::DBTeamMember::clear_cache(
|
||||
project_item.inner.team_id,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
database::models::Project::clear_cache(
|
||||
database::models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -1052,7 +1058,7 @@ pub async fn organization_icon_edit(
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let organization_item =
|
||||
database::models::Organization::get(&string, &**pool, &redis)
|
||||
database::models::DBOrganization::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -1061,7 +1067,7 @@ pub async fn organization_icon_edit(
|
||||
})?;
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let team_member = database::models::TeamMember::get_from_user_id(
|
||||
let team_member = database::models::DBTeamMember::get_from_user_id(
|
||||
organization_item.team_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1125,7 +1131,7 @@ pub async fn organization_icon_edit(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Organization::clear_cache(
|
||||
database::models::DBOrganization::clear_cache(
|
||||
organization_item.id,
|
||||
Some(organization_item.slug),
|
||||
&redis,
|
||||
@@ -1155,7 +1161,7 @@ pub async fn delete_organization_icon(
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let organization_item =
|
||||
database::models::Organization::get(&string, &**pool, &redis)
|
||||
database::models::DBOrganization::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -1164,7 +1170,7 @@ pub async fn delete_organization_icon(
|
||||
})?;
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let team_member = database::models::TeamMember::get_from_user_id(
|
||||
let team_member = database::models::DBTeamMember::get_from_user_id(
|
||||
organization_item.team_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1208,7 +1214,7 @@ pub async fn delete_organization_icon(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
database::models::Organization::clear_cache(
|
||||
database::models::DBOrganization::clear_cache(
|
||||
organization_item.id,
|
||||
Some(organization_item.slug),
|
||||
&redis,
|
||||
|
||||
@@ -160,7 +160,7 @@ pub async fn paypal_webhook(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
crate::database::models::user_item::User::clear_caches(
|
||||
crate::database::models::user_item::DBUser::clear_caches(
|
||||
&[(
|
||||
crate::database::models::DBUserId(result.user_id),
|
||||
None,
|
||||
@@ -270,7 +270,7 @@ pub async fn tremendous_webhook(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
crate::database::models::user_item::User::clear_caches(
|
||||
crate::database::models::user_item::DBUser::clear_caches(
|
||||
&[(
|
||||
crate::database::models::DBUserId(result.user_id),
|
||||
None,
|
||||
@@ -319,12 +319,12 @@ pub async fn user_payouts(
|
||||
.1;
|
||||
|
||||
let payout_ids =
|
||||
crate::database::models::payout_item::Payout::get_all_for_user(
|
||||
crate::database::models::payout_item::DBPayout::get_all_for_user(
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
let payouts = crate::database::models::payout_item::Payout::get_many(
|
||||
let payouts = crate::database::models::payout_item::DBPayout::get_many(
|
||||
&payout_ids,
|
||||
&**pool,
|
||||
)
|
||||
@@ -477,7 +477,7 @@ pub async fn create_payout(
|
||||
}
|
||||
|
||||
let mut payout_item =
|
||||
crate::database::models::payout_item::Payout {
|
||||
crate::database::models::payout_item::DBPayout {
|
||||
id: payout_id,
|
||||
user_id: user.id,
|
||||
created: Utc::now(),
|
||||
@@ -550,7 +550,7 @@ pub async fn create_payout(
|
||||
if let Some(email) = user.email {
|
||||
if user.email_verified {
|
||||
let mut payout_item =
|
||||
crate::database::models::payout_item::Payout {
|
||||
crate::database::models::payout_item::DBPayout {
|
||||
id: payout_id,
|
||||
user_id: user.id,
|
||||
created: Utc::now(),
|
||||
@@ -633,7 +633,7 @@ pub async fn create_payout(
|
||||
payout_item.insert(&mut transaction).await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
crate::database::models::User::clear_caches(&[(user.id, None)], &redis)
|
||||
crate::database::models::DBUser::clear_caches(&[(user.id, None)], &redis)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
@@ -660,7 +660,7 @@ pub async fn cancel_payout(
|
||||
|
||||
let id = info.into_inner().0;
|
||||
let payout =
|
||||
crate::database::models::payout_item::Payout::get(id.into(), &**pool)
|
||||
crate::database::models::payout_item::DBPayout::get(id.into(), &**pool)
|
||||
.await?;
|
||||
|
||||
if let Some(payout) = payout {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::database::models::loader_fields::{
|
||||
Loader, LoaderField, LoaderFieldEnumValue,
|
||||
};
|
||||
use crate::database::models::thread_item::ThreadBuilder;
|
||||
use crate::database::models::{self, User, image_item};
|
||||
use crate::database::models::{self, DBUser, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::{FileHost, FileHostingError};
|
||||
use crate::models::error::ApiError;
|
||||
@@ -646,7 +646,7 @@ async fn project_create_inner(
|
||||
let mut members = vec![];
|
||||
|
||||
if let Some(organization_id) = project_create_data.organization_id {
|
||||
let org = models::Organization::get_id(
|
||||
let org = models::DBOrganization::get_id(
|
||||
organization_id.into(),
|
||||
pool,
|
||||
redis,
|
||||
@@ -658,7 +658,7 @@ async fn project_create_inner(
|
||||
)
|
||||
})?;
|
||||
|
||||
let team_member = models::TeamMember::get_from_user_id(
|
||||
let team_member = models::DBTeamMember::get_from_user_id(
|
||||
org.team_id,
|
||||
current_user.id.into(),
|
||||
pool,
|
||||
@@ -773,7 +773,7 @@ async fn project_create_inner(
|
||||
link_urls,
|
||||
gallery_items: gallery_urls
|
||||
.iter()
|
||||
.map(|x| models::project_item::GalleryItem {
|
||||
.map(|x| models::project_item::DBGalleryItem {
|
||||
image_url: x.url.clone(),
|
||||
raw_image_url: x.raw_url.clone(),
|
||||
featured: x.featured,
|
||||
@@ -791,10 +791,10 @@ async fn project_create_inner(
|
||||
let now = Utc::now();
|
||||
|
||||
let id = project_builder_actual.insert(&mut *transaction).await?;
|
||||
User::clear_project_cache(&[current_user.id.into()], redis).await?;
|
||||
DBUser::clear_project_cache(&[current_user.id.into()], redis).await?;
|
||||
|
||||
for image_id in project_create_data.uploaded_images {
|
||||
if let Some(db_image) = image_item::Image::get(
|
||||
if let Some(db_image) = image_item::DBImage::get(
|
||||
image_id.into(),
|
||||
&mut **transaction,
|
||||
redis,
|
||||
@@ -822,7 +822,8 @@ async fn project_create_inner(
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
image_item::Image::clear_cache(image.id.into(), redis).await?;
|
||||
image_item::DBImage::clear_cache(image.id.into(), redis)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(CreateError::InvalidInput(format!(
|
||||
"Image {image_id} does not exist"
|
||||
|
||||
@@ -4,9 +4,9 @@ use std::sync::Arc;
|
||||
use crate::auth::checks::{filter_visible_versions, is_visible_project};
|
||||
use crate::auth::{filter_visible_projects, get_user_from_headers};
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::project_item::{GalleryItem, ModCategory};
|
||||
use crate::database::models::project_item::{DBGalleryItem, DBModCategory};
|
||||
use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||
use crate::database::models::{TeamMember, ids as db_ids, image_item};
|
||||
use crate::database::models::{DBTeamMember, ids as db_ids, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::database::{self, models as db_models};
|
||||
use crate::file_hosting::FileHost;
|
||||
@@ -109,7 +109,7 @@ pub async fn random_projects_get(
|
||||
.await?;
|
||||
|
||||
let projects_data =
|
||||
db_models::Project::get_many_ids(&project_ids, &**pool, &redis)
|
||||
db_models::DBProject::get_many_ids(&project_ids, &**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(Project::from)
|
||||
@@ -132,7 +132,7 @@ pub async fn projects_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let ids = serde_json::from_str::<Vec<&str>>(&ids.ids)?;
|
||||
let projects_data =
|
||||
db_models::Project::get_many(&ids, &**pool, &redis).await?;
|
||||
db_models::DBProject::get_many(&ids, &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -162,7 +162,7 @@ pub async fn project_get(
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let project_data =
|
||||
db_models::Project::get(&string, &**pool, &redis).await?;
|
||||
db_models::DBProject::get(&string, &**pool, &redis).await?;
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
&**pool,
|
||||
@@ -268,12 +268,12 @@ pub async fn project_edit(
|
||||
})?;
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let result = db_models::Project::get(&string, &**pool, &redis).await?;
|
||||
let result = db_models::DBProject::get(&string, &**pool, &redis).await?;
|
||||
if let Some(project_item) = result {
|
||||
let id = project_item.inner.id;
|
||||
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -884,7 +884,7 @@ pub async fn project_edit(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -929,7 +929,7 @@ pub async fn edit_project_categories(
|
||||
|
||||
let mcategories = category_ids
|
||||
.values()
|
||||
.map(|&category_id| ModCategory {
|
||||
.map(|&category_id| DBModCategory {
|
||||
project_id,
|
||||
category_id,
|
||||
is_additional,
|
||||
@@ -937,7 +937,7 @@ pub async fn edit_project_categories(
|
||||
.collect::<Vec<_>>();
|
||||
mod_categories.extend(mcategories);
|
||||
}
|
||||
ModCategory::insert_many(mod_categories, &mut *transaction).await?;
|
||||
DBModCategory::insert_many(mod_categories, &mut *transaction).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -980,7 +980,8 @@ pub async fn project_get_check(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let slug = info.into_inner().0;
|
||||
|
||||
let project_data = db_models::Project::get(&slug, &**pool, &redis).await?;
|
||||
let project_data =
|
||||
db_models::DBProject::get(&slug, &**pool, &redis).await?;
|
||||
|
||||
if let Some(project) = project_data {
|
||||
Ok(HttpResponse::Ok().json(json! ({
|
||||
@@ -1006,7 +1007,7 @@ pub async fn dependency_list(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let result = db_models::Project::get(&string, &**pool, &redis).await?;
|
||||
let result = db_models::DBProject::get(&string, &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -1026,7 +1027,7 @@ pub async fn dependency_list(
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let dependencies = database::Project::get_dependencies(
|
||||
let dependencies = database::DBProject::get_dependencies(
|
||||
project.inner.id,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -1054,8 +1055,8 @@ pub async fn dependency_list(
|
||||
.unique()
|
||||
.collect::<Vec<db_models::DBVersionId>>();
|
||||
let (projects_result, versions_result) = futures::future::try_join(
|
||||
database::Project::get_many_ids(&project_ids, &**pool, &redis),
|
||||
database::Version::get_many(&dep_version_ids, &**pool, &redis),
|
||||
database::DBProject::get_many_ids(&project_ids, &**pool, &redis),
|
||||
database::DBVersion::get_many(&dep_version_ids, &**pool, &redis),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -1141,7 +1142,8 @@ pub async fn projects_edit(
|
||||
.collect();
|
||||
|
||||
let projects_data =
|
||||
db_models::Project::get_many_ids(&project_ids, &**pool, &redis).await?;
|
||||
db_models::DBProject::get_many_ids(&project_ids, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
if let Some(id) = project_ids
|
||||
.iter()
|
||||
@@ -1157,7 +1159,7 @@ pub async fn projects_edit(
|
||||
.iter()
|
||||
.map(|x| x.inner.team_id)
|
||||
.collect::<Vec<db_models::DBTeamId>>();
|
||||
let team_members = db_models::TeamMember::get_from_team_full_many(
|
||||
let team_members = db_models::DBTeamMember::get_from_team_full_many(
|
||||
&team_ids, &**pool, &redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -1166,7 +1168,7 @@ pub async fn projects_edit(
|
||||
.iter()
|
||||
.filter_map(|x| x.inner.organization_id)
|
||||
.collect::<Vec<db_models::DBOrganizationId>>();
|
||||
let organizations = db_models::Organization::get_many_ids(
|
||||
let organizations = db_models::DBOrganization::get_many_ids(
|
||||
&organization_ids,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -1178,7 +1180,7 @@ pub async fn projects_edit(
|
||||
.map(|x| x.team_id)
|
||||
.collect::<Vec<db_models::DBTeamId>>();
|
||||
let organization_team_members =
|
||||
db_models::TeamMember::get_from_team_full_many(
|
||||
db_models::DBTeamMember::get_from_team_full_many(
|
||||
&organization_team_ids,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -1315,7 +1317,7 @@ pub async fn projects_edit(
|
||||
}
|
||||
}
|
||||
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project.inner.id,
|
||||
project.inner.slug,
|
||||
None,
|
||||
@@ -1388,13 +1390,13 @@ pub async fn bulk_edit_project_categories(
|
||||
))
|
||||
})?
|
||||
.id;
|
||||
mod_categories.push(ModCategory {
|
||||
mod_categories.push(DBModCategory {
|
||||
project_id,
|
||||
category_id,
|
||||
is_additional,
|
||||
});
|
||||
}
|
||||
ModCategory::insert_many(mod_categories, &mut *transaction).await?;
|
||||
DBModCategory::insert_many(mod_categories, &mut *transaction).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1427,7 +1429,7 @@ pub async fn project_icon_edit(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let project_item = db_models::Project::get(&string, &**pool, &redis)
|
||||
let project_item = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -1437,7 +1439,7 @@ pub async fn project_icon_edit(
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1508,7 +1510,7 @@ pub async fn project_icon_edit(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -1538,7 +1540,7 @@ pub async fn delete_project_icon(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let project_item = db_models::Project::get(&string, &**pool, &redis)
|
||||
let project_item = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -1548,7 +1550,7 @@ pub async fn delete_project_icon(
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1597,7 +1599,7 @@ pub async fn delete_project_icon(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -1645,7 +1647,7 @@ pub async fn add_gallery_item(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let project_item = db_models::Project::get(&string, &**pool, &redis)
|
||||
let project_item = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -1662,7 +1664,7 @@ pub async fn add_gallery_item(
|
||||
|
||||
if !user.role.is_admin() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1735,7 +1737,7 @@ pub async fn add_gallery_item(
|
||||
.await?;
|
||||
}
|
||||
|
||||
let gallery_item = vec![db_models::project_item::GalleryItem {
|
||||
let gallery_item = vec![db_models::project_item::DBGalleryItem {
|
||||
image_url: upload_result.url,
|
||||
raw_image_url: upload_result.raw_url,
|
||||
featured: item.featured,
|
||||
@@ -1744,7 +1746,7 @@ pub async fn add_gallery_item(
|
||||
created: Utc::now(),
|
||||
ordering: item.ordering.unwrap_or(0),
|
||||
}];
|
||||
GalleryItem::insert_many(
|
||||
DBGalleryItem::insert_many(
|
||||
gallery_item,
|
||||
project_item.inner.id,
|
||||
&mut transaction,
|
||||
@@ -1752,7 +1754,7 @@ pub async fn add_gallery_item(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -1822,7 +1824,7 @@ pub async fn edit_gallery_item(
|
||||
))
|
||||
})?;
|
||||
|
||||
let project_item = db_models::Project::get_id(
|
||||
let project_item = db_models::DBProject::get_id(
|
||||
database::models::DBProjectId(result.mod_id),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -1836,7 +1838,7 @@ pub async fn edit_gallery_item(
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -1935,7 +1937,7 @@ pub async fn edit_gallery_item(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -1985,7 +1987,7 @@ pub async fn delete_gallery_item(
|
||||
))
|
||||
})?;
|
||||
|
||||
let project_item = db_models::Project::get_id(
|
||||
let project_item = db_models::DBProject::get_id(
|
||||
database::models::DBProjectId(item.mod_id),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -1999,7 +2001,7 @@ pub async fn delete_gallery_item(
|
||||
|
||||
if !user.role.is_mod() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project_item.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -2049,7 +2051,7 @@ pub async fn delete_gallery_item(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
db_models::Project::clear_cache(
|
||||
db_models::DBProject::clear_cache(
|
||||
project_item.inner.id,
|
||||
project_item.inner.slug,
|
||||
None,
|
||||
@@ -2079,7 +2081,7 @@ pub async fn project_delete(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let project = db_models::Project::get(&string, &**pool, &redis)
|
||||
let project = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -2089,7 +2091,7 @@ pub async fn project_delete(
|
||||
|
||||
if !user.role.is_admin() {
|
||||
let (team_member, organization_team_member) =
|
||||
db_models::TeamMember::get_for_project_permissions(
|
||||
db_models::DBTeamMember::get_for_project_permissions(
|
||||
&project.inner,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -2122,9 +2124,10 @@ pub async fn project_delete(
|
||||
project_id: Some(project.inner.id.into()),
|
||||
};
|
||||
let uploaded_images =
|
||||
db_models::Image::get_many_contexted(context, &mut transaction).await?;
|
||||
db_models::DBImage::get_many_contexted(context, &mut transaction)
|
||||
.await?;
|
||||
for image in uploaded_images {
|
||||
image_item::Image::remove(image.id, &mut transaction, &redis).await?;
|
||||
image_item::DBImage::remove(image.id, &mut transaction, &redis).await?;
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
@@ -2137,9 +2140,12 @@ pub async fn project_delete(
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
let result =
|
||||
db_models::Project::remove(project.inner.id, &mut transaction, &redis)
|
||||
.await?;
|
||||
let result = db_models::DBProject::remove(
|
||||
project.inner.id,
|
||||
&mut transaction,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -2178,7 +2184,7 @@ pub async fn project_follow(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let result = db_models::Project::get(&string, &**pool, &redis)
|
||||
let result = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -2258,7 +2264,7 @@ pub async fn project_unfollow(
|
||||
.1;
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let result = db_models::Project::get(&string, &**pool, &redis)
|
||||
let result = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -2336,7 +2342,7 @@ pub async fn project_get_organization(
|
||||
let user_id = current_user.as_ref().map(|x| x.id.into());
|
||||
|
||||
let string = info.into_inner().0;
|
||||
let result = db_models::Project::get(&string, &**pool, &redis)
|
||||
let result = db_models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -2350,7 +2356,7 @@ pub async fn project_get_organization(
|
||||
))
|
||||
} else if let Some(organization_id) = result.inner.organization_id {
|
||||
let organization =
|
||||
db_models::Organization::get_id(organization_id, &**pool, &redis)
|
||||
db_models::DBOrganization::get_id(organization_id, &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -2358,14 +2364,14 @@ pub async fn project_get_organization(
|
||||
)
|
||||
})?;
|
||||
|
||||
let members_data = TeamMember::get_from_team_full(
|
||||
let members_data = DBTeamMember::get_from_team_full(
|
||||
organization.team_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&members_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
|
||||
@@ -87,7 +87,7 @@ pub async fn report_create(
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut report = crate::database::models::report_item::Report {
|
||||
let mut report = crate::database::models::report_item::DBReport {
|
||||
id,
|
||||
report_type_id: report_type,
|
||||
project_id: None,
|
||||
@@ -171,7 +171,7 @@ pub async fn report_create(
|
||||
|
||||
for image_id in new_report.uploaded_images {
|
||||
if let Some(db_image) =
|
||||
image_item::Image::get(image_id.into(), &mut *transaction, &redis)
|
||||
image_item::DBImage::get(image_id.into(), &mut *transaction, &redis)
|
||||
.await?
|
||||
{
|
||||
let image: Image = db_image.into();
|
||||
@@ -195,7 +195,7 @@ pub async fn report_create(
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
image_item::Image::clear_cache(image.id.into(), &redis).await?;
|
||||
image_item::DBImage::clear_cache(image.id.into(), &redis).await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
"Image {image_id} could not be found"
|
||||
@@ -292,11 +292,12 @@ pub async fn reports(
|
||||
.await?
|
||||
};
|
||||
|
||||
let query_reports = crate::database::models::report_item::Report::get_many(
|
||||
&report_ids,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
let query_reports =
|
||||
crate::database::models::report_item::DBReport::get_many(
|
||||
&report_ids,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let mut reports: Vec<Report> = Vec::new();
|
||||
|
||||
@@ -325,11 +326,12 @@ pub async fn reports_get(
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
|
||||
let reports_data = crate::database::models::report_item::Report::get_many(
|
||||
&report_ids,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
let reports_data =
|
||||
crate::database::models::report_item::DBReport::get_many(
|
||||
&report_ids,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
@@ -369,7 +371,8 @@ pub async fn report_get(
|
||||
let id = info.into_inner().0.into();
|
||||
|
||||
let report =
|
||||
crate::database::models::report_item::Report::get(id, &**pool).await?;
|
||||
crate::database::models::report_item::DBReport::get(id, &**pool)
|
||||
.await?;
|
||||
|
||||
if let Some(report) = report {
|
||||
if !user.role.is_mod() && report.reporter != user.id.into() {
|
||||
@@ -410,7 +413,8 @@ pub async fn report_edit(
|
||||
let id = info.into_inner().0.into();
|
||||
|
||||
let report =
|
||||
crate::database::models::report_item::Report::get(id, &**pool).await?;
|
||||
crate::database::models::report_item::DBReport::get(id, &**pool)
|
||||
.await?;
|
||||
|
||||
if let Some(report) = report {
|
||||
if !user.role.is_mod() && report.reporter != user.id.into() {
|
||||
@@ -512,14 +516,16 @@ pub async fn report_delete(
|
||||
let context = ImageContext::Report {
|
||||
report_id: Some(id),
|
||||
};
|
||||
let uploaded_images =
|
||||
database::models::Image::get_many_contexted(context, &mut transaction)
|
||||
.await?;
|
||||
let uploaded_images = database::models::DBImage::get_many_contexted(
|
||||
context,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
for image in uploaded_images {
|
||||
image_item::Image::remove(image.id, &mut transaction, &redis).await?;
|
||||
image_item::DBImage::remove(image.id, &mut transaction, &redis).await?;
|
||||
}
|
||||
|
||||
let result = crate::database::models::report_item::Report::remove_full(
|
||||
let result = crate::database::models::report_item::DBReport::remove_full(
|
||||
id.into(),
|
||||
&mut transaction,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::auth::checks::is_visible_project;
|
||||
use crate::auth::get_user_from_headers;
|
||||
use crate::database::Project;
|
||||
use crate::database::DBProject;
|
||||
use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::team_item::TeamAssociationId;
|
||||
use crate::database::models::{Organization, Team, TeamMember, User};
|
||||
use crate::database::models::{DBOrganization, DBTeam, DBTeamMember, DBUser};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models::ids::TeamId;
|
||||
use crate::models::notifications::NotificationBody;
|
||||
@@ -48,7 +48,8 @@ pub async fn team_members_get_project(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
let project_data =
|
||||
crate::database::models::Project::get(&string, &**pool, &redis).await?;
|
||||
crate::database::models::DBProject::get(&string, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
if let Some(project) = project_data {
|
||||
let current_user = get_user_from_headers(
|
||||
@@ -67,13 +68,13 @@ pub async fn team_members_get_project(
|
||||
{
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
let members_data = TeamMember::get_from_team_full(
|
||||
let members_data = DBTeamMember::get_from_team_full(
|
||||
project.inner.team_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
let users = User::get_many_ids(
|
||||
let users = DBUser::get_many_ids(
|
||||
&members_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -83,7 +84,7 @@ pub async fn team_members_get_project(
|
||||
let user_id = current_user.as_ref().map(|x| x.id.into());
|
||||
let logged_in = if let Some(user_id) = user_id {
|
||||
let (team_member, organization_team_member) =
|
||||
TeamMember::get_for_project_permissions(
|
||||
DBTeamMember::get_for_project_permissions(
|
||||
&project.inner,
|
||||
user_id,
|
||||
&**pool,
|
||||
@@ -132,7 +133,7 @@ pub async fn team_members_get_organization(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
let organization_data =
|
||||
crate::database::models::Organization::get(&string, &**pool, &redis)
|
||||
crate::database::models::DBOrganization::get(&string, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
if let Some(organization) = organization_data {
|
||||
@@ -147,13 +148,13 @@ pub async fn team_members_get_organization(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let members_data = TeamMember::get_from_team_full(
|
||||
let members_data = DBTeamMember::get_from_team_full(
|
||||
organization.team_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&members_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -208,8 +209,8 @@ pub async fn team_members_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let id = info.into_inner().0;
|
||||
let members_data =
|
||||
TeamMember::get_from_team_full(id.into(), &**pool, &redis).await?;
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
DBTeamMember::get_from_team_full(id.into(), &**pool, &redis).await?;
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&members_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -279,8 +280,9 @@ pub async fn teams_get(
|
||||
.collect::<Vec<crate::database::models::ids::DBTeamId>>();
|
||||
|
||||
let teams_data =
|
||||
TeamMember::get_from_team_full_many(&team_ids, &**pool, &redis).await?;
|
||||
let users = crate::database::models::User::get_many_ids(
|
||||
DBTeamMember::get_from_team_full_many(&team_ids, &**pool, &redis)
|
||||
.await?;
|
||||
let users = crate::database::models::DBUser::get_many_ids(
|
||||
&teams_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -351,7 +353,7 @@ pub async fn join_team(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let member = TeamMember::get_from_user_id_pending(
|
||||
let member = DBTeamMember::get_from_user_id_pending(
|
||||
team_id,
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -367,7 +369,7 @@ pub async fn join_team(
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
// Edit Team Member to set Accepted to True
|
||||
TeamMember::edit_team_member(
|
||||
DBTeamMember::edit_team_member(
|
||||
team_id,
|
||||
current_user.id.into(),
|
||||
None,
|
||||
@@ -383,8 +385,8 @@ pub async fn join_team(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
User::clear_project_cache(&[current_user.id.into()], &redis).await?;
|
||||
TeamMember::clear_cache(team_id, &redis).await?;
|
||||
DBUser::clear_project_cache(&[current_user.id.into()], &redis).await?;
|
||||
DBTeamMember::clear_cache(team_id, &redis).await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"There is no pending request from this team".to_string(),
|
||||
@@ -439,27 +441,30 @@ pub async fn add_team_member(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let team_association = Team::get_association(team_id, &**pool)
|
||||
let team_association = DBTeam::get_association(team_id, &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The team specified does not exist".to_string(),
|
||||
)
|
||||
})?;
|
||||
let member =
|
||||
TeamMember::get_from_user_id(team_id, current_user.id.into(), &**pool)
|
||||
.await?;
|
||||
let member = DBTeamMember::get_from_user_id(
|
||||
team_id,
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
match team_association {
|
||||
// If team is associated with a project, check if they have permissions to invite users to that project
|
||||
TeamAssociationId::Project(pid) => {
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
pid, &**pool,
|
||||
)
|
||||
.await?;
|
||||
let organization_team_member =
|
||||
if let Some(organization) = &organization {
|
||||
TeamMember::get_from_user_id(
|
||||
DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -537,7 +542,7 @@ pub async fn add_team_member(
|
||||
));
|
||||
}
|
||||
|
||||
let request = TeamMember::get_from_user_id_pending(
|
||||
let request = DBTeamMember::get_from_user_id_pending(
|
||||
team_id,
|
||||
new_member.user_id.into(),
|
||||
&**pool,
|
||||
@@ -556,7 +561,7 @@ pub async fn add_team_member(
|
||||
));
|
||||
}
|
||||
}
|
||||
let new_user = crate::database::models::User::get_id(
|
||||
let new_user = crate::database::models::DBUser::get_id(
|
||||
new_member.user_id.into(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -570,11 +575,13 @@ pub async fn add_team_member(
|
||||
if let TeamAssociationId::Project(pid) = team_association {
|
||||
// We cannot add the owner to a project team in their own org
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(pid, &**pool)
|
||||
.await?;
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
pid, &**pool,
|
||||
)
|
||||
.await?;
|
||||
let new_user_organization_team_member =
|
||||
if let Some(organization) = &organization {
|
||||
TeamMember::get_from_user_id(
|
||||
DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
new_user.id,
|
||||
&**pool,
|
||||
@@ -607,7 +614,7 @@ pub async fn add_team_member(
|
||||
let new_id =
|
||||
crate::database::models::ids::generate_team_member_id(&mut transaction)
|
||||
.await?;
|
||||
TeamMember {
|
||||
DBTeamMember {
|
||||
id: new_id,
|
||||
team_id,
|
||||
user_id: new_member.user_id.into(),
|
||||
@@ -653,8 +660,8 @@ pub async fn add_team_member(
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
TeamMember::clear_cache(team_id, &redis).await?;
|
||||
User::clear_project_cache(&[new_member.user_id.into()], &redis).await?;
|
||||
DBTeamMember::clear_cache(team_id, &redis).await?;
|
||||
DBUser::clear_project_cache(&[new_member.user_id.into()], &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
@@ -691,16 +698,16 @@ pub async fn edit_team_member(
|
||||
.1;
|
||||
|
||||
let team_association =
|
||||
Team::get_association(id, &**pool).await?.ok_or_else(|| {
|
||||
DBTeam::get_association(id, &**pool).await?.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The team specified does not exist".to_string(),
|
||||
)
|
||||
})?;
|
||||
let member =
|
||||
TeamMember::get_from_user_id(id, current_user.id.into(), &**pool)
|
||||
DBTeamMember::get_from_user_id(id, current_user.id.into(), &**pool)
|
||||
.await?;
|
||||
let edit_member_db =
|
||||
TeamMember::get_from_user_id_pending(id, user_id, &**pool)
|
||||
DBTeamMember::get_from_user_id_pending(id, user_id, &**pool)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::CustomAuthentication(
|
||||
@@ -723,13 +730,13 @@ pub async fn edit_team_member(
|
||||
match team_association {
|
||||
TeamAssociationId::Project(project_id) => {
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
project_id, &**pool,
|
||||
)
|
||||
.await?;
|
||||
let organization_team_member =
|
||||
if let Some(organization) = &organization {
|
||||
TeamMember::get_from_user_id(
|
||||
DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -831,7 +838,7 @@ pub async fn edit_team_member(
|
||||
}
|
||||
}
|
||||
|
||||
TeamMember::edit_team_member(
|
||||
DBTeamMember::edit_team_member(
|
||||
id,
|
||||
user_id,
|
||||
edit_member.permissions,
|
||||
@@ -846,7 +853,7 @@ pub async fn edit_team_member(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
TeamMember::clear_cache(id, &redis).await?;
|
||||
DBTeamMember::clear_cache(id, &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
@@ -879,9 +886,10 @@ pub async fn transfer_ownership(
|
||||
// Forbid transferring ownership of a project team that is owned by an organization
|
||||
// These are owned by the organization owner, and must be removed from the organization first
|
||||
// There shouldnt be an ownr on these projects in these cases, but just in case.
|
||||
let team_association_id = Team::get_association(id.into(), &**pool).await?;
|
||||
let team_association_id =
|
||||
DBTeam::get_association(id.into(), &**pool).await?;
|
||||
if let Some(TeamAssociationId::Project(pid)) = team_association_id {
|
||||
let result = Project::get_id(pid, &**pool, &redis).await?;
|
||||
let result = DBProject::get_id(pid, &**pool, &redis).await?;
|
||||
if let Some(project_item) = result {
|
||||
if project_item.inner.organization_id.is_some() {
|
||||
return Err(ApiError::InvalidInput(
|
||||
@@ -893,7 +901,7 @@ pub async fn transfer_ownership(
|
||||
}
|
||||
|
||||
if !current_user.role.is_admin() {
|
||||
let member = TeamMember::get_from_user_id(
|
||||
let member = DBTeamMember::get_from_user_id(
|
||||
id.into(),
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -914,7 +922,7 @@ pub async fn transfer_ownership(
|
||||
}
|
||||
}
|
||||
|
||||
let new_member = TeamMember::get_from_user_id(
|
||||
let new_member = DBTeamMember::get_from_user_id(
|
||||
id.into(),
|
||||
new_owner.user_id.into(),
|
||||
&**pool,
|
||||
@@ -936,12 +944,12 @@ pub async fn transfer_ownership(
|
||||
|
||||
// The following are the only places new_is_owner is modified.
|
||||
if let Some(former_owner) =
|
||||
TeamMember::get_from_team_full(id.into(), &**pool, &redis)
|
||||
DBTeamMember::get_from_team_full(id.into(), &**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.find(|x| x.is_owner)
|
||||
{
|
||||
TeamMember::edit_team_member(
|
||||
DBTeamMember::edit_team_member(
|
||||
id.into(),
|
||||
former_owner.user_id,
|
||||
None,
|
||||
@@ -956,7 +964,7 @@ pub async fn transfer_ownership(
|
||||
.await?;
|
||||
}
|
||||
|
||||
TeamMember::edit_team_member(
|
||||
DBTeamMember::edit_team_member(
|
||||
id.into(),
|
||||
new_owner.user_id.into(),
|
||||
Some(ProjectPermissions::all()),
|
||||
@@ -1004,7 +1012,7 @@ pub async fn transfer_ownership(
|
||||
|
||||
// If the owner of the organization is a member of the project, remove them
|
||||
for team_id in team_ids.iter() {
|
||||
TeamMember::delete(
|
||||
DBTeamMember::delete(
|
||||
*team_id,
|
||||
new_owner.user_id.into(),
|
||||
&mut transaction,
|
||||
@@ -1018,9 +1026,9 @@ pub async fn transfer_ownership(
|
||||
};
|
||||
|
||||
transaction.commit().await?;
|
||||
TeamMember::clear_cache(id.into(), &redis).await?;
|
||||
DBTeamMember::clear_cache(id.into(), &redis).await?;
|
||||
for team_id in project_teams_edited {
|
||||
TeamMember::clear_cache(team_id, &redis).await?;
|
||||
DBTeamMember::clear_cache(team_id, &redis).await?;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
@@ -1048,17 +1056,17 @@ pub async fn remove_team_member(
|
||||
.1;
|
||||
|
||||
let team_association =
|
||||
Team::get_association(id, &**pool).await?.ok_or_else(|| {
|
||||
DBTeam::get_association(id, &**pool).await?.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
"The team specified does not exist".to_string(),
|
||||
)
|
||||
})?;
|
||||
let member =
|
||||
TeamMember::get_from_user_id(id, current_user.id.into(), &**pool)
|
||||
DBTeamMember::get_from_user_id(id, current_user.id.into(), &**pool)
|
||||
.await?;
|
||||
|
||||
let delete_member =
|
||||
TeamMember::get_from_user_id_pending(id, user_id, &**pool).await?;
|
||||
DBTeamMember::get_from_user_id_pending(id, user_id, &**pool).await?;
|
||||
|
||||
if let Some(delete_member) = delete_member {
|
||||
if delete_member.is_owner {
|
||||
@@ -1074,13 +1082,13 @@ pub async fn remove_team_member(
|
||||
match team_association {
|
||||
TeamAssociationId::Project(pid) => {
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
pid, &**pool,
|
||||
)
|
||||
.await?;
|
||||
let organization_team_member =
|
||||
if let Some(organization) = &organization {
|
||||
TeamMember::get_from_user_id(
|
||||
DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
current_user.id.into(),
|
||||
&**pool,
|
||||
@@ -1105,7 +1113,7 @@ pub async fn remove_team_member(
|
||||
.contains(ProjectPermissions::REMOVE_MEMBER)
|
||||
// true as if the permission exists, but the member does not, they are part of an org
|
||||
{
|
||||
TeamMember::delete(id, user_id, &mut transaction)
|
||||
DBTeamMember::delete(id, user_id, &mut transaction)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
@@ -1121,7 +1129,7 @@ pub async fn remove_team_member(
|
||||
// This is a pending invite rather than a member, so the
|
||||
// user being invited or team members with the MANAGE_INVITES
|
||||
// permission can remove it.
|
||||
TeamMember::delete(id, user_id, &mut transaction).await?;
|
||||
DBTeamMember::delete(id, user_id, &mut transaction).await?;
|
||||
} else {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to cancel a team invite"
|
||||
@@ -1144,7 +1152,7 @@ pub async fn remove_team_member(
|
||||
|| organization_permissions
|
||||
.contains(OrganizationPermissions::REMOVE_MEMBER)
|
||||
{
|
||||
TeamMember::delete(id, user_id, &mut transaction)
|
||||
DBTeamMember::delete(id, user_id, &mut transaction)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
@@ -1160,7 +1168,7 @@ pub async fn remove_team_member(
|
||||
// This is a pending invite rather than a member, so the
|
||||
// user being invited or team members with the MANAGE_INVITES
|
||||
// permission can remove it.
|
||||
TeamMember::delete(id, user_id, &mut transaction).await?;
|
||||
DBTeamMember::delete(id, user_id, &mut transaction).await?;
|
||||
} else {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have permission to cancel an organization invite".to_string(),
|
||||
@@ -1171,8 +1179,8 @@ pub async fn remove_team_member(
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
TeamMember::clear_cache(id, &redis).await?;
|
||||
User::clear_project_cache(&[delete_member.user_id], &redis).await?;
|
||||
DBTeamMember::clear_cache(id, &redis).await?;
|
||||
DBUser::clear_project_cache(&[delete_member.user_id], &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
|
||||
@@ -34,7 +34,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
}
|
||||
|
||||
pub async fn is_authorized_thread(
|
||||
thread: &database::models::Thread,
|
||||
thread: &database::models::DBThread,
|
||||
user: &User,
|
||||
pool: &PgPool,
|
||||
) -> Result<bool, ApiError> {
|
||||
@@ -94,7 +94,7 @@ pub async fn is_authorized_thread(
|
||||
}
|
||||
|
||||
pub async fn filter_authorized_threads(
|
||||
threads: Vec<database::models::Thread>,
|
||||
threads: Vec<database::models::DBThread>,
|
||||
user: &User,
|
||||
pool: &web::Data<PgPool>,
|
||||
redis: &RedisPool,
|
||||
@@ -230,7 +230,7 @@ pub async fn filter_authorized_threads(
|
||||
);
|
||||
|
||||
let users: Vec<User> =
|
||||
database::models::User::get_many_ids(&user_ids, &***pool, redis)
|
||||
database::models::DBUser::get_many_ids(&user_ids, &***pool, redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(From::from)
|
||||
@@ -278,7 +278,7 @@ pub async fn thread_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0.into();
|
||||
|
||||
let thread_data = database::models::Thread::get(string, &**pool).await?;
|
||||
let thread_data = database::models::DBThread::get(string, &**pool).await?;
|
||||
|
||||
let user = get_user_from_headers(
|
||||
&req,
|
||||
@@ -308,12 +308,13 @@ pub async fn thread_get(
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
let users: Vec<User> =
|
||||
database::models::User::get_many_ids(authors, &**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(From::from)
|
||||
.collect();
|
||||
let users: Vec<User> = database::models::DBUser::get_many_ids(
|
||||
authors, &**pool, &redis,
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(From::from)
|
||||
.collect();
|
||||
|
||||
return Ok(
|
||||
HttpResponse::Ok().json(Thread::from(data, users, &user))
|
||||
@@ -352,7 +353,7 @@ pub async fn threads_get(
|
||||
.collect();
|
||||
|
||||
let threads_data =
|
||||
database::models::Thread::get_many(&thread_ids, &**pool).await?;
|
||||
database::models::DBThread::get_many(&thread_ids, &**pool).await?;
|
||||
|
||||
let threads =
|
||||
filter_authorized_threads(threads_data, &user, &pool, &redis).await?;
|
||||
@@ -405,7 +406,7 @@ pub async fn thread_send_message(
|
||||
}
|
||||
|
||||
if let Some(replying_to) = replying_to {
|
||||
let thread_message = database::models::ThreadMessage::get(
|
||||
let thread_message = database::models::DBThreadMessage::get(
|
||||
(*replying_to).into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -430,7 +431,7 @@ pub async fn thread_send_message(
|
||||
));
|
||||
}
|
||||
|
||||
let result = database::models::Thread::get(string, &**pool).await?;
|
||||
let result = database::models::DBThread::get(string, &**pool).await?;
|
||||
|
||||
if let Some(thread) = result {
|
||||
if !is_authorized_thread(&thread, &user, &pool).await? {
|
||||
@@ -449,16 +450,17 @@ pub async fn thread_send_message(
|
||||
.await?;
|
||||
|
||||
if let Some(project_id) = thread.project_id {
|
||||
let project =
|
||||
database::models::Project::get_id(project_id, &**pool, &redis)
|
||||
.await?;
|
||||
let project = database::models::DBProject::get_id(
|
||||
project_id, &**pool, &redis,
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(project) = project {
|
||||
if project.inner.status != ProjectStatus::Processing
|
||||
&& user.role.is_mod()
|
||||
{
|
||||
let members =
|
||||
database::models::TeamMember::get_from_team_full(
|
||||
database::models::DBTeamMember::get_from_team_full(
|
||||
project.inner.team_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -482,9 +484,10 @@ pub async fn thread_send_message(
|
||||
}
|
||||
}
|
||||
} else if let Some(report_id) = thread.report_id {
|
||||
let report =
|
||||
database::models::report_item::Report::get(report_id, &**pool)
|
||||
.await?;
|
||||
let report = database::models::report_item::DBReport::get(
|
||||
report_id, &**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(report) = report {
|
||||
if report.closed && !user.role.is_mod() {
|
||||
@@ -513,7 +516,7 @@ pub async fn thread_send_message(
|
||||
} = &new_message.body
|
||||
{
|
||||
for image_id in associated_images {
|
||||
if let Some(db_image) = image_item::Image::get(
|
||||
if let Some(db_image) = image_item::DBImage::get(
|
||||
(*image_id).into(),
|
||||
&mut *transaction,
|
||||
&redis,
|
||||
@@ -543,7 +546,7 @@ pub async fn thread_send_message(
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
image_item::Image::clear_cache(image.id.into(), &redis)
|
||||
image_item::DBImage::clear_cache(image.id.into(), &redis)
|
||||
.await?;
|
||||
} else {
|
||||
return Err(ApiError::InvalidInput(format!(
|
||||
@@ -579,7 +582,7 @@ pub async fn message_delete(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let result = database::models::ThreadMessage::get(
|
||||
let result = database::models::DBThreadMessage::get(
|
||||
info.into_inner().0.into(),
|
||||
&**pool,
|
||||
)
|
||||
@@ -598,7 +601,7 @@ pub async fn message_delete(
|
||||
thread_message_id: Some(thread.id.into()),
|
||||
};
|
||||
let images =
|
||||
database::Image::get_many_contexted(context, &mut transaction)
|
||||
database::DBImage::get_many_contexted(context, &mut transaction)
|
||||
.await?;
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
for image in images {
|
||||
@@ -606,7 +609,8 @@ pub async fn message_delete(
|
||||
if let Some(icon_path) = name {
|
||||
file_host.delete_file_version("", icon_path).await?;
|
||||
}
|
||||
database::Image::remove(image.id, &mut transaction, &redis).await?;
|
||||
database::DBImage::remove(image.id, &mut transaction, &redis)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let private = if let MessageBody::Text { private, .. } = thread.body {
|
||||
@@ -617,7 +621,7 @@ pub async fn message_delete(
|
||||
false
|
||||
};
|
||||
|
||||
database::models::ThreadMessage::remove_full(
|
||||
database::models::DBThreadMessage::remove_full(
|
||||
thread.id,
|
||||
private,
|
||||
&mut transaction,
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{ApiError, oauth_clients::get_user_clients};
|
||||
use crate::util::img::delete_old_images;
|
||||
use crate::{
|
||||
auth::{filter_visible_projects, get_user_from_headers},
|
||||
database::{models::User, redis::RedisPool},
|
||||
database::{models::DBUser, redis::RedisPool},
|
||||
file_hosting::FileHost,
|
||||
models::{
|
||||
collections::{Collection, CollectionStatus},
|
||||
@@ -88,7 +88,7 @@ pub async fn admin_user_email(
|
||||
)
|
||||
})?;
|
||||
|
||||
let user = User::get_id(
|
||||
let user = DBUser::get_id(
|
||||
crate::database::models::DBUserId(user_id),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -120,12 +120,12 @@ pub async fn projects_list(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
let project_data = User::get_projects(id, &**pool, &redis).await?;
|
||||
let project_data = DBUser::get_projects(id, &**pool, &redis).await?;
|
||||
|
||||
let projects: Vec<_> = crate::database::Project::get_many_ids(
|
||||
let projects: Vec<_> = crate::database::DBProject::get_many_ids(
|
||||
&project_data,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -177,7 +177,7 @@ pub async fn users_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_ids = serde_json::from_str::<Vec<String>>(&ids.ids)?;
|
||||
|
||||
let users_data = User::get_many(&user_ids, &**pool, &redis).await?;
|
||||
let users_data = DBUser::get_many(&user_ids, &**pool, &redis).await?;
|
||||
|
||||
let users: Vec<crate::models::users::User> =
|
||||
users_data.into_iter().map(From::from).collect();
|
||||
@@ -192,7 +192,7 @@ pub async fn user_get(
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_data = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let user_data = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(data) = user_data {
|
||||
let auth_user = get_user_from_headers(
|
||||
@@ -237,7 +237,7 @@ pub async fn collections_list(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
let user_id: UserId = id.into();
|
||||
@@ -246,9 +246,9 @@ pub async fn collections_list(
|
||||
.map(|y| y.role.is_mod() || y.id == user_id)
|
||||
.unwrap_or(false);
|
||||
|
||||
let project_data = User::get_collections(id, &**pool).await?;
|
||||
let project_data = DBUser::get_collections(id, &**pool).await?;
|
||||
|
||||
let response: Vec<_> = crate::database::models::Collection::get_many(
|
||||
let response: Vec<_> = crate::database::models::DBCollection::get_many(
|
||||
&project_data,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -285,13 +285,13 @@ pub async fn orgs_list(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
let org_data = User::get_organizations(id, &**pool).await?;
|
||||
let org_data = DBUser::get_organizations(id, &**pool).await?;
|
||||
|
||||
let organizations_data =
|
||||
crate::database::models::organization_item::Organization::get_many_ids(
|
||||
crate::database::models::organization_item::DBOrganization::get_many_ids(
|
||||
&org_data, &**pool, &redis,
|
||||
)
|
||||
.await?;
|
||||
@@ -302,11 +302,11 @@ pub async fn orgs_list(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let teams_data =
|
||||
crate::database::models::TeamMember::get_from_team_full_many(
|
||||
crate::database::models::DBTeamMember::get_from_team_full_many(
|
||||
&team_ids, &**pool, &redis,
|
||||
)
|
||||
.await?;
|
||||
let users = User::get_many_ids(
|
||||
let users = DBUser::get_many_ids(
|
||||
&teams_data.iter().map(|x| x.user_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -397,7 +397,7 @@ pub async fn user_edit(
|
||||
ApiError::Validation(validation_errors_to_string(err, None))
|
||||
})?;
|
||||
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(actual_user) = id_option {
|
||||
let id = actual_user.id;
|
||||
@@ -408,7 +408,7 @@ pub async fn user_edit(
|
||||
|
||||
if let Some(username) = &new_user.username {
|
||||
let existing_user_id_option =
|
||||
User::get(username, &**pool, &redis).await?;
|
||||
DBUser::get(username, &**pool, &redis).await?;
|
||||
|
||||
if existing_user_id_option
|
||||
.map(|x| UserId::from(x.id))
|
||||
@@ -527,7 +527,7 @@ pub async fn user_edit(
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
User::clear_caches(&[(id, Some(actual_user.username))], &redis)
|
||||
DBUser::clear_caches(&[(id, Some(actual_user.username))], &redis)
|
||||
.await?;
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
@@ -565,7 +565,7 @@ pub async fn user_icon_edit(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(actual_user) = id_option {
|
||||
if user.id != actual_user.id.into() && !user.role.is_mod() {
|
||||
@@ -612,7 +612,7 @@ pub async fn user_icon_edit(
|
||||
)
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
User::clear_caches(&[(actual_user.id, None)], &redis).await?;
|
||||
DBUser::clear_caches(&[(actual_user.id, None)], &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
@@ -637,7 +637,7 @@ pub async fn user_icon_delete(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(actual_user) = id_option {
|
||||
if user.id != actual_user.id.into() && !user.role.is_mod() {
|
||||
@@ -665,7 +665,7 @@ pub async fn user_icon_delete(
|
||||
.execute(&**pool)
|
||||
.await?;
|
||||
|
||||
User::clear_caches(&[(actual_user.id, None)], &redis).await?;
|
||||
DBUser::clear_caches(&[(actual_user.id, None)], &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
} else {
|
||||
@@ -689,7 +689,7 @@ pub async fn user_delete(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
@@ -700,7 +700,7 @@ pub async fn user_delete(
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let result = User::remove(id, &mut transaction, &redis).await?;
|
||||
let result = DBUser::remove(id, &mut transaction, &redis).await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
@@ -730,7 +730,7 @@ pub async fn user_follows(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
@@ -739,8 +739,8 @@ pub async fn user_follows(
|
||||
));
|
||||
}
|
||||
|
||||
let project_ids = User::get_follows(id, &**pool).await?;
|
||||
let projects: Vec<_> = crate::database::Project::get_many_ids(
|
||||
let project_ids = DBUser::get_follows(id, &**pool).await?;
|
||||
let projects: Vec<_> = crate::database::DBProject::get_many_ids(
|
||||
&project_ids,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -772,7 +772,7 @@ pub async fn user_notifications(
|
||||
)
|
||||
.await?
|
||||
.1;
|
||||
let id_option = User::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
let id_option = DBUser::get(&info.into_inner().0, &**pool, &redis).await?;
|
||||
|
||||
if let Some(id) = id_option.map(|x| x.id) {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
@@ -782,7 +782,7 @@ pub async fn user_notifications(
|
||||
}
|
||||
|
||||
let mut notifications: Vec<Notification> =
|
||||
crate::database::models::notification_item::Notification::get_many_user(
|
||||
crate::database::models::notification_item::DBNotification::get_many_user(
|
||||
id, &**pool, &redis,
|
||||
)
|
||||
.await?
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::database::models::notification_item::NotificationBuilder;
|
||||
use crate::database::models::version_item::{
|
||||
DependencyBuilder, VersionBuilder, VersionFileBuilder,
|
||||
};
|
||||
use crate::database::models::{self, Organization, image_item};
|
||||
use crate::database::models::{self, DBOrganization, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::file_hosting::FileHost;
|
||||
use crate::models::ids::{ImageId, ProjectId, VersionId};
|
||||
@@ -216,7 +216,7 @@ async fn version_create_inner(
|
||||
let project_id: models::DBProjectId = version_create_data.project_id.unwrap().into();
|
||||
|
||||
// Ensure that the project this version is being added to exists
|
||||
if models::Project::get_id(project_id, &mut **transaction, redis)
|
||||
if models::DBProject::get_id(project_id, &mut **transaction, redis)
|
||||
.await?
|
||||
.is_none()
|
||||
{
|
||||
@@ -227,7 +227,7 @@ async fn version_create_inner(
|
||||
|
||||
// Check that the user creating this version is a team member
|
||||
// of the project the version is being added to.
|
||||
let team_member = models::TeamMember::get_from_user_id_project(
|
||||
let team_member = models::DBTeamMember::get_from_user_id_project(
|
||||
project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
@@ -236,14 +236,14 @@ async fn version_create_inner(
|
||||
.await?;
|
||||
|
||||
// Get organization attached, if exists, and the member project permissions
|
||||
let organization = models::Organization::get_associated_organization_project_id(
|
||||
let organization = models::DBOrganization::get_associated_organization_project_id(
|
||||
project_id,
|
||||
&mut **transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let organization_team_member = if let Some(organization) = &organization {
|
||||
models::TeamMember::get_from_user_id(
|
||||
models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&mut **transaction,
|
||||
@@ -481,7 +481,7 @@ async fn version_create_inner(
|
||||
|
||||
for image_id in version_data.uploaded_images {
|
||||
if let Some(db_image) =
|
||||
image_item::Image::get(image_id.into(), &mut **transaction, redis)
|
||||
image_item::DBImage::get(image_id.into(), &mut **transaction, redis)
|
||||
.await?
|
||||
{
|
||||
let image: Image = db_image.into();
|
||||
@@ -505,7 +505,7 @@ async fn version_create_inner(
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
image_item::Image::clear_cache(image.id.into(), redis).await?;
|
||||
image_item::DBImage::clear_cache(image.id.into(), redis).await?;
|
||||
} else {
|
||||
return Err(CreateError::InvalidInput(format!(
|
||||
"Image {image_id} does not exist"
|
||||
@@ -513,7 +513,7 @@ async fn version_create_inner(
|
||||
}
|
||||
}
|
||||
|
||||
models::Project::clear_cache(project_id, None, Some(true), redis).await?;
|
||||
models::DBProject::clear_cache(project_id, None, Some(true), redis).await?;
|
||||
|
||||
let project_status = sqlx::query!(
|
||||
"SELECT status FROM mods WHERE id = $1",
|
||||
@@ -604,7 +604,7 @@ async fn upload_file_to_version_inner(
|
||||
.await?
|
||||
.1;
|
||||
|
||||
let result = models::Version::get(version_id, &**client, &redis).await?;
|
||||
let result = models::DBVersion::get(version_id, &**client, &redis).await?;
|
||||
|
||||
let version = match result {
|
||||
Some(v) => v,
|
||||
@@ -629,7 +629,7 @@ async fn upload_file_to_version_inner(
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
if models::Project::get_id(
|
||||
if models::DBProject::get_id(
|
||||
version.inner.project_id,
|
||||
&mut **transaction,
|
||||
&redis,
|
||||
@@ -643,7 +643,7 @@ async fn upload_file_to_version_inner(
|
||||
}
|
||||
|
||||
if !user.role.is_admin() {
|
||||
let team_member = models::TeamMember::get_from_user_id_project(
|
||||
let team_member = models::DBTeamMember::get_from_user_id_project(
|
||||
version.inner.project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
@@ -652,7 +652,7 @@ async fn upload_file_to_version_inner(
|
||||
.await?;
|
||||
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
version.inner.project_id,
|
||||
&**client,
|
||||
)
|
||||
@@ -660,7 +660,7 @@ async fn upload_file_to_version_inner(
|
||||
|
||||
let organization_team_member = if let Some(organization) = &organization
|
||||
{
|
||||
models::TeamMember::get_from_user_id(
|
||||
models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&mut **transaction,
|
||||
@@ -782,7 +782,7 @@ async fn upload_file_to_version_inner(
|
||||
}
|
||||
|
||||
// Clear version cache
|
||||
models::Version::clear_cache(&version, &redis).await?;
|
||||
models::DBVersion::clear_cache(&version, &redis).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().body(""))
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ pub async fn get_version_from_hash(
|
||||
.algorithm
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&[hash.clone()]));
|
||||
let file = database::models::Version::get_file_from_hash(
|
||||
let file = database::models::DBVersion::get_file_from_hash(
|
||||
algorithm,
|
||||
hash,
|
||||
hash_query.version_id.map(|x| x.into()),
|
||||
@@ -66,7 +66,7 @@ pub async fn get_version_from_hash(
|
||||
.await?;
|
||||
if let Some(file) = file {
|
||||
let version =
|
||||
database::models::Version::get(file.version_id, &**pool, &redis)
|
||||
database::models::DBVersion::get(file.version_id, &**pool, &redis)
|
||||
.await?;
|
||||
if let Some(version) = version {
|
||||
if !is_visible_version(&version.inner, &user_option, &pool, &redis)
|
||||
@@ -139,7 +139,7 @@ pub async fn get_update_from_hash(
|
||||
.map(|x| x.1)
|
||||
.ok();
|
||||
let hash = info.into_inner().0.to_lowercase();
|
||||
if let Some(file) = database::models::Version::get_file_from_hash(
|
||||
if let Some(file) = database::models::DBVersion::get_file_from_hash(
|
||||
hash_query
|
||||
.algorithm
|
||||
.clone()
|
||||
@@ -151,11 +151,14 @@ pub async fn get_update_from_hash(
|
||||
)
|
||||
.await?
|
||||
{
|
||||
if let Some(project) =
|
||||
database::models::Project::get_id(file.project_id, &**pool, &redis)
|
||||
.await?
|
||||
if let Some(project) = database::models::DBProject::get_id(
|
||||
file.project_id,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
let mut versions = database::models::Version::get_many(
|
||||
let mut versions = database::models::DBVersion::get_many(
|
||||
&project.versions,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -241,7 +244,7 @@ pub async fn get_versions_from_hashes(
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&file_data.hashes));
|
||||
|
||||
let files = database::models::Version::get_files_from_hash(
|
||||
let files = database::models::DBVersion::get_files_from_hash(
|
||||
algorithm.clone(),
|
||||
&file_data.hashes,
|
||||
&**pool,
|
||||
@@ -251,7 +254,7 @@ pub async fn get_versions_from_hashes(
|
||||
|
||||
let version_ids = files.iter().map(|x| x.version_id).collect::<Vec<_>>();
|
||||
let versions_data = filter_visible_versions(
|
||||
database::models::Version::get_many(&version_ids, &**pool, &redis)
|
||||
database::models::DBVersion::get_many(&version_ids, &**pool, &redis)
|
||||
.await?,
|
||||
&user_option,
|
||||
&pool,
|
||||
@@ -294,7 +297,7 @@ pub async fn get_projects_from_hashes(
|
||||
.algorithm
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&file_data.hashes));
|
||||
let files = database::models::Version::get_files_from_hash(
|
||||
let files = database::models::DBVersion::get_files_from_hash(
|
||||
algorithm.clone(),
|
||||
&file_data.hashes,
|
||||
&**pool,
|
||||
@@ -305,8 +308,12 @@ pub async fn get_projects_from_hashes(
|
||||
let project_ids = files.iter().map(|x| x.project_id).collect::<Vec<_>>();
|
||||
|
||||
let projects_data = filter_visible_projects(
|
||||
database::models::Project::get_many_ids(&project_ids, &**pool, &redis)
|
||||
.await?,
|
||||
database::models::DBProject::get_many_ids(
|
||||
&project_ids,
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?,
|
||||
&user_option,
|
||||
&pool,
|
||||
false,
|
||||
@@ -343,7 +350,7 @@ pub async fn update_files(
|
||||
.algorithm
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&update_data.hashes));
|
||||
let files = database::models::Version::get_files_from_hash(
|
||||
let files = database::models::DBVersion::get_files_from_hash(
|
||||
algorithm.clone(),
|
||||
&update_data.hashes,
|
||||
&**pool,
|
||||
@@ -378,7 +385,7 @@ pub async fn update_files(
|
||||
})
|
||||
.await?;
|
||||
|
||||
let versions = database::models::Version::get_many(
|
||||
let versions = database::models::DBVersion::get_many(
|
||||
&update_version_ids
|
||||
.into_iter()
|
||||
.filter_map(|x| x.1.last().copied())
|
||||
@@ -447,7 +454,7 @@ pub async fn update_individual_files(
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
});
|
||||
let files = database::models::Version::get_files_from_hash(
|
||||
let files = database::models::DBVersion::get_files_from_hash(
|
||||
algorithm.clone(),
|
||||
&update_data
|
||||
.hashes
|
||||
@@ -459,13 +466,13 @@ pub async fn update_individual_files(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let projects = database::models::Project::get_many_ids(
|
||||
let projects = database::models::DBProject::get_many_ids(
|
||||
&files.iter().map(|x| x.project_id).collect::<Vec<_>>(),
|
||||
&**pool,
|
||||
&redis,
|
||||
)
|
||||
.await?;
|
||||
let all_versions = database::models::Version::get_many(
|
||||
let all_versions = database::models::DBVersion::get_many(
|
||||
&projects
|
||||
.iter()
|
||||
.flat_map(|x| x.versions.clone())
|
||||
@@ -574,7 +581,7 @@ pub async fn delete_file(
|
||||
.algorithm
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&[hash.clone()]));
|
||||
let file = database::models::Version::get_file_from_hash(
|
||||
let file = database::models::DBVersion::get_file_from_hash(
|
||||
algorithm.clone(),
|
||||
hash,
|
||||
hash_query.version_id.map(|x| x.into()),
|
||||
@@ -586,7 +593,7 @@ pub async fn delete_file(
|
||||
if let Some(row) = file {
|
||||
if !user.role.is_admin() {
|
||||
let team_member =
|
||||
database::models::TeamMember::get_from_user_id_version(
|
||||
database::models::DBTeamMember::get_from_user_id_version(
|
||||
row.version_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -595,26 +602,27 @@ pub async fn delete_file(
|
||||
.map_err(ApiError::Database)?;
|
||||
|
||||
let organization =
|
||||
database::models::Organization::get_associated_organization_project_id(
|
||||
database::models::DBOrganization::get_associated_organization_project_id(
|
||||
row.project_id,
|
||||
&**pool,
|
||||
)
|
||||
.await
|
||||
.map_err(ApiError::Database)?;
|
||||
|
||||
let organization_team_member =
|
||||
if let Some(organization) = &organization {
|
||||
database::models::TeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
user.id.into(),
|
||||
false,
|
||||
&**pool,
|
||||
)
|
||||
.await
|
||||
.map_err(ApiError::Database)?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let organization_team_member = if let Some(organization) =
|
||||
&organization
|
||||
{
|
||||
database::models::DBTeamMember::get_from_user_id_organization(
|
||||
organization.id,
|
||||
user.id.into(),
|
||||
false,
|
||||
&**pool,
|
||||
)
|
||||
.await
|
||||
.map_err(ApiError::Database)?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let permissions = ProjectPermissions::get_permissions_by_role(
|
||||
&user.role,
|
||||
@@ -632,7 +640,7 @@ pub async fn delete_file(
|
||||
}
|
||||
|
||||
let version =
|
||||
database::models::Version::get(row.version_id, &**pool, &redis)
|
||||
database::models::DBVersion::get(row.version_id, &**pool, &redis)
|
||||
.await?;
|
||||
if let Some(version) = version {
|
||||
if version.files.len() < 2 {
|
||||
@@ -642,7 +650,7 @@ pub async fn delete_file(
|
||||
));
|
||||
}
|
||||
|
||||
database::models::Version::clear_cache(&version, &redis).await?;
|
||||
database::models::DBVersion::clear_cache(&version, &redis).await?;
|
||||
}
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
@@ -705,7 +713,7 @@ pub async fn download_version(
|
||||
.algorithm
|
||||
.clone()
|
||||
.unwrap_or_else(|| default_algorithm_from_hashes(&[hash.clone()]));
|
||||
let file = database::models::Version::get_file_from_hash(
|
||||
let file = database::models::DBVersion::get_file_from_hash(
|
||||
algorithm.clone(),
|
||||
hash,
|
||||
hash_query.version_id.map(|x| x.into()),
|
||||
@@ -716,7 +724,7 @@ pub async fn download_version(
|
||||
|
||||
if let Some(file) = file {
|
||||
let version =
|
||||
database::models::Version::get(file.version_id, &**pool, &redis)
|
||||
database::models::DBVersion::get(file.version_id, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
if let Some(version) = version {
|
||||
|
||||
@@ -9,8 +9,10 @@ use crate::database;
|
||||
use crate::database::models::loader_fields::{
|
||||
self, LoaderField, LoaderFieldEnumValue, VersionField,
|
||||
};
|
||||
use crate::database::models::version_item::{DependencyBuilder, LoaderVersion};
|
||||
use crate::database::models::{Organization, image_item};
|
||||
use crate::database::models::version_item::{
|
||||
DBLoaderVersion, DependencyBuilder,
|
||||
};
|
||||
use crate::database::models::{DBOrganization, image_item};
|
||||
use crate::database::redis::RedisPool;
|
||||
use crate::models;
|
||||
use crate::models::ids::VersionId;
|
||||
@@ -70,7 +72,8 @@ pub async fn version_project_get_helper(
|
||||
redis: web::Data<RedisPool>,
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let result = database::models::Project::get(&id.0, &**pool, &redis).await?;
|
||||
let result =
|
||||
database::models::DBProject::get(&id.0, &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -90,7 +93,7 @@ pub async fn version_project_get_helper(
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
|
||||
let versions = database::models::Version::get_many(
|
||||
let versions = database::models::DBVersion::get_many(
|
||||
&project.versions,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -134,7 +137,7 @@ pub async fn versions_get(
|
||||
.map(|x| x.into())
|
||||
.collect::<Vec<database::models::DBVersionId>>();
|
||||
let versions_data =
|
||||
database::models::Version::get_many(&version_ids, &**pool, &redis)
|
||||
database::models::DBVersion::get_many(&version_ids, &**pool, &redis)
|
||||
.await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
@@ -174,7 +177,7 @@ pub async fn version_get_helper(
|
||||
session_queue: web::Data<AuthQueue>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_data =
|
||||
database::models::Version::get(id.into(), &**pool, &redis).await?;
|
||||
database::models::DBVersion::get(id.into(), &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -290,11 +293,11 @@ pub async fn version_edit_helper(
|
||||
let version_id = info.0.into();
|
||||
|
||||
let result =
|
||||
database::models::Version::get(version_id, &**pool, &redis).await?;
|
||||
database::models::DBVersion::get(version_id, &**pool, &redis).await?;
|
||||
|
||||
if let Some(version_item) = result {
|
||||
let team_member =
|
||||
database::models::TeamMember::get_from_user_id_project(
|
||||
database::models::DBTeamMember::get_from_user_id_project(
|
||||
version_item.inner.project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
@@ -303,7 +306,7 @@ pub async fn version_edit_helper(
|
||||
.await?;
|
||||
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
version_item.inner.project_id,
|
||||
&**pool,
|
||||
)
|
||||
@@ -311,7 +314,7 @@ pub async fn version_edit_helper(
|
||||
|
||||
let organization_team_member = if let Some(organization) = &organization
|
||||
{
|
||||
database::models::TeamMember::get_from_user_id(
|
||||
database::models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -513,15 +516,15 @@ pub async fn version_edit_helper(
|
||||
.to_string(),
|
||||
)
|
||||
})?;
|
||||
loader_versions.push(LoaderVersion {
|
||||
loader_versions.push(DBLoaderVersion {
|
||||
loader_id,
|
||||
version_id,
|
||||
});
|
||||
}
|
||||
LoaderVersion::insert_many(loader_versions, &mut transaction)
|
||||
DBLoaderVersion::insert_many(loader_versions, &mut transaction)
|
||||
.await?;
|
||||
|
||||
crate::database::models::Project::clear_cache(
|
||||
crate::database::models::DBProject::clear_cache(
|
||||
version_item.inner.project_id,
|
||||
None,
|
||||
None,
|
||||
@@ -679,9 +682,9 @@ pub async fn version_edit_helper(
|
||||
.await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
database::models::Version::clear_cache(&version_item, &redis)
|
||||
database::models::DBVersion::clear_cache(&version_item, &redis)
|
||||
.await?;
|
||||
database::models::Project::clear_cache(
|
||||
database::models::DBProject::clear_cache(
|
||||
version_item.inner.project_id,
|
||||
None,
|
||||
Some(true),
|
||||
@@ -726,7 +729,7 @@ pub async fn version_list(
|
||||
let string = info.into_inner().0;
|
||||
|
||||
let result =
|
||||
database::models::Project::get(&string, &**pool, &redis).await?;
|
||||
database::models::DBProject::get(&string, &**pool, &redis).await?;
|
||||
|
||||
let user_option = get_user_from_headers(
|
||||
&req,
|
||||
@@ -753,7 +756,7 @@ pub async fn version_list(
|
||||
let loader_filters = filters.loaders.as_ref().map(|x| {
|
||||
serde_json::from_str::<Vec<String>>(x).unwrap_or_default()
|
||||
});
|
||||
let mut versions = database::models::Version::get_many(
|
||||
let mut versions = database::models::DBVersion::get_many(
|
||||
&project.versions,
|
||||
&**pool,
|
||||
&redis,
|
||||
@@ -886,7 +889,7 @@ pub async fn version_delete(
|
||||
.1;
|
||||
let id = info.into_inner().0;
|
||||
|
||||
let version = database::models::Version::get(id.into(), &**pool, &redis)
|
||||
let version = database::models::DBVersion::get(id.into(), &**pool, &redis)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(
|
||||
@@ -896,7 +899,7 @@ pub async fn version_delete(
|
||||
|
||||
if !user.role.is_admin() {
|
||||
let team_member =
|
||||
database::models::TeamMember::get_from_user_id_project(
|
||||
database::models::DBTeamMember::get_from_user_id_project(
|
||||
version.inner.project_id,
|
||||
user.id.into(),
|
||||
false,
|
||||
@@ -906,7 +909,7 @@ pub async fn version_delete(
|
||||
.map_err(ApiError::Database)?;
|
||||
|
||||
let organization =
|
||||
Organization::get_associated_organization_project_id(
|
||||
DBOrganization::get_associated_organization_project_id(
|
||||
version.inner.project_id,
|
||||
&**pool,
|
||||
)
|
||||
@@ -914,7 +917,7 @@ pub async fn version_delete(
|
||||
|
||||
let organization_team_member = if let Some(organization) = &organization
|
||||
{
|
||||
database::models::TeamMember::get_from_user_id(
|
||||
database::models::DBTeamMember::get_from_user_id(
|
||||
organization.team_id,
|
||||
user.id.into(),
|
||||
&**pool,
|
||||
@@ -942,14 +945,16 @@ pub async fn version_delete(
|
||||
let context = ImageContext::Version {
|
||||
version_id: Some(version.inner.id.into()),
|
||||
};
|
||||
let uploaded_images =
|
||||
database::models::Image::get_many_contexted(context, &mut transaction)
|
||||
.await?;
|
||||
let uploaded_images = database::models::DBImage::get_many_contexted(
|
||||
context,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
for image in uploaded_images {
|
||||
image_item::Image::remove(image.id, &mut transaction, &redis).await?;
|
||||
image_item::DBImage::remove(image.id, &mut transaction, &redis).await?;
|
||||
}
|
||||
|
||||
let result = database::models::Version::remove_full(
|
||||
let result = database::models::DBVersion::remove_full(
|
||||
version.inner.id,
|
||||
&redis,
|
||||
&mut transaction,
|
||||
@@ -957,7 +962,7 @@ pub async fn version_delete(
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
remove_documents(&[version.inner.id.into()], &search_config).await?;
|
||||
database::models::Project::clear_cache(
|
||||
database::models::DBProject::clear_cache(
|
||||
version.inner.project_id,
|
||||
None,
|
||||
Some(true),
|
||||
|
||||
Reference in New Issue
Block a user