[IMPROVEMENT] Honor profile fields edit settings (#1687)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
a9e61c5d8b
commit
d271e56b2b
|
@ -1,4 +1,22 @@
|
||||||
export default {
|
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'
|
||||||
|
},
|
||||||
Accounts_CustomFields: {
|
Accounts_CustomFields: {
|
||||||
type: 'valueAsString'
|
type: 'valueAsString'
|
||||||
},
|
},
|
||||||
|
|
|
@ -50,6 +50,11 @@ class ProfileView extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
baseUrl: PropTypes.string,
|
baseUrl: PropTypes.string,
|
||||||
user: PropTypes.object,
|
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,
|
Accounts_CustomFields: PropTypes.string,
|
||||||
setUser: PropTypes.func,
|
setUser: PropTypes.func,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
|
@ -98,6 +103,12 @@ class ProfileView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
setAvatar = (avatar) => {
|
setAvatar = (avatar) => {
|
||||||
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
||||||
|
|
||||||
|
if (!Accounts_AllowUserAvatarChange) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({ avatar });
|
this.setState({ avatar });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +244,12 @@ class ProfileView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
resetAvatar = async() => {
|
resetAvatar = async() => {
|
||||||
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
||||||
|
|
||||||
|
if (!Accounts_AllowUserAvatarChange) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { user } = this.props;
|
const { user } = this.props;
|
||||||
await RocketChat.resetAvatar(user.id);
|
await RocketChat.resetAvatar(user.id);
|
||||||
|
@ -244,6 +261,12 @@ class ProfileView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
pickImage = async() => {
|
pickImage = async() => {
|
||||||
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
||||||
|
|
||||||
|
if (!Accounts_AllowUserAvatarChange) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
cropping: true,
|
cropping: true,
|
||||||
compressImageQuality: 0.8,
|
compressImageQuality: 0.8,
|
||||||
|
@ -280,18 +303,25 @@ class ProfileView extends React.Component {
|
||||||
|
|
||||||
renderAvatarButtons = () => {
|
renderAvatarButtons = () => {
|
||||||
const { avatarUrl, avatarSuggestions } = this.state;
|
const { avatarUrl, avatarSuggestions } = this.state;
|
||||||
const { user, baseUrl, theme } = this.props;
|
const {
|
||||||
|
user,
|
||||||
|
baseUrl,
|
||||||
|
theme,
|
||||||
|
Accounts_AllowUserAvatarChange
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.avatarButtons}>
|
<View style={styles.avatarButtons}>
|
||||||
{this.renderAvatarButton({
|
{this.renderAvatarButton({
|
||||||
child: <Avatar text={`@${ user.username }`} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
|
child: <Avatar text={`@${ user.username }`} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
|
||||||
onPress: () => this.resetAvatar(),
|
onPress: () => this.resetAvatar(),
|
||||||
|
disabled: !Accounts_AllowUserAvatarChange,
|
||||||
key: 'profile-view-reset-avatar'
|
key: 'profile-view-reset-avatar'
|
||||||
})}
|
})}
|
||||||
{this.renderAvatarButton({
|
{this.renderAvatarButton({
|
||||||
child: <CustomIcon name='upload' size={30} color={themes[theme].bodyText} />,
|
child: <CustomIcon name='upload' size={30} color={themes[theme].bodyText} />,
|
||||||
onPress: () => this.pickImage(),
|
onPress: () => this.pickImage(),
|
||||||
|
disabled: !Accounts_AllowUserAvatarChange,
|
||||||
key: 'profile-view-upload-avatar'
|
key: 'profile-view-upload-avatar'
|
||||||
})}
|
})}
|
||||||
{this.renderAvatarButton({
|
{this.renderAvatarButton({
|
||||||
|
@ -303,6 +333,7 @@ class ProfileView extends React.Component {
|
||||||
{Object.keys(avatarSuggestions).map((service) => {
|
{Object.keys(avatarSuggestions).map((service) => {
|
||||||
const { url, blob, contentType } = avatarSuggestions[service];
|
const { url, blob, contentType } = avatarSuggestions[service];
|
||||||
return this.renderAvatarButton({
|
return this.renderAvatarButton({
|
||||||
|
disabled: !Accounts_AllowUserAvatarChange,
|
||||||
key: `profile-view-avatar-${ service }`,
|
key: `profile-view-avatar-${ service }`,
|
||||||
child: <Avatar avatar={url} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
|
child: <Avatar avatar={url} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
|
||||||
onPress: () => this.setAvatar({
|
onPress: () => this.setAvatar({
|
||||||
|
@ -381,7 +412,15 @@ class ProfileView extends React.Component {
|
||||||
name, username, email, newPassword, avatarUrl, customFields, avatar, saving, showPasswordAlert
|
name, username, email, newPassword, avatarUrl, customFields, avatar, saving, showPasswordAlert
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const {
|
const {
|
||||||
baseUrl, user, theme, Accounts_CustomFields
|
baseUrl,
|
||||||
|
user,
|
||||||
|
theme,
|
||||||
|
Accounts_AllowEmailChange,
|
||||||
|
Accounts_AllowPasswordChange,
|
||||||
|
Accounts_AllowRealNameChange,
|
||||||
|
Accounts_AllowUserAvatarChange,
|
||||||
|
Accounts_AllowUsernameChange,
|
||||||
|
Accounts_CustomFields
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -408,6 +447,10 @@ class ProfileView extends React.Component {
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<RCTextInput
|
<RCTextInput
|
||||||
|
editable={Accounts_AllowRealNameChange}
|
||||||
|
inputStyle={[
|
||||||
|
!Accounts_AllowRealNameChange && styles.disabled
|
||||||
|
]}
|
||||||
inputRef={(e) => { this.name = e; }}
|
inputRef={(e) => { this.name = e; }}
|
||||||
label={I18n.t('Name')}
|
label={I18n.t('Name')}
|
||||||
placeholder={I18n.t('Name')}
|
placeholder={I18n.t('Name')}
|
||||||
|
@ -418,6 +461,10 @@ class ProfileView extends React.Component {
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
<RCTextInput
|
<RCTextInput
|
||||||
|
editable={Accounts_AllowUsernameChange}
|
||||||
|
inputStyle={[
|
||||||
|
!Accounts_AllowUsernameChange && styles.disabled
|
||||||
|
]}
|
||||||
inputRef={(e) => { this.username = e; }}
|
inputRef={(e) => { this.username = e; }}
|
||||||
label={I18n.t('Username')}
|
label={I18n.t('Username')}
|
||||||
placeholder={I18n.t('Username')}
|
placeholder={I18n.t('Username')}
|
||||||
|
@ -428,6 +475,10 @@ class ProfileView extends React.Component {
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
<RCTextInput
|
<RCTextInput
|
||||||
|
editable={Accounts_AllowEmailChange}
|
||||||
|
inputStyle={[
|
||||||
|
!Accounts_AllowEmailChange && styles.disabled
|
||||||
|
]}
|
||||||
inputRef={(e) => { this.email = e; }}
|
inputRef={(e) => { this.email = e; }}
|
||||||
label={I18n.t('Email')}
|
label={I18n.t('Email')}
|
||||||
placeholder={I18n.t('Email')}
|
placeholder={I18n.t('Email')}
|
||||||
|
@ -438,6 +489,10 @@ class ProfileView extends React.Component {
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
<RCTextInput
|
<RCTextInput
|
||||||
|
editable={Accounts_AllowPasswordChange}
|
||||||
|
inputStyle={[
|
||||||
|
!Accounts_AllowPasswordChange && styles.disabled
|
||||||
|
]}
|
||||||
inputRef={(e) => { this.newPassword = e; }}
|
inputRef={(e) => { this.newPassword = e; }}
|
||||||
label={I18n.t('New_Password')}
|
label={I18n.t('New_Password')}
|
||||||
placeholder={I18n.t('New_Password')}
|
placeholder={I18n.t('New_Password')}
|
||||||
|
@ -455,6 +510,10 @@ class ProfileView extends React.Component {
|
||||||
/>
|
/>
|
||||||
{this.renderCustomFields()}
|
{this.renderCustomFields()}
|
||||||
<RCTextInput
|
<RCTextInput
|
||||||
|
editable={Accounts_AllowUserAvatarChange}
|
||||||
|
inputStyle={[
|
||||||
|
!Accounts_AllowUserAvatarChange && styles.disabled
|
||||||
|
]}
|
||||||
inputRef={(e) => { this.avatarUrl = e; }}
|
inputRef={(e) => { this.avatarUrl = e; }}
|
||||||
label={I18n.t('Avatar_Url')}
|
label={I18n.t('Avatar_Url')}
|
||||||
placeholder={I18n.t('Avatar_Url')}
|
placeholder={I18n.t('Avatar_Url')}
|
||||||
|
@ -499,6 +558,11 @@ class ProfileView extends React.Component {
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
user: getUserSelector(state),
|
user: getUserSelector(state),
|
||||||
|
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,
|
Accounts_CustomFields: state.settings.Accounts_CustomFields,
|
||||||
baseUrl: state.server.server
|
baseUrl: state.server.server
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { StyleSheet, Platform } from 'react-native';
|
import { StyleSheet, Platform } from 'react-native';
|
||||||
|
|
||||||
export default StyleSheet.create({
|
export default StyleSheet.create({
|
||||||
|
disabled: {
|
||||||
|
opacity: 0.3
|
||||||
|
},
|
||||||
avatarContainer: {
|
avatarContainer: {
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
|
Loading…
Reference in New Issue