Commit 0b07c47c authored by Josianne Hyson's avatar Josianne Hyson

Add members added event and start broadcasting

We want to be able to react to changes in the quantity of users in a
group. Start broadcasting a members added event in the create member
service so that we can listen for these events async.

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/348487
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79291
parent c19719a6
# frozen_string_literal: true
module Members
class MembersAddedEvent < ::Gitlab::EventStore::Event
def schema
{
'type' => 'object',
'required' => %w[source_id source_type],
'properties' => {
'source_id' => { 'type' => 'integer' },
'source_type' => { 'type' => 'string' }
}
}
end
end
end
...@@ -24,6 +24,9 @@ module Members ...@@ -24,6 +24,9 @@ module Members
add_members add_members
enqueue_onboarding_progress_action enqueue_onboarding_progress_action
publish_event!
result result
rescue BlankInvitesError, TooManyInvitesError, MembershipLockedError => e rescue BlankInvitesError, TooManyInvitesError, MembershipLockedError => e
error(e.message) error(e.message)
...@@ -144,6 +147,15 @@ module Members ...@@ -144,6 +147,15 @@ module Members
def formatted_errors def formatted_errors
errors.to_sentence errors.to_sentence
end end
def publish_event!
Gitlab::EventStore.publish(
Members::MembersAddedEvent.new(data: {
source_id: source.id,
source_type: source.class.name
})
)
end
end end
end end
......
...@@ -177,6 +177,8 @@ ...@@ -177,6 +177,8 @@
- 1 - 1
- - gitlab_shell - - gitlab_shell
- 2 - 2
- - gitlab_subscriptions_notify_seats_exceeded
- 1
- - group_destroy - - group_destroy
- 1 - 1
- - group_export - - group_export
......
...@@ -1020,6 +1020,15 @@ ...@@ -1020,6 +1020,15 @@
:weight: 1 :weight: 1
:idempotent: :idempotent:
:tags: [] :tags: []
- :name: gitlab_subscriptions_notify_seats_exceeded
:worker_name: GitlabSubscriptions::NotifySeatsExceededWorker
:feature_category: :purchase
:has_external_dependencies: true
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: group_saml_group_sync - :name: group_saml_group_sync
:worker_name: GroupSamlGroupSyncWorker :worker_name: GroupSamlGroupSyncWorker
:feature_category: :authentication_and_authorization :feature_category: :authentication_and_authorization
......
# frozen_string_literal: true
module GitlabSubscriptions
class NotifySeatsExceededWorker
include ApplicationWorker
include Gitlab::EventStore::Subscriber
feature_category :purchase
data_consistency :delayed
deduplicate :until_executing, including_scheduled: true
idempotent!
worker_has_external_dependencies!
def handle_event(event)
# no-op for now, to be implemented in https://gitlab.com/gitlab-org/gitlab/-/issues/348487
end
end
end
...@@ -22,6 +22,8 @@ module EE ...@@ -22,6 +22,8 @@ module EE
### ###
# Add EE only subscriptions here: # Add EE only subscriptions here:
store.subscribe ::GitlabSubscriptions::NotifySeatsExceededWorker, to: ::Members::MembersAddedEvent
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::EventStore do
describe '.instance' do
it 'returns a store with CE and EE subscriptions' do
instance = described_class.instance
expect(instance.subscriptions.keys).to include(
::Ci::PipelineCreatedEvent,
::Members::MembersAddedEvent
)
end
end
end
...@@ -39,6 +39,15 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_ ...@@ -39,6 +39,15 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_
expect(source.users).to include member expect(source.users).to include member
expect(OnboardingProgress.completed?(source, :user_added)).to be(true) expect(OnboardingProgress.completed?(source, :user_added)).to be(true)
end end
it 'triggers a members added event' do
expect(Gitlab::EventStore)
.to receive(:publish)
.with(an_instance_of(Members::MembersAddedEvent))
.and_call_original
expect(execute_service[:status]).to eq(:success)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment