From 6dff96957bf336e96367ebd1011d93c1a717eb60 Mon Sep 17 00:00:00 2001 From: tanmoyopenroot Date: Sun, 9 Feb 2020 10:59:20 +0530 Subject: [PATCH 1/3] fix(settings): check Accounts_AllowUsernameChange to allow editing of username field --- app/constants/settings.js | 3 +++ app/views/ProfileView/index.js | 8 +++++++- app/views/ProfileView/styles.js | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index 74c6234f6a..f4cdc56968 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -1,4 +1,7 @@ export default { + Accounts_AllowUsernameChange: { + type: 'valueAsBoolean' + }, Accounts_CustomFields: { type: 'valueAsString' }, diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index 3121db989b..c949013563 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -49,6 +49,7 @@ class ProfileView extends React.Component { static propTypes = { baseUrl: PropTypes.string, user: PropTypes.object, + Accounts_AllowUsernameChange: PropTypes.bool, Accounts_CustomFields: PropTypes.string, setUser: PropTypes.func, theme: PropTypes.string @@ -380,7 +381,7 @@ class ProfileView extends React.Component { name, username, email, newPassword, avatarUrl, customFields, avatar, saving, showPasswordAlert } = this.state; const { - baseUrl, user, theme, Accounts_CustomFields + baseUrl, user, theme, Accounts_AllowUsernameChange, Accounts_CustomFields } = this.props; return ( @@ -417,6 +418,10 @@ class ProfileView extends React.Component { theme={theme} /> { this.username = e; }} label={I18n.t('Username')} placeholder={I18n.t('Username')} @@ -505,6 +510,7 @@ const mapStateToProps = state => ({ emails: state.login.user && state.login.user.emails, token: state.login.user && state.login.user.token }, + Accounts_AllowUsernameChange: state.settings.Accounts_AllowUsernameChange, Accounts_CustomFields: state.settings.Accounts_CustomFields, baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' }); diff --git a/app/views/ProfileView/styles.js b/app/views/ProfileView/styles.js index bf38e0a1a4..bdfe48efc6 100644 --- a/app/views/ProfileView/styles.js +++ b/app/views/ProfileView/styles.js @@ -1,6 +1,9 @@ import { StyleSheet, Platform } from 'react-native'; export default StyleSheet.create({ + disabled: { + opacity: 0.3 + }, avatarContainer: { alignItems: 'center', justifyContent: 'center', From 6f31b18964185a415fe7364e68c7314c4bff3986 Mon Sep 17 00:00:00 2001 From: tanmoyopenroot Date: Sun, 9 Feb 2020 11:45:59 +0530 Subject: [PATCH 2/3] fix(settings): check if profile fields are editable or not --- app/constants/settings.js | 15 ++++++++ app/views/ProfileView/index.js | 65 ++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index f4cdc56968..2f6c24775a 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -1,4 +1,19 @@ export default { + Accounts_AllowEmailChange: { + type: 'valueAsBoolean' + }, + Accounts_AllowPasswordChange: { + type: 'valueAsBoolean' + }, + Accounts_AllowRealNameChange: { + type: 'valueAsBoolean' + }, + Accounts_AllowUserAvatarChange: { + type: 'valueAsBoolean' + }, + Accounts_AllowUserProfileChange: { + type: 'valueAsBoolean' + }, Accounts_AllowUsernameChange: { type: 'valueAsBoolean' }, diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index c949013563..2596c0232f 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -49,6 +49,10 @@ class ProfileView extends React.Component { static propTypes = { baseUrl: PropTypes.string, user: PropTypes.object, + Accounts_AllowEmailChange: PropTypes.bool, + Accounts_AllowPasswordChange: PropTypes.bool, + Accounts_AllowRealNameChange: PropTypes.bool, + Accounts_AllowUserAvatarChange: PropTypes.bool, Accounts_AllowUsernameChange: PropTypes.bool, Accounts_CustomFields: PropTypes.string, setUser: PropTypes.func, @@ -98,6 +102,12 @@ class ProfileView extends React.Component { } setAvatar = (avatar) => { + const { Accounts_AllowUserAvatarChange } = this.props; + + if (!Accounts_AllowUserAvatarChange) { + return; + } + this.setState({ avatar }); } @@ -233,6 +243,12 @@ class ProfileView extends React.Component { } resetAvatar = async() => { + const { Accounts_AllowUserAvatarChange } = this.props; + + if (!Accounts_AllowUserAvatarChange) { + return; + } + try { const { user } = this.props; await RocketChat.resetAvatar(user.id); @@ -244,6 +260,12 @@ class ProfileView extends React.Component { } pickImage = async() => { + const { Accounts_AllowUserAvatarChange } = this.props; + + if (!Accounts_AllowUserAvatarChange) { + return; + } + const options = { cropping: true, compressImageQuality: 0.8, @@ -280,10 +302,19 @@ class ProfileView extends React.Component { renderAvatarButtons = () => { const { avatarUrl, avatarSuggestions } = this.state; - const { user, baseUrl, theme } = this.props; + const { + user, + baseUrl, + theme, + Accounts_AllowUserAvatarChange + } = this.props; return ( - + {this.renderAvatarButton({ child: , onPress: () => this.resetAvatar(), @@ -381,7 +412,15 @@ class ProfileView extends React.Component { name, username, email, newPassword, avatarUrl, customFields, avatar, saving, showPasswordAlert } = this.state; const { - baseUrl, user, theme, Accounts_AllowUsernameChange, Accounts_CustomFields + baseUrl, + user, + theme, + Accounts_AllowEmailChange, + Accounts_AllowPasswordChange, + Accounts_AllowRealNameChange, + Accounts_AllowUserAvatarChange, + Accounts_AllowUsernameChange, + Accounts_CustomFields } = this.props; return ( @@ -408,6 +447,10 @@ class ProfileView extends React.Component { /> { this.name = e; }} label={I18n.t('Name')} placeholder={I18n.t('Name')} @@ -432,6 +475,10 @@ class ProfileView extends React.Component { theme={theme} /> { this.email = e; }} label={I18n.t('Email')} placeholder={I18n.t('Email')} @@ -442,6 +489,10 @@ class ProfileView extends React.Component { theme={theme} /> { this.newPassword = e; }} label={I18n.t('New_Password')} placeholder={I18n.t('New_Password')} @@ -459,6 +510,10 @@ class ProfileView extends React.Component { /> {this.renderCustomFields()} { this.avatarUrl = e; }} label={I18n.t('Avatar_Url')} placeholder={I18n.t('Avatar_Url')} @@ -510,6 +565,10 @@ const mapStateToProps = state => ({ emails: state.login.user && state.login.user.emails, token: state.login.user && state.login.user.token }, + Accounts_AllowEmailChange: state.settings.Accounts_AllowEmailChange, + Accounts_AllowPasswordChange: state.settings.Accounts_AllowPasswordChange, + Accounts_AllowRealNameChange: state.settings.Accounts_AllowRealNameChange, + Accounts_AllowUserAvatarChange: state.settings.Accounts_AllowUserAvatarChange, Accounts_AllowUsernameChange: state.settings.Accounts_AllowUsernameChange, Accounts_CustomFields: state.settings.Accounts_CustomFields, baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' From 4efb5deabfba7cbf2a6a58d6ca457e5d27550f28 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 20 Feb 2020 15:23:34 -0300 Subject: [PATCH 3/3] Some fixes --- app/views/ProfileView/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index b948cef11e..ecbd4e6934 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -311,19 +311,17 @@ class ProfileView extends React.Component { } = this.props; return ( - + {this.renderAvatarButton({ child: , onPress: () => this.resetAvatar(), + disabled: !Accounts_AllowUserAvatarChange, key: 'profile-view-reset-avatar' })} {this.renderAvatarButton({ child: , onPress: () => this.pickImage(), + disabled: !Accounts_AllowUserAvatarChange, key: 'profile-view-upload-avatar' })} {this.renderAvatarButton({ @@ -335,6 +333,7 @@ class ProfileView extends React.Component { {Object.keys(avatarSuggestions).map((service) => { const { url, blob, contentType } = avatarSuggestions[service]; return this.renderAvatarButton({ + disabled: !Accounts_AllowUserAvatarChange, key: `profile-view-avatar-${ service }`, child: , onPress: () => this.setAvatar({