Skip to content

Feat/get user roles#1462

Merged
Qinyouzeng merged 3 commits intomainfrom
feat/get_user_roles
Jan 23, 2026
Merged

Feat/get user roles#1462
Qinyouzeng merged 3 commits intomainfrom
feat/get_user_roles

Conversation

@MayueCif
Copy link
Contributor

增加获取用户角色的接口

RoleSelectDto 类新增 CreationTime(创建时间)属性,移除无参构造函数,所有相关构造函数调用均需传入 CreationTime。同步调整 User.cs 和 QueryHandler.cs 中 RoleModel 及 RoleSelectDto 的创建逻辑,确保角色信息包含创建时间,便于前端展示和业务处理。
- 移除 RoleSelectDto 的 CreationTime 属性及相关参数,简化角色选择数据结构
- 新增 UserRoleDto 类,支持用户角色信息(编码、名称、绑定时间)
- 新增 UserRolesQuery 查询对象,实现按用户ID查询角色列表
- QueryHandler 增加 GetUserRolesAsync 方法,完善角色查询逻辑
- UserService 新增 GetUserRolesAsync 接口,路由为 /{id}/roles
- 补充部分文件的 Apache License 版权声明
- 提升用户角色相关功能的规范性和可维护性
Copilot AI review requested due to automatic review settings January 23, 2026 02:30
新增RoleSelectDto.CreationTime属性,并调整相关构造函数参数。同步更新QueryHandler中所有RoleSelectDto的创建逻辑,确保传递CreationTime字段,以便角色信息包含创建时间。
@Qinyouzeng Qinyouzeng merged commit 51caa5d into main Jan 23, 2026
1 check passed
@Qinyouzeng Qinyouzeng deleted the feat/get_user_roles branch January 23, 2026 02:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new API endpoint to retrieve user roles for a specific user. The main feature adds GET /api/user/{id}/roles endpoint that returns a list of enabled roles associated with a user, including role code, name, and the binding time. However, the PR has critical compilation issues due to a missing type definition.

Changes:

  • Added new GET endpoint /api/user/{id}/roles to retrieve user roles by user ID
  • Added query handler GetUserRolesAsync and query class UserRolesQuery to support the new endpoint
  • Enhanced RoleModel mapping in User.cs to include additional properties (CreationTime, ModificationTime, Enabled)
  • Added enabled role filtering to GetRoleSelectAsync method
  • Removed parameterless constructor from RoleSelectDto
  • Minor code formatting improvements

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Services/Masa.Auth.Service.Admin/Services/UserService.cs Adds new MapGet route for getting user roles endpoint
src/Services/Masa.Auth.Service.Admin/Application/Subjects/QueryHandler.cs Implements GetUserRolesAsync query handler to fetch enabled roles for a user
src/Services/Masa.Auth.Service.Admin/Application/Subjects/Queries/UserRolesQuery.cs Defines new query class for user roles retrieval
src/Services/Masa.Auth.Service.Admin/Application/Permissions/QueryHandler.cs Adds filtering for enabled roles in GetRoleSelectAsync helper method
src/Domain/Masa.Auth.Domain/Subjects/Aggregates/User.cs Enriches RoleModel with CreationTime, ModificationTime, and Enabled properties
src/Contracts/Masa.Auth.Contracts.Admin/Permissions/RoleSelectDto.cs Removes parameterless constructor
Comments suppressed due to low confidence (1)

src/Contracts/Masa.Auth.Contracts.Admin/Permissions/RoleSelectDto.cs:26

  • Removing the parameterless constructor may cause issues with serialization/deserialization in certain scenarios and breaks consistency with similar DTOs in the codebase (e.g., UserSelectDto in src/Contracts/Masa.Auth.Contracts.Admin/Subjects/UserSelectDto.cs:22). The Name and Code properties are non-nullable strings but are no longer initialized to empty strings when a parameterless constructor would be used. Consider keeping the parameterless constructor for compatibility, or verify that all serialization scenarios work correctly without it.
    public RoleSelectDto(Guid id, string name, string code, int limit, int availableQuantity)
    {
        Id = id;
        Name = name;
        Code = code;
        Limit = limit;
        AvailableQuantity = availableQuantity;
        CreationTime = creationTime;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Auth.Service.Admin.Application.Subjects.Queries;

Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UserRoleModel type does not exist in the codebase. This query definition will cause compilation errors. You need to either:

  1. Create a UserRoleModel class/record in the appropriate location (e.g., in src/Contracts/Masa.Auth.Contracts.Admin/Subjects/), or
  2. Use an existing type like RoleModel or RoleSelectDto

Based on the query handler implementation that uses Code, Name, and BindTime properties, you should create a new UserRoleModel with these properties.

Suggested change
public record UserRoleModel(string Code, string Name, DateTime BindTime);

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +215
.Select(ur => new UserRoleModel
{
Code = ur.Role.Code,
Name = ur.Role.Name,
BindTime = ur.CreationTime
})
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UserRoleModel type does not exist in the codebase, which will cause compilation errors. The query handler attempts to create instances of UserRoleModel with Code, Name, and BindTime properties, but this type is not defined anywhere in the repository or imported from external packages.

Copilot uses AI. Check for mistakes.
return query.Result;
}

public async Task<List<UserRoleModel>> GetUserRolesAsync(IEventBus eventBus, Guid id)
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UserRoleModel return type does not exist in the codebase, which will cause compilation errors. This endpoint cannot function until the UserRoleModel class/record is defined with the appropriate properties (Code, Name, BindTime based on the query handler implementation).

Copilot uses AI. Check for mistakes.
Comment on lines +212 to +214
Code = ur.Role.Code,
Name = ur.Role.Name,
BindTime = ur.CreationTime
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference exception when accessing ur.Role properties. The Where clause filters for ur.Role.Enabled, but if ur.Role is null at the time of Select, this will throw a NullReferenceException. Consider adding an additional null check in the Where clause or using null-conditional operators in the Select clause to make the code more defensive.

Copilot uses AI. Check for mistakes.
Comment on lines 16 to 19
MapGet(GetListByRoleAsync, "getListByRole");
MapGet(GetUserRolesAsync, "{id}/roles");
MapGet(GetClaimValuesAsync, "claim-values/{id}");
MapGet(GetClaimValuesAsync, "claim-values");
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to obsolete method MapGet.

Suggested change
MapGet(GetListByRoleAsync, "getListByRole");
MapGet(GetUserRolesAsync, "{id}/roles");
MapGet(GetClaimValuesAsync, "claim-values/{id}");
MapGet(GetClaimValuesAsync, "claim-values");
MapGet("getListByRole", GetListByRoleAsync);
MapGet("{id}/roles", GetUserRolesAsync);
MapGet("claim-values/{id}", GetClaimValuesAsync);
MapGet("claim-values", GetClaimValuesAsync);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments