Fix SlackIntegration duplicate bug when inheriting from parent
What does this MR do and why?
This MR fixes an issue where SlackIntegration records are not properly created when inheriting GitLab Slack Application integrations from group or instance level to projects.
Problem
When calling Integration.build_from_integration to create project-level integrations from parent (group/instance) integrations:
- The
dupmethod doesn't duplicate associated records (slack_integration) - The new integration lacks the required
SlackIntegrationassociation - This causes the integration to fail as the
aliasfield (required for Slack commands) is missing
Solution
Introduces a after_build_from_integration hook in the integration inheritance flow:
- Added
after_build_from_integrationmethod toIntegrationbase class (no-op by default) -
build_from_integrationcalls this hook after setting the parent context -
GitlabSlackApplicationoverrides this hook to duplicate theslack_integrationwith the correct alias based on the new parent'sfull_path
This ensures that when projects inherit Slack integrations from their parent group/instance, they get properly configured SlackIntegration records with unique aliases.
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to test
Test instance-level inheritance
-
Enable GitLab for Slack app feature:
- Navigate to Admin Area > Settings > General
- Expand GitLab for Slack app section
- Check Enable GitLab for Slack app
- Save changes
-
Configure instance-level integration:
- Navigate to Admin Area > Settings > Integrations
- Click on GitLab for Slack app
- Install/configure the integration
- Save the integration
-
Verify project inheritance:
- Create a new project
- Navigate to Project > Settings > Integrations
- Verify GitLab for Slack app shows as inherited (with inheritance icon)
- Click on the integration
- Verify the button shows "Reinstall GitLab for Slack app" (not a broken state)
Test group-level inheritance
-
Enable GitLab for Slack app feature (same as step 1 above)
-
Configure group-level integration:
- Navigate to Group > Settings > Integrations
- Click on GitLab for Slack app
- Install/configure the integration
- Save the integration
-
Verify project inheritance:
- Create a new project under this group
- Navigate to Project > Settings > Integrations
- Verify GitLab for Slack app shows as inherited from group
- Click on the integration
- Verify the button shows "Reinstall GitLab for Slack app" (not a broken state)
Expected behavior
- The integration should be properly inherited without errors
- The SlackIntegration association should be created with correct alias
- The "Reinstall" button should be functional
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #461056 (closed)