Skip to content

Commit 27b6dc5

Browse files
authored
25704 - Add org types for readonly staff (#3270)
1 parent b214b84 commit 27b6dc5

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Add org types for read-only staff.
2+
3+
Revision ID: 7f48833011c3
4+
Revises: 63cfd9b160d7
5+
Create Date: 2025-02-19 15:54:22.459049
6+
7+
"""
8+
from alembic import op
9+
from sqlalchemy import Boolean, String
10+
from sqlalchemy.sql import column, table
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '7f48833011c3'
15+
down_revision = '63cfd9b160d7'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
op.alter_column('org_types', 'code', type_=String(30))
22+
23+
org_type_table = table('org_types',
24+
column('code', String),
25+
column('description', String),
26+
column('default', Boolean)
27+
)
28+
29+
op.bulk_insert(
30+
org_type_table,
31+
[
32+
{'code': 'MAXIMUS_STAFF', 'description': 'Maximus Staff', 'default': False},
33+
{'code': 'CONTACT_CENTRE_STAFF', 'description': 'Contact Centre Staff', 'default': False},
34+
]
35+
)
36+
37+
38+
def downgrade():
39+
op.execute('delete from org_types where code=\'MAXIMUS_STAFF\'')
40+
op.execute('delete from org_types where code=\'CONTACT_CENTRE_STAFF\'')

auth-api/src/auth_api/exceptions/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Error(Enum):
2525

2626
INVALID_ORG = "The organization ID is in an incorrect format.", HTTPStatus.BAD_REQUEST
2727
INVALID_INPUT = "Invalid input, please check.", HTTPStatus.BAD_REQUEST
28+
INSUFFICIENT_PERMISSION = "Insufficient permissions.", HTTPStatus.BAD_REQUEST
2829
DATA_NOT_FOUND = "No matching record found.", HTTPStatus.NOT_FOUND
2930
DATA_ALREADY_EXISTS = "The data you want to insert already exists.", HTTPStatus.BAD_REQUEST
3031
INVALID_USER_CREDENTIALS = "Invalid user credentials.", HTTPStatus.UNAUTHORIZED

auth-api/src/auth_api/models/org.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from auth_api.utils.enums import AccessType, InvitationStatus, InvitationType
3131
from auth_api.utils.enums import OrgStatus as OrgStatusEnum
3232
from auth_api.utils.enums import OrgType as OrgTypeEnum
33-
from auth_api.utils.roles import EXCLUDED_FIELDS, VALID_STATUSES
33+
from auth_api.utils.roles import EXCLUDED_FIELDS, INVALID_ORG_CREATE_TYPE_CODES, VALID_STATUSES
3434

3535
from .base_model import BaseModel
3636
from .contact import Contact
@@ -348,8 +348,8 @@ def reset(self):
348348
def receive_before_insert(mapper, connection, target): # pylint: disable=unused-argument; SQLAlchemy callback signature
349349
"""Rejects invalid type_codes on insert."""
350350
org = target
351-
if org.type_code in (OrgTypeEnum.SBC_STAFF.value, OrgTypeEnum.STAFF.value):
352-
raise BusinessException(Error.INVALID_INPUT, None)
351+
if org.type_code in INVALID_ORG_CREATE_TYPE_CODES:
352+
raise BusinessException(Error.INSUFFICIENT_PERMISSION, None)
353353

354354

355355
@event.listens_for(Org, "before_update", raw=True)

auth-api/src/auth_api/utils/enums.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ class PaymentAccountStatus(Enum):
9797
class OrgType(Enum):
9898
"""Org types."""
9999

100+
PUBLIC = "PUBLIC"
100101
PREMIUM = "PREMIUM"
101102
BASIC = "BASIC"
102103
STAFF = "STAFF"
103104
SBC_STAFF = "SBC_STAFF"
105+
MAXIMUS_STAFF = "MAXIMUS_STAFF"
106+
CONTACT_CENTRE_STAFF = "CONTACT_CENTRE_STAFF"
104107

105108

106109
class DocumentType(Enum):

auth-api/src/auth_api/utils/roles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class Role(Enum):
7070
ProductSubscriptionStatus.PENDING_STAFF_REVIEW.value,
7171
ProductSubscriptionStatus.REJECTED.value,
7272
)
73+
INVALID_ORG_CREATE_TYPE_CODES = (
74+
OrgType.SBC_STAFF.value,
75+
OrgType.STAFF.value,
76+
OrgType.MAXIMUS_STAFF.value,
77+
OrgType.CONTACT_CENTRE_STAFF.value,
78+
)
7379

7480
CLIENT_ADMIN_ROLES = (COORDINATOR, ADMIN)
7581
CLIENT_AUTH_ROLES = (*CLIENT_ADMIN_ROLES, USER)

auth-api/tests/unit/models/test_org.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
Test suite to ensure that the Org model routines are working as expected.
1717
"""
1818

19+
import pytest
20+
21+
from auth_api.exceptions.errors import Error
22+
from auth_api.exceptions.exceptions import BusinessException
1923
from auth_api.models import Org as OrgModel
2024
from auth_api.models import OrgStatus as OrgStatusModel
2125
from auth_api.models import OrgType as OrgTypeModel
2226
from auth_api.models import PaymentType as PaymentTypeModel
2327
from auth_api.utils.enums import OrgStatus as OrgStatusEnum
28+
from auth_api.utils.enums import OrgType as OrgTypeEnum
2429
from tests.utilities.factory_utils import factory_user_model
2530

2631

@@ -187,3 +192,17 @@ def test_delete(session): # pylint:disable=unused-argument
187192
org.delete()
188193
assert org
189194
assert org.status_code == OrgStatusEnum.INACTIVE.value
195+
196+
197+
def test_invalid_org_create_type_code(session):
198+
"""Test that creating an Org with an invalid type code is rejected."""
199+
invalid_type_code = OrgTypeEnum.CONTACT_CENTRE_STAFF.value
200+
201+
org_info = {"name": "Invalid Org", "type_code": invalid_type_code}
202+
203+
with pytest.raises(BusinessException) as excinfo:
204+
org = OrgModel.create_from_dict(org_info)
205+
session.add(org)
206+
session.commit()
207+
208+
assert excinfo.value.code == Error.INSUFFICIENT_PERMISSION.name

auth-api/tests/unit/services/test_org.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def test_create_staff_org_failure(session, keycloak_mock, staff_org, monkeypatch
826826
patch_token_info({"sub": user.keycloak_guid, "idp_userid": user.idp_userid}, monkeypatch)
827827
with pytest.raises(BusinessException) as exception:
828828
OrgService.create_org(TestOrgInfo.staff_org, user.id)
829-
assert exception.value.code == Error.INVALID_INPUT.name
829+
assert exception.value.code == Error.INSUFFICIENT_PERMISSION.name
830830

831831

832832
@mock.patch("auth_api.services.affiliation_invitation.RestService.get_service_account_token", mock_token)

0 commit comments

Comments
 (0)