Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2415)

Unified Diff: chrome/browser/resources/md_user_manager/create_profile.js

Issue 1826903002: updated UI, default profile name, check for existing supervised user before create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_user_manager/create_profile.js
diff --git a/chrome/browser/resources/md_user_manager/create_profile.js b/chrome/browser/resources/md_user_manager/create_profile.js
index c49d5f52318602c13429a637e76780316e52c346..29258b17de7f21a6f49aaf4e233ce2f6c437ee29 100644
--- a/chrome/browser/resources/md_user_manager/create_profile.js
+++ b/chrome/browser/resources/md_user_manager/create_profile.js
@@ -11,26 +11,19 @@
Polymer({
is: 'create-profile',
- behaviors: [WebUIListenerBehavior],
+ behaviors: [
+ I18nBehavior,
+ WebUIListenerBehavior
+ ],
properties: {
/**
- * True if supervised user checkbox is disabled.
- * @private {boolean}
- */
- supervisedUserCheckboxDisabled_: {
- type: Boolean,
- computed:
- 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)'
- },
-
- /**
* The current profile name.
* @private {string}
*/
profileName_: {
type: String,
- value: '',
+ value: ''
},
/**
@@ -91,9 +84,9 @@ Polymer({
* Index of the selected signed-in user.
* @private {number}
*/
- selectedEmail_: {
+ signedInUserIndex_: {
tommycli 2016/03/24 19:28:51 Just add a comment here that -1 means no user is s
Moe 2016/03/24 22:07:56 Done.
tommycli 2016/03/24 22:18:54 Can we make this a constant? NO_USER_SELECTED or s
Moe 2016/03/29 20:51:16 Done.
type: Number,
- value: 0
+ value: -1
},
/** @private {!signin.ProfileBrowserProxy} */
@@ -106,9 +99,7 @@ Polymer({
},
/** @override */
- attached: function() {
- this.resetForm_();
-
+ ready: function() {
this.addWebUIListener(
'create-profile-success', this.handleSuccess_.bind(this));
this.addWebUIListener(
@@ -118,6 +109,8 @@ Polymer({
this.addWebUIListener(
'profile-icons-received', this.handleProfileIcons_.bind(this));
this.addWebUIListener(
+ 'profile-defaults-received', this.handleProfileDefaults_.bind(this));
+ this.addWebUIListener(
'signedin-users-received', this.handleSignedInUsers_.bind(this));
this.browserProxy_.getAvailableIcons();
@@ -125,21 +118,6 @@ Polymer({
},
/**
- * Resets the state of the page.
- * @private
- */
- resetForm_: function() {
- this.profileName_ = '';
- this.availableIconUrls_ = [];
- this.profileIconUrl_ = '';
- this.createInProgress_ = false;
- this.message_ = '';
- this.isSupervised_ = false;
- this.signedInUsers_ = [];
- this.selectedEmail_ = 0;
- },
-
- /**
* Handler for when the profile icons are pushed from the browser.
* @param {!Array<string>} iconUrls
* @private
@@ -150,17 +128,25 @@ Polymer({
},
/**
- * Updates the signed-in users.
+ * Handler for when the profile defaults are pushed from the browser.
+ * @param {ProfileInfo} profileInfo Default Info for the new profile.
+ * @private
+ */
+ handleProfileDefaults_: function(profileInfo) {
+ this.profileName_ = profileInfo.name;
+ },
+
+ /**
+ * Handler for when signed-in users are pushed from the browser.
* @param {!Array<SignedInUser>} signedInUsers
* @private
*/
handleSignedInUsers_: function(signedInUsers) {
this.signedInUsers_ = signedInUsers;
- this.signedIn_ = signedInUsers.length > 0;
},
/**
- * Handler for the 'Learn More' button click event.
+ * Handler for the 'Learn More' link tap event.
* @param {!Event} event
* @private
*/
@@ -169,19 +155,85 @@ Polymer({
},
/**
- * Handler for the 'Ok' button click event.
+ * Handler for the 'Save' button tap event.
* @param {!Event} event
* @private
*/
onSaveTap_: function(event) {
this.createInProgress_ = true;
+
+ var signedInUser = this.signedInUsers_[this.signedInUserIndex_];
tommycli 2016/03/24 19:28:50 Is there anything to prevent Save from occuring if
Moe 2016/03/24 22:07:57 If the new profile is not marked to be supervised,
tommycli 2016/03/24 22:18:54 Relying on undefined was too subtle for me to unde
Moe 2016/03/29 20:51:16 Done.
+
+ if (!this.isSupervised_) {
+ this.createProfile_();
+ } else if (!signedInUser) {
+ this.handleMessage_(this.i18n('supervisorAccountNotSelectedError'));
+ this.createInProgress_ = false;
+ } else {
+ this.browserProxy_.getExistingSupervisedUsers(
+ signedInUser.profilePath).then(
+ this.createProfileIfValidSupervisedUser_.bind(this),
+ /** @param {*} error */
+ function(error) { this.handleMessage_(error); }.bind(this));
+ }
+ },
+
+ /**
+ * Checks if the entered name matches name of an existing supervised user.
+ * user. If yes, the user is prompted to import the existing supervised user.
Roger Tawa OOO till Jul 10th 2016/03/24 14:39:05 Remove "user."
Moe 2016/03/24 22:07:56 Done.
+ * If no, the new supervised profile gets created.
+ * @param {Array<SupervisedUser>} supervisedUsers The list of existing
+ * supervised users.
+ * @private
+ */
+ createProfileIfValidSupervisedUser_: function(supervisedUsers) {
+ for (var i = 0; i < supervisedUsers.length; ++i) {
+ if (supervisedUsers[i].name != this.profileName_)
+ continue;
+ // Check if another supervised user also exists with that name.
+ var nameIsUnique = true;
+ // Handling the case when multiple supervised users with the same
+ // name exist, but not all of them are on the device.
+ // If at least one is not imported, we want to offer that
+ // option to the user. This could happen due to a bug that allowed
+ // creating SUs with the same name (https://crbug.com/557445).
+ var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice;
+ for (var j = i + 1; j < supervisedUsers.length; ++j) {
+ if (supervisedUsers[j].name == this.profileName_) {
+ nameIsUnique = false;
+ allOnCurrentDevice = allOnCurrentDevice &&
+ supervisedUsers[j].onCurrentDevice;
+ }
+ }
+
+ this.handleMessage_(allOnCurrentDevice ?
+ this.i18n('managedProfilesExistingLocalSupervisedUser') :
+ this.i18n('manageProfilesExistingSupervisedUser',
+ HTMLEscape(elide(this.profileName_, /* maxLength */ 50))));
+
+ this.createInProgress_ = false;
+ return;
+ }
+ // No existing supervised user's name matches the entered profile name.
+ // Continue with creating the new supervised profile.
+ this.createProfile_();
+ },
+
+ /**
+ * Creates the new profile.
+ * @private
+ */
+ createProfile_: function() {
+ var signedInUser = this.signedInUsers_[this.signedInUserIndex_];
tommycli 2016/03/24 19:28:50 Same here. How do we prevent a -1 signedInUserInde
Moe 2016/03/24 22:07:56 Same here. We don't need to prevent it when the ne
tommycli 2016/03/24 22:18:54 Same comment as above, explicitly checking vs. the
Moe 2016/03/29 20:51:16 Done.
+ var supervisorProfilePath = signedInUser ? signedInUser.profilePath : '';
+
this.browserProxy_.createProfile(
this.profileName_, this.profileIconUrl_, this.isSupervised_,
- this.signedInUsers_[this.selectedEmail_].profilePath);
+ supervisorProfilePath);
},
/**
- * Handler for the 'Cancel' button click event.
+ * Handler for the 'Cancel' button tap event.
* @param {!Event} event
* @private
*/
@@ -230,6 +282,12 @@ Polymer({
handleMessage_: function(message) {
this.createInProgress_ = false;
this.message_ = message;
+
+ // TODO(mahmadi): attach handler to '#supervised-user-import-existing'
+ // in order to import supervised user with the given name.
+
+ // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate
+ // supervisor.
},
/**
@@ -244,30 +302,27 @@ Polymer({
},
/**
- * Computed binding determining whether 'Ok' button is disabled.
+ * Computed binding determining whether 'Save' button is disabled.
* @param {boolean} createInProgress Is create in progress?
* @param {string} profileName Profile Name.
- * @param {string} message Existing warning/error message.
* @return {boolean}
* @private
*/
- isOkDisabled_: function(createInProgress, profileName, message) {
+ isSaveDisabled_: function(createInProgress, profileName) {
tommycli 2016/03/24 19:28:50 How is this disabled if the selectedUserIndex = -1
Moe 2016/03/24 22:07:57 The button is not disabled in that case by design.
// TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
// dependency and cast to PaperInputElement instead.
/** @type {{validate: function():boolean}} */
var nameInput = this.$.nameInput;
- return createInProgress || !profileName || message != '' ||
- !nameInput.validate();
+ return createInProgress || !profileName || !nameInput.validate();
},
/**
- * Computed binding determining whether supervised user checkbox is disabled.
- * @param {boolean} createInProgress Is create in progress?
- * @param {boolean} signedIn Are there any signed-in users?
+ * Computed binding that returns True if there are any signed-in users.
+ * @param {!Array<SignedInUser>} signedInUsers signed-in users.
* @return {boolean}
* @private
*/
- isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
- return createInProgress || !signedIn;
+ isSignedIn_: function(signedInUsers) {
+ return signedInUsers.length > 0;
}
});

Powered by Google App Engine
This is Rietveld 408576698