def test_get_account_authorizations_for_product(session, monkeypatch): # pylint:disable=unused-argument """Assert that user authorizations for product is working.""" user = factory_user_model() org = factory_org_model() factory_membership_model(user.id, org.id) patch_token_info(TestJwtClaims.get_test_real_user(user.keycloak_guid), monkeypatch) authorization = Authorization.get_account_authorizations_for_product(org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 0 # Now add some product subscription for the org patch_token_info(TestJwtClaims.get_test_real_user(user.keycloak_guid), monkeypatch) factory_product_model(org.id) authorization = Authorization.get_account_authorizations_for_product(org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) > 0 # Create another org and assert that the roles are empty org = factory_org_model(org_info=TestOrgInfo.org2, org_type_info=TestOrgTypeInfo.implicit, org_status_info=None, payment_type_info=None) factory_membership_model(user.id, org.id) patch_token_info(TestJwtClaims.get_test_real_user(user.keycloak_guid), monkeypatch) authorization = Authorization.get_account_authorizations_for_product(org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 0 factory_product_model(org.id) patch_token_info(TestJwtClaims.get_test_real_user(user.keycloak_guid), monkeypatch) authorization = Authorization.get_account_authorizations_for_product(org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) > 0
def get(account_id, product_code): """Return authorizations for a product in an account.""" expanded: bool = request.args.get('expanded', False) authorizations = AuthorizationService.get_account_authorizations_for_product( g.jwt_oidc_token_info.get('sub', None), account_id, product_code, expanded) return authorizations, http_status.HTTP_200_OK
def test_get_account_authorizations_for_product(session): # pylint:disable=unused-argument """Assert that user authorizations for product is working.""" user = factory_user_model() org = factory_org_model() factory_membership_model(user.id, org.id) authorization = Authorization.get_account_authorizations_for_product( str(user.keycloak_guid), org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 0 # Now add some product subscription for the org factory_product_model(org.id) authorization = Authorization.get_account_authorizations_for_product( str(user.keycloak_guid), org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 1 assert authorization.get('roles')[0] == 'search' # Create another org and assert that the roles are empty org = factory_org_model(org_info=TestOrgInfo.org2, org_type_info=TestOrgTypeInfo.implicit, org_status_info=None, payment_type_info=None) factory_membership_model(user.id, org.id) authorization = Authorization.get_account_authorizations_for_product( str(user.keycloak_guid), org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 0 factory_product_model(org.id, product_role_codes=['search', 'register']) authorization = Authorization.get_account_authorizations_for_product( str(user.keycloak_guid), org.id, 'PPR') assert authorization is not None assert len(authorization.get('roles')) == 2 assert 'search' in authorization.get('roles') assert 'register' in authorization.get('roles')
def get(account_id, product_code): """Return authorizations for a product in an account.""" authorizations = AuthorizationService.get_account_authorizations_for_product( g.jwt_oidc_token_info.get('sub', None), account_id, product_code) return authorizations, http_status.HTTP_200_OK