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

Side by Side Diff: appengine/findit/model/versioned_config.py

Issue 1836293002: [Findit] Adding central config test class for unit tests (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressing comments Created 4 years, 8 months 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 unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Versioned singleton entity with the global configuration.""" 5 """Versioned singleton entity with the global configuration."""
6 6
7 import logging 7 import logging
8 8
9 from google.appengine.api import users 9 from google.appengine.api import users
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
(...skipping 12 matching lines...) Expand all
23 23
24 # Who created this revision of configuration. 24 # Who created this revision of configuration.
25 updated_by = ndb.StringProperty(indexed=False) 25 updated_by = ndb.StringProperty(indexed=False)
26 26
27 @classmethod 27 @classmethod
28 def Get(cls, version=None): 28 def Get(cls, version=None):
29 """Returns the version of the config entity, the latest if not specified.""" 29 """Returns the version of the config entity, the latest if not specified."""
30 config_data = cls.GetVersion(version) 30 config_data = cls.GetVersion(version)
31 return config_data or cls() if version is None else config_data 31 return config_data or cls() if version is None else config_data
32 32
33 def Update(self, **kwargs): 33 def Update(self, user=None, is_admin=False, **kwargs):
34 """Applies |kwargs| dict to the entity and stores the entity if changed.""" 34 """Applies |kwargs| dict to the entity and stores the entity if changed."""
35 if not users.is_current_user_admin(): 35 if not user and not is_admin and not users.is_current_user_admin():
stgao 2016/04/01 23:35:48 As we already pass in the user and is_admin, why w
stgao 2016/04/01 23:35:48 bug: seems we should use 'or' instead of 'and' her
lijeffrey 2016/04/04 21:35:05 Done.
36 raise Exception('Only admin could update config.') 36 raise Exception('Only admin could update config.')
37 37
38 dirty = False 38 dirty = False
39 for k, v in kwargs.iteritems(): 39 for k, v in kwargs.iteritems():
40 assert k in self._properties, k 40 assert k in self._properties, k
41 if getattr(self, k) != v: 41 if getattr(self, k) != v:
42 setattr(self, k, v) 42 setattr(self, k, v)
43 dirty = True 43 dirty = True
44 44
45 if dirty: 45 if dirty:
46 user_name = users.get_current_user().email().split('@')[0] 46 current_user = user if user else users.get_current_user()
47 user_name = current_user.email().split('@')[0]
47 self.updated_by = user_name 48 self.updated_by = user_name
48 self.Save() 49 self.Save()
49 logging.info('Config %s was updated by %s', self.__class__, user_name) 50 logging.info('Config %s was updated by %s', self.__class__, user_name)
50 51
51 return dirty 52 return dirty
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698