Changeset 50030
- Timestamp:
- 01/27/2021 07:03:42 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/application-passwords.js
r50001 r50030 58 58 59 59 $newAppPassForm.after( tmplNewAppPass( { 60 name: name,60 name: response.name, 61 61 password: response.password 62 62 } ) ); -
trunk/src/js/_enqueues/admin/auth-app.js
r49920 r50030 99 99 100 100 // We're using .text() to write the variables to avoid any chance of XSS. 101 $( 'strong', $notice ).text( name );101 $( 'strong', $notice ).text( response.name ); 102 102 $( 'input', $notice ).val( response.password ); 103 103 -
trunk/src/wp-includes/class-wp-application-passwords.php
r49787 r50030 59 59 * 60 60 * @since 5.6.0 61 * @since 5.7.0 Returns WP_Error if application name already exists. 61 62 * 62 63 * @param int $user_id User ID. … … 66 67 */ 67 68 public static function create_new_application_password( $user_id, $args = array() ) { 69 if ( ! empty( $args['name'] ) ) { 70 $args['name'] = sanitize_text_field( $args['name'] ); 71 } 72 68 73 if ( empty( $args['name'] ) ) { 69 return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ) ); 74 return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) ); 75 } 76 77 if ( self::application_name_exists_for_user( $user_id, $args['name'] ) ) { 78 return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) ); 70 79 } 71 80 … … 164 173 165 174 /** 175 * Check if application name exists before for this user. 176 * 177 * @since 5.7.0 178 * 179 * @param int $user_id User ID. 180 * @param string $name Application name. 181 * 182 * @return bool Provided application name exists or not. 183 */ 184 public static function application_name_exists_for_user( $user_id, $name ) { 185 $passwords = static::get_user_application_passwords( $user_id ); 186 187 foreach ( $passwords as $password ) { 188 if ( strtolower( $password['name'] ) === strtolower( $name ) ) { 189 return true; 190 } 191 } 192 193 return false; 194 } 195 196 /** 166 197 * Updates an application password. 167 198 * … … 179 210 if ( $item['uuid'] !== $uuid ) { 180 211 continue; 212 } 213 214 if ( ! empty( $update['name'] ) ) { 215 $update['name'] = sanitize_text_field( $update['name'] ); 181 216 } 182 217 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php
r49617 r50030 632 632 'required' => true, 633 633 'context' => array( 'view', 'edit', 'embed' ), 634 'minLength' => 1, 635 'pattern' => '.*\S.*', 634 636 ), 635 637 'password' => array( -
trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
r49752 r50030 539 539 /** 540 540 * @ticket 51583 541 * @ticket 51941 541 542 */ 542 543 public function test_update_item_cannot_overwrite_app_id() { … … 555 556 self::$admin, 556 557 array( 557 'name' => 'App ',558 'name' => 'App 2', 558 559 'app_id' => $app_id, 559 560 ) -
trunk/tests/qunit/fixtures/wp-api-generated.js
r50024 r50030 4975 4975 "description": "The name of the application password.", 4976 4976 "type": "string", 4977 "minLength": 1, 4978 "pattern": ".*\\S.*", 4977 4979 "required": true 4978 4980 } … … 5031 5033 "description": "The name of the application password.", 5032 5034 "type": "string", 5035 "minLength": 1, 5036 "pattern": ".*\\S.*", 5033 5037 "required": false 5034 5038 }
Note: See TracChangeset
for help on using the changeset viewer.