mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-11-04 03:54:44 +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]
 | 
			
		||||
flowy_test = []
 | 
			
		||||
ignore_auth = []
 | 
			
		||||
 | 
			
		||||
[dev-dependencies]
 | 
			
		||||
parking_lot = "0.11"
 | 
			
		||||
 | 
			
		||||
@ -49,9 +49,7 @@ where
 | 
			
		||||
    type Error = Error;
 | 
			
		||||
    type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
 | 
			
		||||
 | 
			
		||||
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
 | 
			
		||||
        self.service.poll_ready(cx)
 | 
			
		||||
    }
 | 
			
		||||
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.service.poll_ready(cx) }
 | 
			
		||||
 | 
			
		||||
    fn call(&self, req: ServiceRequest) -> Self::Future {
 | 
			
		||||
        let mut authenticate_pass: bool = false;
 | 
			
		||||
@ -68,9 +66,15 @@ where
 | 
			
		||||
                let result: Result<LoggedUser, ServerError> = header.try_into();
 | 
			
		||||
                match result {
 | 
			
		||||
                    Ok(logged_user) => {
 | 
			
		||||
                        authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
 | 
			
		||||
                        // Update user timestamp
 | 
			
		||||
                        AUTHORIZED_USERS.store_auth(logged_user, true);
 | 
			
		||||
                        if cfg!(feature = "ignore_auth") {
 | 
			
		||||
                            authenticate_pass = 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),
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -15,11 +15,7 @@ pub struct LoggedUser {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl std::convert::From<Claim> for LoggedUser {
 | 
			
		||||
    fn from(c: Claim) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            user_id: c.user_id(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    fn from(c: Claim) -> Self { Self { user_id: c.user_id() } }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl LoggedUser {
 | 
			
		||||
@ -93,7 +89,6 @@ impl AuthorizedUsers {
 | 
			
		||||
                AuthStatus::Authorized(last_time) => {
 | 
			
		||||
                    let current_time = Utc::now();
 | 
			
		||||
                    let days = (current_time - last_time).num_days();
 | 
			
		||||
                    log::debug!("user active {} from now", days);
 | 
			
		||||
                    days < EXPIRED_DURATION_DAYS
 | 
			
		||||
                },
 | 
			
		||||
                AuthStatus::NotAuthorized => {
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,6 @@ impl RevisionManager {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[tracing::instrument(level = "debug", skip(self))]
 | 
			
		||||
    pub async fn add_revision(&self, revision: &Revision) -> Result<(), DocError> {
 | 
			
		||||
        let (ret, rx) = oneshot::channel();
 | 
			
		||||
        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<()> {
 | 
			
		||||
        if self.revs.contains_key(&revision.rev_id) {
 | 
			
		||||
            return Err(DocError::duplicate_rev().context(format!("Duplicate revision id: {}", revision.rev_id)));
 | 
			
		||||
@ -107,6 +108,7 @@ impl RevisionStoreActor {
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[tracing::instrument(level = "debug", skip(self, rev_id))]
 | 
			
		||||
    async fn handle_revision_acked(&self, rev_id: RevId) {
 | 
			
		||||
        match self.revs.get_mut(rev_id.as_ref()) {
 | 
			
		||||
            None => {},
 | 
			
		||||
@ -138,7 +140,6 @@ impl RevisionStoreActor {
 | 
			
		||||
 | 
			
		||||
            // TODO: Ok to unwrap?
 | 
			
		||||
            let conn = &*persistence.pool.get().map_err(internal_error).unwrap();
 | 
			
		||||
 | 
			
		||||
            let result = conn.immediate_transaction::<_, DocError, _>(|| {
 | 
			
		||||
                let _ = persistence.rev_sql.create_rev_table(revisions, conn).unwrap();
 | 
			
		||||
                Ok(())
 | 
			
		||||
 | 
			
		||||
@ -292,7 +292,6 @@ impl UserSession {
 | 
			
		||||
        let mut notify = self.ws_controller.state_subscribe();
 | 
			
		||||
        let ws_controller = self.ws_controller.clone();
 | 
			
		||||
        let _ = tokio::spawn(async move {
 | 
			
		||||
            log::debug!("listen ws state");
 | 
			
		||||
            loop {
 | 
			
		||||
                match notify.recv().await {
 | 
			
		||||
                    Ok(state) => {
 | 
			
		||||
 | 
			
		||||
@ -88,7 +88,7 @@ impl WsController {
 | 
			
		||||
    pub async fn start_connect(&self, addr: String) -> Result<(), ServerError> {
 | 
			
		||||
        *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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -326,7 +326,7 @@ impl Future for WsConnectActionFut {
 | 
			
		||||
                    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