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

Add follow button to patron profile pages #9374

8 changes: 8 additions & 0 deletions openlibrary/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,14 @@ def is_usergroup_member(self, usergroup):
usergroup = '/usergroup/%s' % usergroup
return usergroup in [g.key for g in self.usergroups]

def is_subscribed_user(self, username):
my_username = self.get_username()
return (
PubSub.is_subscribed(my_username, username)
if my_username != username
else -1
)

def has_cookie(self, name):
return web.cookies().get(name, False)

Expand Down
5 changes: 2 additions & 3 deletions openlibrary/plugins/upstream/mybooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,10 @@ def __init__(self, username, key):
self.user_itemname = self.user.get_account().get('internetarchive_itemname')

self.me = accounts.get_current_user()
self.my_username = self.me and self.me.key.split('/')[-1]
self.is_my_page = self.me and self.me.key.split('/')[-1] == self.username
self.is_subscribed = (
PubSub.is_subscribed(self.my_username, self.username)
if not self.is_my_page and self.is_public
self.me.is_subscribed_user(self.username)
if self.me and self.is_public
else -1
)
self.key = key.lower()
Expand Down
6 changes: 6 additions & 0 deletions openlibrary/templates/type/user/view.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
$def with (page)

$var title: $page.displayname
$ username = page.key.split('/')[-1]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a safer way to get this, such as from get_users_settings? Or is this way of doing it considered pretty safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be okay in this case.

$ settings = page.get_users_settings()
$ owners_page = ctx.user and ctx.user.key == page.key
$ is_public = settings and settings.get('public_readlog', 'no') == "yes"

$ is_subscribed = ctx.user and ctx.user.is_subscribed_user(username)
$if days_since(page.created) < 30:
$ putctx('robots', 'noindex')

Expand All @@ -13,6 +16,9 @@
$ lists = []

<div id="contentHead">
<h1>$settings.get('username')</h1>
$if ctx.user and is_public and not owners_page and is_subscribed == False:
<div class="right">$:macros.Follow(ctx.user.get_username(), following=is_subscribed)</div>
$:macros.databarView(page)
<h1>$page.displayname</h1>
<div class="small sansserif">
Expand Down
Loading