Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
e8f931392e | |||
36709b6b80 | |||
cd79f47caa | |||
48143979e5 | |||
717e3fda49 | |||
22fa59334c | |||
5c0c03fd7a | |||
c8ed40c3cc | |||
8373b278cc |
6 changed files with 76 additions and 53 deletions
|
@ -7,12 +7,25 @@ on:
|
||||||
- '[0-9]+.[0-9]+.[0-9]+'
|
- '[0-9]+.[0-9]+.[0-9]+'
|
||||||
- '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
|
- '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
test:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
steps:
|
steps:
|
||||||
|
-
|
||||||
|
name: Checking Out Repository Code
|
||||||
|
uses: https://code.forgejo.org/actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Placeholder
|
name: Placeholder
|
||||||
run: echo Placeholder Job
|
run: echo Placeholder Job
|
||||||
|
-
|
||||||
|
name: Check if Version in Cargo.toml matches Tag
|
||||||
|
run: |
|
||||||
|
VERSION=$(cat Cargo.toml | grep -E "(^|\|)version =" | cut -f2- -d= | tr -d \" | tr -d " ")
|
||||||
|
if test $VERSION != "${{ github.ref_name }}"; then
|
||||||
|
echo "Expected Version is: '${{ github.ref_name }}' actual Version is: '$VERSION'";
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Version is: '$VERSION'";
|
||||||
|
fi
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: test
|
needs: test
|
||||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -397,7 +397,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chellaris-rust-api"
|
name = "chellaris-rust-api"
|
||||||
version = "1.0.3"
|
version = "1.2.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chellaris-rust-api"
|
name = "chellaris-rust-api"
|
||||||
version = "1.0.3"
|
version = "1.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -221,9 +221,9 @@ async fn main() {
|
||||||
struct ApiDocV1;
|
struct ApiDocV1;
|
||||||
|
|
||||||
let openapi_urls = vec![
|
let openapi_urls = vec![
|
||||||
Url::new("v1", concat!(api_base_1!(), "/openapi.json")),
|
Url::new("v1", concat!(api_base!(), "-docs/openapi1.json")),
|
||||||
Url::new("v2-L", concat!(api_base_2!(), "/openapi.json")),
|
Url::new("v2-L", concat!(api_base!(), "-docs/openapi2l.json")),
|
||||||
Url::new("v3-L", concat!(api_base_3!(), "/openapi.json")),
|
Url::new("v3-L", concat!(api_base!(), "-docs/openapi3l.json")),
|
||||||
];
|
];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -299,15 +299,15 @@ async fn main() {
|
||||||
SwaggerUi::new(concat!(api_base!(), "/swagger/{_:.*}"))
|
SwaggerUi::new(concat!(api_base!(), "/swagger/{_:.*}"))
|
||||||
.urls(vec![
|
.urls(vec![
|
||||||
(
|
(
|
||||||
Url::new("v1", concat!(api_base_1!(), "/openapi.json")),
|
Url::new("v1", concat!(api_base!(), "-docs/openapi1.json")),
|
||||||
openapi_v1.clone(),
|
openapi_v1.clone(),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Url::new("v2-l", concat!(api_base_2!(), "/openapi.json")),
|
Url::new("v2-l", concat!(api_base!(), "-docs/openapi2l.json")),
|
||||||
openapi_v2_l.clone(),
|
openapi_v2_l.clone(),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Url::new("v3-l", concat!(api_base_3!(), "/openapi.json")),
|
Url::new("v3-l", concat!(api_base!(), "-docs/openapi3l.json")),
|
||||||
openapi_v3_l.clone(),
|
openapi_v3_l.clone(),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
|
|
|
@ -48,7 +48,7 @@ async fn verify_user_auth(data: &web::Data<AppState>, auth_token: &str, user_tok
|
||||||
|
|
||||||
// User Endpoints
|
// User Endpoints
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
request_body = schemas::GetUserParams,
|
request_body = GetUserParams,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "OK", body = User),
|
(status = 200, description = "OK", body = User),
|
||||||
(status = 403, description = "Unauthorized"),
|
(status = 403, description = "Unauthorized"),
|
||||||
|
@ -58,8 +58,8 @@ async fn verify_user_auth(data: &web::Data<AppState>, auth_token: &str, user_tok
|
||||||
("api_key" = [])
|
("api_key" = [])
|
||||||
),
|
),
|
||||||
)]
|
)]
|
||||||
#[get("/api/v1/user")]
|
#[post("/api/v1/user")]
|
||||||
async fn get_user(
|
pub(crate) async fn get_user(
|
||||||
data: web::Data<AppState>,
|
data: web::Data<AppState>,
|
||||||
params: web::Json<schemas::GetUserParams>,
|
params: web::Json<schemas::GetUserParams>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
|
@ -116,7 +116,7 @@ async fn get_user(
|
||||||
(status = 500, description = "Internal Server Error")
|
(status = 500, description = "Internal Server Error")
|
||||||
),
|
),
|
||||||
)]
|
)]
|
||||||
#[post("/api/v1/user")]
|
#[post("/api/v1/user/create")]
|
||||||
pub(crate) async fn create_user(
|
pub(crate) async fn create_user(
|
||||||
data: web::Data<AppState>,
|
data: web::Data<AppState>,
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
|
@ -195,9 +195,17 @@ pub(crate) async fn update_user(
|
||||||
None => return HttpResponse::Unauthorized().finish(),
|
None => return HttpResponse::Unauthorized().finish(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut user_permissions: HashMap<String, bool> = HashMap::new();
|
||||||
|
match params.permissions {
|
||||||
|
Some(data) => {user_permissions = data.clone()},
|
||||||
|
None => {},
|
||||||
|
}
|
||||||
|
|
||||||
let mut elevated_auth = false;
|
let mut elevated_auth = false;
|
||||||
if params.permissions["game_permissions"] || params.permissions["empire_permissions"] || params.permissions["data_permissions"] || params.permissions["user_permissions"] {
|
if user_permissions.len() != 0 {
|
||||||
elevated_auth = true;
|
if user_permissions["game_permissions"] || user_permissions["empire_permissions"] || user_permissions["data_permissions"] || user_permissions["user_permissions"] {
|
||||||
|
elevated_auth = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let auth = verify_user_auth(&data, &auth_token, ¶ms.user_token, schemas::TablePermission::User, elevated_auth).await;
|
let auth = verify_user_auth(&data, &auth_token, ¶ms.user_token, schemas::TablePermission::User, elevated_auth).await;
|
||||||
|
@ -225,41 +233,43 @@ pub(crate) async fn update_user(
|
||||||
any_param_present = true;
|
any_param_present = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (entry, value) in params.permissions.iter() {
|
if user_permissions.len() != 0 {
|
||||||
match entry.deref() {
|
for (entry, value) in user_permissions.iter() {
|
||||||
"game_permissions" => {
|
match entry.deref() {
|
||||||
user_query_separated.push( " game_permissions = ");
|
"game_permissions" => {
|
||||||
match any_param_present {
|
user_query_separated.push( " game_permissions = ");
|
||||||
true => user_query_separated.push_bind(value),
|
match any_param_present {
|
||||||
false => user_query_separated.push_bind_unseparated(value)
|
true => user_query_separated.push_bind(value),
|
||||||
};
|
false => user_query_separated.push_bind_unseparated(value)
|
||||||
any_param_present = true;
|
};
|
||||||
},
|
any_param_present = true;
|
||||||
"empire_permissions" => {
|
},
|
||||||
user_query_separated.push( " empire_permissions = ");
|
"empire_permissions" => {
|
||||||
match any_param_present {
|
user_query_separated.push( " empire_permissions = ");
|
||||||
true => user_query_separated.push_bind(value),
|
match any_param_present {
|
||||||
false => user_query_separated.push_bind_unseparated(value)
|
true => user_query_separated.push_bind(value),
|
||||||
};
|
false => user_query_separated.push_bind_unseparated(value)
|
||||||
any_param_present = true;
|
};
|
||||||
},
|
any_param_present = true;
|
||||||
"data_permissions" => {
|
},
|
||||||
user_query_separated.push( " data_permissions = ");
|
"data_permissions" => {
|
||||||
match any_param_present {
|
user_query_separated.push( " data_permissions = ");
|
||||||
true => user_query_separated.push_bind(value),
|
match any_param_present {
|
||||||
false => user_query_separated.push_bind_unseparated(value)
|
true => user_query_separated.push_bind(value),
|
||||||
};
|
false => user_query_separated.push_bind_unseparated(value)
|
||||||
any_param_present = true;
|
};
|
||||||
},
|
any_param_present = true;
|
||||||
"user_permissions" => {
|
},
|
||||||
user_query_separated.push( " user_permissions = ");
|
"user_permissions" => {
|
||||||
match any_param_present {
|
user_query_separated.push( " user_permissions = ");
|
||||||
true => user_query_separated.push_bind(value),
|
match any_param_present {
|
||||||
false => user_query_separated.push_bind_unseparated(value)
|
true => user_query_separated.push_bind(value),
|
||||||
};
|
false => user_query_separated.push_bind_unseparated(value)
|
||||||
any_param_present = true;
|
};
|
||||||
},
|
any_param_present = true;
|
||||||
_ => {}
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +318,7 @@ pub(crate) async fn update_user(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
request_body = schemas::DeleteUserParams,
|
request_body = DeleteUserParams,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "OK"),
|
(status = 200, description = "OK"),
|
||||||
(status = 403, description = "Unauthorized"),
|
(status = 403, description = "Unauthorized"),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use utoipa::{ToSchema};
|
use utoipa::{IntoParams, ToSchema};
|
||||||
|
|
||||||
// DB Permission Enums
|
// DB Permission Enums
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ pub struct UpdateUserParams {
|
||||||
[\"user_permissions\"]: false,
|
[\"user_permissions\"]: false,
|
||||||
}\
|
}\
|
||||||
")]
|
")]
|
||||||
pub permissions: HashMap<String, bool>,
|
pub permissions: Option<HashMap<String, bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, ToSchema, Debug)]
|
#[derive(Serialize, Deserialize, ToSchema, Debug)]
|
||||||
|
|
Reference in a new issue