diff --git a/passbook/admin/forms/users.py b/passbook/admin/forms/users.py index d6ef9a084..c150071a1 100644 --- a/passbook/admin/forms/users.py +++ b/passbook/admin/forms/users.py @@ -11,7 +11,7 @@ class UserForm(forms.ModelForm): class Meta: model = User - fields = ['username', 'name', 'email', 'is_staff', 'is_active'] + fields = ['username', 'name', 'email', 'is_staff', 'is_active', 'attributes'] widgets = { 'name': forms.TextInput } diff --git a/passbook/audit/models.py b/passbook/audit/models.py index 6febb1698..d9693d4bc 100644 --- a/passbook/audit/models.py +++ b/passbook/audit/models.py @@ -60,7 +60,8 @@ class AuditEntry(UUIDModel): # User 255.255.255.255 as fallback if IP cannot be determined request_ip=client_ip or '255.255.255.255', context=kwargs) - LOGGER.debug("Logged %s from %s (%s)", action, user, client_ip) + LOGGER.debug("Created Audit entry", action=action, + user=user, from_ip=client_ip, context=kwargs) return entry def save(self, *args, **kwargs): diff --git a/passbook/core/forms/groups.py b/passbook/core/forms/groups.py index 3a776cd17..e57240f09 100644 --- a/passbook/core/forms/groups.py +++ b/passbook/core/forms/groups.py @@ -26,7 +26,7 @@ class GroupForm(forms.ModelForm): class Meta: model = Group - fields = ['name', 'parent', 'members', 'tags'] + fields = ['name', 'parent', 'members', 'attributes'] widgets = { 'name': forms.TextInput(), } diff --git a/passbook/core/migrations/0003_auto_20191011_0914.py b/passbook/core/migrations/0003_auto_20191011_0914.py new file mode 100644 index 000000000..8321f1a0b --- /dev/null +++ b/passbook/core/migrations/0003_auto_20191011_0914.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.6 on 2019-10-11 09:14 + +import django.contrib.postgres.fields.jsonb +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0002_nonce_description'), + ] + + operations = [ + migrations.RenameField( + model_name='group', + old_name='tags', + new_name='attributes', + ), + migrations.AddField( + model_name='source', + name='property_mappings', + field=models.ManyToManyField(blank=True, default=None, to='passbook_core.PropertyMapping'), + ), + migrations.AddField( + model_name='user', + name='attributes', + field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict), + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index 4b413151e..294a18cd4 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -32,7 +32,7 @@ class Group(UUIDModel): name = models.CharField(_('name'), max_length=80) parent = models.ForeignKey('Group', blank=True, null=True, on_delete=models.SET_NULL, related_name='children') - tags = JSONField(default=dict, blank=True) + attributes = JSONField(default=dict, blank=True) def __str__(self): return f"Group {self.name}" @@ -51,6 +51,8 @@ class User(AbstractUser): groups = models.ManyToManyField('Group') password_change_date = models.DateTimeField(auto_now_add=True) + attributes = JSONField(default=dict, blank=True) + def set_password(self, password): if self.pk: password_changed.send(sender=self, user=self, password=password) @@ -143,6 +145,7 @@ class Source(PolicyModel): name = models.TextField() slug = models.SlugField() enabled = models.BooleanField(default=True) + property_mappings = models.ManyToManyField('PropertyMapping', default=None, blank=True) form = '' # ModelForm-based class ued to create/edit instance diff --git a/passbook/factors/password/factor.py b/passbook/factors/password/factor.py index 0d5325be1..ed2a2244a 100644 --- a/passbook/factors/password/factor.py +++ b/passbook/factors/password/factor.py @@ -30,7 +30,7 @@ def authenticate(request, backends, **credentials) -> Optional[User]: signature = Signature.from_callable(backend.authenticate) signature.bind(request, **credentials) except TypeError: - LOGGER.debug("Backend doesn't accept our arguments", backend=backend) + LOGGER.warning("Backend doesn't accept our arguments", backend=backend) # This backend doesn't accept these credentials as arguments. Try the next one. continue LOGGER.debug('Attempting authentication...', backend=backend) diff --git a/passbook/factors/view.py b/passbook/factors/view.py index d53d38502..062bab75e 100644 --- a/passbook/factors/view.py +++ b/passbook/factors/view.py @@ -134,7 +134,7 @@ class AuthenticationView(UserPassesTestMixin, View): LOGGER.debug("Rendering Factor", next_factor=next_factor) return _redirect_with_qs('passbook_core:auth-process', self.request.GET) # User passed all factors - LOGGER.debug("User passed all factors, logging in") + LOGGER.debug("User passed all factors, logging in", user=self.pending_user) return self._user_passed() def user_invalid(self): diff --git a/passbook/root/settings.py b/passbook/root/settings.py index 0c7041798..f829520aa 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -307,7 +307,12 @@ if any('test' in arg for arg in sys.argv): CELERY_TASK_ALWAYS_EAGER = True -_DISALLOWED_ITEMS = ['INSTALLED_APPS', 'MIDDLEWARE', 'AUTHENTICATION_BACKENDS'] +_DISALLOWED_ITEMS = [ + 'INSTALLED_APPS', + 'MIDDLEWARE', + 'AUTHENTICATION_BACKENDS', + 'CELERY_BEAT_SCHEDULE' +] # Load subapps's INSTALLED_APPS for _app in INSTALLED_APPS: if _app.startswith('passbook'): @@ -318,6 +323,7 @@ for _app in INSTALLED_APPS: INSTALLED_APPS.extend(getattr(app_settings, 'INSTALLED_APPS', [])) MIDDLEWARE.extend(getattr(app_settings, 'MIDDLEWARE', [])) AUTHENTICATION_BACKENDS.extend(getattr(app_settings, 'AUTHENTICATION_BACKENDS', [])) + CELERY_BEAT_SCHEDULE.update(getattr(app_settings, 'CELERY_BEAT_SCHEDULE', {})) for _attr in dir(app_settings): if not _attr.startswith('__') and _attr not in _DISALLOWED_ITEMS: globals()[_attr] = getattr(app_settings, _attr)