works on adding from list

This commit is contained in:
2019-11-14 16:26:03 +01:00
parent 61a03f1781
commit cb8dfa9a2a
2 changed files with 44 additions and 11 deletions

View File

@@ -1,13 +1,16 @@
use actix_cors::Cors;
use actix_files as fs;
use actix_identity::{CookieIdentityPolicy, Identity, IdentityService, RequestIdentity};
use actix_service::{Service, Transform};
use actix_web::{
dev::{ServiceRequest, ServiceResponse},
http::{header, StatusCode},
middleware, web, App, Error, HttpResponse, HttpServer,
};
use actix_service::{Service, Transform};
use futures::{Future, future::{ok, Either, FutureResult}};
use futures::{
future::{ok, Either, FutureResult},
Future,
};
use std::env;
use crate::api;
@@ -46,7 +49,6 @@ fn restricted_to_group(id: i32, params: (AppPool, api::ApiActions)) -> MaybeForb
}
}
struct RestrictedAccess;
impl<S, B> Transform<S> for RestrictedAccess
@@ -67,7 +69,7 @@ where
}
struct RestrictedAccessMiddleware<S> {
service: S
service: S,
}
impl<S, B> Service for RestrictedAccessMiddleware<S>
@@ -90,9 +92,9 @@ where
if is_logged_in {
Either::A(self.service.call(req))
} else {
Either::B(ok(req.into_response(
HttpResponse::Forbidden().finish().into_body()
)))
Either::B(ok(
req.into_response(HttpResponse::Forbidden().finish().into_body())
))
}
}
}
@@ -186,9 +188,16 @@ fn configure_api(config: &mut web::ServiceConfig) {
"/claims",
web::get().to_async(|pool| db_call(pool, Q::FetchClaims)),
)
.route(
"/items",
web::get().to_async(move |pool: AppPool| db_call(pool, Q::FetchInventory)),
.service(
web::resource("/items")
.route(
web::get().to_async(move |pool: AppPool| db_call(pool, Q::FetchInventory)),
)
.route(web::post().to_async(
move |pool: AppPool, items: web::Json<Vec<String>>| {
db_call(pool, Q::CheckItemList(items.into_inner()))
},
)),
),
);
}