Skip to content

Commit 7032ed2

Browse files
anshulk-publicAnshul Kumar
andauthored
fix: updated the createdBy in plg onboarding (#2398)
## fix: stamp customer identity as `createdBy` on PLG onboarding for pre-seeded records ### Problem When a PLG onboarding record is pre-seeded by an admin with `PRE_ONBOARDING` or `INACTIVE` status, the `createdBy` field is set to `'system'` (or the admin identity). When the real customer later triggers the onboarding flow for that domain, `updatedBy` correctly captured their identity but `createdBy` remained as `'system'` — misrepresenting who actually initiated the onboarding. ### Solution In `performAsoPlgOnboarding`, after setting `updatedBy`, stamp `createdBy` with the caller's identity when the existing record's status is `PRE_ONBOARDING` or `INACTIVE`. These are the two statuses that indicate a record was pre-seeded before the customer triggered the flow. ```js onboarding.setUpdatedBy(callerIdentity); if ([STATUSES.PRE_ONBOARDING, STATUSES.INACTIVE].includes(onboarding.getStatus())) { onboarding.setCreatedBy(callerIdentity); } ``` ### Changes - **`src/controllers/plg/plg-onboarding.js`** — sets `createdBy` to the real caller identity when resuming a `PRE_ONBOARDING` or `INACTIVE` record - **`test/controllers/plg/plg-onboarding.test.js`** — adds 3 unit tests covering PRE_ONBOARDING, INACTIVE, and the no-op case for other statuses ### Testing - All 330 unit tests pass - Covered scenarios: - `PRE_ONBOARDING` record → `createdBy` updated to customer email - `INACTIVE` record → `createdBy` updated to customer email - Any other status (e.g. `IN_PROGRESS`) → `createdBy` left unchanged Please ensure your pull request adheres to the following guidelines: - [ ] make sure to link the related issues in this description. Or if there's no issue created, make sure you describe here the problem you're solving. - [ ] when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes If the PR is changing the API specification: - [ ] make sure you add a "Not implemented yet" note the endpoint description, if the implementation is not ready yet. Ideally, return a 501 status code with a message explaining the feature is not implemented yet. - [ ] make sure you add at least one example of the request and response. If the PR is changing the API implementation or an entity exposed through the API: - [ ] make sure you update the API specification and the examples to reflect the changes. If the PR is introducing a new audit type: - [ ] make sure you update the API specification with the type, schema of the audit result and an example ## Related Issues Thanks for contributing! Co-authored-by: Anshul Kumar <anshulk@Anshuls-MacBook-Pro-2.local>
1 parent d7889ac commit 7032ed2

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/controllers/plg/plg-onboarding.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ async function performAsoPlgOnboarding({
704704
}
705705
}
706706
onboarding.setUpdatedBy(callerIdentity);
707+
if ([STATUSES.PRE_ONBOARDING, STATUSES.INACTIVE].includes(onboarding.getStatus())) {
708+
onboarding.setCreatedBy(callerIdentity);
709+
}
707710

708711
// Guard: only one domain per IMS org can be onboarded
709712
const existingRecords = await PlgOnboarding.allByImsOrgId(imsOrgId);

test/controllers/plg/plg-onboarding.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,6 +3209,32 @@ describe('PlgOnboardingController', function describePlgOnboarding() {
32093209
expect(mockOnboarding.setStatus).to.have.been.calledWith('ONBOARDED');
32103210
});
32113211

3212+
it('stamps customer identity as createdBy when existing record is PRE_ONBOARDING', async () => {
3213+
mockOnboarding.getStatus.returns('PRE_ONBOARDING');
3214+
const authInfo = { getProfile: sandbox.stub().returns({ tenants: [{ id: 'AAAAAAAABBBBBBBBCCCCCCCC' }], email: 'customer@example.com' }) };
3215+
const context = buildContext({ domain: TEST_DOMAIN }, { authInfo });
3216+
const res = await controller.onboard(context);
3217+
expect(res.status).to.equal(200);
3218+
expect(mockOnboarding.setCreatedBy).to.have.been.calledWith('customer@example.com');
3219+
});
3220+
3221+
it('stamps customer identity as createdBy when existing record is INACTIVE', async () => {
3222+
mockOnboarding.getStatus.returns('INACTIVE');
3223+
const authInfo = { getProfile: sandbox.stub().returns({ tenants: [{ id: 'AAAAAAAABBBBBBBBCCCCCCCC' }], email: 'customer@example.com' }) };
3224+
const context = buildContext({ domain: TEST_DOMAIN }, { authInfo });
3225+
const res = await controller.onboard(context);
3226+
expect(res.status).to.equal(200);
3227+
expect(mockOnboarding.setCreatedBy).to.have.been.calledWith('customer@example.com');
3228+
});
3229+
3230+
it('does not overwrite createdBy when status is not PRE_ONBOARDING or INACTIVE', async () => {
3231+
mockOnboarding.getStatus.returns('IN_PROGRESS');
3232+
const context = buildContext({ domain: TEST_DOMAIN });
3233+
const res = await controller.onboard(context);
3234+
expect(res.status).to.equal(200);
3235+
expect(mockOnboarding.setCreatedBy).to.not.have.been.called;
3236+
});
3237+
32123238
it('allows onboarding when other domains exist but none are onboarded', async () => {
32133239
const waitlistedRecord = createMockOnboarding({
32143240
id: 'other-onboarding-id',

0 commit comments

Comments
 (0)