From cd2e0165cd38a896b2d7e984eef547c4388de523 Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Mon, 30 Nov 2015 15:26:36 -0800 Subject: [PATCH 1/2] Add AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT to prevent spam --- README.md | 9 ++++++++- sentry_ldap_auth/backend.py | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 164473e..9c2e0f5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,14 @@ Member type auto-added users are assigned. Valid values are 'MEMBER', 'ADMIN', ' AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS = True ``` Whether auto-created users should be granted global access within the default organization. - + +```Python +AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT = False +``` +Whether new users should be subscribed to any new projects by default. Disabling +this is useful for large organizations where a subscription to each project +might be spammy. + ### Sentry Options ```Python diff --git a/sentry_ldap_auth/backend.py b/sentry_ldap_auth/backend.py index 5b012f3..01de394 100644 --- a/sentry_ldap_auth/backend.py +++ b/sentry_ldap_auth/backend.py @@ -2,7 +2,13 @@ from django_auth_ldap.backend import LDAPBackend from django.conf import settings -from sentry.models import Organization, OrganizationMember, OrganizationMemberType +from sentry.models import ( + Organization, + OrganizationMember, + OrganizationMemberType, + UserOption, +) + class SentryLdapBackend(LDAPBackend): def get_or_create_user(self, username, ldap_user): @@ -40,7 +46,7 @@ def get_or_create_user(self, username, ldap_user): has_global_access = False # Add the user to the organization with global access - OrganizationMember.objects.create( + member = OrganizationMember.objects.create( organization=organizations[0], type=member_type, has_global_access=has_global_access, @@ -48,4 +54,12 @@ def get_or_create_user(self, username, ldap_user): flags=getattr(OrganizationMember.flags, 'sso:linked'), ) + if not settings.AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT: + UserOption.objects.set_value( + user=member.user, + project=None, + key='subscribe_by_default', + value='0', + ) + return model From 1205b99b030cf24a01549163e7e5a1c717e15156 Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Mon, 30 Nov 2015 16:47:32 -0800 Subject: [PATCH 2/2] Add sensible defaults --- sentry_ldap_auth/backend.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sentry_ldap_auth/backend.py b/sentry_ldap_auth/backend.py index 01de394..e32543a 100644 --- a/sentry_ldap_auth/backend.py +++ b/sentry_ldap_auth/backend.py @@ -35,18 +35,18 @@ def get_or_create_user(self, username, ldap_user): if not organizations or len(organizations) < 1: return model - if settings.AUTH_LDAP_SENTRY_ORGANIZATION_MEMBER_TYPE: + if getattr(settings, 'AUTH_LDAP_SENTRY_ORGANIZATION_MEMBER_TYPE', None): member_type = getattr(OrganizationMemberType, settings.AUTH_LDAP_SENTRY_ORGANIZATION_MEMBER_TYPE) else: member_type = OrganizationMemberType.MEMBER - if settings.AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS: + if getattr(settings, 'AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS', False): has_global_access = True else: has_global_access = False # Add the user to the organization with global access - member = OrganizationMember.objects.create( + OrganizationMember.objects.create( organization=organizations[0], type=member_type, has_global_access=has_global_access, @@ -54,9 +54,9 @@ def get_or_create_user(self, username, ldap_user): flags=getattr(OrganizationMember.flags, 'sso:linked'), ) - if not settings.AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT: + if not getattr(settings, 'AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT', True): UserOption.objects.set_value( - user=member.user, + user=user, project=None, key='subscribe_by_default', value='0',