Skip to content
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

[ENG-4255] update to public true on ham just the objects that were public before were spammed #10970

Open
wants to merge 2 commits into
base: feature/b-and-i-25-01
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from api.share.utils import update_share
from api.caching.tasks import update_storage_usage_cache
from framework.auth import Auth

from osf.exceptions import NodeStateError
from osf.models import (
Expand Down Expand Up @@ -635,7 +636,8 @@ class NodeMakePublic(NodeMixin, View):
def post(self, request, *args, **kwargs):
node = self.get_object()
try:
node.set_privacy('public')
auth = Auth(request.user._wrapped, private_key=None)
node.set_privacy('public', auth=auth)
except NodeStateError as e:
messages.error(request, str(e))
return redirect(self.get_success_url())
Expand Down
8 changes: 8 additions & 0 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,14 @@ def confirm_spam(self, domains=None, save=True, train_spam_services=True):
super().confirm_spam(save=save, domains=domains or [], train_spam_services=train_spam_services)
self.deleted = timezone.now()
was_public = self.is_public
# the approach below helps to update to public true on ham just the objects that were public before were spammed
is_public_changings = self.logs.filter(action__in=['made_public', 'made_private'])
if is_public_changings:
latest_privacy_edit_time = is_public_changings.latest('created').created
last_spam_log = self.logs.filter(action__in=['confirm_spam', 'flag_spam'],
created__gt=latest_privacy_edit_time)
if last_spam_log:
was_public = last_spam_log.latest().params.get('was_public', was_public)
self.set_privacy('private', auth=None, log=False, save=False, force=True, should_hide=True)

log = self.add_log(
Expand Down
Loading