Преглед изворни кода

feat: add visible_to_groups and editable_by_groups to ViewSettings

Add access control fields to the ViewSettings struct to enable view-level
permission management. Views can now restrict visibility and edit access
to specific groups.
Fszontagh пре 6 месеци
родитељ
комит
fc0906839f

+ 2 - 0
webserver/include/smartbotic/webserver/view_service.hpp

@@ -58,6 +58,8 @@ struct ViewSettings {
     std::string icon;
     nlohmann::json filters;  // Default filters
     nlohmann::json sort;     // Default sort
+    std::vector<std::string> visible_to_groups;   // Groups that can see this view (empty = all)
+    std::vector<std::string> editable_by_groups;  // Groups that can edit this view (empty = admins only)
 };
 
 /// View information

+ 20 - 1
webserver/src/view_service.cpp

@@ -555,7 +555,9 @@ auto ViewService::SettingsToJson(const ViewSettings& settings) -> nlohmann::json
         {"show_in_sidebar", settings.show_in_sidebar},
         {"icon", settings.icon},
         {"filters", settings.filters},
-        {"sort", settings.sort}
+        {"sort", settings.sort},
+        {"visible_to_groups", settings.visible_to_groups},
+        {"editable_by_groups", settings.editable_by_groups}
     };
 }
 
@@ -566,6 +568,23 @@ auto ViewService::JsonToSettings(const nlohmann::json& json) -> ViewSettings {
     settings.icon = json.value("icon", "");
     settings.filters = json.value("filters", nlohmann::json::object());
     settings.sort = json.value("sort", nlohmann::json::object());
+
+    // Parse access control arrays
+    if (json.contains("visible_to_groups") && json["visible_to_groups"].is_array()) {
+        for (const auto& group : json["visible_to_groups"]) {
+            if (group.is_string()) {
+                settings.visible_to_groups.push_back(group.get<std::string>());
+            }
+        }
+    }
+    if (json.contains("editable_by_groups") && json["editable_by_groups"].is_array()) {
+        for (const auto& group : json["editable_by_groups"]) {
+            if (group.is_string()) {
+                settings.editable_by_groups.push_back(group.get<std::string>());
+            }
+        }
+    }
+
     return settings;
 }