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] = None)

entity: Entity
entity_id: int
policy_data: list[GeneratedTransactionRights | Subsidiaries | Account | Features] = 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]

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

await self.db.policy_data.set(Entity.User, self.online_user.user_id, policy_data)
await self.db.policy_data.set(Entity.Customer, self.online_user.customer_id, policy_data)
await self.db.policy_data.set(Entity.Group, self.online_user.group_id, policy_data)
await self.db.policy_data.set(Entity.UserRole, user[0].UserRoleID, policy_data)
await self.db.policy_data.set(Entity.SSOIdentifier, sso_user_logon[0].SSOUserLogonID, user policy_data)
Parameters:
  • entity – Either User, Customer, Group, UserRole, Company, or SSO Identifier of the Entity enum. If SSO Identifier provided, ensure to specify the policy details for the user

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

  • policy_data (PolicyDataValues) – The list of policy information you are setting. These must be of GeneratedTransactionRights, Subsidiaries, Account, Features type

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