Skip to content

Commit e972999

Browse files
authored
Make role mapping be optional
1 parent 0d96910 commit e972999

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

sentry_auth_ldap/backend.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99

1010

11-
def _get_effective_sentry_role(group_names):
11+
def _get_effective_sentry_role(ldap_user):
1212
role_priority_order = [
1313
'member',
1414
'admin',
@@ -17,17 +17,18 @@ def _get_effective_sentry_role(group_names):
1717
]
1818

1919
role_mapping = getattr(settings, 'AUTH_LDAP_SENTRY_GROUP_ROLE_MAPPING', None)
20+
if not role_mapping:
21+
return None
2022

21-
if not group_names or not role_mapping:
23+
group_names = ldap_user.group_names
24+
if not group_names:
2225
return None
2326

2427
applicable_roles = [role for role, groups in role_mapping.items() if group_names.intersection(groups)]
25-
2628
if not applicable_roles:
2729
return None
2830

2931
highest_role = [role for role in role_priority_order if role in applicable_roles][-1]
30-
3132
return highest_role
3233

3334

@@ -79,9 +80,7 @@ def get_or_build_user(self, username, ldap_user):
7980
if not organizations or len(organizations) < 1:
8081
return (user, built)
8182

82-
member_role = _get_effective_sentry_role(ldap_user.group_names)
83-
if not member_role:
84-
member_role = getattr(settings, 'AUTH_LDAP_SENTRY_ORGANIZATION_ROLE_TYPE', None)
83+
member_role = _get_effective_sentry_role(ldap_user) or getattr(settings, 'AUTH_LDAP_SENTRY_ORGANIZATION_ROLE_TYPE', None)
8584

8685
has_global_access = getattr(settings, 'AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS', False)
8786

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setup(
2020
name='sentry-auth-ldap',
21-
version='21.9.8',
21+
version='21.9.9',
2222
author='Chad Killingsworth <chad.killingsworth@banno.com>, Barron Hagerman <barron.hagerman@banno.com>, PM Extra <pm@jubeat.net>',
2323
author_email='pm@jubeat.net',
2424
url='https://github.com/PMExtra/sentry-auth-ldap',

0 commit comments

Comments
 (0)