-
Notifications
You must be signed in to change notification settings - Fork 428
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
Add GDPR removal for pubsub (alternative) #2349
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,14 +185,22 @@ | |
-callback get_user_subscriptions(LUser :: jid:luser(), LServer :: jid:lserver()) -> | ||
[NodeName :: [binary()]]. | ||
|
||
-callback find_nodes_by_affiliated_user(JID :: jid:ljid()) -> | ||
[{mod_pubsub:pubsubNode(), mod_pubsub:affiliation()}]. | ||
|
||
-callback delete_user_subscriptions(JID :: jid:ljid()) -> | ||
ok. | ||
|
||
%%==================================================================== | ||
%% API | ||
%%==================================================================== | ||
|
||
-spec db_error(ReasonData :: map(), ErrorDebug :: map(), Event :: any()) -> | ||
% ReasonData may either be a debug map provided by mod_pubsub | ||
% or some other term if the crash is serious enough to lose the debug map somewhere. | ||
-spec db_error(ReasonData :: map() | any(), ErrorDebug :: map(), Event :: any()) -> | ||
{error, Details :: map()}. | ||
db_error(ReasonData, ErrorDebug, Event) -> | ||
{error, maps:merge(ErrorDebug#{ event => Event }, ReasonData)}. | ||
{error, maps:merge(ErrorDebug#{ event => Event }, sanitize_reason(ReasonData))}. | ||
|
||
%% transaction and sync_dirty return very truncated error data so we add extra | ||
%% try to gather stack trace etc. | ||
|
@@ -214,3 +222,8 @@ extra_debug_fun(Fun) -> | |
%% Internal functions | ||
%%==================================================================== | ||
|
||
sanitize_reason(Map) when is_map(Map) -> | ||
Map; | ||
sanitize_reason(Other) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is that possible? The spec above says There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For disabled backends |
||
#{ unexpected_reason => Other }. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,9 @@ | |
-export([ | ||
get_user_payloads/2, | ||
get_user_nodes/2, | ||
get_user_subscriptions/2 | ||
get_user_subscriptions/2, | ||
delete_user_subscriptions/1, | ||
find_nodes_by_affiliated_user/1 | ||
]). | ||
|
||
%%==================================================================== | ||
|
@@ -208,6 +210,15 @@ node_name(Nidx) -> | |
_ -> <<>> | ||
end. | ||
|
||
-spec find_nodes_by_affiliated_user(JID :: jid:ljid()) -> | ||
[{mod_pubsub:pubsubNode(), mod_pubsub:affiliation()}]. | ||
find_nodes_by_affiliated_user(LJID) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this function on such low-level module? Isn't there a plugin API that would do the same? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think that such function fits better in DB layer because it should be a simple data retrieval instead the processing done in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't suggesting to move it, I was just asking if there is similar functionality already there :) |
||
{ok, States} = get_states_by_lus(LJID), | ||
lists:map(fun(#pubsub_state{ stateid = {_, Nidx}, affiliation = Aff }) -> | ||
{ok, Node} = find_node_by_id(Nidx), | ||
{Node, Aff} | ||
end, States). | ||
|
||
%% ------------------------ Direct #pubsub_state access ------------------------ | ||
|
||
-spec get_state(Nidx :: mod_pubsub:nodeIdx(), | ||
|
@@ -269,7 +280,7 @@ del_node(Nidx) -> | |
{ok, States} = get_states(Nidx), | ||
lists:foreach(fun (#pubsub_state{stateid = {LJID, _}, items = Items}) -> | ||
del_items(Nidx, Items), | ||
del_state(Nidx, LJID) | ||
del_state_by_idx_and_ljid(Nidx, LJID) | ||
end, States), | ||
{ok, States}. | ||
|
||
|
@@ -458,7 +469,7 @@ set_affiliation(Nidx, LJID, Affiliation) -> | |
BareLJID = jid:to_bare(LJID), | ||
{ok, State} = get_state(Nidx, BareLJID, write), | ||
case {Affiliation, State#pubsub_state.subscriptions} of | ||
{none, []} -> del_state(Nidx, BareLJID); | ||
{none, []} -> del_state_by_idx_and_ljid(Nidx, BareLJID); | ||
_ -> mnesia:write(State#pubsub_state{ affiliation = Affiliation }) | ||
end. | ||
|
||
|
@@ -517,7 +528,7 @@ delete_subscription(Nidx, LJID, SubId) -> | |
NewSubs = lists:keydelete(SubId, 2, State#pubsub_state.subscriptions), | ||
mnesia:delete({pubsub_subscription, SubId}), | ||
case {State#pubsub_state.affiliation, NewSubs} of | ||
{none, []} -> del_state(Nidx, LJID); | ||
{none, []} -> del_state_by_idx_and_ljid(Nidx, LJID); | ||
_ -> mnesia:write(State#pubsub_state{subscriptions = NewSubs}) | ||
end. | ||
|
||
|
@@ -527,10 +538,19 @@ delete_subscription(Nidx, LJID, SubId) -> | |
ok. | ||
delete_all_subscriptions(Nidx, LJID) -> | ||
{ok, State} = get_state(Nidx, LJID, write), | ||
delete_all_subscriptions_by_state(State). | ||
|
||
-spec delete_user_subscriptions(jid:ljid()) -> ok. | ||
delete_user_subscriptions(LJID) -> | ||
{ok, States} = get_states_by_lus(LJID), | ||
lists:foreach(fun delete_all_subscriptions_by_state/1, States). | ||
|
||
-spec delete_all_subscriptions_by_state(mod_pubsub:pubsubState()) -> ok. | ||
delete_all_subscriptions_by_state(State) -> | ||
lists:foreach(fun({_, SubId}) -> mnesia:delete({pubsub_subscription, SubId}) end, | ||
State#pubsub_state.subscriptions), | ||
case State#pubsub_state.affiliation of | ||
none -> del_state(Nidx, LJID); | ||
none -> del_state(State); | ||
_ -> mnesia:write(State#pubsub_state{subscriptions = []}) | ||
end. | ||
|
||
|
@@ -623,10 +643,14 @@ del_items(Nidx, ItemIds) -> | |
%% Internal functions | ||
%%==================================================================== | ||
|
||
-spec del_state(Nidx :: mod_pubsub:nodeIdx(), | ||
LJID :: jid:ljid()) -> ok. | ||
del_state(Nidx, LJID) -> | ||
{ok, #pubsub_state{ subscriptions = Subs }} = get_state(Nidx, LJID, write), | ||
-spec del_state_by_idx_and_ljid(Nidx :: mod_pubsub:nodeIdx(), | ||
LJID :: jid:ljid()) -> ok. | ||
del_state_by_idx_and_ljid(Nidx, LJID) -> | ||
{ok, State} = get_state(Nidx, LJID, write), | ||
del_state(State). | ||
|
||
-spec del_state(mod_pubsub:pubsubState()) -> ok. | ||
del_state(#pubsub_state{ stateid = {LJID, Nidx}, subscriptions = Subs }) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like the fact that this function behaves differently based on type of the argument. I know that arity is different, but the name is the same, so I would expect this function to do the same thing, only maybe based on different data. I would suggest renaming here. |
||
lists:foreach(fun({_, SubId}) -> mnesia:delete({pubsub_subscription, SubId}) end, Subs), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why do we even need this function? The code above seem to be the same as in https://github.com/esl/MongooseIM/pull/2349/files#diff-76947e0e8d171032fa48bd99ed39698dR550 . What is the difference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but do we need to delete subs here? This function is called only from https://github.com/esl/MongooseIM/pull/2349/files#diff-76947e0e8d171032fa48bd99ed39698dR553, just after removing subs. Isn't this code redundant? |
||
mnesia:delete({pubsub_state, {LJID, Nidx}}). | ||
|
||
|
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.
And this just makes me think of one thing: why did we spawn a different process and return ok immediately before? Was it because of some timeout? Do we want to receive a notification for failure or so?
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.
Original pubsub's
remove_user
implementation probably assumed that the operator doesn't care if the removal action actually finished when the function exits. Currently all GDPR ops we've added are synchronous, even for MAM.