Skip to content

Commit

Permalink
24651 - updates for contact_centre_staff KC group
Browse files Browse the repository at this point in the history
  • Loading branch information
ochiu committed Dec 18, 2024
1 parent d4e6499 commit f4e75a5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/resources/v1/activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@bp.route("", methods=["GET", "OPTIONS"])
@cross_origin(origins="*", methods="GET")
@_jwt.has_one_of_roles([Role.SYSTEM.value, Role.STAFF.value, Role.ACCOUNT_HOLDER.value])
@_jwt.has_one_of_roles([Role.SYSTEM.value, Role.STAFF.value, Role.ACCOUNT_HOLDER.value, Role.VIEW_ACTIVITY_LOGS.value])
def get_activities(org_id):
"""Fetch activities."""
try:
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/resources/v1/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def search_organizations():

roles = token.get("realm_access").get("roles")
# public user can only get status of orgs in search, unless they have special roles.
allowed_roles = [Role.STAFF.value, Role.SYSTEM.value, Role.ACCOUNT_IDENTITY]
allowed_roles = [Role.STAFF.value, Role.SYSTEM.value, Role.ACCOUNT_IDENTITY, Role.STAFF_VIEW_ACCOUNTS.value]
if Role.PUBLIC_USER.value in roles and not set(roles).intersection(set(allowed_roles)):
if response and response.get("orgs"):
status = HTTPStatus.OK
Expand Down
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/resources/v1/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@bp.route("", methods=["GET", "OPTIONS"])
@cross_origin(origins="*", methods=["GET"])
@_jwt.has_one_of_roles([Role.STAFF.value])
@_jwt.has_one_of_roles([Role.STAFF.value, Role.STAFF_TASK_SEARCH.value])
def get_tasks():
"""Fetch tasks."""
try:
Expand Down Expand Up @@ -62,7 +62,7 @@ def get_tasks():

@bp.route("/<int:task_id>", methods=["GET", "OPTIONS"])
@cross_origin(origins="*", methods=["GET", "PUT"])
@_jwt.has_one_of_roles([Role.STAFF.value])
@_jwt.has_one_of_roles([Role.STAFF.value, Role.VIEW_TASK_DETAILS.value])
def get_task(task_id):
"""Fetch task by id."""
try:
Expand Down
3 changes: 1 addition & 2 deletions auth-api/src/auth_api/services/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def get_account_authorizations_for_org(
auth = None
token_roles = user_from_context.roles

# todo the service account level access has not been defined
if Role.STAFF.value in token_roles:
if Role.STAFF.value in token_roles or Role.CONTACT_CENTRE_STAFF.value in token_roles:
if expanded:
# Query Authorization view by business identifier
auth = AuthorizationView.find_authorization_for_admin_by_org_id(account_id)
Expand Down
7 changes: 5 additions & 2 deletions auth-api/src/auth_api/services/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,17 @@ def get_orgs(user_id, valid_statuses=VALID_STATUSES):
return MembershipModel.find_orgs_for_user(user_id, valid_statuses)

@staticmethod
def search_orgs(search: OrgSearch, environment): # pylint: disable=too-many-locals
@user_context
def search_orgs(search: OrgSearch, environment, **kwargs): # pylint: disable=too-many-locals
"""Search for orgs based on input parameters."""
orgs_result = {"orgs": [], "page": search.page, "limit": search.limit, "total": 0}
include_invitations: bool = False
user_from_context: UserContext = kwargs["user_context"]
roles = user_from_context.roles
search.access_type, is_staff_admin = Org.refine_access_type(search.access_type)
if search.statuses and OrgStatus.PENDING_ACTIVATION.value in search.statuses:
# only staff admin can see director search accounts
if not is_staff_admin:
if not is_staff_admin and Role.VIEW_ACCOUNT_PENDING_INVITATIONS.value not in roles:
raise BusinessException(Error.INVALID_USER_CREDENTIALS, None)
org_models, orgs_result["total"] = OrgModel.search_pending_activation_orgs(name=search.name)
include_invitations = True
Expand Down
6 changes: 6 additions & 0 deletions auth-api/src/auth_api/utils/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Role(Enum):
# Used by Business-AR to create affiliations that may already have a passcode (bypass passcode check)
SKIP_AFFILIATION_AUTH = "skip_affiliation_auth"

CONTACT_CENTRE_STAFF = "contact_centre_staff"
STAFF_TASK_SEARCH = "staff_task_search"
VIEW_TASK_DETAILS = "view_task_details"
VIEW_ACCOUNT_PENDING_INVITATIONS = "view_account_pending_invitations"
VIEW_ACTIVITY_LOGS = "view_activity_logs"


# Membership types
STAFF = "STAFF"
Expand Down
6 changes: 4 additions & 2 deletions auth-api/src/auth_api/utils/user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def has_role(self, role_name: str) -> bool:
return role_name in self._roles

def is_staff(self) -> bool:
"""Return True if the user is staff user."""
return Role.STAFF.value in self._roles if self._roles else False
"""Return True if the user is staff user or contact centre staff."""
if self._roles:
return Role.STAFF.value in self._roles or Role.CONTACT_CENTRE_STAFF.value in self._roles
return False

def is_staff_admin(self) -> bool:
"""Return True if the user is staff user."""
Expand Down

0 comments on commit f4e75a5

Please sign in to comment.