mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 00:37:37 -02:30
Basic License feature gating changes
This commit is contained in:
@@ -13,9 +13,6 @@ from social_core.exceptions import AuthException
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db.models import Q
|
||||
|
||||
# Tower
|
||||
from awx.conf.license import feature_enabled
|
||||
|
||||
|
||||
logger = logging.getLogger('awx.sso.pipeline')
|
||||
|
||||
@@ -83,18 +80,11 @@ def _update_m2m_from_expression(user, rel, expr, remove=True):
|
||||
|
||||
def _update_org_from_attr(user, rel, attr, remove, remove_admins):
|
||||
from awx.main.models import Organization
|
||||
multiple_orgs = feature_enabled('multiple_organizations')
|
||||
|
||||
org_ids = []
|
||||
|
||||
for org_name in attr:
|
||||
if multiple_orgs:
|
||||
org = Organization.objects.get_or_create(name=org_name)[0]
|
||||
else:
|
||||
try:
|
||||
org = Organization.objects.order_by('pk')[0]
|
||||
except IndexError:
|
||||
continue
|
||||
org = Organization.objects.get_or_create(name=org_name)[0]
|
||||
|
||||
org_ids.append(org.id)
|
||||
getattr(org, rel).members.add(user)
|
||||
@@ -116,19 +106,10 @@ def update_user_orgs(backend, details, user=None, *args, **kwargs):
|
||||
if not user:
|
||||
return
|
||||
from awx.main.models import Organization
|
||||
multiple_orgs = feature_enabled('multiple_organizations')
|
||||
org_map = backend.setting('ORGANIZATION_MAP') or {}
|
||||
for org_name, org_opts in org_map.items():
|
||||
org = Organization.objects.get_or_create(name=org_name)[0]
|
||||
|
||||
# Get or create the org to update. If the license only allows for one
|
||||
# org, always use the first active org, unless no org exists.
|
||||
if multiple_orgs:
|
||||
org = Organization.objects.get_or_create(name=org_name)[0]
|
||||
else:
|
||||
try:
|
||||
org = Organization.objects.order_by('pk')[0]
|
||||
except IndexError:
|
||||
continue
|
||||
|
||||
# Update org admins from expression(s).
|
||||
remove = bool(org_opts.get('remove', True))
|
||||
@@ -150,21 +131,13 @@ def update_user_teams(backend, details, user=None, *args, **kwargs):
|
||||
if not user:
|
||||
return
|
||||
from awx.main.models import Organization, Team
|
||||
multiple_orgs = feature_enabled('multiple_organizations')
|
||||
team_map = backend.setting('TEAM_MAP') or {}
|
||||
for team_name, team_opts in team_map.items():
|
||||
# Get or create the org to update.
|
||||
if 'organization' not in team_opts:
|
||||
continue
|
||||
org = Organization.objects.get_or_create(name=team_opts['organization'])[0]
|
||||
|
||||
# Get or create the org to update. If the license only allows for one
|
||||
# org, always use the first active org, unless no org exists.
|
||||
if multiple_orgs:
|
||||
if 'organization' not in team_opts:
|
||||
continue
|
||||
org = Organization.objects.get_or_create(name=team_opts['organization'])[0]
|
||||
else:
|
||||
try:
|
||||
org = Organization.objects.order_by('pk')[0]
|
||||
except IndexError:
|
||||
continue
|
||||
|
||||
# Update team members from expression(s).
|
||||
team = Team.objects.get_or_create(name=team_name, organization=org)[0]
|
||||
@@ -196,7 +169,6 @@ def update_user_teams_by_saml_attr(backend, details, user=None, *args, **kwargs)
|
||||
return
|
||||
from awx.main.models import Organization, Team
|
||||
from django.conf import settings
|
||||
multiple_orgs = feature_enabled('multiple_organizations')
|
||||
team_map = settings.SOCIAL_AUTH_SAML_TEAM_ATTR
|
||||
if team_map.get('saml_attr') is None:
|
||||
return
|
||||
@@ -210,17 +182,11 @@ def update_user_teams_by_saml_attr(backend, details, user=None, *args, **kwargs)
|
||||
for team_name_map in team_map.get('team_org_map', []):
|
||||
team_name = team_name_map.get('team', '')
|
||||
if team_name in saml_team_names:
|
||||
if multiple_orgs:
|
||||
if not team_name_map.get('organization', ''):
|
||||
# Settings field validation should prevent this.
|
||||
logger.error("organization name invalid for team {}".format(team_name))
|
||||
continue
|
||||
org = Organization.objects.get_or_create(name=team_name_map['organization'])[0]
|
||||
else:
|
||||
try:
|
||||
org = Organization.objects.order_by('pk')[0]
|
||||
except IndexError:
|
||||
continue
|
||||
if not team_name_map.get('organization', ''):
|
||||
# Settings field validation should prevent this.
|
||||
logger.error("organization name invalid for team {}".format(team_name))
|
||||
continue
|
||||
org = Organization.objects.get_or_create(name=team_name_map['organization'])[0]
|
||||
team = Team.objects.get_or_create(name=team_name, organization=org)[0]
|
||||
|
||||
team_ids.append(team.id)
|
||||
|
||||
Reference in New Issue
Block a user