mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 08:34:44 +08:00
add UI name to roles
This commit is contained in:
parent
bc1f2d0c72
commit
4003848447
8 changed files with 44 additions and 7 deletions
|
@ -219,6 +219,20 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
newHost := newHostData.ConvertAPIHostToNMHost(currHost)
|
newHost := newHostData.ConvertAPIHostToNMHost(currHost)
|
||||||
|
|
||||||
|
if newHost.Name != currHost.Name {
|
||||||
|
// update any rag role ids
|
||||||
|
for _, nodeID := range newHost.Nodes {
|
||||||
|
node, err := logic.GetNodeByID(nodeID)
|
||||||
|
if err == nil && node.IsIngressGateway {
|
||||||
|
role, err := logic.GetRole(models.GetRAGRoleID(node.Network, currHost.ID.String()))
|
||||||
|
if err == nil {
|
||||||
|
role.UiName = models.GetRAGRoleName(node.Network, newHost.Name)
|
||||||
|
logic.UpdateRole(role)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
logic.UpdateHost(newHost, currHost) // update the in memory struct values
|
logic.UpdateHost(newHost, currHost) // update the in memory struct values
|
||||||
if err = logic.UpsertHost(newHost); err != nil {
|
if err = logic.UpsertHost(newHost); err != nil {
|
||||||
logger.Log(0, r.Header.Get("user"), "failed to update a host:", err.Error())
|
logger.Log(0, r.Header.Get("user"), "failed to update a host:", err.Error())
|
||||||
|
|
|
@ -180,7 +180,8 @@ func CreateIngressGateway(netid string, nodeid string, ingress models.IngressReq
|
||||||
}
|
}
|
||||||
// create network role for this gateway
|
// create network role for this gateway
|
||||||
CreateRole(models.UserRolePermissionTemplate{
|
CreateRole(models.UserRolePermissionTemplate{
|
||||||
ID: models.GetRAGRoleName(node.Network, host.Name),
|
ID: models.GetRAGRoleID(node.Network, host.ID.String()),
|
||||||
|
UiName: models.GetRAGRoleName(node.Network, host.Name),
|
||||||
NetworkID: models.NetworkID(node.Network),
|
NetworkID: models.NetworkID(node.Network),
|
||||||
Default: true,
|
Default: true,
|
||||||
NetworkLevelAccess: map[models.RsrcType]map[models.RsrcID]models.RsrcPermissionScope{
|
NetworkLevelAccess: map[models.RsrcType]map[models.RsrcID]models.RsrcPermissionScope{
|
||||||
|
@ -258,7 +259,7 @@ func DeleteIngressGateway(nodeid string) (models.Node, []models.ExtClient, error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Node{}, removedClients, err
|
return models.Node{}, removedClients, err
|
||||||
}
|
}
|
||||||
go DeleteRole(models.GetRAGRoleName(node.Network, host.Name), true)
|
go DeleteRole(models.GetRAGRoleID(node.Network, host.ID.String()), true)
|
||||||
err = SetNetworkNodesLastModified(node.Network)
|
err = SetNetworkNodesLastModified(node.Network)
|
||||||
return node, removedClients, err
|
return node, removedClients, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,6 +269,19 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
||||||
currHost.IsStaticPort = newHost.IsStaticPort
|
currHost.IsStaticPort = newHost.IsStaticPort
|
||||||
currHost.IsStatic = newHost.IsStatic
|
currHost.IsStatic = newHost.IsStatic
|
||||||
currHost.MTU = newHost.MTU
|
currHost.MTU = newHost.MTU
|
||||||
|
if newHost.Name != currHost.Name {
|
||||||
|
// update any rag role ids
|
||||||
|
for _, nodeID := range newHost.Nodes {
|
||||||
|
node, err := GetNodeByID(nodeID)
|
||||||
|
if err == nil && node.IsIngressGateway {
|
||||||
|
role, err := GetRole(models.GetRAGRoleID(node.Network, currHost.ID.String()))
|
||||||
|
if err == nil {
|
||||||
|
role.UiName = models.GetRAGRoleName(node.Network, newHost.Name)
|
||||||
|
UpdateRole(role)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
currHost.Name = newHost.Name
|
currHost.Name = newHost.Name
|
||||||
if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {
|
if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {
|
||||||
currHost.NatType = newHost.NatType
|
currHost.NatType = newHost.NatType
|
||||||
|
|
|
@ -197,7 +197,7 @@ func DeleteNode(node *models.Node, purge bool) error {
|
||||||
}
|
}
|
||||||
host, err := GetHost(node.HostID.String())
|
host, err := GetHost(node.HostID.String())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
go DeleteRole(models.GetRAGRoleName(node.Network, host.Name), true)
|
go DeleteRole(models.GetRAGRoleID(node.Network, host.ID.String()), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.IsRelayed {
|
if node.IsRelayed {
|
||||||
|
|
|
@ -43,6 +43,8 @@ var IsNetworkRolesValid = func(networkRoles map[models.NetworkID]map[models.User
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var UpdateRole = func(r models.UserRolePermissionTemplate) error { return nil }
|
||||||
|
|
||||||
var InitialiseRoles = userRolesInit
|
var InitialiseRoles = userRolesInit
|
||||||
var DeleteNetworkRoles = func(netID string) {}
|
var DeleteNetworkRoles = func(netID string) {}
|
||||||
var CreateDefaultNetworkRolesAndGroups = func(netID models.NetworkID) {}
|
var CreateDefaultNetworkRolesAndGroups = func(netID models.NetworkID) {}
|
||||||
|
|
|
@ -323,7 +323,8 @@ func syncUsers() {
|
||||||
h, err := logic.GetHost(networkNodeI.HostID.String())
|
h, err := logic.GetHost(networkNodeI.HostID.String())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logic.CreateRole(models.UserRolePermissionTemplate{
|
logic.CreateRole(models.UserRolePermissionTemplate{
|
||||||
ID: models.GetRAGRoleName(networkNodeI.Network, h.Name),
|
ID: models.GetRAGRoleID(networkNodeI.Network, h.ID.String()),
|
||||||
|
UiName: models.GetRAGRoleName(networkNodeI.Network, h.Name),
|
||||||
NetworkID: models.NetworkID(netI.NetID),
|
NetworkID: models.NetworkID(netI.NetID),
|
||||||
NetworkLevelAccess: map[models.RsrcType]map[models.RsrcID]models.RsrcPermissionScope{
|
NetworkLevelAccess: map[models.RsrcType]map[models.RsrcID]models.RsrcPermissionScope{
|
||||||
models.RemoteAccessGwRsrc: {
|
models.RemoteAccessGwRsrc: {
|
||||||
|
@ -387,7 +388,7 @@ func syncUsers() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r, err := logic.GetRole(models.GetRAGRoleName(gwNode.Network, h.Name))
|
r, err := logic.GetRole(models.GetRAGRoleID(gwNode.Network, h.ID.String()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,12 @@ func (rid RsrcID) String() string {
|
||||||
return string(rid)
|
return string(rid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRAGRoleName(netID, hostName string) UserRoleID {
|
func GetRAGRoleName(netID, hostName string) string {
|
||||||
return UserRoleID(fmt.Sprintf("netID-%s-rag-%s", netID, hostName))
|
return fmt.Sprintf("netID-%s-rag-%s", netID, hostName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRAGRoleID(netID, hostID string) UserRoleID {
|
||||||
|
return UserRoleID(fmt.Sprintf("netID-%s-rag-%s", netID, hostID))
|
||||||
}
|
}
|
||||||
|
|
||||||
var RsrcTypeMap = map[RsrcType]struct{}{
|
var RsrcTypeMap = map[RsrcType]struct{}{
|
||||||
|
@ -112,6 +116,7 @@ type RsrcPermissionScope struct {
|
||||||
|
|
||||||
type UserRolePermissionTemplate struct {
|
type UserRolePermissionTemplate struct {
|
||||||
ID UserRoleID `json:"id"`
|
ID UserRoleID `json:"id"`
|
||||||
|
UiName string `json:"ui_name"`
|
||||||
Default bool `json:"default"`
|
Default bool `json:"default"`
|
||||||
DenyDashboardAccess bool `json:"deny_dashboard_access"`
|
DenyDashboardAccess bool `json:"deny_dashboard_access"`
|
||||||
FullAccess bool `json:"full_access"`
|
FullAccess bool `json:"full_access"`
|
||||||
|
|
|
@ -121,6 +121,7 @@ func InitPro() {
|
||||||
mq.UpdateMetricsFallBack = proLogic.MQUpdateMetricsFallBack
|
mq.UpdateMetricsFallBack = proLogic.MQUpdateMetricsFallBack
|
||||||
logic.GetFilteredNodesByUserAccess = proLogic.GetFilteredNodesByUserAccess
|
logic.GetFilteredNodesByUserAccess = proLogic.GetFilteredNodesByUserAccess
|
||||||
logic.CreateRole = proLogic.CreateRole
|
logic.CreateRole = proLogic.CreateRole
|
||||||
|
logic.UpdateRole = proLogic.UpdateRole
|
||||||
logic.DeleteRole = proLogic.DeleteRole
|
logic.DeleteRole = proLogic.DeleteRole
|
||||||
logic.NetworkPermissionsCheck = proLogic.NetworkPermissionsCheck
|
logic.NetworkPermissionsCheck = proLogic.NetworkPermissionsCheck
|
||||||
logic.GlobalPermissionsCheck = proLogic.GlobalPermissionsCheck
|
logic.GlobalPermissionsCheck = proLogic.GlobalPermissionsCheck
|
||||||
|
|
Loading…
Add table
Reference in a new issue