Skip to content

Commit

Permalink
added real name change setting
Browse files Browse the repository at this point in the history
  • Loading branch information
AmShaegar13 committed Nov 24, 2017
1 parent 62ef697 commit 16a4fd4
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 83 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"Accounts_AllowEmailChange": "Ändern der E-Mail-Adresse erlauben",
"Accounts_AllowPasswordChange": "Ändern des Passworts erlauben",
"Accounts_AllowUserAvatarChange": "Benutzern das Ändern des Profilbilds erlauben",
"Accounts_AllowRealNameChange": "Ändern des Namens erlauben",
"Accounts_AllowUsernameChange": "Ändern des Benutzernamens erlauben",
"Accounts_AllowUserProfileChange": "Benutzern das Ändern des Profils erlauben",
"Accounts_AvatarResize": "Größe des Profilbilds anpassen",
Expand Down Expand Up @@ -1424,6 +1425,7 @@
"Read_only_changed_successfully": "Erfolgreich schreibgeschützt",
"Read_only_channel": "Kanal schreibgeschützt",
"Read_only_group": "Schreibgeschützte Gruppe",
"RealName_Change_Disabled": "Der Administrator hat das Ändern von Namen deaktiviert",
"Record": "Aufnehmen",
"Redirect_URI": "Weiterleitungs-URL",
"Refresh_keys": "Schlüssel aktualisieren",
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"Accounts_AllowEmailChange": "Allow Email Change",
"Accounts_AllowPasswordChange": "Allow Password Change",
"Accounts_AllowUserAvatarChange": "Allow User Avatar Change",
"Accounts_AllowRealNameChange": "Allow Name Change",
"Accounts_AllowUsernameChange": "Allow Username Change",
"Accounts_AllowUserProfileChange": "Allow User Profile Change",
"Accounts_AvatarResize": "Resize Avatars",
Expand Down Expand Up @@ -1456,6 +1457,7 @@
"Read_only_changed_successfully": "Read only changed successfully",
"Read_only_channel": "Read Only Channel",
"Read_only_group": "Read Only Group",
"RealName_Change_Disabled": "Your Rocket.Chat administrator has disabled the changing of names",
"Record": "Record",
"Redirect_URI": "Redirect URI",
"Refresh_keys": "Refresh keys",
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/methods/setRealName.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setRealName' });
}

if (!RocketChat.settings.get('Accounts_AllowRealNameChange')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setRealName' });
}

if (!RocketChat.setRealName(Meteor.userId(), name)) {
throw new Meteor.Error('error-could-not-change-name', 'Could not change name', { method: 'setRealName' });
}
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ RocketChat.settings.addGroup('Accounts', function() {
type: 'boolean',
'public': true
});
this.add('Accounts_AllowRealNameChange', true, {
type: 'boolean',
'public': true
});
this.add('Accounts_AllowUsernameChange', true, {
type: 'boolean',
'public': true
Expand Down
7 changes: 6 additions & 1 deletion packages/rocketchat-ui-account/client/accountProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ <h2 style="flex: 1 1; white-space: nowrap;">{{_ "Profile"}}</h2>
</div>
</div>
<div class="rc-form-group rc-grid">
{{# with canChange=allowRealNameChange}}
<div class="rc-input rc-w50 padded {{#if nameInvalid}}rc-input--error{{/if}}">
<label class="rc-input__label">
<div class="rc-input__title">{{_ "Name"}}</div>
<div class="rc-input__wrapper">
<input type="text" class="rc-input__element" name="realname" id="realname" placeholder="{{_ "Name_Placeholder" }}" value="{{realname}}" >
<input type="text" class="rc-input__element" name="realname" id="realname" placeholder="{{_ "Name_Placeholder" }}" value="{{realname}}" {{ifThenElse canChange '' 'disabled'}}>
</div>
</label>
{{# unless canChange}}
<div class="rc-input__description">{{_ 'RealName_Change_Disabled'}}</div>
{{/unless}}
</div>
{{/with}}
{{# with canChange=allowUsernameChange}}
<div class="rc-input rc-w50 padded {{#if usernameInvalid}}rc-input--error{{/if}} {{#unless usernameAvaliable}}rc-input--error{{/unless}}">
<label class="rc-input__label">
Expand Down
12 changes: 11 additions & 1 deletion packages/rocketchat-ui-account/client/accountProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ Template.accountProfile.helpers({
const user = Meteor.user();
return user.emails && user.emails[0] && user.emails[0].verified;
},
allowRealNameChange() {
return RocketChat.settings.get('Accounts_AllowRealNameChange');
},
allowUsernameChange() {
return RocketChat.settings.get('Accounts_AllowUsernameChange') && RocketChat.settings.get('LDAP_Enable') !== true;
},
Expand Down Expand Up @@ -203,7 +206,14 @@ Template.accountProfile.onCreated(function() {
data.newPassword = self.password.get();
}
if (s.trim(self.realname.get()) !== user.name) {
data.realname = s.trim(self.realname.get());
if (!RocketChat.settings.get('Accounts_AllowRealNameChange')) {
toastr.remove();
toastr.error(t('RealName_Change_Disabled'));
instance.clearForm();
return cb && cb();
} else {
data.realname = s.trim(self.realname.get());
}
}
if (s.trim(self.username.get()) !== user.username) {
if (!RocketChat.settings.get('Accounts_AllowUsernameChange')) {
Expand Down
215 changes: 134 additions & 81 deletions tests/end-to-end/ui/10-user-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,118 +5,171 @@ import flexTab from '../../pageobjects/flex-tab.page';
import mainContent from '../../pageobjects/main-content.page';
import sideNav from '../../pageobjects/side-nav.page';
import preferencesMainContent from '../../pageobjects/preferences-main-content.page';
import admin from '../../pageobjects/administration.page';

import {username, password, email} from '../../data/user.js';
import {username, password, email, adminUsername, adminEmail, adminPassword} from '../../data/user.js';
// import {imgURL} from '../../data/interactions.js';

import {checkIfUserIsValid} from '../../data/checks';
import {checkIfUserIsValid, checkIfUserIsAdmin} from '../../data/checks';


describe('[User Preferences]', ()=> {
before(() => {
checkIfUserIsValid(username, email, password);
sideNav.spotlightSearch.waitForVisible(10000);
sideNav.searchChannel('general');

sideNav.accountMenu.waitForVisible();
sideNav.accountMenu.click();
sideNav.account.waitForVisible();
sideNav.account.click();
});
describe('default', () => {
before(() => {
checkIfUserIsValid(username, email, password);
sideNav.spotlightSearch.waitForVisible(10000);
sideNav.searchChannel('general');

describe('render:', ()=> {
it('it should show the preferences link', ()=> {
sideNav.preferences.isVisible().should.be.true;
sideNav.accountMenu.waitForVisible();
sideNav.accountMenu.click();
sideNav.account.waitForVisible();
sideNav.account.click();
});

it('it should show the profile link', ()=> {
sideNav.profile.isVisible().should.be.true;
});
describe('render:', () => {
it('it should show the preferences link', () => {
sideNav.preferences.isVisible().should.be.true;
});

it('it should click on the profile link', ()=> {
sideNav.profile.click();
});
it('it should show the profile link', () => {
sideNav.profile.isVisible().should.be.true;
});

it('it should show the username input', ()=> {
preferencesMainContent.userNameTextInput.isVisible().should.be.true;
});
it('it should click on the profile link', () => {
sideNav.profile.click();
});

it('it should show the real name input', ()=> {
preferencesMainContent.realNameTextInput.isVisible().should.be.true;
});
it('it should show the username input', () => {
preferencesMainContent.userNameTextInput.isVisible().should.be.true;
});

it('it should show the email input', ()=> {
preferencesMainContent.emailTextInput.isVisible().should.be.true;
});
it('it should show the real name input', () => {
preferencesMainContent.realNameTextInput.isVisible().should.be.true;
});

it('it should show the password input', ()=> {
preferencesMainContent.passwordTextInput.isVisible().should.be.true;
});
it('it should show the email input', () => {
preferencesMainContent.emailTextInput.isVisible().should.be.true;
});

it('it should show the submit button', ()=> {
preferencesMainContent.submitBtn.isVisible().should.be.true;
});
it('it should show the password input', () => {
preferencesMainContent.passwordTextInput.isVisible().should.be.true;
});

});
it('it should show the submit button', () => {
preferencesMainContent.submitBtn.isVisible().should.be.true;
});

describe('user info change:', ()=> {
it('it should click on the profile link', ()=> {
sideNav.profile.click();
});

it('it should change the name field', ()=> {
preferencesMainContent.changeRealName(`EditedRealName${ username }`);
});
describe('user info change:', () => {
it('it should click on the profile link', () => {
sideNav.profile.click();
});

it('it should change the Username field', ()=> {
preferencesMainContent.changeUsername(`EditedUserName${ username }`);
});
it('it should change the name field', () => {
preferencesMainContent.changeRealName(`EditedRealName${ username }`);
});

it.skip('it should change the email field', ()=> {
preferencesMainContent.changeEmail(`EditedUserEmail${ username }@gmail.com`);
});
it('it should change the Username field', () => {
preferencesMainContent.changeUsername(`EditedUserName${ username }`);
});

it('it should save the settings', ()=> {
preferencesMainContent.saveChanges();
});
it.skip('it should change the email field', () => {
preferencesMainContent.changeEmail(`EditedUserEmail${ username }@gmail.com`);
});

it.skip('it should put the password in the sweet alert input', ()=> {
preferencesMainContent.acceptPasswordOverlay(password);
});
it('it should save the settings', () => {
preferencesMainContent.saveChanges();
});

it('it should close the preferences menu', () => {
sideNav.preferencesClose.waitForVisible(5000);
sideNav.preferencesClose.click();
sideNav.getChannelFromList('general').waitForVisible(5000);
});
it.skip('it should put the password in the sweet alert input', () => {
preferencesMainContent.acceptPasswordOverlay(password);
});

it('it should open GENERAL', () => {
sideNav.searchChannel('general');
});
it('it should close the preferences menu', () => {
sideNav.preferencesClose.waitForVisible(5000);
sideNav.preferencesClose.click();
sideNav.getChannelFromList('general').waitForVisible(5000);
});

it('it should send a message to be tested', () => {
mainContent.sendMessage('HI');
mainContent.waitForLastMessageEqualsText('HI');
});
it('it should open GENERAL', () => {
sideNav.searchChannel('general');
});

it.skip('it should be that the name on the last message is the edited one', () => {
mainContent.waitForLastMessageUserEqualsText(`EditedUserName${ username }`);
mainContent.lastMessageUser.getText().should.equal(`EditedUserName${ username }`);
});
it('it should send a message to be tested', () => {
mainContent.sendMessage('HI');
mainContent.waitForLastMessageEqualsText('HI');
});

it('it should be that the name on the nav bar is the edited one', () => {
sideNav.accountBoxUserName.getText().should.equal(`@EditeduserName${ username }`.toLowerCase());
});
it.skip('it should be that the name on the last message is the edited one', () => {
mainContent.waitForLastMessageUserEqualsText(`EditedUserName${ username }`);
mainContent.lastMessageUser.getText().should.equal(`EditedUserName${ username }`);
});

it.skip('it should be that the user name on the members flex tab is the edited one', () => {
mainContent.lastMessageUser.click();
flexTab.memberUserName.waitForVisible(5000);
flexTab.memberUserName.getText().should.equal(`EditedUserName${ username }`);
it('it should be that the name on the nav bar is the edited one', () => {
sideNav.accountBoxUserName.getText().should.equal(`@EditeduserName${ username }`.toLowerCase());
});

it.skip('it should be that the user name on the members flex tab is the edited one', () => {
mainContent.lastMessageUser.click();
flexTab.memberUserName.waitForVisible(5000);
flexTab.memberUserName.getText().should.equal(`EditedUserName${ username }`);
});

it.skip('it should that the real name on the members flex tab is the edited one', () => {
flexTab.memberRealName.waitForVisible(5000);
flexTab.memberRealName.getText().should.equal(`EditedRealName${ username }`);
});
});
});

it.skip('it should that the real name on the members flex tab is the edited one', () => {
flexTab.memberRealName.waitForVisible(5000);
flexTab.memberRealName.getText().should.equal(`EditedRealName${ username }`);
describe('admin', () => {
describe('user info change forbidden:', () => {
before(() => {
checkIfUserIsAdmin(adminUsername, adminEmail, adminPassword);
admin.open('admin/Accounts');
admin.accountsRealNameChangeFalse.waitForVisible(5000);
admin.accountsRealNameChangeFalse.click();
admin.adminSaveChanges();
admin.accountsUsernameChangeFalse.waitForVisible(5000);
admin.accountsUsernameChangeFalse.click();
admin.adminSaveChanges();
admin.settingsSearch.setValue('');
sideNav.preferencesClose.click();
sideNav.spotlightSearch.waitForVisible(10000);
sideNav.searchChannel('general');
});

after(() => {
admin.open('admin/Accounts');
admin.accountsRealNameChangeTrue.waitForVisible(5000);
admin.accountsRealNameChangeTrue.click();
admin.adminSaveChanges();
admin.accountsUsernameChangeTrue.waitForVisible(5000);
admin.accountsUsernameChangeTrue.click();
admin.adminSaveChanges();
admin.settingsSearch.setValue('');
sideNav.preferencesClose.waitForVisible(5000);
sideNav.preferencesClose.click();
});

it('it should open profile', () => {
sideNav.accountMenu.click();
sideNav.account.click();
sideNav.profile.click();
});

it('it should be that the name field is disabled', ()=> {
preferencesMainContent.realNameTextInputEnabled().should.be.false;
});

it('it should be that the Username field is disabled', ()=> {
preferencesMainContent.userNameTextInputEnabled().should.be.false;
});

it('it should close profile', ()=> {
sideNav.preferencesClose.click();
});
});
});
});
16 changes: 16 additions & 0 deletions tests/pageobjects/administration.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Administration extends Page {
get infoLink() { return browser.element('.flex-nav [href="/admin/info"]'); }
get roomsLink() { return browser.element('.flex-nav [href="/admin/rooms"]'); }
get usersLink() { return browser.element('.flex-nav [href="/admin/users"]'); }
get accountsLink() { return browser.element('.flex-nav [href="/admin/Accounts"]'); }
get generalLink() { return browser.element('.flex-nav [href="/admin/General"]'); }
get permissionsLink() { return browser.element('.flex-nav [href="/admin/permissions"]'); }
get customScriptBtn() { return browser.element('.section:nth-of-type(6) .collapse'); }
Expand Down Expand Up @@ -62,6 +63,8 @@ class Administration extends Page {
get emojiFilter() { return browser.element('#emoji-filter'); }

//settings
get buttonSave() { return browser.element('button.save'); }

get generalButtonExpandIframe() { return browser.element('.section:nth-of-type(2) .button.expand'); }
get generalButtonExpandNotifications() { return browser.element('.section:nth-of-type(3) .button.expand'); }
get generalButtonExpandRest() { return browser.element('.section:nth-of-type(4) .button.expand'); }
Expand Down Expand Up @@ -119,6 +122,11 @@ class Administration extends Page {
get generalUTF8NamesSlugFalse() { return browser.element('label:nth-of-type(2) [name="UTF8_Names_Slugify"]'); }
get generalUTF8NamesSlugReset() { return browser.element('.reset-setting[data-setting="UTF8_Names_Slugify"]'); }

get accountsRealNameChangeTrue() { return browser.element('label:nth-of-type(1) [name="Accounts_AllowRealNameChange"]'); }
get accountsRealNameChangeFalse() { return browser.element('label:nth-of-type(2) [name="Accounts_AllowRealNameChange"]'); }
get accountsUsernameChangeTrue() { return browser.element('label:nth-of-type(1) [name="Accounts_AllowUsernameChange"]'); }
get accountsUsernameChangeFalse() { return browser.element('label:nth-of-type(2) [name="Accounts_AllowUsernameChange"]'); }

checkUserList(user) {
const element = browser.element(`td=adminCreated${ user }`);
element.waitForVisible(5000);
Expand All @@ -136,6 +144,14 @@ class Administration extends Page {
element.waitForVisible(5000);
return element;
}

adminSaveChanges() {
this.buttonSave.waitForVisible(5000);
browser.waitUntil(function() {
return browser.isEnabled('button.save');
}, 5000);
this.buttonSave.click();
}
}

module.exports = new Administration();
Loading

0 comments on commit 16a4fd4

Please sign in to comment.