-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from refactor-group/continued_authz
Continued authz
- Loading branch information
Showing
14 changed files
with
457 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::{extractors::authenticated_user::AuthenticatedUser, AppState}; | ||
use axum::{ | ||
extract::{Query, Request, State}, | ||
http::StatusCode, | ||
middleware::Next, | ||
response::IntoResponse, | ||
}; | ||
use entity::Id; | ||
use entity_api::coaching_session; | ||
use log::*; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub(crate) struct QueryParams { | ||
coaching_session_id: Id, | ||
} | ||
|
||
/// Checks that coaching relationship record associated with the coaching session | ||
/// referenced by `coaching_session_id exists and that the authenticated user is associated with it. | ||
/// Intended to be given to axum::middleware::from_fn_with_state in the router | ||
pub(crate) async fn index( | ||
State(app_state): State<AppState>, | ||
AuthenticatedUser(user): AuthenticatedUser, | ||
Query(params): Query<QueryParams>, | ||
request: Request, | ||
next: Next, | ||
) -> impl IntoResponse { | ||
match coaching_session::find_by_id_with_coaching_relationship( | ||
app_state.db_conn_ref(), | ||
params.coaching_session_id, | ||
) | ||
.await | ||
{ | ||
Ok((_coaching_session, coaching_relationship)) => { | ||
if coaching_relationship.coach_id == user.id | ||
|| coaching_relationship.coachee_id == user.id | ||
{ | ||
// User has access to coaching relationship | ||
next.run(request).await | ||
} else { | ||
// User does not have access to coaching relationship | ||
(StatusCode::UNAUTHORIZED, "UNAUTHORIZED").into_response() | ||
} | ||
} | ||
Err(e) => { | ||
error!("Error authorizing overarching goals index{:?}", e); | ||
|
||
(StatusCode::INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR").into_response() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::{extractors::authenticated_user::AuthenticatedUser, AppState}; | ||
use axum::{ | ||
extract::{Query, Request, State}, | ||
http::StatusCode, | ||
middleware::Next, | ||
response::IntoResponse, | ||
}; | ||
use entity::Id; | ||
use entity_api::coaching_session; | ||
use log::*; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub(crate) struct QueryParams { | ||
coaching_session_id: Id, | ||
} | ||
|
||
/// Checks that coaching relationship record associated with the coaching session | ||
/// referenced by `coaching_session_id exists and that the authenticated user is associated with it. | ||
/// Intended to be given to axum::middleware::from_fn_with_state in the router | ||
pub(crate) async fn index( | ||
State(app_state): State<AppState>, | ||
AuthenticatedUser(user): AuthenticatedUser, | ||
Query(params): Query<QueryParams>, | ||
request: Request, | ||
next: Next, | ||
) -> impl IntoResponse { | ||
match coaching_session::find_by_id_with_coaching_relationship( | ||
app_state.db_conn_ref(), | ||
params.coaching_session_id, | ||
) | ||
.await | ||
{ | ||
Ok((_coaching_session, coaching_relationship)) => { | ||
if coaching_relationship.coach_id == user.id | ||
|| coaching_relationship.coachee_id == user.id | ||
{ | ||
// User has access to coaching relationship | ||
next.run(request).await | ||
} else { | ||
// User does not have access to coaching relationship | ||
(StatusCode::UNAUTHORIZED, "UNAUTHORIZED").into_response() | ||
} | ||
} | ||
Err(e) => { | ||
error!("Error authorizing overarching goals index{:?}", e); | ||
|
||
(StatusCode::INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR").into_response() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::{extractors::authenticated_user::AuthenticatedUser, AppState}; | ||
use axum::{ | ||
extract::{Path, Request, State}, | ||
http::StatusCode, | ||
middleware::Next, | ||
response::IntoResponse, | ||
}; | ||
|
||
use entity::Id; | ||
use entity_api::organization; | ||
use std::collections::HashSet; | ||
|
||
/// Checks that the organization record referenced by `organization_id` | ||
/// exists and that the authenticated user is associated with i.t | ||
/// Intended to be given to axum::middleware::from_fn_with_state in the router | ||
pub(crate) async fn index( | ||
State(app_state): State<AppState>, | ||
AuthenticatedUser(user): AuthenticatedUser, | ||
Path(organization_id): Path<Id>, | ||
request: Request, | ||
next: Next, | ||
) -> impl IntoResponse { | ||
let user_organization_ids = organization::find_by_user(app_state.db_conn_ref(), user.id) | ||
.await | ||
.unwrap_or(vec![]) | ||
.into_iter() | ||
.map(|org| org.id) | ||
.collect::<HashSet<Id>>(); | ||
if user_organization_ids.contains(&organization_id) { | ||
next.run(request).await | ||
} else { | ||
(StatusCode::UNAUTHORIZED, "UNAUTHORIZED").into_response() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{extractors::authenticated_user::AuthenticatedUser, AppState}; | ||
use axum::{ | ||
extract::{Query, Request, State}, | ||
http::StatusCode, | ||
middleware::Next, | ||
response::IntoResponse, | ||
}; | ||
use serde::Deserialize; | ||
|
||
use entity::Id; | ||
use entity_api::coaching_relationship; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub(crate) struct QueryParams { | ||
coaching_relationship_id: Id, | ||
} | ||
|
||
/// Checks that coaching relationship record referenced by `coaching_relationship_id` | ||
/// exists and that the authenticated user is associated with it. | ||
/// Intended to be given to axum::middleware::from_fn_with_state in the router | ||
pub(crate) async fn index( | ||
State(app_state): State<AppState>, | ||
AuthenticatedUser(user): AuthenticatedUser, | ||
Query(params): Query<QueryParams>, | ||
request: Request, | ||
next: Next, | ||
) -> impl IntoResponse { | ||
let coaching_relationship = | ||
coaching_relationship::find_by_id(app_state.db_conn_ref(), params.coaching_relationship_id) | ||
.await | ||
.unwrap_or_default(); | ||
match coaching_relationship { | ||
Some(coaching_relationship) => { | ||
if coaching_relationship.coach_id == user.id | ||
|| coaching_relationship.coachee_id == user.id | ||
{ | ||
// User has access to coaching relationship | ||
next.run(request).await | ||
} else { | ||
// User does not have access to coaching relationship | ||
(StatusCode::UNAUTHORIZED, "UNAUTHORIZED").into_response() | ||
} | ||
} | ||
// coaching relationship with given ID not found | ||
None => (StatusCode::NOT_FOUND, "NOT FOUND").into_response(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub(crate) mod actions; | ||
pub(crate) mod agreements; | ||
pub(crate) mod coaching_relationships; | ||
pub(crate) mod coaching_sessions; | ||
pub(crate) mod notes; | ||
pub(crate) mod overarching_goals; |
Oops, something went wrong.