✨ Authkit can get user
This commit is contained in:
parent
40a0403521
commit
808e7998dd
@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="dataSourceStorageLocal" created-in="GO-242.23339.24">
|
<component name="dataSourceStorageLocal" created-in="GO-242.23339.24">
|
||||||
<data-source name="hy_passport@localhost" uuid="74bcf3ef-a2b9-435b-b9e5-f32902a33b25">
|
<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>
|
<identifier-quote-string>"</identifier-quote-string>
|
||||||
</database-info>
|
</database-info>
|
||||||
<case-sensitivity plain-identifiers="lower" quoted-identifiers="exact" />
|
<case-sensitivity plain-identifiers="lower" quoted-identifiers="exact" />
|
||||||
@ -11,10 +11,15 @@
|
|||||||
<schema-mapping>
|
<schema-mapping>
|
||||||
<introspection-scope>
|
<introspection-scope>
|
||||||
<node negative="1">
|
<node negative="1">
|
||||||
<node kind="database" qname="@">
|
<node kind="database">
|
||||||
<node kind="schema" qname="@" />
|
<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>
|
||||||
<node kind="database" qname="hy_passport" />
|
|
||||||
</node>
|
</node>
|
||||||
</introspection-scope>
|
</introspection-scope>
|
||||||
</schema-mapping>
|
</schema-mapping>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,15 @@
|
|||||||
<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=":bug: Fix grpc namespace conflict">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Authkit support check user related permission">
|
||||||
<change afterPath="$PROJECT_DIR$/pkg/authkit/auth.go" afterDir="false" />
|
<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$/.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$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" 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$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" 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/internal/grpc/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notify.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$/pkg/internal/grpc/user.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/user.go" afterDir="false" />
|
||||||
</list>
|
</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" />
|
||||||
@ -49,34 +51,34 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"DefaultGoTemplateProperty": "Go File",
|
"DefaultGoTemplateProperty": "Go File",
|
||||||
"Go Build.Backend.executor": "Run",
|
"Go Build.Backend.executor": "Debug",
|
||||||
"Go 构建.Backend.executor": "Run",
|
"Go 构建.Backend.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"go.sdk.automatically.set": "true",
|
"go.sdk.automatically.set": "true",
|
||||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Passport",
|
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Passport",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||||
"settings.editor.selected.configurable": "preferences.intentionPowerPack",
|
"settings.editor.selected.configurable": "preferences.intentionPowerPack",
|
||||||
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
"postgresql"
|
"postgresql"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="$PROJECT_DIR$/keys" />
|
<recent name="$PROJECT_DIR$/keys" />
|
||||||
@ -162,8 +164,6 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
<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=":sparkles: New login alert" />
|
||||||
<MESSAGE value=":bug: Bug fixes in non-cached notification preferences" />
|
<MESSAGE value=":bug: Bug fixes in non-cached notification preferences" />
|
||||||
<MESSAGE value=":alien: Support better metadata encoder / decoder" />
|
<MESSAGE value=":alien: Support better metadata encoder / decoder" />
|
||||||
@ -187,7 +187,9 @@
|
|||||||
<MESSAGE value=":sparkles: Add list relative method into authkit" />
|
<MESSAGE value=":sparkles: Add list relative method into authkit" />
|
||||||
<MESSAGE value=":sparkles: Realm operations now available in authkit" />
|
<MESSAGE value=":sparkles: Realm operations now available in authkit" />
|
||||||
<MESSAGE value=":bug: Fix grpc namespace conflict" />
|
<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" />
|
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.solsynth.dev/hypernet/passport
|
|||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
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
|
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e
|
||||||
github.com/dgraph-io/ristretto v0.1.1
|
github.com/dgraph-io/ristretto v0.1.1
|
||||||
github.com/eko/gocache/lib/v4 v4.1.6
|
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-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 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-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 h1:DtHhMjgxS/spUt/KEdbRFtaVnepI6Vx8pbHdJaNH1hs=
|
||||||
git.solsynth.dev/hypernet/pusher v0.0.0-20241026153052-cd2c326efa4e/go.mod h1:XHTqFU/vBe4JiuAjl87GUcL8+w/IizSNoqH6n3WkQFc=
|
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=
|
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)
|
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...")
|
log.Debug().Str("topic", notifications[0].Topic).Any("uid", lo.Keys(checklist)).Msg("Notifying users...")
|
||||||
|
|
||||||
if in.GetNotify().GetUnsaved() {
|
if in.GetNotify().GetUnsaved() {
|
||||||
|
@ -12,8 +12,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (v *App) GetUser(ctx context.Context, request *proto.GetUserRequest) (*proto.UserInfo, error) {
|
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
|
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 nil, status.Errorf(codes.NotFound, fmt.Sprintf("requested user with id %d was not found", request.GetUserId()))
|
||||||
}
|
}
|
||||||
return account.EncodeToUserInfo(), nil
|
return account.EncodeToUserInfo(), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user