Skip to content

Commit 19f1091

Browse files
committed
Config option to allow account self-deactivation
1 parent b8c7a2d commit 19f1091

File tree

8 files changed

+26
-0
lines changed

8 files changed

+26
-0
lines changed

crates/cli/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub fn site_config_from_config(
207207
&& account_config.password_change_allowed,
208208
account_recovery_allowed: password_config.enabled()
209209
&& account_config.password_recovery_enabled,
210+
account_deactivation_allowed: account_config.account_deactivation_allowed,
210211
captcha,
211212
minimum_password_complexity: password_config.minimum_complexity(),
212213
session_expiration,

crates/config/src/sections/account.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ pub struct AccountConfig {
6161
/// This has no effect if password login is disabled.
6262
#[serde(default = "default_false", skip_serializing_if = "is_default_false")]
6363
pub password_recovery_enabled: bool,
64+
65+
/// Whether users are allowed to delete their own account. Defaults to
66+
/// `false`.
67+
#[serde(default = "default_false", skip_serializing_if = "is_default_false")]
68+
pub account_deactivation_allowed: bool,
6469
}
6570

6671
impl Default for AccountConfig {
@@ -71,6 +76,7 @@ impl Default for AccountConfig {
7176
password_registration_enabled: default_false(),
7277
password_change_allowed: default_true(),
7378
password_recovery_enabled: default_false(),
79+
account_deactivation_allowed: default_false(),
7480
}
7581
}
7682
}
@@ -83,6 +89,7 @@ impl AccountConfig {
8389
&& is_default_true(&self.displayname_change_allowed)
8490
&& is_default_true(&self.password_change_allowed)
8591
&& is_default_false(&self.password_recovery_enabled)
92+
&& is_default_false(&self.account_deactivation_allowed)
8693
}
8794
}
8895

crates/data-model/src/site_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub struct SiteConfig {
7676
/// Whether users can recover their account via email.
7777
pub account_recovery_allowed: bool,
7878

79+
/// Whether users can delete their own account.
80+
pub account_deactivation_allowed: bool,
81+
7982
/// Captcha configuration
8083
pub captcha: Option<CaptchaConfig>,
8184

crates/handlers/src/graphql/model/site_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub struct SiteConfig {
4646
/// Whether passwords are enabled and users can register using a password.
4747
password_registration_enabled: bool,
4848

49+
/// Whether users can delete their own account.
50+
account_deactivation_allowed: bool,
51+
4952
/// Minimum password complexity, from 0 to 4, in terms of a zxcvbn score.
5053
/// The exact scorer (including dictionaries and other data tables)
5154
/// in use is <https://crates.io/crates/zxcvbn>.
@@ -93,6 +96,7 @@ impl SiteConfig {
9396
password_login_enabled: data_model.password_login_enabled,
9497
password_change_allowed: data_model.password_change_allowed,
9598
password_registration_enabled: data_model.password_registration_enabled,
99+
account_deactivation_allowed: data_model.account_deactivation_allowed,
96100
minimum_password_complexity: data_model.minimum_password_complexity,
97101
}
98102
}

crates/handlers/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub fn test_site_config() -> SiteConfig {
137137
displayname_change_allowed: true,
138138
password_change_allowed: true,
139139
account_recovery_allowed: true,
140+
account_deactivation_allowed: true,
140141
captcha: None,
141142
minimum_password_complexity: 1,
142143
session_expiration: None,

docs/config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,10 @@
24632463
"password_recovery_enabled": {
24642464
"description": "Whether email-based password recovery is enabled. Defaults to `false`.\n\nThis has no effect if password login is disabled.",
24652465
"type": "boolean"
2466+
},
2467+
"account_deactivation_allowed": {
2468+
"description": "Whether users are allowed to delete their own account. Defaults to `false`.",
2469+
"type": "boolean"
24662470
}
24672471
}
24682472
},

frontend/schema.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,10 @@ type SiteConfig implements Node {
15991599
"""
16001600
passwordRegistrationEnabled: Boolean!
16011601
"""
1602+
Whether users can delete their own account.
1603+
"""
1604+
accountDeactivationAllowed: Boolean!
1605+
"""
16021606
Minimum password complexity, from 0 to 4, in terms of a zxcvbn score.
16031607
The exact scorer (including dictionaries and other data tables)
16041608
in use is <https://crates.io/crates/zxcvbn>.

frontend/src/gql/graphql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,8 @@ export type SetPrimaryEmailStatus =
11611161

11621162
export type SiteConfig = Node & {
11631163
__typename?: 'SiteConfig';
1164+
/** Whether users can delete their own account. */
1165+
accountDeactivationAllowed: Scalars['Boolean']['output'];
11641166
/** The configuration of CAPTCHA provider. */
11651167
captchaConfig?: Maybe<CaptchaConfig>;
11661168
/** Whether users can change their display name. */

0 commit comments

Comments
 (0)