💥 Move remove member api arguments from body to querystring just as messaging
This commit is contained in:
parent
192a03e9d1
commit
10e9813bea
8
.idea/workspace.xml
generated
8
.idea/workspace.xml
generated
@ -4,9 +4,11 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Better relationships stauts query">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":truck: Move make friendship api">
|
||||
<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/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/index.go" 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" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/realms.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -159,7 +161,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<MESSAGE value=":sparkles: Realm operations now available in authkit" />
|
||||
<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" />
|
||||
@ -184,7 +185,8 @@
|
||||
<MESSAGE value=":boom: Passing relationship api arguments in body instead of querystring" />
|
||||
<MESSAGE value=":sparkles: Better check in experience random algorithm" />
|
||||
<MESSAGE value=":sparkles: Better relationships stauts query" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Better relationships stauts query" />
|
||||
<MESSAGE value=":truck: Move make friendship api" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":truck: Move make friendship api" />
|
||||
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
|
@ -124,7 +124,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
realms.Get("/me", listOwnedRealm)
|
||||
realms.Get("/me/available", listAvailableRealm)
|
||||
realms.Get("/:realm", getRealm)
|
||||
realms.Get("/:realm/members", listRealmMembers)
|
||||
realms.Get("/:realm/members/:memberId", listRealmMembers)
|
||||
realms.Get("/:realm/members/me", getMyRealmMember)
|
||||
realms.Post("/", createRealm)
|
||||
realms.Put("/:realmId", editRealm)
|
||||
|
@ -77,14 +77,6 @@ func removeRealmMember(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(models.Account)
|
||||
alias := c.Params("realm")
|
||||
|
||||
var data struct {
|
||||
Target string `json:"target" validate:"required"`
|
||||
}
|
||||
|
||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
realm, err := services.GetRealmWithAlias(alias)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
@ -97,7 +89,15 @@ func removeRealmMember(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
if err := services.RemoveRealmMember(user, account, realm); err != nil {
|
||||
var member models.RealmMember
|
||||
if err := database.C.Where(&models.RealmMember{
|
||||
RealmID: realm.ID,
|
||||
AccountID: account.ID,
|
||||
}).First(&member).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
if err := services.RemoveRealmMember(user, member, realm); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
@ -118,14 +118,15 @@ func leaveRealm(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "you cannot leave your own realm")
|
||||
}
|
||||
|
||||
var account models.Account
|
||||
if err := database.C.Where(&models.Account{
|
||||
BaseModel: models.BaseModel{ID: user.ID},
|
||||
}).First(&account).Error; err != nil {
|
||||
var member models.RealmMember
|
||||
if err := database.C.Where(&models.RealmMember{
|
||||
RealmID: realm.ID,
|
||||
AccountID: user.ID,
|
||||
}).First(&member).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
if err := services.RemoveRealmMember(user, account, realm); err != nil {
|
||||
if err := services.RemoveRealmMember(user, member, realm); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -101,7 +101,7 @@ func AddRealmMember(user models.Account, affected models.Account, target models.
|
||||
if member, err := GetRealmMember(user.ID, target.ID); err != nil {
|
||||
return fmt.Errorf("only realm member can add people: %v", err)
|
||||
} else if member.PowerLevel < 50 {
|
||||
return fmt.Errorf("only realm moderator can add people")
|
||||
return fmt.Errorf("only realm moderator can add member")
|
||||
}
|
||||
rel, err := GetRelationWithTwoNode(affected.ID, user.ID)
|
||||
if err != nil || HasPermNodeWithDefault(
|
||||
@ -122,24 +122,16 @@ func AddRealmMember(user models.Account, affected models.Account, target models.
|
||||
return err
|
||||
}
|
||||
|
||||
func RemoveRealmMember(user models.Account, affected models.Account, target models.Realm) error {
|
||||
if user.ID != affected.ID {
|
||||
func RemoveRealmMember(user models.Account, affected models.RealmMember, target models.Realm) error {
|
||||
if user.ID != affected.AccountID {
|
||||
if member, err := GetRealmMember(user.ID, target.ID); err != nil {
|
||||
return fmt.Errorf("only realm member can remove other member: %v", err)
|
||||
} else if member.PowerLevel < 50 {
|
||||
return fmt.Errorf("only realm moderator can invite people")
|
||||
return fmt.Errorf("only realm moderator can kick member")
|
||||
}
|
||||
}
|
||||
|
||||
var member models.RealmMember
|
||||
if err := database.C.Where(&models.RealmMember{
|
||||
RealmID: target.ID,
|
||||
AccountID: affected.ID,
|
||||
}).First(&member).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return database.C.Delete(&member).Error
|
||||
return database.C.Delete(&affected).Error
|
||||
}
|
||||
|
||||
func EditRealm(realm models.Realm) (models.Realm, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user