mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
add ingore_auth feature on backend
This commit is contained in:
parent
155a526d04
commit
ef4ee320f7
@ -92,6 +92,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
flowy_test = []
|
flowy_test = []
|
||||||
|
ignore_auth = []
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
parking_lot = "0.11"
|
parking_lot = "0.11"
|
||||||
|
@ -49,9 +49,7 @@ where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.service.poll_ready(cx) }
|
||||||
self.service.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||||
let mut authenticate_pass: bool = false;
|
let mut authenticate_pass: bool = false;
|
||||||
@ -68,9 +66,15 @@ where
|
|||||||
let result: Result<LoggedUser, ServerError> = header.try_into();
|
let result: Result<LoggedUser, ServerError> = header.try_into();
|
||||||
match result {
|
match result {
|
||||||
Ok(logged_user) => {
|
Ok(logged_user) => {
|
||||||
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
|
if cfg!(feature = "ignore_auth") {
|
||||||
// Update user timestamp
|
authenticate_pass = true;
|
||||||
AUTHORIZED_USERS.store_auth(logged_user, true);
|
AUTHORIZED_USERS.store_auth(logged_user, true);
|
||||||
|
} else {
|
||||||
|
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
|
||||||
|
if authenticate_pass {
|
||||||
|
AUTHORIZED_USERS.store_auth(logged_user, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => log::error!("{:?}", e),
|
Err(e) => log::error!("{:?}", e),
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,7 @@ pub struct LoggedUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<Claim> for LoggedUser {
|
impl std::convert::From<Claim> for LoggedUser {
|
||||||
fn from(c: Claim) -> Self {
|
fn from(c: Claim) -> Self { Self { user_id: c.user_id() } }
|
||||||
Self {
|
|
||||||
user_id: c.user_id(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoggedUser {
|
impl LoggedUser {
|
||||||
@ -93,7 +89,6 @@ impl AuthorizedUsers {
|
|||||||
AuthStatus::Authorized(last_time) => {
|
AuthStatus::Authorized(last_time) => {
|
||||||
let current_time = Utc::now();
|
let current_time = Utc::now();
|
||||||
let days = (current_time - last_time).num_days();
|
let days = (current_time - last_time).num_days();
|
||||||
log::debug!("user active {} from now", days);
|
|
||||||
days < EXPIRED_DURATION_DAYS
|
days < EXPIRED_DURATION_DAYS
|
||||||
},
|
},
|
||||||
AuthStatus::NotAuthorized => {
|
AuthStatus::NotAuthorized => {
|
||||||
|
@ -32,7 +32,6 @@ impl RevisionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(self))]
|
|
||||||
pub async fn add_revision(&self, revision: &Revision) -> Result<(), DocError> {
|
pub async fn add_revision(&self, revision: &Revision) -> Result<(), DocError> {
|
||||||
let (ret, rx) = oneshot::channel();
|
let (ret, rx) = oneshot::channel();
|
||||||
let cmd = RevisionCmd::Revision {
|
let cmd = RevisionCmd::Revision {
|
||||||
|
@ -95,6 +95,7 @@ impl RevisionStoreActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip(self, revision))]
|
||||||
async fn handle_new_revision(&self, revision: Revision) -> DocResult<()> {
|
async fn handle_new_revision(&self, revision: Revision) -> DocResult<()> {
|
||||||
if self.revs.contains_key(&revision.rev_id) {
|
if self.revs.contains_key(&revision.rev_id) {
|
||||||
return Err(DocError::duplicate_rev().context(format!("Duplicate revision id: {}", revision.rev_id)));
|
return Err(DocError::duplicate_rev().context(format!("Duplicate revision id: {}", revision.rev_id)));
|
||||||
@ -107,6 +108,7 @@ impl RevisionStoreActor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip(self, rev_id))]
|
||||||
async fn handle_revision_acked(&self, rev_id: RevId) {
|
async fn handle_revision_acked(&self, rev_id: RevId) {
|
||||||
match self.revs.get_mut(rev_id.as_ref()) {
|
match self.revs.get_mut(rev_id.as_ref()) {
|
||||||
None => {},
|
None => {},
|
||||||
@ -138,7 +140,6 @@ impl RevisionStoreActor {
|
|||||||
|
|
||||||
// TODO: Ok to unwrap?
|
// TODO: Ok to unwrap?
|
||||||
let conn = &*persistence.pool.get().map_err(internal_error).unwrap();
|
let conn = &*persistence.pool.get().map_err(internal_error).unwrap();
|
||||||
|
|
||||||
let result = conn.immediate_transaction::<_, DocError, _>(|| {
|
let result = conn.immediate_transaction::<_, DocError, _>(|| {
|
||||||
let _ = persistence.rev_sql.create_rev_table(revisions, conn).unwrap();
|
let _ = persistence.rev_sql.create_rev_table(revisions, conn).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -292,7 +292,6 @@ impl UserSession {
|
|||||||
let mut notify = self.ws_controller.state_subscribe();
|
let mut notify = self.ws_controller.state_subscribe();
|
||||||
let ws_controller = self.ws_controller.clone();
|
let ws_controller = self.ws_controller.clone();
|
||||||
let _ = tokio::spawn(async move {
|
let _ = tokio::spawn(async move {
|
||||||
log::debug!("listen ws state");
|
|
||||||
loop {
|
loop {
|
||||||
match notify.recv().await {
|
match notify.recv().await {
|
||||||
Ok(state) => {
|
Ok(state) => {
|
||||||
|
@ -88,7 +88,7 @@ impl WsController {
|
|||||||
pub async fn start_connect(&self, addr: String) -> Result<(), ServerError> {
|
pub async fn start_connect(&self, addr: String) -> Result<(), ServerError> {
|
||||||
*self.addr.write() = Some(addr.clone());
|
*self.addr.write() = Some(addr.clone());
|
||||||
|
|
||||||
let strategy = ExponentialBackoff::from_millis(100).take(5);
|
let strategy = FixedInterval::from_millis(5000).take(3);
|
||||||
self.connect(addr, strategy).await
|
self.connect(addr, strategy).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +326,7 @@ impl Future for WsConnectActionFut {
|
|||||||
sender,
|
sender,
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
Err(e) => Poll::Ready(Err(WsError::internal().context(e))),
|
Err(e) => Poll::Ready(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user