-
Notifications
You must be signed in to change notification settings - Fork 71
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
User moderation: Delete a user's communities on block #1023
User moderation: Delete a user's communities on block #1023
Conversation
@@ -463,18 +448,27 @@ def featured_delete( | |||
# Deletion workflows | |||
# | |||
@unit_of_work() | |||
def delete_community(self, identity, id_, data, expand=False, uow=None): | |||
def delete_community( | |||
self, identity, id_, data=None, revision_id=None, expand=False, uow=None |
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.
the revision_id
is accepted but ignored because the old signature (and the resource actually provides a value from the if_match
request context header)
not sure if that's the way to go?
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.
# Set a record to 'metadata only' if its files got cleaned up | ||
if not record.files.entries: | ||
record.files.enabled = False |
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.
that caused the community's settings page to break after a restore...
it's just relevant for records (where it was copied from), but not for communities
current_user_filter = CommunityMembers().query_filter(identity) & dsl.Q( | ||
"term", **{"deletion_status": CommunityDeletionStatusEnum.PUBLISHED.value} | ||
) |
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 will certainly hide deleted records from the search results for the user's communities (without it, they'd still pop up)
maybe this should be done via generator query filters somehow?
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.
PIng @kpsherva
# collect the owners for each community | ||
comm_owners = defaultdict(list) | ||
for comm_owner in [ | ||
mem_cls(m.data, model=m) | ||
for m in mem_model_cls.query.filter(mem_model_cls.role == "owner").all() | ||
]: | ||
comm_owners[comm_owner.community_id].append(comm_owner) | ||
|
||
# filter for communities that are owned solely by the user in question | ||
relevant_comm_ids = [ | ||
comm_id | ||
for comm_id, owners in comm_owners.items() | ||
if len(owners) == 1 and str(owners[0].user_id) == user_id | ||
] |
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 have a feeling that this should be doable with a group_by
and/or having
for better performance
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 we have a helper function to get all memberships of a user. It returns though all memberships and not filtered by a specific role but it could be improved. Ping @ntarocco I think in this case the performance issue with getting all communities of a user from DB is done on demand so it should not affect overall performance right?
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.
to be discussed, it seems to me that it is not a blocker for now
75cf6ea
to
e4574f0
Compare
self, identity, id_, data=None, expand=False, revision_id=None, uow=None | ||
): | ||
"""Alias for ``delete_community()``.""" | ||
return self.delete_community(identity, id_, data, expand=expand, uow=uow) |
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.
why don't we just keep the delete
and we introduce a delete_community
?
@@ -463,18 +448,27 @@ def featured_delete( | |||
# Deletion workflows | |||
# | |||
@unit_of_work() | |||
def delete_community(self, identity, id_, data, expand=False, uow=None): | |||
def delete_community( | |||
self, identity, id_, data=None, revision_id=None, expand=False, uow=None |
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.
# collect the owners for each community | ||
comm_owners = defaultdict(list) | ||
for comm_owner in [ | ||
mem_cls(m.data, model=m) | ||
for m in mem_model_cls.query.filter(mem_model_cls.role == "owner").all() | ||
]: | ||
comm_owners[comm_owner.community_id].append(comm_owner) | ||
|
||
# filter for communities that are owned solely by the user in question | ||
relevant_comm_ids = [ | ||
comm_id | ||
for comm_id, owners in comm_owners.items() | ||
if len(owners) == 1 and str(owners[0].user_id) == user_id | ||
] |
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 we have a helper function to get all memberships of a user. It returns though all memberships and not filtered by a specific role but it could be improved. Ping @ntarocco I think in this case the performance issue with getting all communities of a user from DB is done on demand so it should not affect overall performance right?
current_user_filter = CommunityMembers().query_filter(identity) & dsl.Q( | ||
"term", **{"deletion_status": CommunityDeletionStatusEnum.PUBLISHED.value} | ||
) |
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.
PIng @kpsherva
* when a user gets blocked, delete all communities of which they are the only owner
* resources: add restore and delete communities actions
9579fa3
to
6b8d966
Compare
6b8d966
to
54a0778
Compare
a2e0a30
to
cf1ed1c
Compare
When a user gets blocked, delete all communities of which they are the only owner