Skip to content

Commit

Permalink
Merge pull request #8486 from jimchamp/remove-screener-code
Browse files Browse the repository at this point in the history
Revert persona research banner code
  • Loading branch information
cdrini authored Nov 2, 2023
2 parents 21b05cc + 4de6b46 commit d22a7ad
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 10,256 deletions.
3 changes: 0 additions & 3 deletions openlibrary/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,6 @@ def has_cookie(self, name):
def is_printdisabled(self):
return web.cookies().get('pd')

def is_screener_eligible(self):
return web.cookies().get('se')

def is_admin(self):
return self.is_usergroup_member('/usergroup/admin')

Expand Down
45 changes: 0 additions & 45 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from openlibrary.core import helpers as h, lending
from openlibrary.core.booknotes import Booknotes
from openlibrary.core.bookshelves import Bookshelves
from openlibrary.core.helpers import days_since
from openlibrary.core.lending import s3_loan_api
from openlibrary.core.observations import Observations
from openlibrary.core.ratings import Ratings
from openlibrary.plugins.recaptcha import recaptcha
Expand Down Expand Up @@ -406,10 +404,6 @@ def POST(self):
)
ol_account = OpenLibraryAccount.get(email=email)

# Don't overwrite the cookie, which will contain banner display preferences
if not web.cookies().get('se', False):
self.set_screener_cookie(ol_account)

if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
blacklist = [
Expand Down Expand Up @@ -438,45 +432,6 @@ def POST_resend_verification_email(self, i):
)
return render.message(title, message)

def set_screener_cookie(self, account: OpenLibraryAccount):
if self.is_eligible_for_screener(account):
# `se` is "Survey eligible"
web.setcookie('se', '1', expires=(3600 * 24 * 30)) # Expires in 30 days

def is_eligible_for_screener(self, account: OpenLibraryAccount) -> bool:
# It is August 2023:
if (now := datetime.now()) and now.month != 9 and now.year != 2023:
return False

# Account must be at least 90 days old:
if days_since(account.creation_time()) < 90:
return False

# Account was created using a university's domain:
email = account.email
if not self.is_edu_domain(email):
return False

# Has borrowed at least three books:
if not self.has_borrowed_at_least(3, account.s3_keys):
return False

return True

def is_edu_domain(self, email: str) -> bool:
if not email or '@' not in email:
return False

domain = email.split('@')[-1]

sorted_edu_domains = utils.get_edu_domains()

return domain in sorted_edu_domains

def has_borrowed_at_least(self, amount: int, s3_keys) -> bool:
resp = s3_loan_api(s3_keys, action='user_borrow_history', limit=amount).json()
return len(resp) == amount


class account_verify(delegate.page):
"""Verify user account."""
Expand Down
18 changes: 0 additions & 18 deletions openlibrary/plugins/upstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,24 +1313,6 @@ def get_location_and_publisher(loc_pub: str) -> tuple[list[str], list[str]]:
return ([], [loc_pub.strip(STRIP_CHARS)])


@cache.memoize(engine="memcache", key="edu_domains", expires=0)
def get_edu_domains() -> list[str]:
"""
This list created using this gist: https://gist.github.com/jimchamp/f67ef14c3bcf11593f393ee5288f6476 on
https://raw.githubusercontent.com/Hipo/university-domains-list/master/world_universities_and_domains.json.
See: https://github.com/internetarchive/openlibrary/issues/8180
"""
p = Path(Path.cwd(), 'static', 'edu-domains.txt')

results = []
with p.open() as f:
for line in f:
results.append(line.strip())

return results


def setup() -> None:
"""Do required initialization"""
# monkey-patch get_markdown to use OL Flavored Markdown
Expand Down
9 changes: 0 additions & 9 deletions openlibrary/templates/account/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@
</div>
$ component_times['Yearly Goal Banner'] = time() - component_times['Yearly Goal Banner']

$# Start : Persona research banner
$if user:
$if user.is_screener_eligible():
$ banner_key = 'pr2308'
$ hide_banner = user.preferences().get('hidden-banner') == banner_key
$if not hide_banner:
$ announcement = _('Are you a teacher, student, or researcher? Please <a href="https://forms.gle/sR7V2hZFJbavhffy5" class="btn primary">help us improve</a>')
$:render_template('site/banner', announcement, banner_key)
$# End : Persona research banner

$ component_times['Details header'] = time()
<header>
Expand Down
Loading

0 comments on commit d22a7ad

Please sign in to comment.