Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6339)

Unified Diff: appengine/findit/model/versioned_config.py

Issue 1499583002: [Findit] Add a model to provide versioning and also a verioned config model. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add versioned config model. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/model/test/versioned_model_test.py ('k') | appengine/findit/model/versioned_model.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/model/versioned_config.py
diff --git a/appengine/findit/model/versioned_config.py b/appengine/findit/model/versioned_config.py
new file mode 100644
index 0000000000000000000000000000000000000000..c0e3447573a77d9b9accf72b8f4f0640e809da7c
--- /dev/null
+++ b/appengine/findit/model/versioned_config.py
@@ -0,0 +1,50 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Versioned singleton entity with the global configuration."""
+
+import logging
+
+from google.appengine.api import users
+from google.appengine.ext import ndb
+
+from model.versioned_model import VersionedModel
+
+
+class VersionedConfig(VersionedModel):
+ """Singleton entity with the global configuration of the service.
+
+ All changes are stored in the revision log.
+ """
+
+ # When this revision of configuration was created.
+ updated_ts = ndb.DateTimeProperty(indexed=False, auto_now_add=True)
+
+ # Who created this revision of configuration.
+ updated_by = ndb.StringProperty(indexed=False)
+
+ @classmethod
+ def Get(cls):
+ """Returns the current up-to-date version of the config entity."""
+ return cls.GetMostRecentVersion() or cls()
+
+ def Update(self, **kwargs):
+ """Applies |kwargs| dict to the entity and stores the entity if changed."""
+ if not users.is_current_user_admin():
+ raise Exception('Only admin could update config.')
+
+ dirty = False
+ for k, v in kwargs.iteritems():
+ assert k in self._properties, k
+ if getattr(self, k) != v:
+ setattr(self, k, v)
+ dirty = True
+
+ if dirty:
+ user_name = users.get_current_user().email().split('@')[0]
+ self.updated_by = user_name
+ self.Save()
+ logging.info('Config %s was updated by %s', self.__class__, user_name)
+
+ return dirty
« no previous file with comments | « appengine/findit/model/test/versioned_model_test.py ('k') | appengine/findit/model/versioned_model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698