diff --git a/passbook/core/forms/rules.py b/passbook/core/forms/rules.py index f4debd952..c965ed4da 100644 --- a/passbook/core/forms/rules.py +++ b/passbook/core/forms/rules.py @@ -2,7 +2,7 @@ from django import forms -from passbook.core.models import FieldMatcherRule +from passbook.core.models import FieldMatcherRule, WebhookRule class FieldMatcherRuleForm(forms.ModelForm): @@ -18,3 +18,19 @@ class FieldMatcherRuleForm(forms.ModelForm): 'user_field': forms.TextInput(), 'value': forms.TextInput(), } + + +class WebhookRuleForm(forms.ModelForm): + """WebhookRuleForm Form""" + + class Meta: + + model = WebhookRule + fields = ['url', 'method', 'json_body', 'json_headers', + 'result_jsonpath', 'result_json_value', ] + widgets = { + 'json_body': forms.TextInput(), + 'json_headers': forms.TextInput(), + 'result_jsonpath': forms.TextInput(), + 'result_json_value': forms.TextInput(), + } diff --git a/passbook/core/migrations/0004_auto_20181127_1341.py b/passbook/core/migrations/0004_auto_20181127_1341.py new file mode 100644 index 000000000..fce3ddf12 --- /dev/null +++ b/passbook/core/migrations/0004_auto_20181127_1341.py @@ -0,0 +1,40 @@ +# Generated by Django 2.1.3 on 2018-11-27 13:41 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0003_rule_order'), + ] + + operations = [ + migrations.CreateModel( + name='WebhookRule', + fields=[ + ('rule_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='passbook_core.Rule')), + ('url', models.URLField()), + ('method', models.CharField(choices=[('get', 'get'), ('post', 'post'), ('patch', 'patch'), ('delete', 'delete'), ('put', 'put')], max_length=10)), + ('json_body', models.TextField()), + ('json_headers', models.TextField()), + ('result_jsonpath', models.TextField()), + ('result_json_value', models.TextField()), + ], + options={ + 'verbose_name': 'Webhook Rule', + 'verbose_name_plural': 'Webhook Rules', + }, + bases=('passbook_core.rule',), + ), + migrations.AlterModelOptions( + name='fieldmatcherrule', + options={'verbose_name': 'Field matcher Rule', 'verbose_name_plural': 'Field matcher Rules'}, + ), + migrations.AlterField( + model_name='fieldmatcherrule', + name='match_action', + field=models.CharField(choices=[('startswith', 'Starts with'), ('endswith', 'Ends with'), ('endswith', 'Contains'), ('regexp', 'Regexp'), ('exact', 'Exact')], max_length=50), + ), + ] diff --git a/passbook/core/migrations/0005_auto_20181127_1522.py b/passbook/core/migrations/0005_auto_20181127_1522.py new file mode 100644 index 000000000..9bd4cf078 --- /dev/null +++ b/passbook/core/migrations/0005_auto_20181127_1522.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-11-27 15:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0004_auto_20181127_1341'), + ] + + operations = [ + migrations.AlterField( + model_name='webhookrule', + name='method', + field=models.CharField(choices=[('GET', 'GET'), ('POST', 'POST'), ('PATCH', 'PATCH'), ('DELETE', 'DELETE'), ('PUT', 'PUT')], max_length=10), + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index 1fe0f8aac..1e793d552 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -175,3 +175,40 @@ class FieldMatcherRule(Rule): verbose_name = _('Field matcher Rule') verbose_name_plural = _('Field matcher Rules') +@reversion.register() +class WebhookRule(Rule): + """Rule that asks webhook""" + + METHOD_GET = 'GET' + METHOD_POST = 'POST' + METHOD_PATCH = 'PATCH' + METHOD_DELETE = 'DELETE' + METHOD_PUT = 'PUT' + + METHODS = ( + (METHOD_GET, METHOD_GET), + (METHOD_POST, METHOD_POST), + (METHOD_PATCH, METHOD_PATCH), + (METHOD_DELETE, METHOD_DELETE), + (METHOD_PUT, METHOD_PUT), + ) + + url = models.URLField() + method = models.CharField(max_length=10, choices=METHODS) + json_body = models.TextField() + json_headers = models.TextField() + result_jsonpath = models.TextField() + result_json_value = models.TextField() + + name = 'passbook_core.WebhookRule' + form = 'passbook.core.forms.rules.WebhookRuleForm' + + def passes(self, user: User): + """Call webhook asynchronously and report back""" + raise NotImplementedError() + + class Meta: + + verbose_name = _('Webhook Rule') + verbose_name_plural = _('Webhook Rules') + diff --git a/passbook/ldap/migrations/0002_auto_20181127_1341.py b/passbook/ldap/migrations/0002_auto_20181127_1341.py new file mode 100644 index 000000000..770d8950d --- /dev/null +++ b/passbook/ldap/migrations/0002_auto_20181127_1341.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.3 on 2018-11-27 13:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_ldap', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='ldapsource', + name='type', + field=models.CharField(choices=[('ad', 'Active Directory'), ('generic', 'Generic')], max_length=20), + ), + ]