users: Get all API keys via wrapper method.

Now reading API keys from a user is done with the get_api_key wrapper
method, rather than directly fetching it from the user object.

Also, every place where an action should be done for each API key is now
using get_all_api_keys. This method returns for the moment a single-item
list, containing the specified user's API key.

This commit is the first step towards allowing users have multiple API
keys.
This commit is contained in:
Yago González
2018-08-01 10:53:40 +02:00
committed by Tim Abbott
parent 13b9dd33fa
commit f6219745de
20 changed files with 110 additions and 52 deletions

View File

@@ -3,6 +3,7 @@ from typing import Dict, Optional
import ujson
from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.users import get_api_key
from zerver.lib.webhooks.git import COMMITS_LIMIT
from zerver.models import Message
@@ -39,7 +40,7 @@ class GithubV1HookTests(WebhookTestCase):
self.assertEqual(prior_count, after_count)
def get_body(self, fixture_name: str) -> Dict[str, str]:
api_key = self.test_user.api_key
api_key = get_api_key(self.test_user)
data = ujson.loads(self.webhook_fixture_data(self.FIXTURE_DIR_NAME, 'v1_' + fixture_name))
data.update({'email': self.TEST_USER_EMAIL,
'api-key': api_key,
@@ -164,7 +165,7 @@ class GithubV2HookTests(WebhookTestCase):
self.assertEqual(prior_count, after_count)
def get_body(self, fixture_name: str) -> Dict[str, str]:
api_key = self.test_user.api_key
api_key = get_api_key(self.test_user)
data = ujson.loads(self.webhook_fixture_data(self.FIXTURE_DIR_NAME, 'v2_' + fixture_name))
data.update({'email': self.TEST_USER_EMAIL,
'api-key': api_key,