Skip to content
This repository has been archived by the owner on Sep 24, 2023. It is now read-only.

Add AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT to prevent spam #2

Merged
merged 2 commits into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions sentry_ldap_auth/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -29,12 +35,12 @@ 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
Expand All @@ -48,4 +54,12 @@ def get_or_create_user(self, username, ldap_user):
flags=getattr(OrganizationMember.flags, 'sso:linked'),
)

if not getattr(settings, 'AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT', True):
UserOption.objects.set_value(
user=user,
project=None,
key='subscribe_by_default',
value='0',
)

return model