abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.27k stars 3.32k forks source link

cannot update the property extraProperties of AbpUser #19617

Closed CY-Ye closed 1 week ago

CY-Ye commented 1 week ago

env:

abp framework: 8.0.4/8.1.1

description

I found that I couldn't update the extraProperties property of AbpUser after upgrade to 8.0.4/8.1.1. I think it bug of abp, because this bug also occurs in new projects created by abp cli 8.1.1

Test:

request:

curl -X 'PUT' \
  'https://localhost:44353/api/identity/users/3a1226a7-fd14-ebd1-1e75-7f765dd5c05b' \
  -H 'accept: text/plain' \
  -H 'Content-Type: application/json' \
  -H 'RequestVerificationToken: CfDJ8Kycf0Hh9QBMg2Me4uFUd2kQFq2hx7vJqZh_eyX3j2AvJfhdm2hzBeHDV6e2A0E4RGlfnvIOZ6UmVQpVc2yzv4WRHngo25RF50E5yMD6oSpS3PW4MH1c8-g2sTvE0c9J9Y2NWyKql5TCw6Y-KT8ZEBVHSyQ-pzMq3sc9vWd-fk-WJmiOlrjaLx1B1dl7Tcbx3A' \
  -H 'X-Requested-With: XMLHttpRequest' \
  -d '{
      "tenantId": null,
      "userName": "admin",
      "name": "admin",
      "surname": null,
      "email": "admin@abp.io",
      "emailConfirmed": false,
      "phoneNumber": null,
      "phoneNumberConfirmed": false,
      "isActive": true,
      "lockoutEnabled": true,
      "accessFailedCount": 0,
      "lockoutEnd": null,
      "concurrencyStamp": "ea8e4579fa8046eeb6f82a324cde944f",
      "entityVersion": 0,
      "lastPasswordChangeTime": "2024-04-25T16:59:25.886601+08:00",
      "isDeleted": false,
      "deleterId": null,
      "deletionTime": null,
      "lastModificationTime": null,
      "lastModifierId": null,
      "creationTime": "2024-04-25T16:59:26.007458",
      "creatorId": null,
      "id": "3a1226a7-fd14-ebd1-1e75-7f765dd5c05b",
      "extraProperties": {"age":20}
    }'

Response body

{
  "tenantId": null,
  "userName": "admin",
  "name": "admin",
  "surname": null,
  "email": "admin@abp.io",
  "emailConfirmed": false,
  "phoneNumber": null,
  "phoneNumberConfirmed": false,
  "isActive": true,
  "lockoutEnabled": true,
  "accessFailedCount": 0,
  "lockoutEnd": null,
  "concurrencyStamp": "6be0d79be9e04fc4b0a6b1fd1307516f",
  "entityVersion": 1,
  "lastPasswordChangeTime": "2024-04-25T16:59:25.886601+08:00",
  "isDeleted": false,
  "deleterId": null,
  "deletionTime": null,
  "lastModificationTime": "2024-04-25T17:17:10.9881531+08:00",
  "lastModifierId": "3a1226a7-fd14-ebd1-1e75-7f765dd5c05b",
  "creationTime": "2024-04-25T16:59:26.007458",
  "creatorId": null,
  "id": "3a1226a7-fd14-ebd1-1e75-7f765dd5c05b",
  "extraProperties": {}
}
realLiangshiwei commented 1 week ago

Please share a small project to reproduce the problem

CY-Ye commented 1 week ago

Please share a small project to reproduce the problem

https://github.com/CY-Ye/TestUpdateExtraProperties thanks

realLiangshiwei commented 1 week ago

Try something like this:

ObjectExtensionManager.Instance.Modules()
              .ConfigureIdentity(identity =>
              {
                  identity.ConfigureUser(user =>
                  {
                      user.AddOrUpdateProperty<string>( //property type: string
                          "SocialSecurityNumber", //property name
                          property =>
                          {
                              //validation rules
                              property.Attributes.Add(new RequiredAttribute());
                              property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4});

                              property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true;

                              //...other configurations for this property
                          }
                      );
                  });
              });
CY-Ye commented 1 week ago

@realLiangshiwei it is worked. thank you!