Skip to content

Commit

Permalink
AAP-25116: Remove the Commercial group (#1341)
Browse files Browse the repository at this point in the history
We don't the group anymore. The last log-in of one of its members was more
than 6 months ago.
  • Loading branch information
goneri authored Oct 11, 2024
1 parent 2f458dd commit 52de54e
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 74 deletions.
41 changes: 0 additions & 41 deletions ansible_ai_connect/ai/api/model_client/tests/test_wca_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import django.utils.timezone
import requests
from django.contrib.auth.models import Group
from django.test import TestCase, override_settings
from prometheus_client import Counter, Histogram
from requests.auth import HTTPBasicAuth
Expand Down Expand Up @@ -67,9 +66,7 @@
WisdomServiceAPITestCaseBaseOIDC,
WisdomServiceLogAwareTestCase,
)
from ansible_ai_connect.users.constants import FAUX_COMMERCIAL_USER_ORG_ID
from ansible_ai_connect.users.models import Plan
from ansible_ai_connect.users.tests.test_users import create_user

DEFAULT_REQUEST_ID = uuid.uuid4()

Expand Down Expand Up @@ -958,44 +955,6 @@ def test_infer_preprocessed_multitask_prompt_error(self):
suggestion_id=DEFAULT_REQUEST_ID,
)

@assert_call_count_metrics(metric=wca_codegen_hist)
def test_infer_with_faux_commercial_user_uses_faux_commercial_org(self):
model_client = WCAClient(inference_url="https://wca_api_url")
model_input = {
"instances": [
{
"context": "null",
"prompt": "- name: install ffmpeg on Red Hat Enterprise Linux",
}
]
}
user = create_user(
username="test_user_name",
password="test_passwords",
provider=None,
external_username="anexternalusername",
)
commercial_group, _ = Group.objects.get_or_create(name="Commercial")
user.groups.add(commercial_group)

token = {
"access_token": "access_token",
}
model_client.get_model_id = Mock(return_value="xxx")
model_client.get_api_key = Mock(return_value="yyy")
model_client.get_token = Mock(return_value=token)
response = MockResponse(json={}, status_code=200)
model_client.session.post = Mock(return_value=response)
model_client.infer(
request=Mock(user=user),
model_input=model_input,
model_id=None,
suggestion_id=DEFAULT_REQUEST_ID,
)

model_client.get_model_id.assert_called_once_with(user, FAUX_COMMERCIAL_USER_ORG_ID, None)
model_client.get_api_key.assert_called_once_with(user, FAUX_COMMERCIAL_USER_ORG_ID)

@assert_call_count_metrics(metric=wca_codegen_hist)
def test_infer_multitask_with_task_preamble(self):
self._do_inference(
Expand Down
4 changes: 2 additions & 2 deletions ansible_ai_connect/healthcheck/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from health_check.exceptions import HealthCheckException, ServiceUnavailable

from ansible_ai_connect.ai.api.aws.wca_secret_manager import Suffixes
from ansible_ai_connect.users.constants import FAUX_COMMERCIAL_USER_ORG_ID

ERROR_MESSAGE = "An error occurred"
MODEL_MESH_HEALTH_CHECK_MODELS = "models"
Expand Down Expand Up @@ -103,9 +102,10 @@ def check_status(self):
if not self.enabled:
return

FAUX_ORG_ID = "9999999999"
try:
apps.get_app_config("ai").get_wca_secret_manager().get_secret(
FAUX_COMMERCIAL_USER_ORG_ID, Suffixes.API_KEY
FAUX_ORG_ID, Suffixes.API_KEY
)
except Exception as e:
self.add_error(ServiceUnavailable(ERROR_MESSAGE), e)
Expand Down
1 change: 0 additions & 1 deletion ansible_ai_connect/users/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
USER_SOCIAL_AUTH_PROVIDER_GITHUB = "github"
USER_SOCIAL_AUTH_PROVIDER_OIDC = "oidc"
USER_SOCIAL_AUTH_PROVIDER_AAP = "aap"
FAUX_COMMERCIAL_USER_ORG_ID = "9999999999"
RHSSO_LIGHTSPEED_SCOPE = "api.lightspeed"
TRIAL_PLAN_NAME = "trial of 90 days"
11 changes: 1 addition & 10 deletions ansible_ai_connect/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@

from ansible_ai_connect.organizations.models import Organization

from .constants import (
FAUX_COMMERCIAL_USER_ORG_ID,
USER_SOCIAL_AUTH_PROVIDER_AAP,
USER_SOCIAL_AUTH_PROVIDER_OIDC,
)
from .constants import USER_SOCIAL_AUTH_PROVIDER_AAP, USER_SOCIAL_AUTH_PROVIDER_OIDC

logger = logging.getLogger("organizations")

Expand Down Expand Up @@ -75,8 +71,6 @@ class User(ExportModelOperationsMixin("user"), AbstractUser):

@property
def org_id(self) -> int | None:
if self.groups.filter(name="Commercial").exists():
return FAUX_COMMERCIAL_USER_ORG_ID
if self.organization and self.organization.id:
return self.organization.id
return None
Expand All @@ -94,9 +88,6 @@ def is_aap_user(self) -> bool:
@cached_property
def rh_user_has_seat(self) -> bool:
"""True if the user comes from RHSSO and has a Wisdom Seat."""
# For dev/test purposes only:
if self.groups.filter(name="Commercial").exists():
return True

# user is of an on-prem AAP with valid license
if self.is_aap_user():
Expand Down
20 changes: 0 additions & 20 deletions ansible_ai_connect/users/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.cache import cache
from django.test import override_settings
from django.urls import reverse
Expand All @@ -38,7 +37,6 @@
create_user,
)
from ansible_ai_connect.users.constants import (
FAUX_COMMERCIAL_USER_ORG_ID,
USER_SOCIAL_AUTH_PROVIDER_AAP,
USER_SOCIAL_AUTH_PROVIDER_GITHUB,
USER_SOCIAL_AUTH_PROVIDER_OIDC,
Expand Down Expand Up @@ -134,24 +132,6 @@ def test_rh_user_onprem_has_no_valid_license(self):
return_true.return_value = True
self.assertFalse(user.rh_org_has_subscription)

def test_rh_user_has_seat_with_github_commercial_group(self):
user = create_user(provider=USER_SOCIAL_AUTH_PROVIDER_GITHUB)

commercial_group, _ = Group.objects.get_or_create(name="Commercial")
user.groups.add(commercial_group)

self.assertTrue(user.rh_user_has_seat)
self.assertEqual(user.org_id, FAUX_COMMERCIAL_USER_ORG_ID)

def test_rh_user_has_seat_with_rhsso_commercial_group(self):
user = create_user(provider=USER_SOCIAL_AUTH_PROVIDER_OIDC)

commercial_group, _ = Group.objects.get_or_create(name="Commercial")
user.groups.add(commercial_group)

self.assertTrue(user.rh_user_has_seat)
self.assertEqual(user.org_id, FAUX_COMMERCIAL_USER_ORG_ID)

def test_rh_user_org_with_sub_but_no_seat_in_ams(self):
user = create_user(
provider=USER_SOCIAL_AUTH_PROVIDER_OIDC,
Expand Down

0 comments on commit 52de54e

Please sign in to comment.