-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete users in segment when they are deleted from system #717
Conversation
@@ -0,0 +1,5 @@ | |||
# frozen_string_literal: true | |||
|
|||
class UserRelatedEvent < BaseEventStoreEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Martouta I assume this is to prepare for other user related events that might be added in the future? Not premature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at user_related_event_test.rb
I guess it's just the way we structure events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is the way that structure events, and also the way that we structure Subscribers to those events (grouping by 'related' events 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user related event makes sense.
assert_equal event.metadata[:provider_id], master_account.id | ||
end | ||
|
||
test 'the event is persisted and with the necessary attributes when its associations are already destroyed' do |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
test/unit/user_test.rb
Outdated
@@ -20,6 +20,16 @@ class UserTest < ActiveSupport::TestCase | |||
ActionMailer::Base.deliveries = [] | |||
end | |||
|
|||
test 'the event is created when the user is destroyed' do |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments and suggestions to improve test decriptions
20ce617
to
2042605
Compare
Codecov Report
@@ Coverage Diff @@
## master #717 +/- ##
==========================================
+ Coverage 92% 92.94% +0.94%
==========================================
Files 2321 2413 +92
Lines 74204 78298 +4094
==========================================
+ Hits 68269 72777 +4508
+ Misses 5935 5521 -414
Continue to review full report at Codecov.
|
1fbeca9
to
b442bb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way we can test this in preview/staging? (We do have an Intercom staging account, not sure about segment)
7b16e91
to
a35cfc9
Compare
bc79dbb
to
d443efc
Compare
end | ||
|
||
def self.config | ||
configuration.config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an instance variable on class level? 🇫🇷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macejmic Yes 😂 It was originally a module because we only need one global config for a feature, but @hallelujah explained me that it is better to have it like a class, the variable @configuration
of the class (which is one of the instances) is the global configuration for the feature, and we can have as many instances as we want with different configs to test them in isolation without having to do dirty stuff from the tests like https://github.com/3scale/porta/pull/589/files#diff-02fd35c4c56ad40080442d610f0cc910L7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that could work :)
06276b6
to
378b905
Compare
[OUTDATED COMMENT! 😉 ] |
497e89b
to
974cede
Compare
974cede
to
a30bd83
Compare
71a8322
to
cf4dd10
Compare
cf4dd10
to
1bde827
Compare
…letedUserEvent is created When segment deletion feature is disabled, do not even enqueue the worker
1. Feature configs implementation 2. GBPRApiRequest implementation 3. Test of the worker
1bde827
to
06ab167
Compare
# frozen_string_literal: true | ||
|
||
module Features | ||
class SegmentDeletionConfig < Config; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I do because we have different types of features (right now AccountDeletionConfig
and SegmentDeletionConfig
) and we need to load them by type (look at the initializer) and fetch them where we use them by type... and even stub them by type. Almost the whole PR is based on that 🤔 check SegmentDeletionConfig
and you will see 15 results so far 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me.
good job! 🍤 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Closes THREESCALE-1846 - Delete users in segment when they are deleted from system
We will need https://github.com/3scale/deploy/pull/550 merged for it to work, but without it, it simply does nothing 😄
Tasks of this PR
SegmentDeletionConfig
as a config feature containing :enabled
,email
,password
,uri
,workspace
.UserDeletedEvent
. The only data we need is the user ID and the tenant ID.Segment::AuthenticatorService
to request token. It uses Faraday and raises an error for wrong responses.Segment::DeleteUserService
to delete the user from the user_id it receives and with the token sent as param.UserDeletedEvent
is created, it is destroyed in segment in the backgroundSegmentSubscriber
.first_admin_id
of Account.Why to remove the SegmentSubscriber
the
SegmentSubscriber
to call segment for the accounts that were deleted to mark their first admin as 'state: deleted' in segment. It was by account and we want it for user, and it didn't delete it for real them for real but just put that state attribute on them.Why to remove the first_admin_id
Some of the times this explanation has been requested are: #717 (comment) & #717 (comment) & #717 (comment)
The

first_admin_id
was introduced in #8 to fix this bug https://github.com/3scale/porta/issues/10 . It was introduced 5 months ago. The problem was thatAccountDeletedEvent
was saving theuser_id
of the first admin but at the time this event was being saved, the user had already been deleted and we didn't have the ID anymore. And we needed it only for theSegmentSubscriber
. Now that we have removed theSegmentSubscriber
, we don't need thefirst_admin_id
at all anymore. Although that time has changed it is not used anywhere else for anything:In preview only seen that the configuration is correct
I checked in preview that the configuration of
Features::SegmentDeletionConfig
is correct for https://github.com/3scale/deploy/pull/550, and then I am testing locally in development environment with that same configuration... with the production one though, and using the list of users that need to be destroyed for real...These are the reasons:
Account.master.third_party_notifications!(tenant)
for this method.2.1 We are not specifying this workspace and url for preview anywhere, so it is impossible that it goes there to create the users
2.2 In segment we can not see the users itself, we need integration with intercom, and apparently there is an intercom for testing but i couldn't access it...
Verification steps (locally and with real production data, so be careful with this!)
config/features.yml
to have a config that can access to the production data. You can see the proper format inconfig/examples/features.yml
and the proper data in https://github.com/3scale/deploy/pull/550true
always, so you can delete any user.porta/app/models/user.rb
Lines 416 to 419 in 3f7fa1d
redis-cli flushall
to have all the sidekiq queue clean.User.last.update_column(:id, user_id)
with theuser_id
of one of those that have to be destroyed for real and has not been destroyed yet.spring stop
). Turn on the Rails Server:OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES UNICORN_WORKERS=8 bundle exec rails server -b 0.0.0.0
default
queue:UNICORN_WORKERS=8 bundle exec sidekiq -q low -q default -L log/sidekiq.log
tail -f log/sidekiq.log
http://provider-admin.example.com.lvh.me:3000/buyers/accounts/3/users/:user_id/edit
.FAILED
orINITIALIZED
, which means that it works.The
FAILED
means that segment does a request to the 3rd party services and the 3rd party services might fail and we can not do anything about it, and for this PR this is still just fine, so for this PR,FAILED
would mean it worked, because we got to notify segment, and we would have a problem only if it doesn't appear at all in the deletion requests page in the Segment page.