Skip to content
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

[IMPROVEMENT] Honor profile fields edit settings #1687

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/constants/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
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: {
type: 'valueAsString'
},
Expand Down
68 changes: 66 additions & 2 deletions app/views/ProfileView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ 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,
theme: PropTypes.string
Expand Down Expand Up @@ -98,6 +103,12 @@ class ProfileView extends React.Component {
}

setAvatar = (avatar) => {
const { Accounts_AllowUserAvatarChange } = this.props;

if (!Accounts_AllowUserAvatarChange) {
return;
}

this.setState({ avatar });
}

Expand Down Expand Up @@ -233,6 +244,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);
Expand All @@ -244,6 +261,12 @@ class ProfileView extends React.Component {
}

pickImage = async() => {
const { Accounts_AllowUserAvatarChange } = this.props;

if (!Accounts_AllowUserAvatarChange) {
return;
}

const options = {
cropping: true,
compressImageQuality: 0.8,
Expand Down Expand Up @@ -280,18 +303,25 @@ 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 (
<View style={styles.avatarButtons}>
{this.renderAvatarButton({
child: <Avatar text={`@${ user.username }`} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
onPress: () => this.resetAvatar(),
disabled: !Accounts_AllowUserAvatarChange,
key: 'profile-view-reset-avatar'
})}
{this.renderAvatarButton({
child: <CustomIcon name='upload' size={30} color={themes[theme].bodyText} />,
onPress: () => this.pickImage(),
disabled: !Accounts_AllowUserAvatarChange,
key: 'profile-view-upload-avatar'
})}
{this.renderAvatarButton({
Expand All @@ -303,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: <Avatar avatar={url} size={50} baseUrl={baseUrl} userId={user.id} token={user.token} />,
onPress: () => this.setAvatar({
Expand Down Expand Up @@ -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_CustomFields
baseUrl,
user,
theme,
Accounts_AllowEmailChange,
Accounts_AllowPasswordChange,
Accounts_AllowRealNameChange,
Accounts_AllowUserAvatarChange,
Accounts_AllowUsernameChange,
Accounts_CustomFields
} = this.props;

return (
Expand All @@ -408,6 +447,10 @@ class ProfileView extends React.Component {
/>
</View>
<RCTextInput
editable={Accounts_AllowRealNameChange}
inputStyle={[
!Accounts_AllowRealNameChange && styles.disabled
]}
inputRef={(e) => { this.name = e; }}
label={I18n.t('Name')}
placeholder={I18n.t('Name')}
Expand All @@ -418,6 +461,10 @@ class ProfileView extends React.Component {
theme={theme}
/>
<RCTextInput
editable={Accounts_AllowUsernameChange}
inputStyle={[
!Accounts_AllowUsernameChange && styles.disabled
]}
inputRef={(e) => { this.username = e; }}
label={I18n.t('Username')}
placeholder={I18n.t('Username')}
Expand All @@ -428,6 +475,10 @@ class ProfileView extends React.Component {
theme={theme}
/>
<RCTextInput
editable={Accounts_AllowEmailChange}
inputStyle={[
!Accounts_AllowEmailChange && styles.disabled
]}
inputRef={(e) => { this.email = e; }}
label={I18n.t('Email')}
placeholder={I18n.t('Email')}
Expand All @@ -438,6 +489,10 @@ class ProfileView extends React.Component {
theme={theme}
/>
<RCTextInput
editable={Accounts_AllowPasswordChange}
inputStyle={[
!Accounts_AllowPasswordChange && styles.disabled
]}
inputRef={(e) => { this.newPassword = e; }}
label={I18n.t('New_Password')}
placeholder={I18n.t('New_Password')}
Expand All @@ -455,6 +510,10 @@ class ProfileView extends React.Component {
/>
{this.renderCustomFields()}
<RCTextInput
editable={Accounts_AllowUserAvatarChange}
inputStyle={[
!Accounts_AllowUserAvatarChange && styles.disabled
]}
inputRef={(e) => { this.avatarUrl = e; }}
label={I18n.t('Avatar_Url')}
placeholder={I18n.t('Avatar_Url')}
Expand Down Expand Up @@ -499,6 +558,11 @@ class ProfileView extends React.Component {

const mapStateToProps = 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,
baseUrl: state.server.server
});
Expand Down
3 changes: 3 additions & 0 deletions app/views/ProfileView/styles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { StyleSheet, Platform } from 'react-native';

export default StyleSheet.create({
disabled: {
opacity: 0.3
},
avatarContainer: {
alignItems: 'center',
justifyContent: 'center',
Expand Down