-
Notifications
You must be signed in to change notification settings - Fork 10
Warn if computer time is off #1657
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35017c1
Add warning about wrong time to exams
nygrenh 1c26835
Use date-fns
nygrenh eba9122
Enhance time handling in exams and improve clock skew warning display
nygrenh af34026
Split exam pages into components
nygrenh 35dc27b
Exam style changes
nygrenh d403646
Enhance exam management page with detailed exam information display
nygrenh 0b05843
Fixes
nygrenh e6de420
Merge remote-tracking branch 'origin/master' into clock-warning
nygrenh ce7631d
Update snapshots
nygrenh c52a73b
Update snapshots
nygrenh e4f1d57
Merge remote-tracking branch 'origin/master' into clock-warning
nygrenh 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
services/headless-lms/server/src/controllers/main_frontend/time.rs
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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /*! | ||
| Handlers for HTTP requests to `/api/v0/main-frontend/time`. | ||
| */ | ||
|
|
||
| use crate::prelude::*; | ||
| use chrono::{SecondsFormat, Utc}; | ||
|
|
||
| /** | ||
| GET `/api/v0/main-frontend/time` Returns the server's current UTC time as an RFC3339 timestamp string. | ||
|
|
||
| Response body example: | ||
| `"2026-02-18T12:34:56.789Z"` | ||
| */ | ||
| pub async fn get_current_time() -> ControllerResult<HttpResponse> { | ||
| let server_time = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true); | ||
| let token = skip_authorize(); | ||
|
|
||
| token.authorized_ok( | ||
| HttpResponse::Ok() | ||
| .insert_header(( | ||
| "Cache-Control", | ||
| "no-store, no-cache, must-revalidate, max-age=0", | ||
| )) | ||
| .insert_header(("Pragma", "no-cache")) | ||
| .insert_header(("Expires", "0")) | ||
| .json(server_time), | ||
| ) | ||
| } | ||
|
|
||
| pub fn _add_routes(cfg: &mut ServiceConfig) { | ||
| cfg.route("", web::get().to(get_current_time)); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use actix_web::{App, test, web}; | ||
|
|
||
| #[actix_web::test] | ||
| async fn returns_non_cacheable_rfc3339_json_string() { | ||
| let app = test::init_service(App::new().service(web::scope("/api/v0").service( | ||
| web::scope("/main-frontend").service(web::scope("/time").configure(_add_routes)), | ||
| ))) | ||
| .await; | ||
|
|
||
| let req = test::TestRequest::with_uri("/api/v0/main-frontend/time").to_request(); | ||
| let resp = test::call_service(&app, req).await; | ||
|
|
||
| assert!(resp.status().is_success()); | ||
| assert_eq!( | ||
| resp.headers().get("Cache-Control").unwrap(), | ||
| "no-store, no-cache, must-revalidate, max-age=0" | ||
| ); | ||
| assert_eq!(resp.headers().get("Pragma").unwrap(), "no-cache"); | ||
| assert_eq!(resp.headers().get("Expires").unwrap(), "0"); | ||
|
|
||
| let body: String = test::read_body_json(resp).await; | ||
| assert!(chrono::DateTime::parse_from_rfc3339(&body).is_ok()); | ||
|
|
||
| let parsed = chrono::DateTime::parse_from_rfc3339(&body).unwrap(); | ||
| let server_utc = parsed.with_timezone(&chrono::Utc); | ||
| let now = chrono::Utc::now(); | ||
| let diff = (server_utc - now).abs(); | ||
| assert!( | ||
| diff < chrono::Duration::seconds(5), | ||
| "server time should be close to now" | ||
| ); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.