From 263fdbafdc14a4c111a94c1e6c6e470128c2bf13 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Fri, 9 Feb 2024 15:07:39 +0800 Subject: [PATCH] Disable casbin (#313) * chore: disable casin test * chore: disable casin test --- src/biz/casbin/access_control.rs | 125 ++++++++++++++++--------------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/src/biz/casbin/access_control.rs b/src/biz/casbin/access_control.rs index 279e9f6a..4f391bb8 100644 --- a/src/biz/casbin/access_control.rs +++ b/src/biz/casbin/access_control.rs @@ -2,9 +2,9 @@ use std::ops::Deref; use std::{str::FromStr, sync::Arc}; use actix_web::http::Method; -use anyhow::anyhow; + use async_trait::async_trait; -use casbin::{CoreApi, MgmtApi}; +use casbin::MgmtApi; use sqlx::{Executor, PgPool, Postgres}; use tokio::sync::{broadcast, RwLock}; use tracing::log::warn; @@ -27,7 +27,7 @@ use crate::biz::casbin::enforcer_ext::{enforcer_remove, enforcer_update}; use realtime::collaborate::CollabAccessControl; use super::{ - Action, ActionType, ObjectType, POLICY_FIELD_INDEX_ACTION, POLICY_FIELD_INDEX_OBJECT, + ActionType, ObjectType, POLICY_FIELD_INDEX_ACTION, POLICY_FIELD_INDEX_OBJECT, POLICY_FIELD_INDEX_USER, }; @@ -273,69 +273,72 @@ impl CollabAccessControl for CasbinCollabAccessControl { async fn can_access_http_method( &self, - uid: &i64, - oid: &str, - method: &Method, + _uid: &i64, + _oid: &str, + _method: &Method, ) -> Result { - let action = if Method::POST == method || Method::PUT == method || Method::DELETE == method { - Action::Write - } else { - Action::Read - }; - - // If collab does not exist, allow access. - // Workspace access control will still check it. - let collab_exists = self - .casbin_access_control - .enforcer - .read() - .await - .get_all_objects() - .contains(&ObjectType::Collab(oid).to_string()); - - if !collab_exists { - return Ok(true); - } - - self - .casbin_access_control - .enforcer - .read() - .await - .enforce(( - uid.to_string(), - ObjectType::Collab(oid).to_string(), - action.to_string(), - )) - .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) + Ok(true) + // let action = if Method::POST == method || Method::PUT == method || Method::DELETE == method { + // Action::Write + // } else { + // Action::Read + // }; + // + // // If collab does not exist, allow access. + // // Workspace access control will still check it. + // let collab_exists = self + // .casbin_access_control + // .enforcer + // .read() + // .await + // .get_all_objects() + // .contains(&ObjectType::Collab(oid).to_string()); + // + // if !collab_exists { + // return Ok(true); + // } + // + // self + // .casbin_access_control + // .enforcer + // .read() + // .await + // .enforce(( + // uid.to_string(), + // ObjectType::Collab(oid).to_string(), + // action.to_string(), + // )) + // .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) } - async fn can_send_collab_update(&self, uid: &i64, oid: &str) -> Result { - self - .casbin_access_control - .enforcer - .read() - .await - .enforce(( - uid.to_string(), - ObjectType::Collab(oid).to_string(), - Action::Write.to_string(), - )) - .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) + async fn can_send_collab_update(&self, _uid: &i64, _oid: &str) -> Result { + Ok(true) + // self + // .casbin_access_control + // .enforcer + // .read() + // .await + // .enforce(( + // uid.to_string(), + // ObjectType::Collab(oid).to_string(), + // Action::Write.to_string(), + // )) + // .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) } - async fn can_receive_collab_update(&self, uid: &i64, oid: &str) -> Result { - self - .casbin_access_control - .enforcer - .read() - .await - .enforce(( - uid.to_string(), - ObjectType::Collab(oid).to_string(), - Action::Read.to_string(), - )) - .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) + async fn can_receive_collab_update(&self, _uid: &i64, _oid: &str) -> Result { + Ok(true) + // self + // .casbin_access_control + // .enforcer + // .read() + // .await + // .enforce(( + // uid.to_string(), + // ObjectType::Collab(oid).to_string(), + // Action::Read.to_string(), + // )) + // .map_err(|e| AppError::Internal(anyhow!("casbin error enforce: {e:?}"))) } }