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(),
|
||||||
|
|
|
@ -94,6 +94,7 @@ const (
|
||||||
SentCmdNewNotification = 41
|
SentCmdNewNotification = 41
|
||||||
SentCmdAllNotificationsDeleted = 42
|
SentCmdAllNotificationsDeleted = 42
|
||||||
SentCmdOneNotificationDeleted = 43
|
SentCmdOneNotificationDeleted = 43
|
||||||
|
SentCmdAdminAreaManageCheckedForAvailableCategories = 44
|
||||||
)
|
)
|
||||||
|
|
||||||
// commands received from web clients
|
// commands received from web clients
|
||||||
|
@ -123,6 +124,7 @@ const (
|
||||||
ReceivedCmdSubscribeToTopic = 23
|
ReceivedCmdSubscribeToTopic = 23
|
||||||
ReceivedCmdDeleteAllNotifications = 24
|
ReceivedCmdDeleteAllNotifications = 24
|
||||||
ReceivedCmdDeleteOneNotification = 25
|
ReceivedCmdDeleteOneNotification = 25
|
||||||
|
ReceivedCmdAdminAreaManageCheckWhichCategoriesAreAvailable = 26
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -184,6 +186,8 @@ const (
|
||||||
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