diff --git a/passbook/admin/templates/administration/base.html b/passbook/admin/templates/administration/base.html index 7ed02b095..fadc37d70 100644 --- a/passbook/admin/templates/administration/base.html +++ b/passbook/admin/templates/administration/base.html @@ -20,8 +20,8 @@
  • {% trans 'Factors' %}
  • -
  • - {% trans 'Policies' %} +
  • + {% trans 'Policies' %}
  • {% trans 'Invitations' %} diff --git a/passbook/admin/views/policy.py b/passbook/admin/views/policy.py index 1bf29dac4..371b75ce3 100644 --- a/passbook/admin/views/policy.py +++ b/passbook/admin/views/policy.py @@ -15,7 +15,7 @@ from passbook.lib.utils.reflection import path_to_class class PolicyListView(AdminRequiredMixin, ListView): - """Show list of all policys""" + """Show list of all policies""" model = Policy template_name = 'administration/policy/list.html' @@ -33,7 +33,7 @@ class PolicyCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView): """Create new Policy""" template_name = 'generic/create_inheritance.html' - success_url = reverse_lazy('passbook_admin:policys') + success_url = reverse_lazy('passbook_admin:policies') success_message = _('Successfully created Policy') def get_form_class(self): @@ -50,7 +50,7 @@ class PolicyUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView): model = Policy template_name = 'generic/update.html' - success_url = reverse_lazy('passbook_admin:policys') + success_url = reverse_lazy('passbook_admin:policies') success_message = _('Successfully updated Policy') def get_form_class(self): @@ -67,7 +67,7 @@ class PolicyDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): model = Policy template_name = 'generic/delete.html' - success_url = reverse_lazy('passbook_admin:policys') + success_url = reverse_lazy('passbook_admin:policies') success_message = _('Successfully updated Policy') def get_object(self, queryset=None): diff --git a/passbook/core/auth/view.py b/passbook/core/auth/view.py index ceb961349..dc85db2c3 100644 --- a/passbook/core/auth/view.py +++ b/passbook/core/auth/view.py @@ -54,11 +54,13 @@ class AuthenticationView(UserPassesTestMixin, View): self.pending_factors = [] for factor in _all_factors: if factor.passes(self.pending_user): - self.pending_factors.append(_all_factors) - # self.pending_factors = Factor + self.pending_factors.append(factor.type) # Read and instantiate factor from session factor_class = None if AuthenticationView.SESSION_FACTOR not in request.session: + # Case when no factors apply to user, return error denied + if not self.pending_factors: + return self.user_invalid() factor_class = self.pending_factors[0] else: factor_class = request.session[AuthenticationView.SESSION_FACTOR] @@ -110,6 +112,7 @@ class AuthenticationView(UserPassesTestMixin, View): LOGGER.debug("Logged in user %s", self.pending_user) # Cleanup self._cleanup() + # TODO: ?next=... return redirect(reverse('passbook_core:overview')) def _cleanup(self): diff --git a/passbook/core/migrations/0002_auto_20190216_1002.py b/passbook/core/migrations/0002_auto_20190216_1002.py new file mode 100644 index 000000000..09704b03a --- /dev/null +++ b/passbook/core/migrations/0002_auto_20190216_1002.py @@ -0,0 +1,29 @@ +# Generated by Django 2.1.7 on 2019-02-16 10:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='debugpolicy', + options={'verbose_name': 'Debug Policy', 'verbose_name_plural': 'Debug Policies'}, + ), + migrations.AlterModelOptions( + name='fieldmatcherpolicy', + options={'verbose_name': 'Field matcher Policy', 'verbose_name_plural': 'Field matcher Policies'}, + ), + migrations.AlterModelOptions( + name='passwordpolicypolicy', + options={'verbose_name': 'Password Policy Policy', 'verbose_name_plural': 'Password Policy Policies'}, + ), + migrations.AlterModelOptions( + name='webhookpolicy', + options={'verbose_name': 'Webhook Policy', 'verbose_name_plural': 'Webhook Policies'}, + ), + ] diff --git a/passbook/core/migrations/0003_auto_20190216_1004.py b/passbook/core/migrations/0003_auto_20190216_1004.py new file mode 100644 index 000000000..88363038d --- /dev/null +++ b/passbook/core/migrations/0003_auto_20190216_1004.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1.7 on 2019-02-16 10:04 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0002_auto_20190216_1002'), + ] + + operations = [ + migrations.RenameModel( + old_name='PasswordPolicyPolicy', + new_name='PasswordPolicy', + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index 82ed89976..93f660412 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -56,7 +56,7 @@ class PolicyModel(UUIDModel, CreatedUpdatedModel): def passes(self, user: User) -> bool: """Return true if user passes, otherwise False or raise Exception""" - for policy in self.policies: + for policy in self.policies.all(): if not policy.passes(user): return False return True @@ -130,7 +130,7 @@ class UserSourceConnection(CreatedUpdatedModel): unique_together = (('user', 'source'),) class Policy(UUIDModel, CreatedUpdatedModel): - """Policys which specify if a user is authorized to use an Application. Can be overridden by + """Policies which specify if a user is authorized to use an Application. Can be overridden by other types to add other fields, more logic, etc.""" ACTION_ALLOW = 'allow' @@ -222,9 +222,9 @@ class FieldMatcherPolicy(Policy): class Meta: verbose_name = _('Field matcher Policy') - verbose_name_plural = _('Field matcher Policys') + verbose_name_plural = _('Field matcher Policies') -class PasswordPolicyPolicy(Policy): +class PasswordPolicy(Policy): """Policy to make sure passwords have certain properties""" amount_uppercase = models.IntegerField(default=0) @@ -233,7 +233,7 @@ class PasswordPolicyPolicy(Policy): length_min = models.IntegerField(default=0) symbol_charset = models.TextField(default=r"!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ ") - form = 'passbook.core.forms.policies.PasswordPolicyPolicyForm' + form = 'passbook.core.forms.policies.PasswordPolicyForm' def passes(self, user: User) -> bool: # Only check if password is being set @@ -254,8 +254,8 @@ class PasswordPolicyPolicy(Policy): class Meta: - verbose_name = _('Password Policy Policy') - verbose_name_plural = _('Password Policy Policys') + verbose_name = _('Password Policy') + verbose_name_plural = _('Password Policies') class WebhookPolicy(Policy): @@ -291,7 +291,7 @@ class WebhookPolicy(Policy): class Meta: verbose_name = _('Webhook Policy') - verbose_name_plural = _('Webhook Policys') + verbose_name_plural = _('Webhook Policies') class DebugPolicy(Policy): """Policy used for debugging the PolicyEngine. Returns a fixed result, @@ -313,7 +313,7 @@ class DebugPolicy(Policy): class Meta: verbose_name = _('Debug Policy') - verbose_name_plural = _('Debug Policys') + verbose_name_plural = _('Debug Policies') class Invitation(UUIDModel): """Single-use invitation link"""