✨ Add realm member support both account name and id
This commit is contained in:
parent
f8492ea1af
commit
d3a1382711
6
.idea/workspace.xml
generated
6
.idea/workspace.xml
generated
@ -4,7 +4,7 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":boom: Move remove member api arguments from body to querystring just as messaging">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Hotfix previous commit compile issue">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/realm_members_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/realm_members_api.go" afterDir="false" />
|
||||
</list>
|
||||
@ -159,7 +159,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<MESSAGE value=":recycle: Replace nil context with context.Background in authkit" />
|
||||
<MESSAGE value=":sparkles: Authkit support check user related permission" />
|
||||
<MESSAGE value=":sparkles: Authkit can get user" />
|
||||
<MESSAGE value=":bug: Fix auth cache" />
|
||||
@ -184,7 +183,8 @@
|
||||
<MESSAGE value=":sparkles: Better relationships stauts query" />
|
||||
<MESSAGE value=":truck: Move make friendship api" />
|
||||
<MESSAGE value=":boom: Move remove member api arguments from body to querystring just as messaging" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":boom: Move remove member api arguments from body to querystring just as messaging" />
|
||||
<MESSAGE value=":bug: Hotfix previous commit compile issue" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Hotfix previous commit compile issue" />
|
||||
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/http/exts"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func listRealmMembers(c *fiber.Ctx) error {
|
||||
@ -44,7 +45,7 @@ func addRealmMember(c *fiber.Ctx) error {
|
||||
alias := c.Params("realm")
|
||||
|
||||
var data struct {
|
||||
Target string `json:"target" validate:"required"`
|
||||
Related string `json:"related" validate:"required"`
|
||||
}
|
||||
|
||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||
@ -57,9 +58,17 @@ func addRealmMember(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
var account models.Account
|
||||
if err := database.C.Where(&models.Account{
|
||||
Name: data.Target,
|
||||
}).First(&account).Error; err != nil {
|
||||
var numericId int
|
||||
if numericId, err = strconv.Atoi(data.Related); err == nil {
|
||||
err = database.C.Where(&models.Account{
|
||||
BaseModel: models.BaseModel{ID: uint(numericId)},
|
||||
}).First(&account).Error
|
||||
} else {
|
||||
err = database.C.Where(&models.Account{
|
||||
Name: data.Related,
|
||||
}).First(&account).Error
|
||||
}
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user