Skip to content

Commit 2ed1355

Browse files
committed
Preventing users with external accounts to modify titles (as well as name and surname).
1 parent 8de72a7 commit 2ed1355

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

src/components/forms/EditUserProfileForm/EditUserProfileForm.js

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import isEmail from 'validator/lib/isEmail';
77
import FormBox from '../../widgets/FormBox';
88
import Callout from '../../widgets/Callout';
99
import SubmitButton from '../SubmitButton';
10+
import Explanation from '../../widgets/Explanation';
1011
import { SaveIcon } from '../../icons';
1112
import { validateRegistrationData } from '../../../redux/modules/users';
1213
import { TextField, PasswordField, PasswordStrength, CheckboxField } from '../Fields';
@@ -61,7 +62,20 @@ const EditUserProfileForm = ({
6162
component={TextField}
6263
maxLength={42}
6364
required
64-
label={<FormattedMessage id="app.editUserProfile.titlesBeforeName" defaultMessage="Prefix Title:" />}
65+
disabled={disabledNameChange}
66+
label={
67+
<>
68+
<FormattedMessage id="app.editUserProfile.titlesBeforeName" defaultMessage="Prefix Title:" />
69+
{disabledNameChange && (
70+
<Explanation id="titles-before-disabled">
71+
<FormattedMessage
72+
id="app.editUserProfile.disabledNameExplanation"
73+
defaultMessage="The name-related fields are disabled since this account was created and is managed by an external provider."
74+
/>
75+
</Explanation>
76+
)}
77+
</>
78+
}
6579
/>
6680

6781
<Field
@@ -70,7 +84,19 @@ const EditUserProfileForm = ({
7084
maxLength={100}
7185
required
7286
disabled={disabledNameChange}
73-
label={<FormattedMessage id="app.editUserProfile.firstName" defaultMessage="Given Name:" />}
87+
label={
88+
<>
89+
<FormattedMessage id="app.editUserProfile.firstName" defaultMessage="Given Name:" />
90+
{disabledNameChange && (
91+
<Explanation id="titles-before-disabled">
92+
<FormattedMessage
93+
id="app.editUserProfile.disabledNameExplanation"
94+
defaultMessage="The name-related fields are disabled since this account was created and is managed by an external provider."
95+
/>
96+
</Explanation>
97+
)}
98+
</>
99+
}
74100
/>
75101

76102
<Field
@@ -79,15 +105,40 @@ const EditUserProfileForm = ({
79105
maxLength={255}
80106
required
81107
disabled={disabledNameChange}
82-
label={<FormattedMessage id="app.editUserProfile.lastName" defaultMessage="Surname:" />}
108+
label={
109+
<>
110+
<FormattedMessage id="app.editUserProfile.lastName" defaultMessage="Surname:" />
111+
{disabledNameChange && (
112+
<Explanation id="titles-before-disabled">
113+
<FormattedMessage
114+
id="app.editUserProfile.disabledNameExplanation"
115+
defaultMessage="The name-related fields are disabled since this account was created and is managed by an external provider."
116+
/>
117+
</Explanation>
118+
)}
119+
</>
120+
}
83121
/>
84122

85123
<Field
86124
name="titlesAfterName"
87125
component={TextField}
88126
maxLength={42}
89127
required
90-
label={<FormattedMessage id="app.editUserProfile.titlesAfterName" defaultMessage="Suffix Title:" />}
128+
disabled={disabledNameChange}
129+
label={
130+
<>
131+
<FormattedMessage id="app.editUserProfile.titlesAfterName" defaultMessage="Suffix Title:" />
132+
{disabledNameChange && (
133+
<Explanation id="titles-before-disabled">
134+
<FormattedMessage
135+
id="app.editUserProfile.disabledNameExplanation"
136+
defaultMessage="The name-related fields are disabled since this account was created and is managed by an external provider."
137+
/>
138+
</Explanation>
139+
)}
140+
</>
141+
}
91142
/>
92143

93144
<Field

src/locales/cs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@
556556
"app.editUser.isEmailAlreadyVefiried": "Pokud jste právě ověřili vaši adresu a stále vidíte tuto hlášku, prosím občerstvěte stránku.",
557557
"app.editUser.makeLocal": "Vytvořit lokální účet",
558558
"app.editUser.title": "Upravit uživatelský profil",
559+
"app.editUserProfile.disabledNameExplanation": "Položky související se jménem není možné měnit, protože tento účet je spravován externí autoritou.",
559560
"app.editUserProfile.emptyLocalPassword": "Lokální účet nemá nastavené heslo.",
560561
"app.editUserProfile.emptyLocalPasswordExplain": "Nebudete se moci přihlásit do ReCodExu pomocí lokálního účtu, dokud si nenastavíte heslo.",
561562
"app.editUserProfile.firstName": "Jméno:",

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@
556556
"app.editUser.isEmailAlreadyVefiried": "If you have just verified your email and still see the message, please refresh the page.",
557557
"app.editUser.makeLocal": "Create local account",
558558
"app.editUser.title": "Edit User's Profile",
559+
"app.editUserProfile.disabledNameExplanation": "The name-related fields are disabled since this account was created and is managed by an external provider.",
559560
"app.editUserProfile.emptyLocalPassword": "Local account does not have a password.",
560561
"app.editUserProfile.emptyLocalPasswordExplain": "You may not sign in to ReCodEx using local account until you set the password.",
561562
"app.editUserProfile.firstName": "Given Name:",

src/pages/EditUser/EditUser.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ class EditUser extends Component {
7575

7676
updateProfile(data, changeNames) {
7777
const { updateProfile } = this.props;
78-
if (!changeNames) {
79-
delete data.firstName;
80-
delete data.lastName;
81-
}
82-
return updateProfile(data);
78+
const { titlesBeforeName, firstName, lastName, titlesAfterName, ...restData } = data;
79+
const transformedData = changeNames ? data : restData;
80+
return updateProfile(transformedData);
8381
}
8482

8583
setRole = ({ role }) => {

0 commit comments

Comments
 (0)