Skip to content

Commit

Permalink
Merge branch 'master' into jmc_aug31
Browse files Browse the repository at this point in the history
  • Loading branch information
stevekaplan123 committed Oct 16, 2023
2 parents e230641 + b9268d6 commit 2158024
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 47 deletions.
4 changes: 4 additions & 0 deletions sefaria/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class SefariaDeleteUserForm(EmailAuthenticationForm):
email = forms.EmailField(max_length=75, widget=forms.EmailInput(attrs={'placeholder': _("Email Address to delete")}))
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': _("Admin Password")}))

class SefariaDeleteSheet(forms.Form):
sid = forms.CharField(max_length=20, widget=forms.TextInput(attrs={'placeholder': _("Sheet ID to delete")}))
password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': _("Admin Password")}))


class SefariaLoginForm(EmailAuthenticationForm):
email = forms.EmailField(max_length=75, widget=forms.EmailInput(attrs={'placeholder': _("Email Address")}))
Expand Down
11 changes: 7 additions & 4 deletions sefaria/helper/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class _FindRefsTextOptions:
class _FindRefsText:
title: str
body: str
lang: str

def __post_init__(self):
from sefaria.utils.hebrew import is_mostly_hebrew
self.lang = 'he' if is_mostly_hebrew(self.body) else 'en'
# def __post_init__(self):
# from sefaria.utils.hebrew import is_mostly_hebrew
# self.lang = 'he' if is_mostly_hebrew(self.body) else 'en'


def _unpack_find_refs_request(request):
Expand All @@ -75,9 +76,11 @@ def _unpack_find_refs_request(request):


def _create_find_refs_text(post_body) -> _FindRefsText:
from sefaria.utils.hebrew import is_mostly_hebrew
title = post_body['text']['title']
body = post_body['text']['body']
return _FindRefsText(title, body)
lang = post_body['lang'] if 'lang' in post_body else 'he' if is_mostly_hebrew(body) else 'en'
return _FindRefsText(title, body, lang)


def _create_find_refs_options(get_body: dict, post_body: dict) -> _FindRefsTextOptions:
Expand Down
19 changes: 10 additions & 9 deletions sefaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@
url(r'^settings/account?$', reader_views.account_settings),
url(r'^settings/profile?$', reader_views.edit_profile),
url(r'^interface/(?P<language>english|hebrew)$', reader_views.interface_language_redirect),
url(r'^api/profile/user_history$', reader_views.user_history_api),
url(r'^api/profile/user_history$', reader_views.user_history_api),
url(r'^api/profile/sync$', reader_views.profile_sync_api),
url(r'^api/profile/upload-photo$', reader_views.profile_upload_photo),
url(r'^api/profile$', reader_views.profile_api),
url(r'^settings/account/user$', reader_views.account_user_update),
url(r'^api/profile/(?P<slug>[^/]+)$', reader_views.profile_get_api),
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),
]

# Topics
urlpatterns += [
url(r'^topics/category/(?P<topicCategory>.+)?$', reader_views.topics_category_page),
url(r'^topics/all/(?P<letter>.)$', reader_views.all_topics_page),
url(r'^topics/all/(?P<letter>.)$', reader_views.all_topics_page),
url(r'^topics/?$', reader_views.topics_page),
url(r'^topics/b/(?P<topic>.+)$', reader_views.topic_page_b),
url(r'^topics/(?P<topic>.+)$', reader_views.topic_page),
Expand Down Expand Up @@ -189,9 +189,9 @@
url(r'^api/sheets/?$', sheets_views.save_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/delete$', sheets_views.delete_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/add$', sheets_views.add_source_to_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/add_ref$', sheets_views.add_ref_to_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/add_ref$', sheets_views.add_ref_to_sheet_api),
url(r'^api/sheets/(?P<parasha>.+)/get_aliyot$', sheets_views.get_aliyot_by_parasha_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/copy_source$', sheets_views.copy_source_to_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/copy_source$', sheets_views.copy_source_to_sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)/topics$', sheets_views.update_sheet_topics_api),
url(r'^api/sheets/(?P<sheet_id>\d+)$', sheets_views.sheet_api),
url(r'^api/sheets/(?P<sheet_id>\d+)\.(?P<node_id>\d+)$', sheets_views.sheet_node_api),
Expand Down Expand Up @@ -229,7 +229,7 @@
url(r'^api/collections/for-sheet/(?P<sheet_id>\d+)$', sheets_views.collections_for_sheet_api),
url(r'^api/collections(/(?P<slug>[^/]+))?$', sheets_views.collections_api),
url(r'^api/collections/(?P<slug>[^/]+)/set-role/(?P<uid>\d+)/(?P<role>[^/]+)$', sheets_views.collections_role_api),
url(r'^api/collections/(?P<slug>[^/]+)/invite/(?P<uid_or_email>[^/]+)(?P<uninvite>\/uninvite)?$', sheets_views.collections_invite_api),
url(r'^api/collections/(?P<slug>[^/]+)/invite/(?P<uid_or_email>[^/]+)(?P<uninvite>\/uninvite)?$', sheets_views.collections_invite_api),
url(r'^api/collections/(?P<slug>[^/]+)/(?P<action>(add|remove))/(?P<sheet_id>\d+)', sheets_views.collections_inclusion_api),
url(r'^api/collections/(?P<slug>[^/]+)/(?P<action>(add|remove))/(?P<sheet_id>\d+)', sheets_views.collections_inclusion_api),
url(r'^api/collections/(?P<slug>[^/]+)/pin-sheet/(?P<sheet_id>\d+)', sheets_views.collections_pin_sheet_api),
Expand Down Expand Up @@ -287,8 +287,8 @@
urlpatterns += [
url(r'^api/locktext/(?P<title>.+)/(?P<lang>\w\w)/(?P<version>.+)$', reader_views.lock_text_api),
url(r'^api/version/flags/(?P<title>.+)/(?P<lang>\w\w)/(?P<version>.+)$', reader_views.flag_text_api),
]
# SEC-AUDIT: do we also want to maybe move these to 'admin'
]
# SEC-AUDIT: do we also want to maybe move these to 'admin'

# Discussions
urlpatterns += [
Expand Down Expand Up @@ -391,7 +391,7 @@
]

# Admin
urlpatterns += [
urlpatterns += [
url(r'^admin/reset/varnish/(?P<tref>.+)$', sefaria_views.reset_varnish),
url(r'^admin/reset/cache$', sefaria_views.reset_cache),
url(r'^admin/reset/cache/(?P<title>.+)$', sefaria_views.reset_index_cache_for_text),
Expand All @@ -405,6 +405,7 @@
url(r'^admin/reset-websites-data', sefaria_views.reset_websites_data),
url(r'^admin/delete/orphaned-counts', sefaria_views.delete_orphaned_counts),
url(r'^admin/delete/user-account', sefaria_views.delete_user_by_email, name="delete/user-account"),
url(r'^admin/delete/sheet$', sefaria_views.delete_sheet_by_id, name="delete/sheet"),
url(r'^admin/rebuild/auto-links/(?P<title>.+)$', sefaria_views.rebuild_auto_links),
url(r'^admin/rebuild/citation-links/(?P<title>.+)$', sefaria_views.rebuild_citation_links),
url(r'^admin/delete/citation-links/(?P<title>.+)$', sefaria_views.delete_citation_links),
Expand Down
59 changes: 55 additions & 4 deletions sefaria/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
from sefaria.helper.crm.crm_mediator import CrmMediator
from sefaria.system.cache import in_memory_cache
from sefaria.client.util import jsonResponse, send_email, read_webpack_bundle
from sefaria.forms import SefariaNewUserForm, SefariaNewUserFormAPI, SefariaDeleteUserForm
from sefaria.forms import SefariaNewUserForm, SefariaNewUserFormAPI, SefariaDeleteUserForm, SefariaDeleteSheet
from sefaria.settings import MAINTENANCE_MESSAGE, USE_VARNISH, MULTISERVER_ENABLED
from sefaria.model.user_profile import UserProfile, user_link
from sefaria.model.collection import CollectionSet
from sefaria.model.collection import CollectionSet, process_sheet_deletion_in_collections
from sefaria.model.notification import process_sheet_deletion_in_notifications
from sefaria.export import export_all as start_export_all
from sefaria.datatype.jagged_array import JaggedTextArray
# noinspection PyUnresolvedReferences
Expand All @@ -58,7 +59,7 @@
from sefaria.system.multiserver.coordinator import server_coordinator
from sefaria.google_storage_manager import GoogleStorageManager
from sefaria.sheets import get_sheet_categorization_info
from reader.views import base_props, render_template
from reader.views import base_props, render_template
from sefaria.helper.link import add_links_from_csv, delete_links_from_text, get_csv_links_by_refs

if USE_VARNISH:
Expand Down Expand Up @@ -202,7 +203,7 @@ def unlink_gauth(request):
return redirect(f"/profile/{profile.slug}")
else:
return jsonResponse({"status": "ok"})
except:
except:
return jsonResponse({"error": "Failed to delete Google account"})


Expand Down Expand Up @@ -971,6 +972,56 @@ def delete_user_by_email(request):



@staff_member_required
def delete_sheet_by_id(request):

from django.contrib.auth.models import User
from sefaria.utils.user import delete_user_account
if request.method == 'GET':
form = SefariaDeleteSheet()
return render_template(request, "delete-sheet.html", None, {'form': form, 'next': next})
elif request.method == 'POST':
user = User.objects.get(id=request.user.id)
sheet_id = request.POST.get("sid")
password = request.POST.get("password")
try:
if not user.check_password(password):
return jsonResponse({"failure": "incorrect password"})
except:
return jsonResponse({"failure": "incorrect password"})
try:

import sefaria.search as search
id = int(sheet_id)
sheet = db.sheets.find_one({"id": id})
if not sheet:
return jsonResponse({"error": "Sheet %d not found." % id})

db.sheets.remove({"id": id})
process_sheet_deletion_in_collections(id)
process_sheet_deletion_in_notifications(id)

try:
es_index_name = search.get_new_and_current_index_names("sheet")['current']
search.delete_sheet(es_index_name, id)
except NewConnectionError as e:
logger.warn("Failed to connect to elastic search server on sheet delete.")
except AuthorizationException as e:
logger.warn("Failed to connect to elastic search server on sheet delete.")


return jsonResponse({"success": f"deleted sheet {sheet_id}"})

except:
return jsonResponse({"failure": "sheet not deleted: try again or contact a developer"})









def purge_spammer_account_data(spammer_id, delete_from_crm=True):
from django.contrib.auth.models import User
Expand Down
Binary file removed static/img/headshots/nissa.jpg
Binary file not shown.
28 changes: 26 additions & 2 deletions static/js/Misc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2221,8 +2221,14 @@ const InterruptingMessage = ({
shouldShowModal = true;
else if (noUserKindIsSet) shouldShowModal = true;
if (!shouldShowModal) return false;

// Don't show the modal on pages where the button link goes to since you're already there
const excludedPaths = ["/donate", "/mobile", "/app", "/ways-to-give"];
if (strapi.modal.buttonURL) {
excludedPaths.push(
new URL(strapi.modal.buttonURL.en).pathname,
new URL(strapi.modal.buttonURL.he).pathname
);
}
return excludedPaths.indexOf(window.location.pathname) === -1;
};

Expand Down Expand Up @@ -2381,6 +2387,13 @@ const Banner = ({ onClose }) => {
if (!shouldShowBanner) return false;

const excludedPaths = ["/donate", "/mobile", "/app", "/ways-to-give"];
// Don't show the banner on pages where the button link goes to since you're already there
if (strapi.banner.buttonURL) {
excludedPaths.push(
new URL(strapi.banner.buttonURL.en).pathname,
new URL(strapi.banner.buttonURL.he).pathname
);
}
return excludedPaths.indexOf(window.location.pathname) === -1;
};

Expand Down Expand Up @@ -2430,18 +2443,29 @@ const Banner = ({ onClose }) => {
<a
className="button white int-en"
href={strapi.banner.buttonURL.en}
onClick={() => {
closeBanner("banner_button_clicked");
}}
>
<span>{strapi.banner.buttonText.en}</span>
</a>
<a
className="button white int-he"
href={strapi.banner.buttonURL.he}
onClick={() => {
closeBanner("banner_button_clicked");
}}
>
<span>{strapi.banner.buttonText.he}</span>
</a>
</div>
</div>
<div id="bannerMessageClose" onClick={closeBanner}>
<div
id="bannerMessageClose"
onClick={() => {
closeBanner("close_clicked");
}}
>
×
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions templates/delete-sheet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load i18n %}

{% block title %}{% trans "Admin: Delete a Sheet" %} | {% trans "Sefaria" %}{% endblock %}

{% block content %}

<div id="deleteSheet" class="static">
<div class="inner">
<h1>
<span class="int-en">Delete Sheet</span>
</h1>
<h2> CAUTION THIS WILL DELETE THE SHEET ID YOU INPUT</h2>
<h3>IT CANNOT BE UNDONE.</h3>
<form method="post" autocomplete="off" if="delete-form" action="{% url "delete/sheet" %}">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="button control-elem">
<span class="int-en">Delete Sheet</span>
</button>
</form>
</div>
</div>
{% endblock %}
16 changes: 2 additions & 14 deletions templates/static/en/team.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{% extends "base.html" %}
{% load i18n static %}

Expand Down Expand Up @@ -265,19 +266,6 @@ <h1>
</div>
</div>
</div>
<div class="teamMember">
<div class="teamMemberImage">
<img src="{% static 'img/headshots/nissa.jpg' %}" alt="Headshot of Nissa Mai-Rose">
</div>
<div class="teamMemberDetails">
<div class="teamName">
<span class="int-en">Nissa Mai-Rose</span>
</div>
<div class="teamTitle">
<span class="int-en">Sr. Software Engineer</span>
</div>
</div>
</div>
<div class="teamMember">
<div class="teamMemberImage">
<img src="{% static 'img/headshots/Amanda_Minsky_Photo.png' %}" alt="Headshot of Amanda Minsky">
Expand Down Expand Up @@ -353,7 +341,7 @@ <h1>
<span class="int-en">Elise Ringo</span>
</div>
<div class="teamTitle">
<span class="int-en">Associate Digital Marketing Manager</span>
<span class="int-en">Database Administrator</span>
</div>
</div>
</div>
Expand Down
16 changes: 2 additions & 14 deletions templates/static/he/team.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,7 @@ <h1>
</div>
<div class="teamMember">
<div class="teamMemberImage">
<img src="{% static 'img/headshots/nissa.png' %}" alt="Headshot of Nissa Mai-Rose">
</div>
<div class="teamMemberDetails">
<div class="teamName sans">
<span class="int-he">נסה מאי-רוז</span>
</div>
<div class="teamTitle">
<span class="int-he">מהנדסת תוכנה בכירה</span>
</div>
</div>
</div>
<div class="teamMember">
<div class="teamMemberImage">

<img src="{% static 'img/headshots/Amanda_Minsky_Photo.png' %}" alt="Headshot of Amanda Minsky">
</div>
<div class="teamMemberDetails">
Expand Down Expand Up @@ -457,7 +445,7 @@ <h1>
<span class="int-he">יעל רינגו</span>
</div>
<div class="teamTitle">
<span class="int-he">רכזת שיווק דיגיטלי</span>
<span class="int-he">מנהלת מאגר נתונים</span>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions templates/static/jobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ <h2 class="anchorable">Learning</h2>
</header>
<section class="jobsListForDepartment">
<div class="job"><a class="jobLink" target="_blank" href="https://sefaria.breezy.hr/p/c693c3ab1b78-hebrew-editorial-associate-part-time">Hebrew Editorial Associate (Part-Time)</a></div>
<div class="job"><a class="jobLink" target="_blank" href="https://docs.google.com/document/d/107rwA4LuShD-szPmYJfKqyqxxU6Ycnj2KWqEUEc9GoU/edit#heading=h.hqg5tv31xe3k">English Editorial Associate (Contractor)</a></div>




</section>
</section>
<!--
Expand Down

0 comments on commit 2158024

Please sign in to comment.