diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index a568a8a45e0..8a8b26c1c48 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -7,6 +7,7 @@ "Access_Online_Demo" : "Access the Online Demo", "Access_Token_URL" : "Access Token URL", "Accounts" : "Accounts", + "Accounts_AllowDeleteOwnAccount" : "Allow users to delete own account", "Accounts_AllowedDomainsList" : "Allowed Domains List", "Accounts_AllowedDomainsList_Description" : "Comma-separated list of allowed domains", "Accounts_AllowEmailChange" : "Allow E-mail Change", diff --git a/packages/rocketchat-lib/server/methods/deleteUserOwnAccount.js b/packages/rocketchat-lib/server/methods/deleteUserOwnAccount.js index cf4463f6a72..6296b40cec7 100644 --- a/packages/rocketchat-lib/server/methods/deleteUserOwnAccount.js +++ b/packages/rocketchat-lib/server/methods/deleteUserOwnAccount.js @@ -4,6 +4,10 @@ Meteor.methods({ throw new Meteor.Error('invalid-user', "[methods] deleteUserOwnAccount -> Invalid user"); } + if (!RocketChat.settings.get('Accounts_AllowDeleteOwnAccount')) { + throw new Meteor.Error('not-authorized', "[methods] deleteUserOwnAccount -> Not authorized"); + } + const userId = Meteor.userId(); const user = RocketChat.models.Users.findOneById(userId); diff --git a/packages/rocketchat-lib/server/startup/settings.coffee b/packages/rocketchat-lib/server/startup/settings.coffee index d711cb9a2b3..9b86492c354 100644 --- a/packages/rocketchat-lib/server/startup/settings.coffee +++ b/packages/rocketchat-lib/server/startup/settings.coffee @@ -3,6 +3,7 @@ if not RocketChat.models.Settings.findOneById 'uniqueID' RocketChat.models.Settings.createWithIdAndValue 'uniqueID', process.env.DEPLOYMENT_ID or Random.id() RocketChat.settings.addGroup 'Accounts', -> + @add 'Accounts_AllowDeleteOwnAccount', true, { type: 'boolean', public: true } @add 'Accounts_AllowUserProfileChange', true, { type: 'boolean', public: true } @add 'Accounts_AllowUserAvatarChange', true, { type: 'boolean', public: true } @add 'Accounts_AllowUsernameChange', true, { type: 'boolean', public: true } diff --git a/packages/rocketchat-ui-account/account/accountPreferences.coffee b/packages/rocketchat-ui-account/account/accountPreferences.coffee index 1c3d41e35bb..93491c849ca 100644 --- a/packages/rocketchat-ui-account/account/accountPreferences.coffee +++ b/packages/rocketchat-ui-account/account/accountPreferences.coffee @@ -1,4 +1,7 @@ Template.accountPreferences.helpers + allowDeleteOwnAccount: -> + return RocketChat.settings.get('Accounts_AllowDeleteOwnAccount') + checked: (property, value, defaultValue) -> if not Meteor.user()?.settings?.preferences?[property]? and defaultValue is true currentValue = value diff --git a/packages/rocketchat-ui-account/account/accountPreferences.html b/packages/rocketchat-ui-account/account/accountPreferences.html index 2325775dadd..a465c97129c 100644 --- a/packages/rocketchat-ui-account/account/accountPreferences.html +++ b/packages/rocketchat-ui-account/account/accountPreferences.html @@ -115,9 +115,11 @@
+ {{#if allowDeleteOwnAccount}}
+ {{/if}}