Skip to content

Commit e0bd3bc

Browse files
Sychicfetchfern
andauthored
feat: account locking (#7749)
* feat(labrinth): user lock db schema * feat(labrinth): check user lock state * feat(frontend): user locking * fix(labrinth): use deleted user if staff account is deleted * fix(labrinth): error text * fix(labrinth): allow perform analytics * fix(labrinth): require user auth write for creating oauth links * fix(labrinth): prevent linking paypal account if user is locked * chore(frontend): reword warning * fix: only allow admins to lock users * refactor(labrinth): user is_admin * remove(frontend): locked banner * fix(labrinth): also prevent reads for locked accounts * refactor(labrinth): remove redundant auth checks * style(labrinth): fmt * refactor(labrinth): endpoint mount point * Update packages/ui/src/layouts/shared/user-profile/components/lock-user-modal.vue Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com> --------- Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com> Co-authored-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
1 parent 64fc2b9 commit e0bd3bc

27 files changed

Lines changed: 681 additions & 14 deletions

‎apps/labrinth/.sqlx/query-423e54060fb4bc548ac6a5d4f01e142f355db0252ff85de40b0052f6a4109bbe.json‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/labrinth/.sqlx/query-4f2874a54a427c8c3d1513b653d78da4fb58df880eb1d0d33a4cafe14e2a3b56.json‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-3ca51012492b969bb6a474ee22c9e53e57b6da3a1145f0d86a2bab36be436eb6.json renamed to apps/labrinth/.sqlx/query-85b6b47438e5d6c00e119bc4c06b42db2fd13f36bca1d25dfe54bfc8991aac8c.json

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/labrinth/.sqlx/query-96f8c4ee1f18a0b02fe8545245e45117a1b551bf6c4a6ef98add8722ff9e9a73.json‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/labrinth/.sqlx/query-c2cc000527f4a47c7d7f44c2245e4160a6e456f022a4f88c8e409f0441a30400.json‎

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE user_locks (
2+
user_id BIGINT PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
3+
locked_by BIGINT NOT NULL REFERENCES users(id),
4+
reason TEXT NOT NULL,
5+
created TIMESTAMPTZ NOT NULL DEFAULT NOW()
6+
);

‎apps/labrinth/src/auth/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub enum AuthenticationError {
5555
SocketError,
5656
#[error("Invalid callback URL specified")]
5757
Url,
58+
#[error("Your account is locked and cannot perform this action")]
59+
AccountLocked,
5860
}
5961

6062
impl actix_web::ResponseError for AuthenticationError {
@@ -83,6 +85,7 @@ impl actix_web::ResponseError for AuthenticationError {
8385
StatusCode::BAD_REQUEST
8486
}
8587
AuthenticationError::SocketError => StatusCode::BAD_REQUEST,
88+
AuthenticationError::AccountLocked => StatusCode::FORBIDDEN,
8689
}
8790
}
8891

@@ -115,6 +118,7 @@ impl AuthenticationError {
115118
"provider_already_linked"
116119
}
117120
AuthenticationError::SocketError => "socket",
121+
AuthenticationError::AccountLocked => "account_locked",
118122
}
119123
}
120124
}

‎apps/labrinth/src/auth/oauth/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub async fn accept_or_reject_client_scopes(
349349
&**pool,
350350
&redis,
351351
&session_queue,
352-
Scopes::SESSION_ACCESS,
352+
Scopes::SESSION_ACCESS | Scopes::USER_AUTH_WRITE,
353353
)
354354
.await?
355355
.1;

‎apps/labrinth/src/auth/validate.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ where
229229
_ => return Err(AuthenticationError::InvalidAuthMethod),
230230
};
231231

232+
if possible_user
233+
.as_ref()
234+
.is_some_and(|(_, user)| user.is_locked())
235+
{
236+
return Err(AuthenticationError::AccountLocked);
237+
}
238+
232239
Ok(possible_user)
233240
}
234241

‎apps/labrinth/src/database/models/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub mod team_item;
3636
pub mod thread_item;
3737
pub mod user_item;
3838
pub mod user_limits;
39+
pub mod user_lock_item;
3940
pub mod user_preferences_item;
4041
pub mod user_subscription_item;
4142
pub mod users_compliance;

0 commit comments

Comments
 (0)