Skip to content

Allow specifying the organization for an Internal User

What does this MR do and why?

Allow specifying the organization for an Internal User

This is optional until all callers support this

Implementation

This implementation is backwards compatible with current implementation and allows us to gradually introduce specifying the organization.

The username / alias problem should also be solved, either in this MR (only create Alias if organization is set) or in a separate MR based on this MR.

# This will continue to work until we migrated all the callers
Users::Internal.support_bot 

# This assigns the user to an organization
Users::Internal.for_organization(some_organization).support_bot 

Alternatives considered:

  • Users::Internal.for(organization: some_organization).support_bot Makes the method more complex but could be future proof
  • Users::Internal.support_bot(some_organization) requires some metaprogramming in order to prevent changing the method signator of all *_bot methods
  • Users::Internal.new(organization: some_organization, type: :support_bot).find_or_create Looks more like ActiveRecord but is a major refactor

References

How to set up and validate locally

Create bots in Rails Console. Try creating a bot, multiple calls should result in the same user id:

This is compatible behaviour with current master branch:

# Run this multiple times: the id should be the same:
Users::Internal.admin_bot.id
Users::Internal.ghost.id

Pass organization (new behaviour):

organization = Organizations::Organization.create(name: "New Org", path: "new-org")
# Run this multiple times: the id should be the same:
Users::Internal.for_organization(organization).admin_bot.id
Users::Internal.for_organization(organization).ghost.id

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.

Edited by Rutger Wessels

Merge request reports

Loading