Skip to content

feat: add an actual is_active field in the DatabaseUser#578

Open
m4tx wants to merge 2 commits into
masterfrom
is_active
Open

feat: add an actual is_active field in the DatabaseUser#578
m4tx wants to merge 2 commits into
masterfrom
is_active

Conversation

@m4tx
Copy link
Copy Markdown
Member

@m4tx m4tx commented May 21, 2026

Description

This adds an is_active field to the DatabaseUser and checks if user is active before allowing to sign in.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / cleanup
  • Performance improvement
  • Other (describe above)

@m4tx m4tx requested review from ElijahAhianyo, Copilot and seqre May 21, 2026 13:47
@github-actions github-actions Bot added the C-lib Crate: cot (main library crate) label May 21, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

🐰 Bencher Report

Branchis_active
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
6,805.40 µs
(+11.52%)Baseline: 6,102.49 µs
7,699.78 µs
(88.38%)
json_api/json_api📈 view plot
🚷 view threshold
1,080.80 µs
(+0.59%)Baseline: 1,074.49 µs
1,323.73 µs
(81.65%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
996.07 µs
(+0.31%)Baseline: 993.03 µs
1,204.49 µs
(82.70%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
975.37 µs
(+2.08%)Baseline: 955.50 µs
1,167.97 µs
(83.51%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
15,983.00 µs
(-9.71%)Baseline: 17,701.50 µs
21,171.80 µs
(75.49%)
🐰 View full continuous benchmarking report in Bencher

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a persistent is_active flag for DatabaseUser and enforces it in the authentication flow so inactive users cannot log in (and won’t be restored from an existing session).

Changes:

  • Added is_active: bool to DatabaseUser, defaulting to true, plus a setter and a small unit test.
  • Added a new DB migration to add the is_active column and registered it in the auth migrations list.
  • Updated auth logic to reject login for inactive users and to treat inactive session users as unauthenticated, with accompanying tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cot/src/auth/db/migrations/m_0002_add_is_active.rs Adds a migration intended to introduce the is_active column.
cot/src/auth/db/migrations.rs Registers the new migration in the auth migration list.
cot/src/auth/db.rs Adds the is_active field to DatabaseUser, initializes it, and exposes a setter + test.
cot/src/auth.rs Enforces is_active during login and when restoring a user from session; adds AuthError::UserInactive and tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +23
&[::cot::db::migrations::Operation::add_field()
.table_name(::cot::db::Identifier::new("cot__database_user"))
.field(
::cot::db::migrations::Field::new(
::cot::db::Identifier::new("is_active"),
<bool as ::cot::db::DatabaseField>::TYPE,
)
.set_null(<bool as ::cot::db::DatabaseField>::NULLABLE),
)
.build()];
Comment thread cot/src/auth/db.rs
Comment on lines +122 to +129
/// ```
/// use cot::auth::db::DatabaseUser;
/// # use cot::common_types::Password;
/// # use cot::db::{Auto, LimitedString};
///
/// # let mut user = DatabaseUser::new(Auto::fixed(1), LimitedString::new("user").unwrap(), &Password::new("password"));
/// user.set_is_active(false);
/// ```
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 96.29630% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot/src/auth.rs 95.00% 0 Missing and 2 partials ⚠️
Flag Coverage Δ
rust 90.44% <96.29%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot/src/auth/db.rs 85.89% <100.00%> (+0.80%) ⬆️
cot/src/auth.rs 91.46% <95.00%> (+0.40%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants