Compare commits

..

No commits in common. "main" and "1.2.3" have entirely different histories.
main ... 1.2.3

6 changed files with 53 additions and 76 deletions

View file

@ -7,25 +7,12 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
jobs:
test:
run-tests:
runs-on: docker
steps:
-
name: Checking Out Repository Code
uses: https://code.forgejo.org/actions/checkout@v3
-
name: Placeholder
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:
needs: test

2
Cargo.lock generated
View file

@ -397,7 +397,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chellaris-rust-api"
version = "1.2.4"
version = "1.0.3"
dependencies = [
"actix-web",
"chrono",

View file

@ -1,6 +1,6 @@
[package]
name = "chellaris-rust-api"
version = "1.2.4"
version = "1.0.3"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -221,9 +221,9 @@ async fn main() {
struct ApiDocV1;
let openapi_urls = vec![
Url::new("v1", concat!(api_base!(), "-docs/openapi1.json")),
Url::new("v2-L", concat!(api_base!(), "-docs/openapi2l.json")),
Url::new("v3-L", concat!(api_base!(), "-docs/openapi3l.json")),
Url::new("v1", concat!(api_base_1!(), "/openapi.json")),
Url::new("v2-L", concat!(api_base_2!(), "/openapi.json")),
Url::new("v3-L", concat!(api_base_3!(), "/openapi.json")),
];
loop {
@ -299,15 +299,15 @@ async fn main() {
SwaggerUi::new(concat!(api_base!(), "/swagger/{_:.*}"))
.urls(vec![
(
Url::new("v1", concat!(api_base!(), "-docs/openapi1.json")),
Url::new("v1", concat!(api_base_1!(), "/openapi.json")),
openapi_v1.clone(),
),
(
Url::new("v2-l", concat!(api_base!(), "-docs/openapi2l.json")),
Url::new("v2-l", concat!(api_base_2!(), "/openapi.json")),
openapi_v2_l.clone(),
),
(
Url::new("v3-l", concat!(api_base!(), "-docs/openapi3l.json")),
Url::new("v3-l", concat!(api_base_3!(), "/openapi.json")),
openapi_v3_l.clone(),
),
])

View file

@ -48,7 +48,7 @@ async fn verify_user_auth(data: &web::Data<AppState>, auth_token: &str, user_tok
// User Endpoints
#[utoipa::path(
request_body = GetUserParams,
request_body = schemas::GetUserParams,
responses(
(status = 200, description = "OK", body = User),
(status = 403, description = "Unauthorized"),
@ -58,8 +58,8 @@ async fn verify_user_auth(data: &web::Data<AppState>, auth_token: &str, user_tok
("api_key" = [])
),
)]
#[post("/api/v1/user")]
pub(crate) async fn get_user(
#[get("/api/v1/user")]
async fn get_user(
data: web::Data<AppState>,
params: web::Json<schemas::GetUserParams>,
req: HttpRequest,
@ -116,7 +116,7 @@ pub(crate) async fn get_user(
(status = 500, description = "Internal Server Error")
),
)]
#[post("/api/v1/user/create")]
#[post("/api/v1/user")]
pub(crate) async fn create_user(
data: web::Data<AppState>,
) -> impl Responder {
@ -195,18 +195,10 @@ pub(crate) async fn update_user(
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;
if user_permissions.len() != 0 {
if user_permissions["game_permissions"] || user_permissions["empire_permissions"] || user_permissions["data_permissions"] || user_permissions["user_permissions"] {
if params.permissions["game_permissions"] || params.permissions["empire_permissions"] || params.permissions["data_permissions"] || params.permissions["user_permissions"] {
elevated_auth = true;
}
}
let auth = verify_user_auth(&data, &auth_token, &params.user_token, schemas::TablePermission::User, elevated_auth).await;
@ -233,8 +225,7 @@ pub(crate) async fn update_user(
any_param_present = true;
}
if user_permissions.len() != 0 {
for (entry, value) in user_permissions.iter() {
for (entry, value) in params.permissions.iter() {
match entry.deref() {
"game_permissions" => {
user_query_separated.push( " game_permissions = ");
@ -271,7 +262,6 @@ pub(crate) async fn update_user(
_ => {}
}
}
}
if any_param_present {
user_query_separated.push_unseparated(" WHERE token = ").push_bind_unseparated(params.user_token);
@ -318,7 +308,7 @@ pub(crate) async fn update_user(
}
#[utoipa::path(
request_body = DeleteUserParams,
request_body = schemas::DeleteUserParams,
responses(
(status = 200, description = "OK"),
(status = 403, description = "Unauthorized"),

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
use utoipa::{ToSchema};
// DB Permission Enums
@ -54,7 +54,7 @@ pub struct UpdateUserParams {
[\"user_permissions\"]: false,
}\
")]
pub permissions: Option<HashMap<String, bool>>,
pub permissions: HashMap<String, bool>,
}
#[derive(Serialize, Deserialize, ToSchema, Debug)]