Skip to content

Conversation

cwjwisse
Copy link
Contributor

@cwjwisse cwjwisse commented Sep 11, 2025

  • reuses the same command for onboarding
  • if brand exists for given site, the users will be prompted with two buttons:
    • users can choose to only add/update entitlements and enrollments (this is done using the tier client)
    • they can also choose to update the IMS org, and subsequently update the entitlements and enrollments
  • success and failure messages are posted in the same thread

Copy link

This PR will trigger a minor release when merged.

@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch 7 times, most recently from bc89c1d to c8bc191 Compare September 12, 2025 11:26
@ravverma
Copy link
Contributor

@cwjwisse I was checking method createEntitlementAndEnrollment

async function createEntitlementAndEnrollment(site, lambdaCtx, slackCtx) {
  const { dataAccess, log } = lambdaCtx;
  const { say } = slackCtx;
  const { Entitlement, SiteEnrollment } = dataAccess;

  const orgId = site.getOrganizationId();

  // find if there are any entitlements for this site enabling LLMO
  const enrollments = await SiteEnrollment.allBySiteId(site.getId());
  const llmoEntitlements = (await Promise.all(enrollments.map(async (enrollment) => {
    // find entitlement for this enrollment
    const entitlement = await Entitlement.findById(enrollment.getEntitlementId());
    // check if the entitlement is for the same organization as the site
    const entitlementOrgId = entitlement.getOrganizationId();
    if (entitlementOrgId !== orgId) return null;
    // check if the entitlement is for LLMO
    const entitlementProductCode = entitlement.getProductCode();
    return entitlementProductCode === LLMO_PRODUCT_CODE ? entitlement : null;
  }))).filter((x) => !!x);

  if (llmoEntitlements.length > 0) {
    await say(`Site ${site.getId()} is already entitled to LLMO. Skipping entitlement grant.`);
    log.warn(`Site ${site.getId()} already entitled to LLMO. Skipping.`);
    return;
  }

  // create an entitlement
  const newEntitlement = await Entitlement.create({
    organizationId: orgId,
    productCode: LLMO_PRODUCT_CODE,
    tier: LLMO_TIER,
    quotas: { llmo_trial_prompts: 200 },
  });
  await newEntitlement.save();
  const newEntitlementId = newEntitlement.getId();

  // create enrollment
  const newEnrollment = await SiteEnrollment.create({
    entitlementId: newEntitlementId,
    siteId: site.getId(),
  });
  await newEnrollment.save();
}

there is a edge case in this flow.
If org O and two sites A and B
on On-boarding A -> it will create an entitlement and siteEnrollment -> good
on On-boarding B -> it will again create an entitlement and siteEnrollment -> NOT good , it will break access.

So in case of B only siteEnrollment need to created with existing entitlement

I would suggest first fetch the entitlement on org level for LLMO , and use that for comparison for siteEnrollment
e.g.

const entitlement = await this.Entitlement.findByOrganizationIdAndProductCode(orgId, this.productCode);

cc: @solaris007

@cwjwisse cwjwisse marked this pull request as draft September 15, 2025 06:05
@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch 6 times, most recently from 8f06175 to 04c8133 Compare September 16, 2025 11:42
@cwjwisse cwjwisse marked this pull request as ready for review September 16, 2025 11:44
@cwjwisse cwjwisse requested a review from ravverma September 16, 2025 11:49
@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch from 04c8133 to 4c42c6d Compare September 16, 2025 13:09
@@ -15,6 +15,7 @@ import { createFrom } from '@adobe/spacecat-helix-content-sdk';
import { Octokit } from '@octokit/rest';
import { Entitlement as EntitlementModel } from '@adobe/spacecat-shared-data-access/src/models/entitlement/index.js';
import { OrganizationIdentityProvider as OrganizationIdentityProviderModel } from '@adobe/spacecat-shared-data-access/src/models/organization-identity-provider/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need OrganizationIdentityProvider as everything handled by Tier Client

@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch 2 times, most recently from d15e727 to aba6df5 Compare September 16, 2025 15:04
@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch 3 times, most recently from 1e38e15 to de2c84f Compare September 16, 2025 15:50
@cwjwisse cwjwisse force-pushed the enable-llmo-reonboarding branch from de2c84f to 7e9ed04 Compare September 16, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants