Api reference
components.customer_admin.public.actions ¶
edit_admin_entities ¶
edit_admin_entities(
admin_user_id,
added_account_ids,
added_company_ids,
removed_account_ids,
removed_company_ids,
)
Source code in components/customer_admin/public/actions.py
edit_admin_responsibilities ¶
edit_admin_responsibilities(
admin_user_id,
account_id,
responsibilities_to_companies,
responsibilities_to_accounts,
responsibilities_to_scopes,
)
Source code in components/customer_admin/public/actions.py
on_completed_customer_admin_onboarding ¶
Called when a customer admin has completed onboarding, used to create the admin rights :param onboarding: The onboarding entity containing the information of the invitations :return: nothing
Source code in components/customer_admin/public/actions.py
promote_user_to_admin ¶
promote_user_to_admin(
*,
user_id,
invited_user_id,
company_ids,
account_ids,
responsibilities_dict
)
Source code in components/customer_admin/public/actions.py
promote_user_to_admin_with_responsibilities ¶
Source code in components/customer_admin/public/actions.py
remove_admin ¶
Source code in components/customer_admin/public/actions.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
components.customer_admin.public.admined_entities ¶
AdminedEntitiesQueryApi ¶
AdminedEntitiesQueryApi(
*,
company_admin_model,
account_admin_model=None,
scope_admin_model=None,
get_account_id_to_company_ids_fn,
get_company_id_to_operational_scope_ids_fn=None,
get_user_active_admined_companies_ids_fn=None,
group_scope_ids_by_company_id_fn=None
)
Design TLDR: SDK approach into Modular Monolith
This class takes a local CompanyAdmin model as argument to the constructor to centralize all the logic and make it easier to later migrate to a modular monolith component. Caveats: - this approach is only possible because FR, BE and ES data models are similar - this code is brittle to any data model change. We can strengthen it by defining a BaseAbstractModel that will be extended by the 3 countries CompanyAdmin models.
Source code in components/customer_admin/public/admined_entities.py
get_account_id_to_company_ids_fn
instance-attribute
¶
get_admin_account_trees ¶
:param user_id: the admin user id :param account_id: filtering account id :return: a list of one or several tree of all the entities in the account admined by the user. There might be several trees if the user is admin of several companies in the account without being account admin.
Source code in components/customer_admin/public/admined_entities.py
get_admined_entities_context_accounts ¶
:param user_id: :return: a set of the accounts in which the user is admin of something. Could be the whole account, one or several companies, one or several operational scopes.
Source code in components/customer_admin/public/admined_entities.py
get_admined_entities_for_user ¶
Retrieves a list of lightweight admined entities for the given user ID. :param user_id: :return: a list of AdminedEntity
Source code in components/customer_admin/public/admined_entities.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_admined_entity_ids ¶
:param user_id: :return: all the ids of entities the user is admin of. /!\ There's no transitivity logic: if the user is account admin, the company_ids set won't contain that account company ids.
Source code in components/customer_admin/public/admined_entities.py
get_company_id_to_operational_scope_ids_fn
instance-attribute
¶
get_list_of_all_sub_admined_entities_from_directly_admined_ones ¶
get_list_of_all_sub_admined_entities_from_directly_admined_ones(
directly_admined_account_ids,
directly_admined_company_ids,
directly_admined_operational_scope_ids,
account_id_to_company_ids=None,
)
Builds the full list of companies and operational scopes ids the user admins, directly and indirectly. :param account_id_to_company_ids: dictionary of company ids per account id. Optional. Useful if we want to filter out some companies :param directly_admined_account_ids: list of account ids the user directly admins :param directly_admined_company_ids: list of company ids the user directly admins :param directly_admined_operational_scope_ids: list of operational scope ids the user directly admins :return:
Source code in components/customer_admin/public/admined_entities.py
get_user_active_admined_companies_ids_fn
instance-attribute
¶
group_scope_ids_by_company_id_fn
instance-attribute
¶
AdminedEntityTreeNode
dataclass
¶
Bases: AccountOrgTreeNode, DataClassJsonMixin
Represents an entity that a user is admin of directly or transitively (account admins are also admin of all the companies of their account)
from_account_org_tree_node
classmethod
¶
Helper function converting an AccountOrgTreeNode into an AdminedEntityTreeNode
Source code in components/customer_admin/public/entities.py
components.customer_admin.public.customer_admin_read_service ¶
CustomerAdminReadService ¶
Utility global class that provides methods to query a given user admin rights.
Source code in components/customer_admin/public/customer_admin_read_service.py
account_org_tree_query_api
instance-attribute
¶
customer_admin_repository
instance-attribute
¶
get_admins_page_for_account ¶
:param account_id: account id for which to get the admins. :param company_ids: if set, only the admins that are admin of the given companies will be returned :param operational_scope_ids: if set, only the admins that are admin of the given operational scope will be returned :param cursor: opaque pagination cursor. It happens to be a number for now, but it could change :param limit: number of admins to return per page (counting distinct user profiles)
:return: Paginated list of all admins that are admin in the given account
Source code in components/customer_admin/public/customer_admin_read_service.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
get_customer_admin_by_profile_id ¶
Uses the customer admin repository to get the customer admin by profile id, when
:param profile_id: :param context_account_id: :param company_ids: :param operational_scope_ids:
entity ids (context account id, company ids, operational scope ids) are used to filter the customer admin entities, so the type is correctly defined according to the (reading) user access.
:return: the customer admin for the given profile id, or None if no customer admin exists.
Source code in components/customer_admin/public/customer_admin_read_service.py
get_user_profile_admined_entities_forest ¶
:param profile_id: user profile id :param filter_account_id: if set, only the companies and operational scopes under that account will be included in the returned tree data structure.
:return: a list of trees of all the entities in the account admined by the user. There might be several trees when: - the user is admin of several companies in the account without being account admin - and/or the user is admin in several accounts
Source code in components/customer_admin/public/customer_admin_read_service.py
is_user_admin ¶
:param profile_id: :return: true if the user is admin, false otherwise.
Source code in components/customer_admin/public/customer_admin_read_service.py
is_user_admin_of_account ¶
:param profile_id: :param account_id: :return: true if the user is admin of the account, false otherwise.
Source code in components/customer_admin/public/customer_admin_read_service.py
is_user_admin_of_company ¶
:param profile_id: :param company_id: :return: true if the user is admin of the company, false otherwise.
Source code in components/customer_admin/public/customer_admin_read_service.py
is_user_admin_of_entities ¶
:param profile_id: :param entities: :return: :return: true if the user is admin of all the entities, false otherwise.
Source code in components/customer_admin/public/customer_admin_read_service.py
is_user_only_operational_scope_admin ¶
is_user_only_operational_scope_admin(
profile_id,
filter_account_id=None,
admined_entities_forest=None,
)
:param profile_id: :param filter_account_id: see get_user_profile_admined_entities_forest for parameter description. :param admined_entities_forest: if set, the admined entities forest will be used to check if the user is only operational scope admin. If not set, the admined entities forest will be fetched from the repository using the profile_id (and filter_account_id if set). :return: true if the user is only operational scope admin, false otherwise.
Source code in components/customer_admin/public/customer_admin_read_service.py
components.customer_admin.public.dependencies ¶
CustomerAdminDependency ¶
CustomerAdminDependency defines the interface that apps using the customer_admin component need to implement
get_account_org_tree_query_api ¶
:return: The method will return a tree data structure of the account entities (account, companies, operational scopes )
Source code in components/customer_admin/public/dependencies.py
get_admined_entities_api ¶
:return: The method will return a helper class that abstracts the DB queries required to fetch a user list of of admined entities
Source code in components/customer_admin/public/dependencies.py
get_customer_admin_repository ¶
:return: The method will return a class that encapsulate DB queries Fallback to the global customer admin repository if the implementation is not provided
Source code in components/customer_admin/public/dependencies.py
get_app_dependency ¶
Retrieves at runtime the account_org_tree dependency set by set_app_dependency
Source code in components/customer_admin/public/dependencies.py
set_app_dependency ¶
Sets the account_org_tree dependency to the app so it can be accessed within this component at runtime
Source code in components/customer_admin/public/dependencies.py
components.customer_admin.public.entities ¶
AdminCompanyInformation
dataclass
¶
Bases: DataClassJsonMixin
Represents a company that an admin manages along with their responsibilities at the account level.
AdminEntitiesByResponsibility
dataclass
¶
AdminEntitiesByResponsibility(
contract_manager,
people_manager,
payroll_manager,
invoice_manager,
wellbeing_referent,
)
Bases: DataClassJsonMixin
Admin entities by responsibility.
all_entities
property
¶
Get all entities. :return: a list of AdminEntities for which the admin will have some responsibility.
AdminedEntitiesForest ¶
Bases: TypedTree[ForestData]
Hierarchical data structure containing all the entities a given user is admin of both - directly (correspond to tree root node(s)) - or indirectly (corresponding to tree leaves and intermediate nodes). with context_account nodes to regroup all admined entities under a given account, has admined entities, without necessarilyy being admin of the whole account.
The forest name is used to differentiate from the existing AdminedEntitiesTree and hint at the fact that this tree can contain data for several accounts and different kinds of nodes.
Source code in components/customer_admin/public/entities.py
find_context_account ¶
:param account_id :return: the context account node corresponding to the entity if found, None otherwise.
Source code in components/customer_admin/public/entities.py
find_entity ¶
:param entity: defined by an id and a type :return: the node corresponding to the entity if found, None otherwise.
Source code in components/customer_admin/public/entities.py
AdminedEntityForestNodeKind ¶
Bases: AlanBaseEnum
We store several kinds of nodes to store the maximum amount of information: - context account (useful for company admins who are not account admins) - and regular entity nodes to store data about the admined entities, both directly and transitively via a parent entity (ex: account admin admins all companies of that account)
AdminedEntityTreeNode
dataclass
¶
Bases: AccountOrgTreeNode, DataClassJsonMixin
Represents an entity that a user is admin of directly or transitively (account admins are also admin of all the companies of their account)
from_account_org_tree_node
classmethod
¶
Helper function converting an AccountOrgTreeNode into an AdminedEntityTreeNode
Source code in components/customer_admin/public/entities.py
ContextAccountTreeNode
dataclass
¶
CursorInfoMeta
dataclass
¶
Bases: DataClassJsonMixin
Store metadata info for pagination
CustomerAdmin
dataclass
¶
CustomerAdmin(
*,
profile_id,
user_id,
first_name,
last_name,
admined_entities,
onboarding_id=None
)
Bases: DataClassJsonMixin
Represent a customer admin
CustomerAdminSummarizedRights
dataclass
¶
Bases: DataClassJsonMixin
Summarized because the type is the highest level of access for a given admin. Note: the type field depends on the context account id
CustomerAdminsPage
dataclass
¶
CustomerDashboardAdminWithEntities
dataclass
¶
CustomerDashboardAdminWithEntities(
id,
email,
first_name,
last_name,
type,
company_ids,
account_id=None,
scope_ids=None,
)
CustomerDashboardCompany
dataclass
¶
CustomerDashboardCompanyAdmin
dataclass
¶
EntitiesByResponsibility
dataclass
¶
EntityInfo
dataclass
¶
EntityInfoProtocol ¶
LastAdminStandingRolesInEntities
dataclass
¶
LastAdminStandingRolesInEntities(
contract_manager,
people_manager,
payroll_manager,
invoice_manager,
wellbeing_referent,
)
Bases: DataClassJsonMixin
Last admin standing for all entities - taking into account critical and non-critical roles
PageInfoMeta
dataclass
¶
components.customer_admin.public.events ¶
subscribe_to_events ¶
All event subscriptions for Customer Admin are here.
Source code in components/customer_admin/public/events.py
components.customer_admin.public.interfaces ¶
AdminsForAccountPage
dataclass
¶
BasicCustomerAdminData
dataclass
¶
BasicCustomerAdminData(
*,
profile_id,
user_id,
first_name,
last_name,
directly_admined_entities,
onboarding_id=None
)
Customer admin data.
Long term, all the data here should comes from customer admin component's internal data model
CustomerAdminRepository ¶
Bases: ABC
Public interface defining the expected methods for each country CustomerAdminRepository implementations.
get_admined_entities_for_profile
abstractmethod
¶
Only returns the direct admin rights. For instance, for an account admin, companies under that account might not be returned.
Source code in components/customer_admin/public/interfaces.py
get_admins_for_account
abstractmethod
¶
Only returns the direct admin rights. For instance, for an account admin, companies under that account might not be returned.
:returns: an admins list page data as a tuple containing a dict mapping profile_id to a set of directly admined entities and the next cursor
Source code in components/customer_admin/public/interfaces.py
get_customer_admin_by_profile_id
abstractmethod
¶
Returns a customer admin via the profile id. Type that is returned will be CustomerDashboardCompanyAdmin. If no customer admin exists, raises BaseErrorCode.missing_resource.
:param profile_id: :return: the customer admin (as CustomerDashboardCompanyAdmin) for the given profile id.
Source code in components/customer_admin/public/interfaces.py
DirectlyAdminedEntity
dataclass
¶
Bases: LeanEntityInfo
Info about an entity that is directly admined = top level entity admined by the user profile. A counter-example of indirectly admined entities is a company under an account for an account admin.
For convenience and typing simplicity, we also set the parent account id for accounts, in which case the id will match the parent_account_id.
components.customer_admin.public.queries ¶
current_user_can_contact_alan_for_custom_coverage ¶
Source code in components/customer_admin/public/queries.py
current_user_can_invite_admins ¶
Source code in components/customer_admin/public/queries.py
get_admin ¶
Source code in components/customer_admin/public/queries.py
get_admin_companies ¶
get_admin_companies(
target_admin_user_id,
current_user_id,
current_user_profile_id,
context_account_id=None,
)
Source code in components/customer_admin/public/queries.py
get_admin_companies_information ¶
Source code in components/customer_admin/public/queries.py
get_admin_responsibilities ¶
Source code in components/customer_admin/public/queries.py
get_admined_companies_and_scope_for_user_and_companies ¶
Source code in components/customer_admin/public/queries.py
get_admins_for_entities ¶
get_admins_for_entities(
context_account_id,
company_ids,
operational_scope_ids,
sort_filter,
sort_direction,
include_scope_admins,
cursor=None,
limit=None,
)
Source code in components/customer_admin/public/queries.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_available_responsibilities ¶
Source code in components/customer_admin/public/queries.py
last_admin_standing_roles_in_entities ¶
last_admin_standing_roles_in_entities(
target_admin_user_id,
account_id,
company_ids,
operational_scope_ids,
)
Source code in components/customer_admin/public/queries.py
user_can_admin_account_or_company_of_account ¶
Source code in components/customer_admin/public/queries.py
user_can_admin_admined_entities ¶
Source code in components/customer_admin/public/queries.py
user_can_admin_entities ¶
:param user_id: The id of the admin user :param account_ids: Ids of accounts to check :param company_ids: Ids of companies to check :param scope_ids: Ids of operational scopes to check :return: Return True if the given user is a direct or indirect admin of all the given entities. /!| Return False, if no admined entities is passed.
Source code in components/customer_admin/public/queries.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |
user_can_admin_entities_ignore_operational_scopes ¶
⚠️ This function relies on local logic, and doesn't handle operational scopes It should only be used in places where we didn't update for operational scopes yet :param user_id: The id of the admin user :param company_ids: Ids of companies to check :param account_ids: Ids of accounts to check :return: Return true if the given user is a direct or indirect admin of all the given entities