Skip to content

Conversation

@svenefftinge
Copy link
Contributor

@svenefftinge svenefftinge commented Aug 2, 2023

Description

If this is called a second time on the first user of an org, we would try to remove the owner role which would fail the whole operation. We instead now keep the first and only owner as an owner.

Summary generated by Copilot

🤖 Generated by Copilot at 7118e46

Improved the robustness and functionality of the organization service and the monitoring endpoints in the server component. Fixed a potential issue with the build script and updated the corresponding test case.

Related Issue(s)

Fixes EXP-356

How to test

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

if (userId) {
await this.auth.checkPermissionOnOrganization(userId, "write_members", orgId);
}
if (role !== "owner") {
Copy link
Contributor Author

@svenefftinge svenefftinge Aug 2, 2023

Choose a reason for hiding this comment

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

If this is called a second time on the first user of an org, we would try to remove the owner role which would fail the whole operation. We instead now keep the first and only owner as an owner.

Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand the comment.

  • This if-statement was checking the membership downgrade to guarantee there is at least a single owner left if the downgrade would be executed. ✔️
  • Why would it be "called a second time on the first user of an org" ❓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would it be "called a second time on the first user of an org"

That is because of the extra call in iam-session-app we added two days ago.

"build": "yarn clean && yarn generate && yarn lint && npx tsc",
"lint": "yarn eslint src/*.ts src/**/*.ts",
"lint:fix": "yarn eslint src/*.ts src/**/*.ts --fix",
"build:clean": "yarn clean && yarn build",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not cleaning on yarn build doesn't make it faster but would leave *.js files in /dist when e.g. switching between branches.

await os.addOrUpdateMember(owner.id, org.id, owner.id, "member");
// verify they are still an owner
const members = await os.listMembers(owner.id, org.id);
expect(members.some((m) => m.userId === owner.id && m.role === "owner")).to.be.true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are not bailing when we try to make the last owner a member but just not do it.

@mustard-mh
Copy link
Contributor

@svenefftinge I can't get preview env work with command $ previewctl admin credentials create.

Server error logs, it seems you have activate it?

{"@type":"type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent","serviceContext":{"service":"server","version":"se-fix-signup-gha.14623"},"stack_trace":"Error: User f071bb8e-b5d1-46cf-a436-da03ae63bcd2 not found.\n    at Authorizer.checkPermissionOnUser (/app/node_modules/@gitpod/server/src/authorization/authorizer.ts:120:19)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at UserService.findUserById (/app/node_modules/@gitpod/server/src/user/user-service.ts:80:9)\n    at /app/node_modules/@gitpod/server/src/user/user-controller.ts:141:30","component":"server","severity":"ERROR","time":"2023-08-02T17:36:01.739Z","message":"Failed to sign-in as admin with OTS Token","error":"Error: User f071bb8e-b5d1-46cf-a436-da03ae63bcd2 not found.\n    at Authorizer.checkPermissionOnUser (/app/node_modules/@gitpod/server/src/authorization/authorizer.ts:120:19)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at UserService.findUserById (/app/node_modules/@gitpod/server/src/user/user-service.ts:80:9)\n    at /app/node_modules/@gitpod/server/src/user/user-controller.ts:141:30"}

@svenefftinge svenefftinge force-pushed the se/fix-signup branch 2 times, most recently from 2be9928 to 88c2944 Compare August 2, 2023 20:31
@roboquat roboquat added size/L and removed size/M labels Aug 2, 2023
m.role === "owner",
).length > 0;
if (!hasOtherRegularOwners) {
// first regular member is going to be an owner
Copy link
Member

Choose a reason for hiding this comment

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

The subtile change here is, that if the single owner would leave the org, the next sign-up would be promote to be an owner. before that, this role change would be only applied for the first regular member to join the org.

Need to think about this case first. (preview env is spinning up...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the single owner cannot leave an org and cannot be downgraded to a member. The change is that before we would throw an exception when someone tried to downgrade the single owner, where now we change the role to owner no matter what the previous state was. I agree the logic seems too involved, i.e.e the method does too much. Let me think how we can simplify things. maybe having two methods makes more sense. addMember and setRole.

Copy link
Member

@AlexTugarev AlexTugarev left a comment

Choose a reason for hiding this comment

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

LGTM!

@svenefftinge
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit 8a8b148 into main Aug 3, 2023
@roboquat roboquat deleted the se/fix-signup branch August 3, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants