##// END OF EJS Templates
user: deprecated usage of api_keys....
marcink -
r1953:9d49c7f1 default
parent child Browse files
Show More
@@ -135,7 +135,7 b' class TestAdminUsersView(TestController)'
135 135 self.log_user()
136 136 user = user_util.create_user()
137 137 user_id = user.user_id
138 keys = user.extra_auth_tokens
138 keys = user.auth_tokens
139 139 assert 2 == len(keys)
140 140
141 141 response = self.app.post(
@@ -87,7 +87,7 b' class TestMyAccountAuthTokens(TestContro'
87 87 self.log_user(user.username, 'qweqwe')
88 88
89 89 user = User.get(user_id)
90 keys = user.extra_auth_tokens
90 keys = user.get_auth_tokens()
91 91 assert 2 == len(keys)
92 92
93 93 response = self.app.post(
@@ -98,7 +98,7 b' class TestMyAccountAuthTokens(TestContro'
98 98 response.follow()
99 99
100 100 user = User.get(user_id)
101 keys = user.extra_auth_tokens
101 keys = user.get_auth_tokens()
102 102 assert 3 == len(keys)
103 103
104 104 response = self.app.post(
@@ -107,5 +107,5 b' class TestMyAccountAuthTokens(TestContro'
107 107 assert_session_flash(response, 'Auth token successfully deleted')
108 108
109 109 user = User.get(user_id)
110 keys = user.extra_auth_tokens
110 keys = user.auth_tokens
111 111 assert 2 == len(keys)
@@ -865,7 +865,7 b' class AuthUser(object):'
865 865 Fills in user data and propagates values to this instance. Maps fetched
866 866 user attributes to this class instance attributes
867 867 """
868 log.debug('starting data propagation for new potential AuthUser')
868 log.debug('AuthUser: starting data propagation for new potential user')
869 869 user_model = UserModel()
870 870 anon_user = self.anonymous_user = User.get_default_user(cache=True)
871 871 is_user_loaded = False
@@ -904,7 +904,7 b' class AuthUser(object):'
904 904 if not self.username:
905 905 self.username = 'None'
906 906
907 log.debug('Auth User is now %s' % self)
907 log.debug('AuthUser: propagated user is now %s' % self)
908 908
909 909 def get_perms(self, user, scope=None, explicit=True, algo='higherwin',
910 910 cache=False):
@@ -619,15 +619,15 b' class User(Base, BaseModel):'
619 619
620 620 @property
621 621 def emails(self):
622 other = UserEmailMap.query().filter(UserEmailMap.user==self).all()
622 other = UserEmailMap.query().filter(UserEmailMap.user == self).all()
623 623 return [self.email] + [x.email for x in other]
624 624
625 625 @property
626 626 def auth_tokens(self):
627 return [x.api_key for x in self.extra_auth_tokens]
628
629 @property
630 def extra_auth_tokens(self):
627 auth_tokens = self.get_auth_tokens()
628 return [x.api_key for x in auth_tokens]
629
630 def get_auth_tokens(self):
631 631 return UserApiKeys.query().filter(UserApiKeys.user == self).all()
632 632
633 633 @property
@@ -938,12 +938,11 b' class User(Base, BaseModel):'
938 938 if details == 'basic':
939 939 return data
940 940
941 api_key_length = 40
942 api_key_replacement = '*' * api_key_length
941 auth_token_length = 40
942 auth_token_replacement = '*' * auth_token_length
943 943
944 944 extras = {
945 'api_keys': [api_key_replacement],
946 'auth_tokens': [api_key_replacement],
945 'auth_tokens': [auth_token_replacement],
947 946 'active': user.active,
948 947 'admin': user.admin,
949 948 'extern_type': user.extern_type,
@@ -956,8 +955,7 b' class User(Base, BaseModel):'
956 955 data.update(extras)
957 956
958 957 if include_secrets:
959 data['api_keys'] = user.auth_tokens
960 data['auth_tokens'] = user.extra_auth_tokens
958 data['auth_tokens'] = user.auth_tokens
961 959 return data
962 960
963 961 def __json__(self):
@@ -372,7 +372,10 b' class UserModel(BaseModel):'
372 372 AuthTokenModel().create(username,
373 373 description='Generated feed token',
374 374 role=AuthTokenModel.cls.ROLE_FEED)
375 log_create_user(created_by=cur_user, **new_user.get_dict())
375 kwargs = new_user.get_dict()
376 # backward compat, require api_keys present
377 kwargs['api_keys'] = kwargs['auth_tokens']
378 log_create_user(created_by=cur_user, **kwargs)
376 379 events.trigger(events.UserPostCreate(user_data))
377 380 return new_user
378 381 except (DatabaseError,):
@@ -675,17 +678,15 b' class UserModel(BaseModel):'
675 678 return False
676 679
677 680 log.debug('filling user:%s data', dbuser)
681 user_data = dbuser.get_dict()
678 682
679 # TODO: johbo: Think about this and find a clean solution
680 user_data = dbuser.get_dict()
681 user_data.update(dbuser.get_api_data(include_secrets=True))
682 683 user_data.update({
683 684 # set explicit the safe escaped values
684 685 'first_name': dbuser.first_name,
685 686 'last_name': dbuser.last_name,
686 687 })
687 688
688 for k, v in user_data.iteritems():
689 for k, v in user_data.items():
689 690 # properties of auth user we dont update
690 691 if k not in ['auth_tokens', 'permissions']:
691 692 setattr(auth_user, k, v)
@@ -190,13 +190,13 b' def test_get_api_data_replaces_secret_da'
190 190 api_key_length = 40
191 191 expected_replacement = '*' * api_key_length
192 192
193 for key in api_data['api_keys']:
193 for key in api_data['auth_tokens']:
194 194 assert key == expected_replacement
195 195
196 196
197 197 def test_get_api_data_includes_secret_data_if_activated(test_user):
198 198 api_data = test_user.get_api_data(include_secrets=True)
199 assert api_data['api_keys'] == test_user.auth_tokens
199 assert api_data['auth_tokens'] == test_user.auth_tokens
200 200
201 201
202 202 def test_add_perm(test_user):
General Comments 0
You need to be logged in to leave comments. Login now