added admin area manage for checking which categories are available
parent
73e5548e32
commit
e72c0252bb
|
@ -41,6 +41,30 @@ func GetCategoryGroupByCategory(category string) structs.CategoryGroup {
|
||||||
return structs.CategoryGroup{}
|
return structs.CategoryGroup{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExistsCategory(category string) bool {
|
||||||
|
cgMu.RLock()
|
||||||
|
defer cgMu.RUnlock()
|
||||||
|
|
||||||
|
for _, categoryGroup := range categoryGroups {
|
||||||
|
if categoryGroup.Category == category {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveCategory(category string) {
|
||||||
|
cgMu.Lock()
|
||||||
|
defer cgMu.Unlock()
|
||||||
|
|
||||||
|
for index, categoryGroup := range categoryGroups {
|
||||||
|
if categoryGroup.Category == category {
|
||||||
|
categoryGroups = append(categoryGroups[:index], categoryGroups[index+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func RemoveAllCategoryGroupsByCategory(category string) {
|
func RemoveAllCategoryGroupsByCategory(category string) {
|
||||||
for index, categoryGroup := range GetCategoryGroups() {
|
for index, categoryGroup := range GetCategoryGroups() {
|
||||||
if categoryGroup.Category == category {
|
if categoryGroup.Category == category {
|
||||||
|
|
|
@ -36,8 +36,6 @@ func InitLoadCategoryGroups() {
|
||||||
|
|
||||||
files, err := os.ReadDir(config.Cfg.FolderPaths.GroupTasksGroups + entry.Name())
|
files, err := os.ReadDir(config.Cfg.FolderPaths.GroupTasksGroups + entry.Name())
|
||||||
|
|
||||||
log.Debug().Msgf("entry %v", entry.Name())
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msg("Failed to read groups directory files, error: " + err.Error())
|
log.Error().Msg("Failed to read groups directory files, error: " + err.Error())
|
||||||
return
|
return
|
||||||
|
@ -1155,3 +1153,82 @@ func InstallPythonPackages(userId string, category string, groupId string) {
|
||||||
Body: messageBody,
|
Body: messageBody,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckWhichCategoriesAreAvailable() []string {
|
||||||
|
entries, err := os.ReadDir(config.Cfg.FolderPaths.GroupTasksGroups)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("Error reading group tasks groups folder %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop throught cached categories and check if for the category exists an folder
|
||||||
|
// if not delete the category from cache
|
||||||
|
for _, category := range cache.GetCategoryGroups() {
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(config.Cfg.FolderPaths.GroupTasksGroups)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("Error reading group tasks groups folder %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists bool
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.Name() == category.Category {
|
||||||
|
exists = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
cache.RemoveCategory(category.Category)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop throught all folders in group tasks groups folder and add them to cache if not already in cache
|
||||||
|
var categories []string
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
categories = append(categories, entry.Name())
|
||||||
|
|
||||||
|
// add category to cache if not already in cache
|
||||||
|
if !cache.ExistsCategory(entry.Name()) {
|
||||||
|
files, err := os.ReadDir(config.Cfg.FolderPaths.GroupTasksGroups + entry.Name())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("Error reading group tasks groups folder %s", err.Error())
|
||||||
|
return categories
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
if file.Name() == "index.json" {
|
||||||
|
content, err := os.ReadFile(config.Cfg.FolderPaths.GroupTasksGroups + entry.Name() + "/index.json")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msg("Failed to read file content, error: " + err.Error())
|
||||||
|
return categories
|
||||||
|
}
|
||||||
|
|
||||||
|
var group structs.Group
|
||||||
|
|
||||||
|
json.Unmarshal(content, &group)
|
||||||
|
|
||||||
|
group.Id = entry.Name()
|
||||||
|
|
||||||
|
cache.AddCategoryGroup(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
systempermissions.HandleMasterRolePermissions()
|
||||||
|
|
||||||
|
// TODO: sent new master role permissions to ws topic
|
||||||
|
|
||||||
|
// TODO: send category list to ws users (check permissions)
|
||||||
|
|
||||||
|
return categories
|
||||||
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func RemoveDynamicGroupTasksPermissionsByCategory(category string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateMasterRoleIfNotExist() {
|
func CreateMasterRoleIfNotExist() {
|
||||||
masterRoleId := handleMasterRolePermissions()
|
masterRoleId := HandleMasterRolePermissions()
|
||||||
createDefaultAdminUser(masterRoleId)
|
createDefaultAdminUser(masterRoleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func createDefaultAdminUser(masterRoleId string) {
|
||||||
log.Info().Msgf("Password: %s", string(pw))
|
log.Info().Msgf("Password: %s", string(pw))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMasterRolePermissions() (roleId string) {
|
func HandleMasterRolePermissions() (roleId string) {
|
||||||
// create admin role if not already existing
|
// create admin role if not already existing
|
||||||
role := structs.Role{
|
role := structs.Role{
|
||||||
Id: uuid.New().String(),
|
Id: uuid.New().String(),
|
||||||
|
|
|
@ -51,78 +51,80 @@ var (
|
||||||
|
|
||||||
// commands sent to web clients
|
// commands sent to web clients
|
||||||
const (
|
const (
|
||||||
SentCmdInitUserSocketConnection = 1
|
SentCmdInitUserSocketConnection = 1
|
||||||
SentCmdUpdateConnectedUsers = 2
|
SentCmdUpdateConnectedUsers = 2
|
||||||
SentCmdNewGroupTaskStarted = 3
|
SentCmdNewGroupTaskStarted = 3
|
||||||
SentCmdNewGroupTaskStep = 4
|
SentCmdNewGroupTaskStep = 4
|
||||||
SentCmdUpdateGroupTaskStep = 5
|
SentCmdUpdateGroupTaskStep = 5
|
||||||
SentCmdUpdateGroupTask = 6
|
SentCmdUpdateGroupTask = 6
|
||||||
SentCmdReloadingGroupTasks = 7
|
SentCmdReloadingGroupTasks = 7
|
||||||
SentCmdGroupTasksReloaded = 8
|
SentCmdGroupTasksReloaded = 8
|
||||||
SentCmdUpdateUserSessions = 9
|
SentCmdUpdateUserSessions = 9
|
||||||
SentCmdUpdateAllUsersUserAvatar = 10
|
SentCmdUpdateAllUsersUserAvatar = 10
|
||||||
SentCmdNewScanner = 11
|
SentCmdNewScanner = 11
|
||||||
SentCmdDeleteScanner = 12
|
SentCmdDeleteScanner = 12
|
||||||
SentCmdUpdateScannerUsedBy = 13
|
SentCmdUpdateScannerUsedBy = 13
|
||||||
SentCmdScanResult = 14
|
SentCmdScanResult = 14
|
||||||
SentCmdUpdateScannerLastUsed = 15
|
SentCmdUpdateScannerLastUsed = 15
|
||||||
SentCmdTaskLocked = 16
|
SentCmdTaskLocked = 16
|
||||||
SentCmdTaskUnlocked = 17
|
SentCmdTaskUnlocked = 17
|
||||||
SentCmdUserProfileUpdated = 18
|
SentCmdUserProfileUpdated = 18
|
||||||
SentCmdAdminAreaNewRoleCreated = 19
|
SentCmdAdminAreaNewRoleCreated = 19
|
||||||
SentCmdAdminAreaRoleUpdated = 20
|
SentCmdAdminAreaRoleUpdated = 20
|
||||||
SentCmdAdminAreaUpdateRoleSortingOrder = 21
|
SentCmdAdminAreaUpdateRoleSortingOrder = 21
|
||||||
SentCmdAdminAreaRoleDeleted = 22
|
SentCmdAdminAreaRoleDeleted = 22
|
||||||
SentCmdAllUsersUserRoleUpdated = 23
|
SentCmdAllUsersUserRoleUpdated = 23
|
||||||
SentCmdRolePermissionsUpdated = 24
|
SentCmdRolePermissionsUpdated = 24
|
||||||
SentCmdErrorNoPermissions = 25
|
SentCmdErrorNoPermissions = 25
|
||||||
SentCmdAllUsersNewUserCreated = 26
|
SentCmdAllUsersNewUserCreated = 26
|
||||||
SentCmdAllUsersUserDeleted = 27
|
SentCmdAllUsersUserDeleted = 27
|
||||||
SentCmdAllUsersUserDeactivation = 28
|
SentCmdAllUsersUserDeactivation = 28
|
||||||
SentCmdGroupTasksCategoryGroupChanges = 29
|
SentCmdGroupTasksCategoryGroupChanges = 29
|
||||||
SentCmdNewUserApiKeyCreated = 30
|
SentCmdNewUserApiKeyCreated = 30
|
||||||
SentCmdDeletedUserApiKey = 31
|
SentCmdDeletedUserApiKey = 31
|
||||||
SentCmdNewApiKeyUsageCount = 32
|
SentCmdNewApiKeyUsageCount = 32
|
||||||
SentCmdInstallingPythonPackages = 33
|
SentCmdInstallingPythonPackages = 33
|
||||||
SentCmdInstallingPythonPackagesFailed = 34
|
SentCmdInstallingPythonPackagesFailed = 34
|
||||||
SentCmdInstallingPythonPackagesFinished = 35
|
SentCmdInstallingPythonPackagesFinished = 35
|
||||||
SentCmdInstallingGlobalPythonPackages = 36
|
SentCmdInstallingGlobalPythonPackages = 36
|
||||||
SentCmdInstallingGlobalPythonPackagesFailed = 37
|
SentCmdInstallingGlobalPythonPackagesFailed = 37
|
||||||
SentCmdInstallingGlobalPythonPackagesFinished = 38
|
SentCmdInstallingGlobalPythonPackagesFinished = 38
|
||||||
SentCmdUpdateUsers = 39
|
SentCmdUpdateUsers = 39
|
||||||
SentCmdCheckingForGroupTasksCategoryGroupChanges = 40
|
SentCmdCheckingForGroupTasksCategoryGroupChanges = 40
|
||||||
SentCmdNewNotification = 41
|
SentCmdNewNotification = 41
|
||||||
SentCmdAllNotificationsDeleted = 42
|
SentCmdAllNotificationsDeleted = 42
|
||||||
SentCmdOneNotificationDeleted = 43
|
SentCmdOneNotificationDeleted = 43
|
||||||
|
SentCmdAdminAreaManageCheckedForAvailableCategories = 44
|
||||||
)
|
)
|
||||||
|
|
||||||
// commands received from web clients
|
// commands received from web clients
|
||||||
const (
|
const (
|
||||||
ReceivedCmdStartGroupTasks = 1
|
ReceivedCmdStartGroupTasks = 1
|
||||||
ReceivedCmdTaskFailedTryAgainRunTaskStep = 2
|
ReceivedCmdTaskFailedTryAgainRunTaskStep = 2
|
||||||
ReceivedCmdTaskContinueTaskStep = 3
|
ReceivedCmdTaskContinueTaskStep = 3
|
||||||
ReceivedCmdReloadGroupTasks = 4
|
ReceivedCmdReloadGroupTasks = 4
|
||||||
ReceivedCmdTaskLocking = 5
|
ReceivedCmdTaskLocking = 5
|
||||||
ReceivedCmdUpdateUserProfile = 6
|
ReceivedCmdUpdateUserProfile = 6
|
||||||
ReceivedCmdAdminAreaCreateNewRole = 7
|
ReceivedCmdAdminAreaCreateNewRole = 7
|
||||||
ReceivedCmdAdminAreaUpdateRole = 8
|
ReceivedCmdAdminAreaUpdateRole = 8
|
||||||
ReceivedCmdAdminAreaUpdateRoleSortingOrder = 9
|
ReceivedCmdAdminAreaUpdateRoleSortingOrder = 9
|
||||||
ReceivedCmdAdminAreaDeleteRole = 10
|
ReceivedCmdAdminAreaDeleteRole = 10
|
||||||
ReceivedCmdAllUsersUpdateUserRole = 11
|
ReceivedCmdAllUsersUpdateUserRole = 11
|
||||||
ReceivedCmdAllUsersCreateNewUser = 12
|
ReceivedCmdAllUsersCreateNewUser = 12
|
||||||
ReceivedCmdAllUsersDeleteUser = 13
|
ReceivedCmdAllUsersDeleteUser = 13
|
||||||
ReceivedCmdAllUsersUserDeactivation = 14
|
ReceivedCmdAllUsersUserDeactivation = 14
|
||||||
ReceivedCmdScannersUseScanners = 15
|
ReceivedCmdScannersUseScanners = 15
|
||||||
ReceivedCmdScannersDisconnectScanner = 16
|
ReceivedCmdScannersDisconnectScanner = 16
|
||||||
ReceivedCmdGroupTasksCheckingForCategoryGroupChanges = 17
|
ReceivedCmdGroupTasksCheckingForCategoryGroupChanges = 17
|
||||||
ReceivedCmdHandleUserActionTaskStep = 18
|
ReceivedCmdHandleUserActionTaskStep = 18
|
||||||
ReceivedCmdCreateNewUserApiKey = 19
|
ReceivedCmdCreateNewUserApiKey = 19
|
||||||
ReceivedCmdDeleteUserApiKey = 20
|
ReceivedCmdDeleteUserApiKey = 20
|
||||||
ReceivedCmdGroupTasksInstallPythonPackages = 21
|
ReceivedCmdGroupTasksInstallPythonPackages = 21
|
||||||
ReceivedCmdGroupTasksInstallGlobalPythonPackages = 22
|
ReceivedCmdGroupTasksInstallGlobalPythonPackages = 22
|
||||||
ReceivedCmdSubscribeToTopic = 23
|
ReceivedCmdSubscribeToTopic = 23
|
||||||
ReceivedCmdDeleteAllNotifications = 24
|
ReceivedCmdDeleteAllNotifications = 24
|
||||||
ReceivedCmdDeleteOneNotification = 25
|
ReceivedCmdDeleteOneNotification = 25
|
||||||
|
ReceivedCmdAdminAreaManageCheckWhichCategoriesAreAvailable = 26
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -177,13 +179,15 @@ const (
|
||||||
PermissionAllUsersActionUserDeactivation = "all_users.action.user_deactivation"
|
PermissionAllUsersActionUserDeactivation = "all_users.action.user_deactivation"
|
||||||
PermissionScannerUseScanners = "scanner.use_scanners"
|
PermissionScannerUseScanners = "scanner.use_scanners"
|
||||||
|
|
||||||
_adminArea = "admin_area."
|
_adminArea = "admin_area."
|
||||||
_adminAreaRoles = _adminArea + "roles."
|
_adminAreaRoles = _adminArea + "roles."
|
||||||
PermissionAdminAreaCreateNewRole = _adminAreaRoles + "create_new_role"
|
PermissionAdminAreaCreateNewRole = _adminAreaRoles + "create_new_role"
|
||||||
PermissionAdminAreaUpdateRole = _adminAreaRoles + "update_role"
|
PermissionAdminAreaUpdateRole = _adminAreaRoles + "update_role"
|
||||||
PermissionAdminAreaDeleteRole = _adminAreaRoles + "delete_role"
|
PermissionAdminAreaDeleteRole = _adminAreaRoles + "delete_role"
|
||||||
PermissionAdminAreaMoveRoleUpDown = _adminAreaRoles + "move_role_up_down"
|
PermissionAdminAreaMoveRoleUpDown = _adminAreaRoles + "move_role_up_down"
|
||||||
PermissionAdminAreaLogs = _adminArea + "logs"
|
PermissionAdminAreaLogs = _adminArea + "logs"
|
||||||
|
PermissionAdminAreaManage = _adminArea + "manage"
|
||||||
|
PermissionAdminAreaManageCheckWhichCategoriesAreAvailable = _adminArea + "manage.check_which_categories_are_available"
|
||||||
|
|
||||||
PermissionUserProfileApiKeys = "user_profile.api_keys"
|
PermissionUserProfileApiKeys = "user_profile.api_keys"
|
||||||
)
|
)
|
||||||
|
@ -205,6 +209,8 @@ var SystemPermissions = []string{
|
||||||
PermissionAdminAreaDeleteRole,
|
PermissionAdminAreaDeleteRole,
|
||||||
PermissionAdminAreaMoveRoleUpDown,
|
PermissionAdminAreaMoveRoleUpDown,
|
||||||
PermissionAdminAreaLogs,
|
PermissionAdminAreaLogs,
|
||||||
|
PermissionAdminAreaManage,
|
||||||
|
PermissionAdminAreaManageCheckWhichCategoriesAreAvailable,
|
||||||
PermissionUserProfileApiKeys,
|
PermissionUserProfileApiKeys,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,4 +232,6 @@ const (
|
||||||
SubscribedTopicAdminAreaRoles = "/admin-area/roles"
|
SubscribedTopicAdminAreaRoles = "/admin-area/roles"
|
||||||
SubscribedTopicUsers = "/users"
|
SubscribedTopicUsers = "/users"
|
||||||
SubscribedTopicUserProfile = "/user-profile"
|
SubscribedTopicUserProfile = "/user-profile"
|
||||||
|
|
||||||
|
SubscribedTopicAdminAreaManage = "/admin-area/manage"
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserInfo(c *fiber.Ctx) error {
|
func UserInfo(c *fiber.Ctx) error {
|
||||||
|
@ -41,6 +42,8 @@ func UserInfo(c *fiber.Ctx) error {
|
||||||
var categories []string
|
var categories []string
|
||||||
|
|
||||||
for _, categoryGroup := range cache.GetCategoryGroups() {
|
for _, categoryGroup := range cache.GetCategoryGroups() {
|
||||||
|
log.Info().Msgf("categoryGroup: %s", categoryGroup.Category)
|
||||||
|
|
||||||
if socketclients.HasXYPermission(user.Id, utils.PermissionGroupTasksOverviewXYView, categoryGroup.Category) {
|
if socketclients.HasXYPermission(user.Id, utils.PermissionGroupTasksOverviewXYView, categoryGroup.Category) {
|
||||||
categories = append(categories, categoryGroup.Category)
|
categories = append(categories, categoryGroup.Category)
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,6 +362,19 @@ func RunHub() {
|
||||||
break
|
break
|
||||||
case utils.ReceivedCmdDeleteOneNotification:
|
case utils.ReceivedCmdDeleteOneNotification:
|
||||||
notification.DeleteOneNotification(data.Conn.Locals("userId").(string), receivedMessage.Body["notificationId"].(string))
|
notification.DeleteOneNotification(data.Conn.Locals("userId").(string), receivedMessage.Body["notificationId"].(string))
|
||||||
|
break
|
||||||
|
case utils.ReceivedCmdAdminAreaManageCheckWhichCategoriesAreAvailable:
|
||||||
|
if !socketclients.HasPermission(data.Conn.Locals("userId").(string), utils.PermissionAdminAreaManageCheckWhichCategoriesAreAvailable) {
|
||||||
|
socketclients.SendErrorMessageNoPermissions(data.Conn.Locals("sessionId").(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
socketclients.BroadcastMessageToTopic(
|
||||||
|
utils.SubscribedTopicAdminAreaManage,
|
||||||
|
structs.SendSocketMessage{
|
||||||
|
Cmd: utils.SentCmdAdminAreaManageCheckedForAvailableCategories,
|
||||||
|
Body: grouptasks.CheckWhichCategoriesAreAvailable(),
|
||||||
|
})
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
log.Error().Msgf("Received unknown message: %v", receivedMessage)
|
log.Error().Msgf("Received unknown message: %v", receivedMessage)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue