Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add orgId to IntegrationProvider #6014

Merged
merged 12 commits into from
Aug 1, 2024

Conversation

Dschoordsch
Copy link
Contributor

@Dschoordsch Dschoordsch commented Feb 8, 2022

Integration providers are added with different scopes. Currently it is
cumbersome to query for org scope since only the teamId is part of the
integration. This migration would add the orgId for org scope and add
constraints that the correct id is set depending on scope.

Summary by CodeRabbit

  • New Features

    • Added support for organisation identifiers in integration provider schemas, allowing for broader data handling.
    • Introduced optional organisation identifier in the input types for integration provider creation.
    • Enhanced subscription capabilities by including updates specific to integration provider success.
    • Expanded component functionality to accommodate team-specific identifiers in the provider details.
  • Bug Fixes

    • Improved error handling for cases with invalid organisational data during integration processes.
  • Improvements

    • Streamlined authorisation checks to ensure only appropriate users can manage integration providers based on scope.
    • Updated GraphQL schema to reflect nullable team identifiers, enhancing the flexibility of integration provider configurations.
    • Removed obsolete fields to simplify data structure in GraphQL responses.

@Dschoordsch Dschoordsch changed the title Add orgId to IntegrationProvidier [RFC] Add orgId to IntegrationProvidier Feb 8, 2022
@Dschoordsch
Copy link
Contributor Author

@mattkrick @BartoszJarocki could you take a look and tell me what you think about that change?

Copy link
Contributor

@BartoszJarocki BartoszJarocki left a comment

Choose a reason for hiding this comment

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

Just two typos otherwise it looks really good! I like how easy it is now to understand the relation between the team, org, and global scopes, nicely done 👌🏻

ALTER TABLE "IntegrationProvider"
ADD CONSTRAINT "scope_org_has_only_orgId" CHECK
("scope" <> 'org' OR ("orgId" IS NOT NULL AND "teamId" IS NULL)),
ADD CONSTRAINT "scope_team_has_only_reamId" CHECK
Copy link
Contributor

Choose a reason for hiding this comment

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

teamId instead of reamId

BEGIN
ALTER TABLE "IntegrationProvider"
DROP CONSTRAINT "scope_org_has_only_orgId",
DROP CONSTRAINT "scope_team_has_only_reamId",
Copy link
Contributor

Choose a reason for hiding this comment

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

teamId instead of reamId

@Dschoordsch Dschoordsch changed the title [RFC] Add orgId to IntegrationProvidier [RFC] Add orgId to IntegrationProvider Feb 9, 2022
@Dschoordsch Dschoordsch changed the title [RFC] Add orgId to IntegrationProvider Add orgId to IntegrationProvider Feb 9, 2022
@Dschoordsch Dschoordsch added the DX Developer Experience label Feb 10, 2022
@Dschoordsch
Copy link
Contributor Author

@BartoszJarocki could you take a look again?

Copy link
Contributor

@BartoszJarocki BartoszJarocki left a comment

Choose a reason for hiding this comment

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

Code looks good but I can't add integrate mattermost anymore. I'm getting the following error when I try to set the webhook URL:

Trace: {
  error: '{"data":null,"errors":[{"message":"there is no unique or exclusion constraint matching the ON CONFLICT specification","locations":[{"line":4,"column":3}],"path":["addIntegrationProvider"]}]}'
}

It works on master so it'd be great if you could take a look @Dschoordsch

@Dschoordsch
Copy link
Contributor Author

@BartoszJarocki thanks for finding this bug! I was missing a unique constraint. I tested with adding and updating a mattermost webhook and adding and removing Jira server auth.

Copy link
Contributor

@BartoszJarocki BartoszJarocki left a comment

Choose a reason for hiding this comment

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

works like a charm now!

@mattkrick
Copy link
Member

mattkrick commented Feb 14, 2022

Teams can change orgs 🙂

Today, if a team changes an org:

  • The provider moves with the team to the new org
  • teamMemberIntegrationAuths keep using the same provider (perhaps this is wrong, but i had to get that massive gitlab PR merged)
  • tasks that are integrated with that provider still load (because they use the teamMemberIntegrationAuths which uses the old provider)

IMO, anytime the ER model goes full circle with two 1:Ms on the same entity, things get messy
image

That said, if you prefer updating moveTeamToOrg, we can do that! IMO having to remember that a table has 2 fields that are inherently tightly coupled is a headache, but then again so is a verbose query!

Also if there's a good place to store this reasoning in the repo let me know. It'd be good to have it stored there to explain why it's built the way it is.

@Dschoordsch
Copy link
Contributor Author

@mattkrick

  • I don't think the ER circle is an issue because both half-circles are mutually exclusive by constraints
  • Moving the organization wide integration with the team is a bit counter-intuitive for me. It really depends on the UI/UX if that is sensible. If we keep all the current UI and just add a "Make available to whole organization" checkbox while integrating, then it seems reasonable. If on the other hand we have a separate integrations menu under organization, then it would be more sensible to associate it with the org directly.

@mattkrick
Copy link
Member

Makes sense, the UI is gonna be real important with regards to how intuitive sharing feels.
I imagine integrations will be owned by a team & shared with the rest of their org, just like your first option.

The closest design we have is how we do templates today:
Screen Shot 2022-03-23 at 4 36 07 PM

@mattkrick
Copy link
Member

@Dschoordsch doing some PR housekeeping. would you like to keep this one open?

@mattkrick
Copy link
Member

pinging @Dschoordsch on next steps for this. shall we close this but leave the branch alive so we can pick it back up when we prioritize?

@Dschoordsch Dschoordsch closed this Jun 8, 2022
@mattkrick mattkrick deleted the add_orgId_to_IntegrationProvider branch May 17, 2023 17:30
@mattkrick mattkrick restored the add_orgId_to_IntegrationProvider branch May 17, 2023 17:30
@Dschoordsch Dschoordsch deleted the add_orgId_to_IntegrationProvider branch May 22, 2023 10:19
@Dschoordsch Dschoordsch restored the add_orgId_to_IntegrationProvider branch July 25, 2024 10:28
@Dschoordsch
Copy link
Contributor Author

There is no good way of attaching an org scoped IntegrationProvider to any specific team from the Organization Settings. I think this indicates that this is necessary after all. I think you're right about a team moving orgs and I agree the currently team scoped integration providers (MS Teams and Mattermost webhook providers) should move with the team.
The usually org scoped providers Jira Server and soon GitLab however are setup by some admin role for the organization and thus should stay with the org.
I think in this case the architecture should follow the UI/UX requirements and allow attaching an IntegrationProvider to an org directly without an intermediate team.

@Dschoordsch Dschoordsch reopened this Jul 25, 2024
Integration providers are added with different scopes. Currently it is
cumbersome to query for org scope since only the `teamId` is part of the
integration. This migration would add the `orgId` for org scope and add
constraints that the correct id is set depending on scope.

TODO: The queries accessing the provider need to be adapted to the new
structure.
@Dschoordsch Dschoordsch force-pushed the add_orgId_to_IntegrationProvider branch from 658791d to 0e70020 Compare July 25, 2024 11:03
Copy link
Contributor

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent changes significantly enhance the management of integration providers by shifting focus from team identifiers to organisational identifiers. This update includes modifications to interfaces, functions, and validations to ensure operations align with an organisational context. Key adjustments involve replacing orgTeamIds with orgIds, introducing new fields for organisational relationships, and refining validation rules to ensure only valid organisational data is processed during integration operations.

Changes

Files Change Summary
packages/server/dataloader/... Updated SharedIntegrationProviderKey to replace orgTeamIds with orgIds, affecting integration fetching logic.
packages/server/graphql/mutations/... Enhanced authorisation and validation in addIntegrationProvider, updateIntegrationProvider, and removeIntegrationProvider functions to include organisational context checks.
packages/server/graphql/types/... Modified teamId to a nullable type and added orgId, increasing input flexibility for various scopes. Removed team fields from success payloads, focusing on user actions.
packages/server/graphql/public/typeDefs/... Made teamId optional and added orgId in various input types, enhancing flexibility for integration provider configurations. Removed unnecessary fields to streamline the schema.
packages/client/modules/teamDashboard/components/... Added teamId to provider objects in MSTeamsPanel and MattermostPanel, expanding component capabilities for team-specific interactions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Database

    Client->>API: Request to add integration provider
    API->>Database: Validate teamId and orgId
    alt orgId exists
        Database-->>API: Return valid orgId
        API->>Database: Insert integration provider with orgId
        Database-->>API: Confirm insertion
        API-->>Client: Success response
    else orgId does not exist
        API-->>Client: Error response
    end
Loading
sequenceDiagram
    participant Client
    participant API
    participant Database

    Client->>API: Request to fetch shared integration providers
    API->>Database: Query using orgIds
    Database-->>API: Return integration providers
    API-->>Client: Response with integration providers
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
packages/server/postgres/queries/src/upsertIntegrationProviderQuery.sql (1)

16-17: Ensure orgId is included in the provider object passed to upsertIntegrationProviderQuery.

The orgId field is missing from the IUpsertIntegrationProviderInput interface. To correctly handle the new structure of the SQL query, add the orgId field to the interface and ensure it is populated when constructing the provider object.

  • File: packages/server/postgres/queries/upsertIntegrationProvider.ts
  • Lines to update:
    • Add orgId to IUpsertIntegrationProviderInput interface.
    • Ensure orgId is included in the provider object passed to upsertIntegrationProviderQuery.run.
Analysis chain

LGTM! Ensure correct usage of the updated SQL query.

The changes to the SQL query align with the PR objectives. The orgId field has been added to the INSERT statement and the ON CONFLICT clause. Ensure that all usages of this query are updated accordingly to handle the new structure.

Also applies to: 31-32, 34-34

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the updated `upsertIntegrationProviderQuery`.

# Test: Search for the query usage. Expect: All usages should handle the new structure.
rg --type sql -A 5 'upsertIntegrationProviderQuery'

Length of output: 598


Script:

#!/bin/bash
# Description: Verify all usages of the updated `upsertIntegrationProviderQuery` in JavaScript and TypeScript files.

# Test: Search for the query usage in JS/TS files. Expect: All usages should handle the new structure.
rg --type js,ts -A 5 'upsertIntegrationProviderQuery'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify all usages of the updated `upsertIntegrationProviderQuery` in JavaScript and TypeScript files.

# Test: Search for the query usage in JS files. Expect: All usages should handle the new structure.
rg --type js -A 5 'upsertIntegrationProviderQuery'

# Test: Search for the query usage in TS files. Expect: All usages should handle the new structure.
rg --type ts -A 5 'upsertIntegrationProviderQuery'

Length of output: 1390


Script:

#!/bin/bash
# Description: Extract relevant parts of the TypeScript file to verify handling of `orgId`.

# Extract the content of the TypeScript file where `upsertIntegrationProviderQuery` is used.
rg --type ts -A 10 'upsertIntegrationProviderQuery' packages/server/postgres/queries/upsertIntegrationProvider.ts

Length of output: 707


Script:

#!/bin/bash
# Description: Search for the definition and construction of the `provider` object in the TypeScript file.

# Extract lines where `provider` is defined or constructed.
rg --type ts 'provider' packages/server/postgres/queries/upsertIntegrationProvider.ts

Length of output: 258

@Dschoordsch Dschoordsch changed the title Add orgId to IntegrationProvider chore: Add orgId to IntegrationProvider Jul 25, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
packages/server/graphql/public/typeDefs/TeamSubscriptionPayload.graphql (1)

Inconsistencies found due to the removal of UpdateIntegrationProviderSuccess from TeamSubscriptionPayload.

The UpdateIntegrationProviderSuccess field is still referenced in several parts of the codebase. To avoid inconsistencies or errors, please review and update the following files:

  • packages/client/subscriptions/OrganizationSubscription.ts
  • packages/server/graphql/types/UpdateIntegrationProviderPayload.ts
  • packages/client/mutations/UpdateIntegrationProviderMutation.ts
  • packages/server/graphql/mutations/updateIntegrationProvider.ts
  • packages/server/graphql/public/typeDefs/OrganizationSubscriptionPayload.graphql
  • packages/server/graphql/public/typeDefs/UpdateIntegrationProviderSuccess.graphql
  • packages/server/graphql/public/typeDefs/UpdateIntegrationProviderPayload.graphql

Please ensure that these references are either updated or removed as appropriate to maintain consistency in the codebase.

Analysis chain

Line range hint 1-63:
Confirm the removal of the UpdateIntegrationProviderSuccess field.

The UpdateIntegrationProviderSuccess field has been removed from the TeamSubscriptionPayload GraphQL type definition. Ensure that this change aligns with the design objectives and does not introduce inconsistencies or errors in the GraphQL schema or client code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the removal of the `UpdateIntegrationProviderSuccess` field does not introduce inconsistencies or errors.

# Test: Search for the usage of `UpdateIntegrationProviderSuccess` in the codebase. Expect: No occurrences of the removed field.
rg --type graphql 'UpdateIntegrationProviderSuccess'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify that the removal of the `UpdateIntegrationProviderSuccess` field does not introduce inconsistencies or errors.

# Test: Search for the usage of `UpdateIntegrationProviderSuccess` in the codebase. Expect: No occurrences of the removed field.
rg 'UpdateIntegrationProviderSuccess'

Length of output: 1208

@github-actions github-actions bot added size/l and removed size/m labels Aug 1, 2024
@Dschoordsch Dschoordsch merged commit 6819e90 into master Aug 1, 2024
8 checks passed
@Dschoordsch Dschoordsch deleted the add_orgId_to_IntegrationProvider branch August 1, 2024 19:16
@github-actions github-actions bot mentioned this pull request Aug 2, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Developer Experience size/l
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants