-
Notifications
You must be signed in to change notification settings - Fork 84
feat: implements allow_new_users setting
#2304
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
base: master
Are you sure you want to change the base?
Changes from all commits
8b1da2e
fde50c8
cf1f8c0
40cab9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,10 @@ pub struct DbError { | |
| } | ||
|
|
||
| impl DbError { | ||
| pub fn is_user_not_created(user: String) -> Self { | ||
| DbErrorKind::UserNotCreated(user).into() | ||
| } | ||
|
|
||
| pub fn internal(msg: String) -> Self { | ||
| DbErrorKind::Internal(msg).into() | ||
| } | ||
|
|
@@ -26,6 +30,11 @@ impl DbError { | |
| DbErrorKind::PoolTimeout(timeout_type).into() | ||
| } | ||
|
|
||
| #[cfg(debug_assertions)] | ||
| pub fn is_user_not_created(&self) -> bool { | ||
| matches!(&self.kind, DbErrorKind::UserNotCreated(_)) | ||
| } | ||
|
HorlogeSkynet marked this conversation as resolved.
|
||
|
|
||
| #[cfg(debug_assertions)] | ||
| pub fn is_diesel_not_found(&self) -> bool { | ||
| matches!(&self.kind, DbErrorKind::Sql(e) if e.is_diesel_not_found()) | ||
|
|
@@ -59,6 +68,9 @@ impl ReportableError for DbError { | |
|
|
||
| #[derive(Debug, Error)] | ||
| enum DbErrorKind { | ||
| #[error("Specified user does not exist (new users are disallowed): {}", _0)] | ||
| UserNotCreated(String), | ||
|
|
||
| #[error("{}", _0)] | ||
| Sql(SqlError), | ||
|
|
||
|
|
@@ -72,6 +84,11 @@ enum DbErrorKind { | |
| impl From<DbErrorKind> for DbError { | ||
| fn from(kind: DbErrorKind) -> Self { | ||
| match kind { | ||
| DbErrorKind::UserNotCreated(_) => Self { | ||
| kind, | ||
| status: StatusCode::FORBIDDEN, | ||
| backtrace: Box::new(Backtrace::new_unresolved()), | ||
| }, | ||
|
Collaborator
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. When
Contributor
Author
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. By explicitly matching
Contributor
Author
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. Hey @chenba, this is a little up 😇 |
||
| DbErrorKind::Sql(ref sqle) => Self { | ||
| status: sqle.status, | ||
| backtrace: Box::new(sqle.backtrace.clone()), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.