🐛 Fix get user grpc method didn't extend group's permission

This commit is contained in:
LittleSheep 2024-11-23 20:24:11 +08:00
parent f89a2244ea
commit bc5a0ea966
2 changed files with 18 additions and 1 deletions

4
.idea/workspace.xml generated
View File

@ -4,7 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Support jwks.json according OIDC stranded" /> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Support jwks.json according OIDC stranded">
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/user.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/user.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />

View File

@ -6,6 +6,7 @@ import (
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models" "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database" "git.solsynth.dev/hypernet/passport/pkg/internal/database"
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
"github.com/samber/lo" "github.com/samber/lo"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -24,6 +25,20 @@ func (v *App) GetUser(ctx context.Context, request *proto.GetUserRequest) (*prot
if err := tx.First(&account).Error; err != nil { if err := tx.First(&account).Error; err != nil {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("requested user with id %d was not found", request.GetUserId())) return nil, status.Errorf(codes.NotFound, fmt.Sprintf("requested user with id %d was not found", request.GetUserId()))
} }
groups, err := services.GetUserAccountGroup(account)
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("unable to get user %d groups: %v", request.GetUserId(), err))
}
for _, group := range groups {
for k, v := range group.PermNodes {
if _, ok := account.PermNodes[k]; !ok {
account.PermNodes[k] = v
}
}
}
return account.EncodeToUserInfo(), nil return account.EncodeToUserInfo(), nil
} }