2018-11-26 21:08:48 +00:00
|
|
|
"""passbook rule forms"""
|
|
|
|
|
|
|
|
from django import forms
|
2018-12-14 14:18:02 +00:00
|
|
|
from django.utils.translation import gettext as _
|
2018-11-26 21:08:48 +00:00
|
|
|
|
2018-12-09 20:06:21 +00:00
|
|
|
from passbook.core.models import DebugRule, FieldMatcherRule, WebhookRule
|
2018-11-26 21:08:48 +00:00
|
|
|
|
2018-12-09 20:06:21 +00:00
|
|
|
GENERAL_FIELDS = ['name', 'action', 'negate', 'order', ]
|
2018-11-26 21:08:48 +00:00
|
|
|
|
|
|
|
class FieldMatcherRuleForm(forms.ModelForm):
|
|
|
|
"""FieldMatcherRule Form"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = FieldMatcherRule
|
2018-12-09 20:06:21 +00:00
|
|
|
fields = GENERAL_FIELDS + ['user_field', 'match_action', 'value', ]
|
2018-11-26 21:08:48 +00:00
|
|
|
widgets = {
|
|
|
|
'name': forms.TextInput(),
|
|
|
|
'value': forms.TextInput(),
|
|
|
|
}
|
2018-11-27 15:23:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WebhookRuleForm(forms.ModelForm):
|
|
|
|
"""WebhookRuleForm Form"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = WebhookRule
|
2018-12-09 20:06:21 +00:00
|
|
|
fields = GENERAL_FIELDS + ['url', 'method', 'json_body', 'json_headers',
|
|
|
|
'result_jsonpath', 'result_json_value', ]
|
2018-11-27 15:23:04 +00:00
|
|
|
widgets = {
|
2018-12-09 20:06:21 +00:00
|
|
|
'name': forms.TextInput(),
|
2018-11-27 15:23:04 +00:00
|
|
|
'json_body': forms.TextInput(),
|
|
|
|
'json_headers': forms.TextInput(),
|
|
|
|
'result_jsonpath': forms.TextInput(),
|
|
|
|
'result_json_value': forms.TextInput(),
|
|
|
|
}
|
2018-12-09 20:06:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DebugRuleForm(forms.ModelForm):
|
|
|
|
"""DebugRuleForm Form"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
model = DebugRule
|
|
|
|
fields = GENERAL_FIELDS + ['result', 'wait_min', 'wait_max']
|
|
|
|
widgets = {
|
|
|
|
'name': forms.TextInput(),
|
|
|
|
}
|
2018-12-14 14:18:02 +00:00
|
|
|
labels = {
|
|
|
|
'result': _('Allow user')
|
|
|
|
}
|