PolicyData

enum q2_sdk.hq.db.policy_data.Entity(value)[source]

Bases: Enum

Valid values are as follows:

User = <Entity.User: 'U'>
Customer = <Entity.Customer: 'C'>
Group = <Entity.Group: 'G'>
UserRole = <Entity.UserRole: 'R'>
Company = <Entity.Company: 'O'>
SSOIdentifier = <Entity.SSOIdentifier: 'S'>
class q2_sdk.hq.db.policy_data.PolicyDataValues(entity, entity_id, policy_data=None)[source]

Bases: object

PolicyDataValues(entity: q2_sdk.hq.db.policy_data.Entity, entity_id: int, policy_data: list[q2_sdk.hq.models.policy_data.GeneratedTransactionRights | q2_sdk.hq.models.policy_data.Subsidiaries | q2_sdk.hq.models.policy_data.Account | q2_sdk.hq.models.policy_data.Features | q2_sdk.hq.models.policy_data.Data] = None)

entity: Entity
entity_id: int
policy_data: list[GeneratedTransactionRights | Subsidiaries | Account | Features | Data] = None
construct_set_policy_shape()[source]
class q2_sdk.hq.db.policy_data.PolicyData(logger, hq_credentials=None, ret_table_obj=None)[source]

Bases: DbObject

Programmatic access to the Q2 database. Not as flexible as a true ORM, but takes the guesswork out of database schemas and ensures safety in the transactions.

Parameters:
  • logger – Reference to calling request’s logger (self.logger in your extension)

  • hq_credentials (Optional[HqCredentials]) – HQ Connectivity Information (Defaults to settings file)

  • ret_table_obj (Optional[bool]) – Flag to return list of LXML elements if False or TableRow objects from DB calls if True (Defaults to settings file)

async get(entity, entity_id, include_parent_policy_data=False)[source]

A helper function for getting policy data for an entity. Example function calls:

await self.db.policy_data.get(Entity.User, self.online_user.user_id)
await self.db.policy_data.get(Entity.Customer, self.online_user.customer_id)
await self.db.policy_data.get(Entity.Group, self.online_user.group_id)
await self.db.policy_data.get(Entity.UserRole, user[0].UserRoleID, include_parent_policy_data=True)
await self.db.policy_data.get(Entity.SSOIdentifier, sso_user_logon[0].SSOUserLogonID, include_parent_policy_data=True)
Parameters:
  • entity (Entity) – Either User, Customer, Group, UserRole, Company of the Entity enum

  • entity_id (int) – The id of the entity. If user, provide the user id. If group, provide the group id

  • include_parent_policy_data (bool) – If true, then all policies in the user hierarchy will also be provided

Return type:

PolicyData

Returns:

PolicyData object

async set(policy_data)[source]

Set policy data for an entity.

This method expects the full policy payload. First call get to retrieve the current policy, apply your updates to that object, and then pass the complete result back via policy_data. If policy_data.entity is Entity.SSOIdentifier, the method resolves the concrete user entity and normalizes entity_id before submitting.

Return type:

str

Returns:

Success or failure message based on hq response

async get_user_details_by_sso_id(entity, entity_id)[source]
Return type:

tuple[Entity, int]

PolicyData return object definition