✨ Able to transfer channel between realms
This commit is contained in:
parent
256c494ad0
commit
a268b7958c
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||||
@ -203,11 +204,12 @@ func editChannel(c *fiber.Ctx) error {
|
|||||||
id, _ := c.ParamsInt("channelId", 0)
|
id, _ := c.ParamsInt("channelId", 0)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Alias string `json:"alias" validate:"required,min=4,max=32"`
|
Alias string `json:"alias" validate:"required,min=4,max=32"`
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
IsPublic bool `json:"is_public"`
|
IsPublic bool `json:"is_public"`
|
||||||
IsCommunity bool `json:"is_community"`
|
IsCommunity bool `json:"is_community"`
|
||||||
|
NewBelongsRealm *string `json:"new_belongs_realm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -241,7 +243,32 @@ func editChannel(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel, err := services.EditChannel(channel, data.Alias, data.Name, data.Description, data.IsPublic, data.IsCommunity)
|
if data.NewBelongsRealm != nil {
|
||||||
|
if *data.NewBelongsRealm == "global" {
|
||||||
|
channel.RealmID = nil
|
||||||
|
} else {
|
||||||
|
realm, err := authkit.GetRealmByAlias(gap.Nx, *data.NewBelongsRealm)
|
||||||
|
if err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("requested channel with realm, but realm was not found: %v", err))
|
||||||
|
} else {
|
||||||
|
if info, err := authkit.GetRealmMember(gap.Nx, realm.ID, user.ID); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusForbidden, "you must be a part of that realm then can transfer channel related to it")
|
||||||
|
} else if info.PowerLevel < 50 {
|
||||||
|
return fiber.NewError(fiber.StatusForbidden, "you must be a moderator of that realm then can transfer channel related to it")
|
||||||
|
} else {
|
||||||
|
channel.RealmID = &realm.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.Alias = data.Alias
|
||||||
|
channel.Name = data.Name
|
||||||
|
channel.Description = data.Description
|
||||||
|
channel.IsPublic = data.IsPublic
|
||||||
|
channel.IsCommunity = data.IsCommunity
|
||||||
|
|
||||||
|
channel, err := services.EditChannel(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -274,13 +274,7 @@ func NewChannel(channel models.Channel) (models.Channel, error) {
|
|||||||
return channel, err
|
return channel, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditChannel(channel models.Channel, alias, name, description string, isPublic, isCommunity bool) (models.Channel, error) {
|
func EditChannel(channel models.Channel) (models.Channel, error) {
|
||||||
channel.Alias = alias
|
|
||||||
channel.Name = name
|
|
||||||
channel.Description = description
|
|
||||||
channel.IsPublic = isPublic
|
|
||||||
channel.IsCommunity = isCommunity
|
|
||||||
|
|
||||||
err := database.C.Save(&channel).Error
|
err := database.C.Save(&channel).Error
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user