5d7c10aeab
- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__. - Changed message types in support host bridge from "cs-agent" to "cs-ai-agent". - Minified SDK script updated to reflect new AI agent naming conventions. - Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package builders
|
|
|
|
import (
|
|
"cs-ai-agent/internal/models"
|
|
"cs-ai-agent/internal/pkg/dto/response"
|
|
"cs-ai-agent/internal/pkg/utils"
|
|
"cs-ai-agent/internal/services"
|
|
)
|
|
|
|
type UserBuildOptions struct {
|
|
Roles bool
|
|
Permissions bool
|
|
}
|
|
|
|
func BuildUserList(items []models.User, options UserBuildOptions) []response.UserResponse {
|
|
results := make([]response.UserResponse, 0, len(items))
|
|
for _, item := range items {
|
|
results = append(results, *BuildUserResponse(&item, options))
|
|
}
|
|
return results
|
|
}
|
|
|
|
func BuildUserResponse(item *models.User, options UserBuildOptions) *response.UserResponse {
|
|
if item == nil {
|
|
return nil
|
|
}
|
|
ret := &response.UserResponse{
|
|
ID: item.ID,
|
|
Username: item.Username,
|
|
Nickname: item.Nickname,
|
|
Avatar: item.Avatar,
|
|
Status: item.Status,
|
|
LastLoginAt: utils.FormatTimePtr(item.LastLoginAt),
|
|
LastLoginIP: item.LastLoginIP,
|
|
}
|
|
|
|
if item.Mobile != nil {
|
|
ret.Mobile = *item.Mobile
|
|
}
|
|
if item.Email != nil {
|
|
ret.Email = *item.Email
|
|
}
|
|
|
|
if options.Roles {
|
|
ret.Roles = buildAssignedRoles(item.ID)
|
|
}
|
|
if options.Permissions {
|
|
permissionCodes, _ := services.AuthService.GetUserPermissions(item.ID)
|
|
ret.Permissions = permissionCodes
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func buildAssignedRoles(userID int64) []response.RoleResponse {
|
|
roles, _ := services.AuthService.GetUserRoles(userID)
|
|
results := make([]response.RoleResponse, 0, len(roles))
|
|
for _, role := range roles {
|
|
results = append(results, response.RoleResponse{
|
|
ID: role.ID,
|
|
Name: role.Name,
|
|
Code: role.Code,
|
|
Status: role.Status,
|
|
IsSystem: role.IsSystem,
|
|
SortNo: role.SortNo,
|
|
})
|
|
}
|
|
return results
|
|
}
|