✨ Authkit can get user
This commit is contained in:
parent
40a0403521
commit
808e7998dd
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="dataSourceStorageLocal" created-in="GO-242.23339.24">
|
||||
<data-source name="hy_passport@localhost" uuid="74bcf3ef-a2b9-435b-b9e5-f32902a33b25">
|
||||
<database-info product="PostgreSQL" version="16.3 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.3" exact-driver-version="42.6">
|
||||
<database-info product="PostgreSQL" version="16.4 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.4" exact-driver-version="42.6">
|
||||
<identifier-quote-string>"</identifier-quote-string>
|
||||
</database-info>
|
||||
<case-sensitivity plain-identifiers="lower" quoted-identifiers="exact" />
|
||||
@ -11,10 +11,15 @@
|
||||
<schema-mapping>
|
||||
<introspection-scope>
|
||||
<node negative="1">
|
||||
<node kind="database" qname="@">
|
||||
<node kind="schema" qname="@" />
|
||||
<node kind="database">
|
||||
<name qname="sn_interactive" />
|
||||
<name qname="sn_messaging" />
|
||||
</node>
|
||||
<node kind="database">
|
||||
<name qname="sn_paperclip" />
|
||||
<name qname="sn_passport" />
|
||||
<node kind="schema" qname="public" />
|
||||
</node>
|
||||
<node kind="database" qname="hy_passport" />
|
||||
</node>
|
||||
</introspection-scope>
|
||||
</schema-mapping>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,15 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix grpc namespace conflict">
|
||||
<change afterPath="$PROJECT_DIR$/pkg/authkit/auth.go" afterDir="false" />
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Authkit support check user related permission">
|
||||
<change afterPath="$PROJECT_DIR$/pkg/authkit/user.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/dataSources.local.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.local.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/authkit/audit.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/audit.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/authkit/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/notify.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/authkit/realm.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/realm.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/authkit/relative.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/relative.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" afterDir="false" />
|
||||
<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="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -49,34 +51,34 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"DefaultGoTemplateProperty": "Go File",
|
||||
"Go Build.Backend.executor": "Run",
|
||||
"Go 构建.Backend.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"go.import.settings.migrated": "true",
|
||||
"go.sdk.automatically.set": "true",
|
||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Passport",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||
"settings.editor.selected.configurable": "preferences.intentionPowerPack",
|
||||
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"DefaultGoTemplateProperty": "Go File",
|
||||
"Go Build.Backend.executor": "Debug",
|
||||
"Go 构建.Backend.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"go.import.settings.migrated": "true",
|
||||
"go.sdk.automatically.set": "true",
|
||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Passport",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||
"settings.editor.selected.configurable": "preferences.intentionPowerPack",
|
||||
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"DatabaseDriversLRU": [
|
||||
"postgresql"
|
||||
"keyToStringList": {
|
||||
"DatabaseDriversLRU": [
|
||||
"postgresql"
|
||||
]
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/keys" />
|
||||
@ -162,8 +164,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<MESSAGE value=":sparkles: Implement event recorder grpc" />
|
||||
<MESSAGE value=":sparkles: More event logs point" />
|
||||
<MESSAGE value=":sparkles: New login alert" />
|
||||
<MESSAGE value=":bug: Bug fixes in non-cached notification preferences" />
|
||||
<MESSAGE value=":alien: Support better metadata encoder / decoder" />
|
||||
@ -187,7 +187,9 @@
|
||||
<MESSAGE value=":sparkles: Add list relative method into authkit" />
|
||||
<MESSAGE value=":sparkles: Realm operations now available in authkit" />
|
||||
<MESSAGE value=":bug: Fix grpc namespace conflict" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix grpc namespace conflict" />
|
||||
<MESSAGE value=":recycle: Replace nil context with context.Background in authkit" />
|
||||
<MESSAGE value=":sparkles: Authkit support check user related permission" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Authkit support check user related permission" />
|
||||
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.solsynth.dev/hypernet/passport
|
||||
go 1.23.2
|
||||
|
||||
require (
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241031125727-aa624ee45428
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e
|
||||
github.com/dgraph-io/ristretto v0.1.1
|
||||
github.com/eko/gocache/lib/v4 v4.1.6
|
||||
|
2
go.sum
2
go.sum
@ -37,6 +37,8 @@ git.solsynth.dev/hypernet/nexus v0.0.0-20241030155904-3f6ea11d2297 h1:g9huTJFUKP
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241030155904-3f6ea11d2297/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241031125727-aa624ee45428 h1:1TnXLOzZZKwdneKHynK1qJ/3UL4r/f5Pp3EM+qdL1n4=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241031125727-aa624ee45428/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415 h1:7K6rv7fLgT1KQptFHJPp6+fHITLdl3Or3uT7cl8fnOM=
|
||||
git.solsynth.dev/hypernet/nexus v0.0.0-20241102174036-194d27090415/go.mod h1:fXQsHXGio+7/0U95IitKF07wS4yTdCMp5ms8wpFBwVI=
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e h1:DtHhMjgxS/spUt/KEdbRFtaVnepI6Vx8pbHdJaNH1hs=
|
||||
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e/go.mod h1:XHTqFU/vBe4JiuAjl87GUcL8+w/IizSNoqH6n3WkQFc=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
|
64
pkg/authkit/user.go
Normal file
64
pkg/authkit/user.go
Normal file
@ -0,0 +1,64 @@
|
||||
package authkit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func GetUser(nx *nex.Conn, userId uint) (models.Account, error) {
|
||||
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||
if err != nil {
|
||||
return models.Account{}, err
|
||||
}
|
||||
raw, _ := proto.NewUserServiceClient(conn).GetUser(context.Background(), &proto.GetUserRequest{
|
||||
UserId: lo.ToPtr(uint64(userId)),
|
||||
})
|
||||
return GetAccountFromUserInfo(&sec.UserInfo{
|
||||
ID: uint(raw.GetId()),
|
||||
Name: raw.GetName(),
|
||||
PermNodes: nex.DecodeMap(raw.GetPermNodes()),
|
||||
Metadata: nex.DecodeMap(raw.GetMetadata()),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func GetUserByName(nx *nex.Conn, name string) (models.Account, error) {
|
||||
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||
if err != nil {
|
||||
return models.Account{}, err
|
||||
}
|
||||
raw, _ := proto.NewUserServiceClient(conn).GetUser(context.Background(), &proto.GetUserRequest{
|
||||
Name: &name,
|
||||
})
|
||||
return GetAccountFromUserInfo(&sec.UserInfo{
|
||||
ID: uint(raw.GetId()),
|
||||
Name: raw.GetName(),
|
||||
PermNodes: nex.DecodeMap(raw.GetPermNodes()),
|
||||
Metadata: nex.DecodeMap(raw.GetMetadata()),
|
||||
}), nil
|
||||
}
|
||||
|
||||
func ListUser(nx *nex.Conn, userId []uint) ([]models.Account, error) {
|
||||
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw, _ := proto.NewUserServiceClient(conn).ListUser(context.Background(), &proto.ListUserRequest{
|
||||
UserId: lo.Map(userId, func(item uint, index int) uint64 {
|
||||
return uint64(item)
|
||||
}),
|
||||
})
|
||||
var out []models.Account
|
||||
for _, item := range raw.GetData() {
|
||||
out = append(out, GetAccountFromUserInfo(&sec.UserInfo{
|
||||
ID: uint(item.GetId()),
|
||||
Name: item.GetName(),
|
||||
PermNodes: nex.DecodeMap(item.GetPermNodes()),
|
||||
Metadata: nex.DecodeMap(item.GetMetadata()),
|
||||
}))
|
||||
}
|
||||
return out, nil
|
||||
}
|
@ -77,6 +77,12 @@ func (v *App) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchReques
|
||||
notifications = append(notifications, notification)
|
||||
}
|
||||
|
||||
if len(notifications) == 0 {
|
||||
return &proto.NotifyResponse{
|
||||
IsSuccess: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
log.Debug().Str("topic", notifications[0].Topic).Any("uid", lo.Keys(checklist)).Msg("Notifying users...")
|
||||
|
||||
if in.GetNotify().GetUnsaved() {
|
||||
|
@ -12,8 +12,16 @@ import (
|
||||
)
|
||||
|
||||
func (v *App) GetUser(ctx context.Context, request *proto.GetUserRequest) (*proto.UserInfo, error) {
|
||||
tx := database.C
|
||||
if request.UserId != nil {
|
||||
tx = tx.Where("id = ?", uint(request.GetUserId()))
|
||||
}
|
||||
if request.Name != nil {
|
||||
tx = tx.Where("name = ?", request.GetName())
|
||||
}
|
||||
|
||||
var account models.Account
|
||||
if err := database.C.Where("id = ?", uint(request.GetUserId())).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 account.EncodeToUserInfo(), nil
|
||||
|
Loading…
Reference in New Issue
Block a user