Able to transfer story / article between realms

This commit is contained in:
LittleSheep 2024-08-10 16:45:42 +08:00
parent 0383cdf407
commit fca4032031
2 changed files with 22 additions and 0 deletions

View File

@ -113,6 +113,7 @@ func editArticle(c *fiber.Ctx) error {
InvisibleUsers []uint `json:"invisible_users_list"`
Visibility *int8 `json:"visibility"`
IsDraft bool `json:"is_draft"`
RealmAlias *string `json:"realm"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
@ -165,6 +166,16 @@ func editArticle(c *fiber.Ctx) error {
item.Visibility = *data.Visibility
}
if data.RealmAlias != nil {
if realm, err := services.GetRealmWithAlias(*data.RealmAlias); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else if _, err = services.GetRealmMember(realm.ExternalID, user.ExternalID); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to post in the realm, access denied: %v", err))
} else {
item.RealmID = &realm.ID
}
}
if item, err := services.EditPost(item); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {

View File

@ -132,6 +132,7 @@ func editStory(c *fiber.Ctx) error {
InvisibleUsers []uint `json:"invisible_users_list"`
Visibility *int8 `json:"visibility"`
IsDraft bool `json:"is_draft"`
RealmAlias *string `json:"realm"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
@ -184,6 +185,16 @@ func editStory(c *fiber.Ctx) error {
item.Visibility = *data.Visibility
}
if data.RealmAlias != nil {
if realm, err := services.GetRealmWithAlias(*data.RealmAlias); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else if _, err = services.GetRealmMember(realm.ExternalID, user.ExternalID); err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to post in the realm, access denied: %v", err))
} else {
item.RealmID = &realm.ID
}
}
if item, err := services.EditPost(item); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {