mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-26 02:11:49 -04:00
Save api_key.key_type from radio buttons
This commit is contained in:
@@ -19,6 +19,7 @@ from wtforms.fields.html5 import EmailField, TelField
|
||||
from wtforms.validators import (DataRequired, Email, Length, Regexp)
|
||||
|
||||
from app.main.validators import (Blacklist, CsvFileValidator, ValidEmailDomainRegex, NoCommasInPlaceHolders)
|
||||
from app.notify_client.api_key_api_client import KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM
|
||||
|
||||
|
||||
def email_address(label='Email address'):
|
||||
@@ -295,9 +296,9 @@ class CreateKeyForm(Form):
|
||||
key_type = RadioField(
|
||||
'What should Notify do when you use this key?',
|
||||
choices=[
|
||||
('normal', 'Send messages to anyone'),
|
||||
('test', 'Simulate sending messages to anyone'),
|
||||
('team', 'Only send messages to members of your team')
|
||||
(KEY_TYPE_NORMAL, 'Send messages to anyone'),
|
||||
(KEY_TYPE_TEST, 'Simulate sending messages to anyone'),
|
||||
(KEY_TYPE_TEAM, 'Only send messages to members of your team')
|
||||
],
|
||||
validators=[
|
||||
DataRequired()
|
||||
|
||||
@@ -25,7 +25,11 @@ def create_api_key(service_id):
|
||||
]
|
||||
form = CreateKeyForm(key_names)
|
||||
if form.validate_on_submit():
|
||||
secret = api_key_api_client.create_api_key(service_id=service_id, key_name=form.key_name.data)
|
||||
secret = api_key_api_client.create_api_key(
|
||||
service_id=service_id,
|
||||
key_name=form.key_name.data,
|
||||
key_type=form.key_type.data
|
||||
)
|
||||
return render_template('views/api-keys/show.html', secret=secret,
|
||||
key_name=form.key_name.data)
|
||||
return render_template(
|
||||
|
||||
@@ -5,6 +5,7 @@ from app.notify_client import _attach_current_user
|
||||
# must match key types in notifications-api/app/models.py
|
||||
KEY_TYPE_NORMAL = 'normal'
|
||||
KEY_TYPE_TEAM = 'team'
|
||||
KEY_TYPE_TEST = 'test'
|
||||
|
||||
|
||||
class ApiKeyApiClient(BaseAPIClient):
|
||||
@@ -24,10 +25,10 @@ class ApiKeyApiClient(BaseAPIClient):
|
||||
else:
|
||||
return self.get(url='/service/{}/api-keys'.format(service_id))
|
||||
|
||||
def create_api_key(self, service_id, key_name):
|
||||
def create_api_key(self, service_id, key_name, key_type):
|
||||
data = {
|
||||
'name': key_name,
|
||||
'key_type': KEY_TYPE_NORMAL
|
||||
'key_type': key_type
|
||||
}
|
||||
_attach_current_user(data)
|
||||
key = self.post(url='/service/{}/api-key'.format(service_id), data=data)
|
||||
|
||||
Reference in New Issue
Block a user