Skip to content
Snippets Groups Projects

Turn Group#owners into a has_many association

Merged yorickpeterse-staging requested to merge group-owners-association into master

What does this MR do?

This turns the regular method Group#owners into a has_many association.

Are there points in the code the reviewer needs to double check?

As far as I can tell there's no way to do this without using an intermediate association, but perhaps I'm missing something. The reason an intermediate association is needed is because the supplied Proc is applied to the final association (the one returning users), this means that when using a single has_many you can't filter out any intermediate rows (e.g. group members).

Why was this MR needed?

This code being a regular method would prevent eager loading of the owners of a Group, turning it into a has_many association resolves this problem. This was discovered in !4410 (merged).

What are the relevant issue numbers?

None.

Does this MR meet the acceptance criteria?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Added 1 commit:

    • a8638a78 - Turn Group#owners into a has_many association
  • yorickpeterse-staging Added ~149423 label

    Added ~149423 label

  • mentioned in issue #18684 (closed)

  • Maintainer

    @dblessing and I actually had a discussion about this in #18616 (closed) yesterday. There is a bug right now where if you add another user as a owner to a project, he/she loses access completely because the Ability class doesn't look for this. You actually can't add another owner in the UI, but you can do this via the API. @dzaporozhets explained the reasoning of having one and only one owner for a project or user namespace in #5980 (closed).

    Edited by Stan Hu
  • Maintainer

    Never mind, I am confusing project owners with group owners. This is valid.

  • Added 1 commit:

    • 84e2be5a - Turn Group#owners into a has_many association
  • @rymai I adjusted the specs based on your suggestions.

  • username-removed-128633 Enabled an automatic merge when the build for 84e2be5a succeeds

    Enabled an automatic merge when the build for 84e2be5a succeeds

  • @yorickpeterse Awesome, thank you!

  • username-removed-128633 Status changed to merged

    Status changed to merged

  • mentioned in commit 5b4e9938

  • @yorickpeterse It looks like this will also resolve the issue describe at https://gitlab.com/gitlab-org/gitlab-ce/issues/17764 (stale owners). Can you please confirm?

  • @dblessing Rails caches associations after the first call so I don't think this will make a difference for that particular case.

  • @yorickpeterse Hmm, that's disappointing but I understand. I suppose we can add a reload in the has_owner? method. If you have other ideas, please post in the linked issue.

  • Picked into 8-9-stable, will be in RC5.

  • Robert Speicher Removed ~149423 label

    Removed ~149423 label

  • mentioned in commit aafbfb00

  • Please register or sign in to reply
    Loading