Merge pull request #4480 from ynput/feature/OP-3026_Studio-Settings-logging-changes

Settings - first implementation of saving settings changes to DB
This commit is contained in:
Petr Kalis 2023-02-24 18:13:23 +01:00 committed by GitHub
commit b2e8d2ff7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import six
import openpype.version
from openpype.client.mongo import OpenPypeMongoConnection
from openpype.client.entities import get_project_connection, get_project
from openpype.lib.pype_info import get_workstation_info
from .constants import (
GLOBAL_SETTINGS_KEY,
@ -235,6 +236,18 @@ class SettingsHandler(object):
"""
pass
@abstractmethod
def save_change_log(self, project_name, changes, settings_type):
"""Stores changes to settings to separate logging collection.
Args:
project_name(str, null): Project name for which overrides are
or None for global settings.
changes(dict): Data of project overrides with override metadata.
settings_type (str): system|project|anatomy
"""
pass
@abstractmethod
def get_studio_system_settings_overrides(self, return_version):
"""Studio overrides of system settings."""
@ -913,6 +926,32 @@ class MongoSettingsHandler(SettingsHandler):
return data
def save_change_log(self, project_name, changes, settings_type):
"""Log all settings changes to separate collection"""
if not changes:
return
if settings_type == "project" and not project_name:
project_name = "default"
host_info = get_workstation_info()
document = {
"local_id": host_info["local_id"],
"username": host_info["username"],
"hostname": host_info["hostname"],
"hostip": host_info["hostip"],
"system_name": host_info["system_name"],
"date_created": datetime.datetime.now(),
"project": project_name,
"settings_type": settings_type,
"changes": changes
}
collection_name = "settings_log"
collection = (self.settings_collection[self.database_name]
[collection_name])
collection.insert_one(document)
def _save_project_anatomy_data(self, project_name, data_cache):
# Create copy of data as they will be modified during save
new_data = data_cache.data_copy()

View file

@ -159,6 +159,7 @@ def save_studio_settings(data):
except SaveWarningExc as exc:
warnings.extend(exc.warnings)
_SETTINGS_HANDLER.save_change_log(None, changes, "system")
_SETTINGS_HANDLER.save_studio_settings(data)
if warnings:
raise SaveWarningExc(warnings)
@ -218,7 +219,7 @@ def save_project_settings(project_name, overrides):
)
except SaveWarningExc as exc:
warnings.extend(exc.warnings)
_SETTINGS_HANDLER.save_change_log(project_name, changes, "project")
_SETTINGS_HANDLER.save_project_settings(project_name, overrides)
if warnings:
@ -280,6 +281,7 @@ def save_project_anatomy(project_name, anatomy_data):
except SaveWarningExc as exc:
warnings.extend(exc.warnings)
_SETTINGS_HANDLER.save_change_log(project_name, changes, "anatomy")
_SETTINGS_HANDLER.save_project_anatomy(project_name, anatomy_data)
if warnings: