Deleting group within shared project breaks protected branches.
Summary
When a project is shared with another group and added to the protected branches, deleting the group doens't remove references in the browser. This causes errors in any other protected branch manipulation.
Steps to reproduce
- Create a group|owner-group|
- Create new project |shared-project| owned by |owner-group|
- Create |test-group| branch
- Create a group|test-group|
- Share |shared-project| with |test-group|
- Add |test-group| to protected branches in |shared-project| with "allowed to push" permission
- Delete |test-group|
- Check protected branches UI in |shared-project|, it will say "Allowed to push: 0 roles, 0 users, and 1 group", even though test-group no longer exists. Also you (the user who performed step
- will no longer be able to add/edit/update protected branches in any project.
- Inspect Protected Branches/Server Logs - you should see the exception pasted in my original ticket.
- Open your browser console with F12, go to the Console tab, and execute this piece of JavaScript:
console.log(JSON.stringify(JSON.parse(localStorage['protected-branches-defaults']), null, 4))
You'll see the deleted group's id appears in the output and is stored in localStorage - this is the source of the problem.
What is the current bug behavior?
When attempting to make additional changes to protected branche 500 Internal Server Error. "Something went wrong on our end"
Menu shows "1 role, 0 users, 1 group" even though the group has been deleted.
Relevant logs and/or screenshots
gitlab tail:
==> /var/log/gitlab/gitlab-rails/production_json.log <==
{"method":"POST","path":"/owner-group/shared-project/protected_branches","format":"*/*","controller":"Projects::ProtectedBranchesController","action":"create","status":500,"error":"ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table \"protected_branch_push_access_levels\" violates foreign key constraint \"fk_7111b68cdb\"\nDETAIL: Key (group_id)=(23) is not present in table \"namespaces\".\n: INSERT INTO \"protected_branch_push_access_levels\" (\"group_id\", \"protected_branch_id\", \"created_at\", \"updated_at\") VALUES (23, 8, '2018-02-15 17:04:48.332795', '2018-02-15 17:04:48.332795') RETURNING \"id\"","duration":52.29,"view":0.0,"db":16.46,"time":"2018-02-15T17:04:48.288Z","params":{"authenticity_token":"[FILTERED]","protected_branch":{"name":"test-branch","merge_access_levels_attributes":{"0":{"access_level":"0"}},"push_access_levels_attributes":{"0":{"access_level":"40"},"1":{"group_id":"23"}}},"namespace_id":"owner-group","project_id":"shared-project"},"remote_ip":"10.0.2.2","user_id":1,"username":"root"}
==> /var/log/gitlab/gitlab-rails/production.log <==
ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: insert or update on table "protected_branch_push_access_levels" violates foreign key constraint "fk_7111b68cdb"
DETAIL: Key (group_id)=(23) is not present in table "namespaces".
: INSERT INTO "protected_branch_push_access_levels" ("group_id", "protected_branch_id", "created_at", "updated_at") VALUES (23, 8, '2018-02-15 17:04:48.332795', '2018-02-15 17:04:48.332795') RETURNING "id"):
config/initializers/active_record_locking.rb:12:in `_create_record'
app/services/protected_branches/create_service.rb:8:in `execute'
app/controllers/projects/protected_refs_controller.rb:16:in `create'
lib/gitlab/i18n.rb:47:in `with_locale'
lib/gitlab/i18n.rb:53:in `with_user_locale'
app/controllers/application_controller.rb:332:in `set_locale'
lib/gitlab/middleware/multipart.rb:93:in `call'
lib/gitlab/request_profiler/middleware.rb:14:in `call'
lib/gitlab/jira/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:18:in `call'
lib/gitlab/etag_caching/middleware.rb:11:in `call'
lib/gitlab/middleware/read_only.rb:31:in `call'
lib/gitlab/request_context.rb:18:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'
Chrome Console Output (Note that 'group 23' is the deleted group, no longer exists)
Example Error UI
Internal ZD: https://gitlab.zendesk.com/agent/tickets/90681
Reproduced on ee 10.4.3