Supply access policy in grpc get realms

This commit is contained in:
LittleSheep 2024-09-17 16:54:45 +08:00
parent 4b4eb3e581
commit 7a9e31fd86

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto" "git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
@ -20,12 +21,13 @@ func (v *Server) ListCommunityRealm(ctx context.Context, empty *proto.ListRealmR
return &proto.ListRealmResponse{ return &proto.ListRealmResponse{
Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo { Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo {
info := &proto.RealmInfo{ info := &proto.RealmInfo{
Id: uint64(item.ID), Id: uint64(item.ID),
Alias: item.Alias, Alias: item.Alias,
Name: item.Name, Name: item.Name,
Description: item.Description, Description: item.Description,
IsPublic: item.IsPublic, IsPublic: item.IsPublic,
IsCommunity: item.IsCommunity, IsCommunity: item.IsCommunity,
AccessPolicy: hyper.EncodeAccessPolicy(item.AccessPolicy),
} }
if item.Avatar != nil { if item.Avatar != nil {
info.Avatar = *item.Avatar info.Avatar = *item.Avatar
@ -51,12 +53,13 @@ func (v *Server) ListAvailableRealm(ctx context.Context, request *proto.LookupUs
return &proto.ListRealmResponse{ return &proto.ListRealmResponse{
Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo { Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo {
info := &proto.RealmInfo{ info := &proto.RealmInfo{
Id: uint64(item.ID), Id: uint64(item.ID),
Alias: item.Alias, Alias: item.Alias,
Name: item.Name, Name: item.Name,
Description: item.Description, Description: item.Description,
IsPublic: item.IsPublic, IsPublic: item.IsPublic,
IsCommunity: item.IsCommunity, IsCommunity: item.IsCommunity,
AccessPolicy: hyper.EncodeAccessPolicy(item.AccessPolicy),
} }
if item.Avatar != nil { if item.Avatar != nil {
info.Avatar = *item.Avatar info.Avatar = *item.Avatar
@ -82,12 +85,13 @@ func (v *Server) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRe
return &proto.ListRealmResponse{ return &proto.ListRealmResponse{
Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo { Data: lo.Map(realms, func(item models.Realm, index int) *proto.RealmInfo {
info := &proto.RealmInfo{ info := &proto.RealmInfo{
Id: uint64(item.ID), Id: uint64(item.ID),
Alias: item.Alias, Alias: item.Alias,
Name: item.Name, Name: item.Name,
Description: item.Description, Description: item.Description,
IsPublic: item.IsPublic, IsPublic: item.IsPublic,
IsCommunity: item.IsCommunity, IsCommunity: item.IsCommunity,
AccessPolicy: hyper.EncodeAccessPolicy(item.AccessPolicy),
} }
if item.Avatar != nil { if item.Avatar != nil {
info.Avatar = *item.Avatar info.Avatar = *item.Avatar
@ -122,12 +126,13 @@ func (v *Server) GetRealm(ctx context.Context, request *proto.LookupRealmRequest
} }
info := &proto.RealmInfo{ info := &proto.RealmInfo{
Id: uint64(realm.ID), Id: uint64(realm.ID),
Alias: realm.Alias, Alias: realm.Alias,
Name: realm.Name, Name: realm.Name,
Description: realm.Description, Description: realm.Description,
IsPublic: realm.IsPublic, IsPublic: realm.IsPublic,
IsCommunity: realm.IsCommunity, IsCommunity: realm.IsCommunity,
AccessPolicy: hyper.EncodeAccessPolicy(realm.AccessPolicy),
} }
if realm.Avatar != nil { if realm.Avatar != nil {
info.Avatar = *realm.Avatar info.Avatar = *realm.Avatar