Skip to content

[SHD-1879] Productionize poc#560

Draft
phylum wants to merge 25 commits into
mainfrom
productionize-poc
Draft

[SHD-1879] Productionize poc#560
phylum wants to merge 25 commits into
mainfrom
productionize-poc

Conversation

@phylum

@phylum phylum commented May 22, 2026

Copy link
Copy Markdown
Contributor

This PR decouples SCIM from Audiences.

The ticket for this PR is here.

@phylum phylum self-assigned this May 22, 2026
@powerhome-portal

Copy link
Copy Markdown

A change to documentation files was detected in your PR. Please visit this link to preview changes: https://portal-staging.powerapp.cloud/docs?filters[kind]=all&filters[user]=all&filters[namespaceFilter]=productionize-poc

Comment on lines +77 to +78
# Return relation, not array, so downstream code can continue querying
Audiences::ConfigurableAdapter.active_audiences_users.merge(matching_users)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can't assume this is a relation because it's configurable, so it could be anything. It doesn't seem like the code is doing it from what I can tell, just mentioning because of the above comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@xjunior We define the active_audiences_users configuration as returning a relation here. We're expecting the configuring app to set this up correctly. Are you thinking we should validate before we attempt to merge as a last safe-guard against it being configured incorrectly?

Comment on lines +3 to +4
module Audiences
module Integrations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is all legacy groups, and users, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this will be removed when we remove support for Audiences::ExternalUser/Audiences::Group.

Comment on lines +135 to +148
# Proc that transforms a user record to the hash format Audiences expects
# Required keys: id, external_id, display_name, active, groups (array with id)
#
# Example:
# config.to_audiences_hash_proc = ->(user) {
# {
# id: user.scim_id, # Maps provider-specific field to generic 'id'
# external_id: user.external_id,
# display_name: user.display_name,
# active: user.active,
# groups: user.scim_groups.map { |g| { id: g.scim_id, ... } }
# }
# }
config_accessor :to_audiences_hash_proc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be part of the adapter instead, perhaps?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same of the other to_*_hash_proc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I put the to_audiences_hash_proc in configuration because it's the integration point between Audiences and our models. If we want to move it into the adapter, we'd need an adapter subclass to configure this. Are you suggesting we create a new class and configure it there instead of here? Something like:

# Connect Server creates subclass
class TwoPercentAdapter < Audiences::ConfigurableAdapter
  def to_audiences_hash
    { ... TwoPercent-specific ... }
  end
end

config.adapter_class = TwoPercentAdapter

Comment thread audiences/lib/audiences.rb Outdated
Comment thread audiences/spec/models/audiences/context_spec.rb Outdated
Audiences::Group.create!(scim_id: scim_id, display_name: "#{resource_type} #{scim_id}",
external_id: scim_id, resource_type: resource_type, **attrs)
# Mode-aware factory - creates appropriate model based on configuration
def create_group(external_id: next_scim_id, resource_type: "Groups", external_users: [], **attrs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is weird to have the factories behaving differently depending on the configuration. It would be more clear to have different factories and different tests, which would test the behavior of audiences depending on the "feature flag". Not a blocker since the idea is to remove this config/flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants