Skip to content

Commit

Permalink
Merge pull request #1606 from Sefaria/strapi-cms-revised
Browse files Browse the repository at this point in the history
Replacement of existing interrupting message system with one that integrates with Strapi CMS
  • Loading branch information
relyks committed Sep 11, 2023
2 parents 58911c6 + 80e4d44 commit e4ed154
Show file tree
Hide file tree
Showing 22 changed files with 1,028 additions and 511 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ node_modules
#####################
venv/
.python-version
.node-version

# Partner files #
#################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ data:
# GLOBAL_INTERRUPTING_MESSAGE = None
STRAPI_LOCATION = os.getenv("STRAPI_LOCATION")
STRAPI_PORT = os.getenv("STRAPI_PORT")
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"cheerio": "^0.22.0",
"classnames": "^2.2.5",
"cookie-parser": "^1.4.2",
"core-js": "^3.15.2",
"core-js": "^3.31.1",
"css-modules-require-hook": "^4.2.3",
"deep-merge": "^1.0.0",
"diff-match-patch": "^1.0.0",
Expand Down
38 changes: 0 additions & 38 deletions reader/browsertest/framework/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,6 @@ def scroll_nav_panel_to_bottom(self):
# Initial Setup
################

def set_modal_cookie(self):
# # set cookie to avoid popup interruption
# # We now longer set the welcomeToS2LoggedOut message by default.
# # TODO is this method still needed? YES
# pass
self.driver.add_cookie({"name": "welcomeToS2LoggedOut", "value": "true"})

def set_cookies_cookie(self):
# set cookie to avoid popup interruption
# We now longer set the welcomeToS2LoggedOut message by default.
Expand All @@ -364,37 +357,6 @@ def click_accept_cookies(self):
except NoSuchElementException:
pass

def close_modal_popup(self):
"""
:return: Boolean - did we manage to close the popup?
"""
message = self.driver.execute_script('return Sefaria.interruptingMessage')
if not message:
return True

time.sleep(3)
try:
self.driver.find_element_by_css_selector('#interruptingMessage #interruptingMessageClose')
self.click('#interruptingMessage #interruptingMessageClose')
return True
except NoSuchElementException:
pass

try:
self.driver.find_element_by_css_selector('#bannerMessageClose')
self.click('#bannerMessageClose')
return True
except NoSuchElementException:
return False

def close_popup_with_accept(self):
try:
alert = self.driver.switch_to.alert
alert.accept()
except NoAlertPresentException:
print('A <<NoAlertPresentException>> was thrown')
pass

# Login
#########

Expand Down
20 changes: 5 additions & 15 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from sefaria.image_generator import make_img_http_response
import sefaria.tracker as tracker

from sefaria.settings import NODE_TIMEOUT, DEBUG, GLOBAL_INTERRUPTING_MESSAGE
from sefaria.settings import NODE_TIMEOUT, DEBUG
from sefaria.model.category import TocCollectionNode
from sefaria.model.abstract import SluggedAbstractMongoRecord
from sefaria.utils.calendars import parashat_hashavua_and_haftara
Expand Down Expand Up @@ -197,14 +197,14 @@ def base_props(request):

if request.user.is_authenticated:
profile = UserProfile(user_obj=request.user)
interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or {"name": profile.interrupting_message()}
user_data = {
"_uid": request.user.id,
"_email": request.user.email,
"_uses_new_editor": getattr(profile, "uses_new_editor", False),
"slug": profile.slug if profile else "",
"is_moderator": request.user.is_staff,
"is_editor": UserWrapper(user_obj=request.user).has_permission_group("Editors"),
"is_sustainer": profile.is_sustainer,
"full_name": profile.full_name,
"profile_pic_url": profile.profile_pic_url,
"is_history_enabled": profile.settings.get("reading_history", True),
Expand All @@ -216,8 +216,7 @@ def base_props(request):
"notificationCount": profile.unread_notification_count(),
"notifications": profile.recent_notifications().client_contents(),
"saved": {"loaded": False, "items": profile.get_history(saved=True, secondary=False, serialized=True, annotate=False)}, # saved is initially loaded without text annotations so it can quickly immediately mark any texts/sheets as saved, but marks as `loaded: false` so the full annotated data will be requested if the user visits the saved/history page
"last_place": profile.get_history(last_place=True, secondary=False, sheets=False, serialized=True),
"interruptingMessage": InterruptingMessage(attrs=interrupting_message_dict, request=request).contents(),
"last_place": profile.get_history(last_place=True, secondary=False, sheets=False, serialized=True)
}
else:
user_data = {
Expand All @@ -226,6 +225,7 @@ def base_props(request):
"slug": "",
"is_moderator": False,
"is_editor": False,
"is_sustainer": False,
"full_name": "",
"profile_pic_url": "",
"is_history_enabled": True,
Expand All @@ -237,8 +237,7 @@ def base_props(request):
"notificationCount": 0,
"notifications": [],
"saved": {"loaded": False, "items": []},
"last_place": [],
"interruptingMessage": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).contents(),
"last_place": []
}
user_data.update({
"last_cached": library.get_last_cached_time(),
Expand Down Expand Up @@ -3767,15 +3766,6 @@ def my_profile(request):
url += "?tab=" + request.GET.get("tab")
return redirect(url)


def interrupting_messages_read_api(request, message):
if not request.user.is_authenticated:
return jsonResponse({"error": "You must be logged in to use this API."})
profile = UserProfile(id=request.user.id)
profile.mark_interrupting_message_read(message)
return jsonResponse({"status": "ok"})


@login_required
@ensure_csrf_cookie
def edit_profile(request):
Expand Down
4 changes: 3 additions & 1 deletion sefaria/local_settings_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
MAINTENANCE_MESSAGE = ""
GLOBAL_WARNING = False
GLOBAL_WARNING_MESSAGE = ""
# GLOBAL_INTERRUPTING_MESSAGE = None


SECRET_KEY = 'insert your long random secret key here !'
Expand Down Expand Up @@ -194,6 +193,9 @@
}
}

STRAPI_LOCATION = None
STRAPI_PORT = None

structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
Expand Down
14 changes: 4 additions & 10 deletions sefaria/local_settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,10 @@
DOWN_FOR_MAINTENANCE = False
MAINTENANCE_MESSAGE = ""

# GLOBAL_INTERRUPTING_MESSAGE = None
"""
GLOBAL_INTERRUPTING_MESSAGE = {
"name": "messageName",
"repetition": 1,
"is_fundraising": True,
"style": "modal" # "modal" or "banner"
"condition": {"returning_only": True}
}
"""
# Location of Strapi CMS instance
# For local development, Strapi is located at http://localhost:1337 by default
STRAPI_LOCATION = None
STRAPI_PORT = None


MANAGERS = ADMINS
Expand Down
1 change: 0 additions & 1 deletion sefaria/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .layer import Layer, LayerSet
from .notification import Notification, NotificationSet, GlobalNotification, GlobalNotificationSet
from .trend import get_session_traits
from .interrupting_message import InterruptingMessage
from .queue import IndexQueue, IndexQueueSet
from .lock import Lock, LockSet, set_lock, release_lock, check_lock, expire_locks
from .following import FollowRelationship, FollowersSet, FolloweesSet
Expand Down
81 changes: 0 additions & 81 deletions sefaria/model/interrupting_message.py

This file was deleted.

18 changes: 0 additions & 18 deletions sefaria/model/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ def __init__(self, user_obj=None, id=None, slug=None, email=None, user_registrat
self.twitter = ""
self.linkedin = ""
self.pinned_sheets = []
self.interrupting_messages = ["newUserWelcome"]
self.last_sync_web = 0 # epoch time for last sync of web app
self.profile_pic_url = ""
self.profile_pic_url_small = ""
Expand Down Expand Up @@ -413,7 +412,6 @@ def __init__(self, user_obj=None, id=None, slug=None, email=None, user_registrat
# create a profile for them. This allows two enviornments to share a user database,
# while maintaining separate profiles (e.g. Sefaria and S4D).
self.assign_slug()
self.interrupting_messages = []
self.save()

@property
Expand Down Expand Up @@ -602,21 +600,6 @@ def unread_notification_count(self):
from sefaria.model.notification import NotificationSet
return NotificationSet().unread_for_user(self.id).count()

def interrupting_message(self):
"""
Returns the next message to interupt the user with, if any are queued up.
"""
messages = self.interrupting_messages
return messages[0] if len(messages) > 0 else None

def mark_interrupting_message_read(self, message):
"""
Removes `message` from the users list of queued interrupting_messages.
"""
if message in self.interrupting_messages:
self.interrupting_messages.remove(message)
self.save()

def process_history_item(self, hist, time_stamp):
action = hist.pop("action", None)
if self.settings.get("reading_history", True) or action == "add_saved": # regular case where history enabled, save/unsave saved item etc. or save history in either case
Expand Down Expand Up @@ -680,7 +663,6 @@ def to_mongo_dict(self):
"settings": self.settings,
"version_preferences_by_corpus": self.version_preferences_by_corpus,
"attr_time_stamps": self.attr_time_stamps,
"interrupting_messages": getattr(self, "interrupting_messages", []),
"is_sustainer": self.is_sustainer,
"tag_order": getattr(self, "tag_order", None),
"last_sync_web": self.last_sync_web,
Expand Down
18 changes: 0 additions & 18 deletions sefaria/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,6 @@
}



GLOBAL_INTERRUPTING_MESSAGE = {
"name": "2023-09-04-new-year",
"style": "banner", # "modal" or "banner"
"repetition": 1,
"is_fundraising": False,
"condition": {
"returning_only": False,
"english_only": False,
"desktop_only": False,
"debug": False,
}
}


# GLOBAL_INTERRUPTING_MESSAGE = None


# Grab environment specific settings from a file which
# is left out of the repo.
try:
Expand Down
3 changes: 2 additions & 1 deletion sefaria/system/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from sefaria.site.site_settings import SITE_SETTINGS
from sefaria.model import library
from sefaria.model.user_profile import UserProfile, UserHistorySet, UserWrapper
from sefaria.model.interrupting_message import InterruptingMessage
from sefaria.utils import calendars
from sefaria.utils.util import short_to_long_lang_code
from sefaria.utils.hebrew import hebrew_parasha_name
Expand Down Expand Up @@ -68,6 +67,8 @@ def global_settings(request):
return {
"SEARCH_INDEX_NAME_TEXT": SEARCH_INDEX_NAME_TEXT,
"SEARCH_INDEX_NAME_SHEET":SEARCH_INDEX_NAME_SHEET,
"STRAPI_LOCATION": STRAPI_LOCATION,
"STRAPI_PORT": STRAPI_PORT,
"GOOGLE_TAG_MANAGER_CODE":GOOGLE_TAG_MANAGER_CODE,
"GOOGLE_GTAG": GOOGLE_GTAG,
"HOTJAR_ID": HOTJAR_ID,
Expand Down
1 change: 0 additions & 1 deletion sefaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
url(r'^api/profile/(?P<slug>[^/]+)$', reader_views.profile_get_api),
url(r'^api/profile/(?P<slug>[^/]+)/(?P<ftype>followers|following)$', reader_views.profile_follow_api),
url(r'^api/user_history/saved$', reader_views.saved_history_for_ref),
url(r'^api/interrupting-messages/read/(?P<message>.+)$', reader_views.interrupting_messages_read_api),
]

# Topics
Expand Down

0 comments on commit e4ed154

Please sign in to comment.