implement access rights for view models
This commit is contained in:
parent
5e5b3571f9
commit
c0291efa28
@ -20,7 +20,6 @@ futures = "0.3.21"
|
||||
serde = "1.0.136"
|
||||
serde_json = "1.0.79"
|
||||
serde_derive = "1.0.136"
|
||||
quote = "1.0"
|
||||
sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
|
||||
syn = "1.0.91"
|
||||
|
||||
|
@ -96,7 +96,7 @@ pub async fn login<T: AppDataTrait>(data: web::Data<T>) -> HttpResponse {
|
||||
pub async fn logout(session: Session) -> HttpResponse {
|
||||
session.remove("user_info");
|
||||
HttpResponse::Found()
|
||||
.append_header((header::LOCATION, "/".to_string()))
|
||||
.append_header((header::LOCATION, "/admin/".to_string()))
|
||||
.finish()
|
||||
}
|
||||
|
||||
@ -155,5 +155,5 @@ pub async fn auth<T: AppDataTrait>(
|
||||
|
||||
session.insert("user_info", &user_info).unwrap();
|
||||
|
||||
HttpResponse::Found().append_header(("location", "/")).finish()
|
||||
HttpResponse::Found().append_header(("location", "/admin/")).finish()
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use actix_admin::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdminModel)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel, DeriveActixAdminViewModelAccess)]
|
||||
#[sea_orm(table_name = "comment")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
|
@ -5,7 +5,7 @@ use std::fmt;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdminModel)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdmin, DeriveActixAdminViewModel, DeriveActixAdminModel, DeriveActixAdminViewModelAccess)]
|
||||
#[sea_orm(table_name = "post")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
|
@ -14,7 +14,7 @@ use tera::{Context, Tera};
|
||||
mod entity;
|
||||
use entity::{Post, Comment};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub oauth: BasicClient,
|
||||
pub tmpl: Tera,
|
||||
@ -57,7 +57,10 @@ fn create_actix_admin_builder() -> ActixAdminBuilder {
|
||||
|
||||
let configuration = ActixAdminConfiguration {
|
||||
enable_auth: true,
|
||||
user_is_logged_in: Some(|session: Session| -> bool { session.get::<UserInfo>("user_info").unwrap().is_some() }),
|
||||
user_is_logged_in: Some(|session: &Session| -> bool {
|
||||
let user_info = session.get::<UserInfo>("user_info").unwrap();
|
||||
user_info.is_some()
|
||||
}),
|
||||
login_link: "/azure-auth/login".to_string(),
|
||||
logout_link: "/azure-auth/logout".to_string()
|
||||
};
|
||||
@ -112,10 +115,11 @@ async fn main() {
|
||||
actix_admin: actix_admin,
|
||||
};
|
||||
|
||||
let cookie_secret_key = Key::generate();
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(app_state.clone()))
|
||||
.wrap(SessionMiddleware::new(CookieSessionStore::default(), Key::generate()))
|
||||
.wrap(SessionMiddleware::new(CookieSessionStore::default(), cookie_secret_key.clone()))
|
||||
.route("/", web::get().to(index))
|
||||
.service(azure_auth.clone().create_scope::<AppState>())
|
||||
.service(
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
{% block content %}
|
||||
<ul>
|
||||
<li><a href="/{{ web_auth_link }}">Auth-Example</a></li>
|
||||
<li><a href="/admin/">Actix-Admin</a></li>
|
||||
</ul>
|
||||
{% endblock content %}
|
||||
|
Loading…
Reference in New Issue
Block a user