complete hub save endpoint
This commit is contained in:
+29
-24
@@ -128,7 +128,7 @@ type RolePermission uint32
|
||||
|
||||
const (
|
||||
// Hub permissions
|
||||
PermissionSetHubName RolePermission = iota
|
||||
PermissionSetHubName RolePermission = 1 << iota
|
||||
PermissionSetHubBg
|
||||
PermissionSetHubColor
|
||||
PermissionRemoveHub
|
||||
@@ -165,38 +165,43 @@ const (
|
||||
)
|
||||
|
||||
type Hub struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff []*Message `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
HaveOverflowed bool `json:"-"`
|
||||
Users map[uuid.UUID]*HubUser `json:"-"`
|
||||
Roles map[uint8]*HubRole `json:"-"`
|
||||
Creator uuid.UUID `json:"creator"`
|
||||
Name string `json:"name"`
|
||||
Color Rgba `json:"color"`
|
||||
AllowUserColor bool `json:"allowUserColor"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
MessagesBuff []*Message `json:"-"`
|
||||
NextBuffIdx uint32 `json:"-"`
|
||||
HaveOverflowed bool `json:"-"`
|
||||
Users map[uuid.UUID]*HubUser `json:"-"`
|
||||
Roles map[uint8]*HubRole `json:"-"`
|
||||
ChannelGroups map[uuid.UUID]*HubChannelGroup `json:"-"`
|
||||
Creator uuid.UUID `json:"creator"`
|
||||
Name string `json:"name"`
|
||||
Color Rgba `json:"color"`
|
||||
AllowUserColor bool `json:"allowUserColor"`
|
||||
}
|
||||
|
||||
func NewHub() *Hub {
|
||||
return &Hub{
|
||||
MessagesBuff: make([]*Message, config.MaxHubMsgCache),
|
||||
Users: make(map[uuid.UUID]*HubUser),
|
||||
Roles: make(map[uint8]*HubRole),
|
||||
Id: uuid.New(),
|
||||
MessagesBuff: make([]*Message, config.MaxHubMsgCache),
|
||||
Users: make(map[uuid.UUID]*HubUser),
|
||||
Roles: make(map[uint8]*HubRole),
|
||||
ChannelGroups: make(map[uuid.UUID]*HubChannelGroup),
|
||||
}
|
||||
}
|
||||
|
||||
type HubChannelGroup struct {
|
||||
Id uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color Rgba `json:"color"`
|
||||
Id uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color Rgba `json:"color"`
|
||||
Position uint8 `json:"position"`
|
||||
}
|
||||
|
||||
type HubChannel struct {
|
||||
Id uuid.UUID `json:"id"`
|
||||
Name uuid.UUID `json:"name"`
|
||||
ParentGroupId uuid.UUID `json:"parentGroupId"`
|
||||
Position uint8 `json:"position"`
|
||||
}
|
||||
|
||||
type HubUser struct {
|
||||
@@ -213,22 +218,22 @@ type HubRole struct {
|
||||
Color Rgba `json:"color"`
|
||||
}
|
||||
|
||||
func (h HubRole) GrantPermission(r RolePermission) {
|
||||
func (h *HubRole) GrantPermission(r RolePermission) {
|
||||
h.RolePermission |= r
|
||||
}
|
||||
func (h HubRole) GrantPermissions(rs []RolePermission) {
|
||||
func (h *HubRole) GrantPermissions(rs []RolePermission) {
|
||||
for _, r := range rs {
|
||||
h.RolePermission |= r
|
||||
}
|
||||
}
|
||||
func (h HubRole) RevokePermission(r RolePermission) {
|
||||
func (h *HubRole) RevokePermission(r RolePermission) {
|
||||
h.RolePermission &^= r
|
||||
}
|
||||
func (h HubRole) RevokePermissions(rs []RolePermission) {
|
||||
func (h *HubRole) RevokePermissions(rs []RolePermission) {
|
||||
for _, r := range rs {
|
||||
h.RolePermission &^= r
|
||||
}
|
||||
}
|
||||
func (h HubRole) HasPermission(r RolePermission) bool {
|
||||
func (h *HubRole) HasPermission(r RolePermission) bool {
|
||||
return h.RolePermission&r != 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user