-
Notifications
You must be signed in to change notification settings - Fork 142
feat(tickets): add way to track changes #1102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AugustinMauroy
wants to merge
6
commits into
jsr-io:main
Choose a base branch
from
AugustinMauroy:update-ticket
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1bfa151
feat(ticket): WIP
AugustinMauroy 75226c7
feat(ticket): add historic of changes
AugustinMauroy 310b7ab
fix: rs test
AugustinMauroy e209be6
Merge remote-tracking branch 'upstream/main' into update-ticket
AugustinMauroy 78e317f
fix: fmt
AugustinMauroy 686eb4e
Merge branch 'main' into update-ticket
crowlKats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
api/.sqlx/query-1a5aa7ce4a5d4e1406709fbe9b9f551649fe57c3ee47629d9c62455c7ee3e764.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
|
@@ -24,6 +24,8 @@ use crate::util::decode_json; | |
use super::ApiError; | ||
use super::ApiTicket; | ||
use super::ApiTicketMessage; | ||
use super::ApiTicketMessageOrAuditLog; | ||
use super::ApiTicketOverview; | ||
|
||
pub fn tickets_router() -> Router<Body, ApiError> { | ||
Router::builder() | ||
|
@@ -35,18 +37,60 @@ pub fn tickets_router() -> Router<Body, ApiError> { | |
} | ||
|
||
#[instrument(name = "GET /api/tickets/:id", skip(req), err, fields(id))] | ||
pub async fn get_handler(req: Request<Body>) -> ApiResult<ApiTicket> { | ||
let id = req.param_uuid("id")?; | ||
pub async fn get_handler(req: Request<Body>) -> ApiResult<ApiTicketOverview> { | ||
let id = match req.param_uuid("id") { | ||
Ok(id) => id, | ||
Err(_) => { | ||
return Err(ApiError::MalformedRequest { | ||
msg: "Invalid ID".into(), | ||
}) | ||
} | ||
}; | ||
Span::current().record("id", field::display(id)); | ||
|
||
let db = req.data::<Database>().unwrap(); | ||
let ticket = db.get_ticket(id).await?.ok_or(ApiError::TicketNotFound)?; | ||
let db = match req.data::<Database>() { | ||
Some(db) => db, | ||
None => return Err(ApiError::InternalServerError), | ||
}; | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
||
let iam = req.iam(); | ||
let ticket = match db.get_ticket(id).await { | ||
Ok(Some(ticket)) => ticket, | ||
Ok(None) => return Err(ApiError::TicketNotFound), | ||
Err(_) => return Err(ApiError::InternalServerError), | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
let ticket_audit = db.get_ticket_audit_logs(id).await; | ||
|
||
let iam = req.iam(); | ||
let current_user = iam.check_current_user_access()?; | ||
|
||
if current_user == &ticket.1 || iam.check_admin_access().is_ok() { | ||
Ok(ticket.into()) | ||
let mut events: Vec<ApiTicketMessageOrAuditLog> = Vec::new(); | ||
|
||
for message in ticket.2 { | ||
events.push(ApiTicketMessageOrAuditLog::Message { | ||
message: message.0, | ||
user: message.1, | ||
}); | ||
} | ||
|
||
if let Ok(audit_logs) = ticket_audit { | ||
for audit_log in audit_logs { | ||
events.push(ApiTicketMessageOrAuditLog::AuditLog { | ||
audit_log: audit_log.0, | ||
user: audit_log.1, | ||
}); | ||
} | ||
} | ||
|
||
events.sort_by_key(|event| match event { | ||
ApiTicketMessageOrAuditLog::Message { message, .. } => message.created_at, | ||
ApiTicketMessageOrAuditLog::AuditLog { audit_log, .. } => { | ||
audit_log.created_at | ||
} | ||
}); | ||
|
||
Ok((ticket.0, ticket.1, events).into()) | ||
} else { | ||
Err(ApiError::TicketNotFound) | ||
} | ||
|
@@ -206,9 +250,22 @@ mod test { | |
.call() | ||
.await | ||
.unwrap(); | ||
let ticket: ApiTicket = resp.expect_ok().await; | ||
assert_eq!(ticket.messages[0].message, "test"); | ||
assert_eq!(ticket.messages[1].message, "test2"); | ||
let ticket_overview: super::ApiTicketOverview = resp.expect_ok().await; | ||
|
||
let mut message_contents: Vec<String> = Vec::new(); | ||
for event in &ticket_overview.events { | ||
if let super::ApiTicketMessageOrAuditLog::Message { message, .. } = event | ||
{ | ||
message_contents.push(message.message.clone()); | ||
} | ||
} | ||
assert!( | ||
message_contents.len() >= 2, | ||
"Expected at least 2 messages, found {}", | ||
message_contents.len() | ||
); | ||
assert_eq!(message_contents[0], "test"); | ||
assert_eq!(message_contents[1], "test2"); | ||
|
||
let other_user_token = t.user2.token.clone(); | ||
let mut resp = t | ||
|
@@ -228,6 +285,22 @@ mod test { | |
.call() | ||
.await | ||
.unwrap(); | ||
let _ticket: ApiTicket = resp.expect_ok().await; | ||
let staff_ticket_overview: super::ApiTicketOverview = | ||
resp.expect_ok().await; | ||
|
||
let mut staff_message_contents: Vec<String> = Vec::new(); | ||
for event in &staff_ticket_overview.events { | ||
if let super::ApiTicketMessageOrAuditLog::Message { message, .. } = event | ||
{ | ||
staff_message_contents.push(message.message.clone()); | ||
} | ||
} | ||
assert!( | ||
staff_message_contents.len() >= 2, | ||
"Expected at least 2 messages for staff view, found {}", | ||
staff_message_contents.len() | ||
); | ||
assert_eq!(staff_message_contents[0], "test"); | ||
assert_eq!(staff_message_contents[1], "test2"); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?