Fix error messages, auth routes, and remove category unique constraint (#293)
* Fix error messages, auth routes, and remove category unique constraint * Run prepare * Remove debug secrets * Fix team member editing
This commit is contained in:
parent
eb4375258e
commit
e576a58ead
1
migrations/20220210032959_remove-categories-unique.sql
Normal file
1
migrations/20220210032959_remove-categories-unique.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE categories DROP CONSTRAINT IF EXISTS categories_category_key;
|
||||||
@ -2230,28 +2230,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"7795938e2b23d06b32dc6d79f6b2b8e7ed24bbf4fa61cb3000259ba3d2ecbc6f": {
|
|
||||||
"query": "\n INSERT INTO categories (category, project_type, icon)\n VALUES ($1, $2, $3)\n ON CONFLICT (category) DO NOTHING\n RETURNING id\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "id",
|
|
||||||
"type_info": "Int4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Varchar",
|
|
||||||
"Int4",
|
|
||||||
"Varchar"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"78a60cf0febcc6e35b8ffe38f2c021c13ab660c81c4775bbb26004d30242a1a8": {
|
"78a60cf0febcc6e35b8ffe38f2c021c13ab660c81c4775bbb26004d30242a1a8": {
|
||||||
"query": "\n SELECT gv.id id, gv.version version_, gv.type type_, gv.created created, gv.major major FROM game_versions gv\n WHERE major = $1\n ORDER BY created DESC\n ",
|
"query": "\n SELECT gv.id id, gv.version version_, gv.type type_, gv.created created, gv.major major FROM game_versions gv\n WHERE major = $1\n ORDER BY created DESC\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
@ -2798,6 +2776,28 @@
|
|||||||
"nullable": []
|
"nullable": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"8bb8be81029b47af0c2a200647abcabb79cb88a41e53467ad3b52d714c83fdf9": {
|
||||||
|
"query": "\n INSERT INTO categories (category, project_type, icon)\n VALUES ($1, $2, $3)\n RETURNING id\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int4"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Varchar",
|
||||||
|
"Int4",
|
||||||
|
"Varchar"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"8f706d78ac4235ea04c59e2c220a4791e1d08fdf287b783b4aaef36fd2445467": {
|
"8f706d78ac4235ea04c59e2c220a4791e1d08fdf287b783b4aaef36fd2445467": {
|
||||||
"query": "\n DELETE FROM loaders\n WHERE loader = $1\n ",
|
"query": "\n DELETE FROM loaders\n WHERE loader = $1\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
|
|||||||
@ -226,7 +226,6 @@ impl<'a> CategoryBuilder<'a> {
|
|||||||
"
|
"
|
||||||
INSERT INTO categories (category, project_type, icon)
|
INSERT INTO categories (category, project_type, icon)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
ON CONFLICT (category) DO NOTHING
|
|
||||||
RETURNING id
|
RETURNING id
|
||||||
",
|
",
|
||||||
self.name,
|
self.name,
|
||||||
|
|||||||
@ -282,7 +282,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.configure(routes::v2_config)
|
.configure(routes::v2_config)
|
||||||
.service(routes::index_get)
|
.service(routes::index_get)
|
||||||
.service(routes::health_get)
|
.service(routes::health_get)
|
||||||
.service(web::scope("/maven/").configure(routes::maven_config))
|
.service(web::scope("maven").configure(routes::maven_config))
|
||||||
.default_service(web::get().to(routes::not_found))
|
.default_service(web::get().to(routes::not_found))
|
||||||
})
|
})
|
||||||
.bind(dotenv::var("BIND_ADDR").unwrap())?
|
.bind(dotenv::var("BIND_ADDR").unwrap())?
|
||||||
|
|||||||
@ -8,13 +8,12 @@ use actix_web::http::StatusCode;
|
|||||||
use actix_web::web::{scope, Data, Query, ServiceConfig};
|
use actix_web::web::{scope, Data, Query, ServiceConfig};
|
||||||
use actix_web::{get, HttpResponse};
|
use actix_web::{get, HttpResponse};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::info;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub fn config(cfg: &mut ServiceConfig) {
|
pub fn config(cfg: &mut ServiceConfig) {
|
||||||
cfg.service(scope("/auth/").service(auth_callback).service(init));
|
cfg.service(scope("auth").service(auth_callback).service(init));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@ -177,7 +176,7 @@ pub async fn auth_callback(
|
|||||||
|
|
||||||
let user_result = User::get_from_github_id(user.id, &mut *transaction).await?;
|
let user_result = User::get_from_github_id(user.id, &mut *transaction).await?;
|
||||||
match user_result {
|
match user_result {
|
||||||
Some(x) => info!("{:?}", x.id),
|
Some(_) => {}
|
||||||
None => {
|
None => {
|
||||||
let user_id = crate::database::models::generate_user_id(&mut transaction).await?;
|
let user_id = crate::database::models::generate_user_id(&mut transaction).await?;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use actix_web::{get, HttpResponse};
|
use actix_web::{get, HttpResponse};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("")]
|
||||||
pub async fn index_get() -> HttpResponse {
|
pub async fn index_get() -> HttpResponse {
|
||||||
let data = json!({
|
let data = json!({
|
||||||
"name": "modrinth-labrinth",
|
"name": "modrinth-labrinth",
|
||||||
|
|||||||
@ -280,10 +280,17 @@ pub async fn edit_team_member(
|
|||||||
"You don't have permission to edit members of this team".to_string(),
|
"You don't have permission to edit members of this team".to_string(),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
let edit_member_db = TeamMember::get_from_user_id(id, user_id, &**pool)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
ApiError::CustomAuthenticationError(
|
||||||
|
"You don't have permission to edit members of this team".to_string(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut transaction = pool.begin().await?;
|
let mut transaction = pool.begin().await?;
|
||||||
|
|
||||||
if &*member.role == crate::models::teams::OWNER_ROLE {
|
if &*edit_member_db.role == crate::models::teams::OWNER_ROLE {
|
||||||
return Err(ApiError::InvalidInputError(
|
return Err(ApiError::InvalidInputError(
|
||||||
"The owner of a team cannot be edited".to_string(),
|
"The owner of a team cannot be edited".to_string(),
|
||||||
));
|
));
|
||||||
|
|||||||
@ -21,10 +21,10 @@ pub fn validation_errors_to_string(errors: ValidationErrors, adder: Option<Strin
|
|||||||
validation_errors_to_string(*errors.clone(), Some(format!("of item {}", field)))
|
validation_errors_to_string(*errors.clone(), Some(format!("of item {}", field)))
|
||||||
}
|
}
|
||||||
ValidationErrorsKind::List(list) => {
|
ValidationErrorsKind::List(list) => {
|
||||||
if let Some(errors) = list.get(&0) {
|
if let Some((index, errors)) = list.iter().next() {
|
||||||
output.push_str(&*validation_errors_to_string(
|
output.push_str(&*validation_errors_to_string(
|
||||||
*errors.clone(),
|
*errors.clone(),
|
||||||
Some(format!("of list {} with index 0", field)),
|
Some(format!("of list {} with index {}", index, field)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user