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

Read Sift moderation whitelist from environment #2018

Open
wants to merge 2 commits into
base: master
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
5 changes: 4 additions & 1 deletion src/researchhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,10 @@ def silky_capture(request):
"[email protected]",
]

SIFT_MODERATION_WHITELIST = [35747, 34581, 36837, 35436, 14, 33287, 34416]
SIFT_MODERATION_WHITELIST = [
user_id.strip()
for user_id in os.environ.get("SIFT_MODERATION_WHITELIST", "").split(",")
]

# Persona
PERSONA_WEBHOOK_SECRET = os.environ.get(
Expand Down
12 changes: 4 additions & 8 deletions src/user/views/user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
DynamicContributionSerializer,
)
from reputation.views import BountyViewSet
from researchhub.settings import (
EMAIL_WHITELIST,
SIFT_MODERATION_WHITELIST,
SIFT_WEBHOOK_SECRET_KEY,
)
from researchhub import settings
from researchhub_comment.models import RhCommentModel
from user.filters import UserFilter
from user.models import Author, Follow, Major, University, User
Expand Down Expand Up @@ -758,7 +754,7 @@
postback_signature = request.headers.get("X-Sift-Science-Signature")

# Next, let's try to assemble the signature on our side to verify
key = SIFT_WEBHOOK_SECRET_KEY.encode("utf-8")
key = settings.SIFT_WEBHOOK_SECRET_KEY.encode("utf-8")

Check warning on line 757 in src/user/views/user_views.py

View check run for this annotation

Codecov / codecov/patch

src/user/views/user_views.py#L757

Added line #L757 was not covered by tests
postback_body = request.body

h = hmac.new(key, postback_body, sha1)
Expand All @@ -771,8 +767,8 @@
user = User.objects.get(id=user_id)

if (
not user.moderator or user.email not in EMAIL_WHITELIST
) and user.id not in SIFT_MODERATION_WHITELIST:
not user.moderator or user.email not in settings.EMAIL_WHITELIST
) and user.id not in settings.SIFT_MODERATION_WHITELIST:
if "mark_as_probable_spammer_content_abuse" in decision_id:
log_info(
f"Possible Spammer - {user.id}: {user.first_name} {user.last_name} - {decision_id}"
Expand Down