Skip to content

Commit f45b3c2

Browse files
authored
feat: add more restrictions for users with expired membership (vas3k#1020)
* fix: disable commenting, like, post manipulations and tags collecting for users with expired membership * refactor: is_active_membership reuse * refactor: is_active_member renaming * Revert "refactor: is_active_member renaming" This reverts commit c67613b. * refactor: reuse is_active_membership * fix: check for not is_active_membership in permissions
1 parent 043e9a1 commit f45b3c2

File tree

14 files changed

+48
-30
lines changed

14 files changed

+48
-30
lines changed

auth/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def check_user_permissions(request, **context):
9494
and not request.path.startswith("/network/") \
9595
and not request.path.startswith("/messages/"):
9696

97-
if request.me.membership_expires_at < datetime.utcnow():
97+
if not request.me.is_active_membership:
9898
log.info("User membership expired. Redirecting to payments page...")
9999
return redirect("membership_expired")
100100

frontend/html/comments/types/battle.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<a href="{% url "edit_comment" comment.id %}" class="comment-footer-button comment-button-visible-on-hover"><i class="fas fa-edit"></i></a>
5151
{% endif %}
5252

53-
{% if me and comment.post.is_commentable %}
53+
{% if me and me.is_active_membership and comment.post.is_commentable %}
5454
<span class="comment-footer-button" v-on:click="showReplyForm('{{ comment.id }}', '', true)"><i class="fas fa-reply"></i>&nbsp;ответить</span>
5555
{% endif %}
5656
</div>

frontend/html/comments/types/bold.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<a href="{% url "edit_comment" comment.id %}" class="comment-footer-button comment-button-visible-on-hover"><i class="fas fa-edit"></i></a>
8686
{% endif %}
8787

88-
{% if me and comment.post.is_commentable %}
88+
{% if me and me.is_active_membership and comment.post.is_commentable %}
8989
<span class="comment-footer-button" v-on:click="showReplyForm('{{ comment.id }}', '{{ comment.author.slug }}', true)"><i class="fas fa-reply"></i>&nbsp;ответить</span>
9090
{% endif %}
9191
</div>

frontend/html/comments/types/normal.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<a href="{% url "edit_comment" comment.id %}" class="comment-footer-button comment-button-visible-on-hover"><i class="fas fa-edit"></i></a>
100100
{% endif %}
101101

102-
{% if me and comment.post.is_commentable %}
102+
{% if me and me.is_active_membership and comment.post.is_commentable %}
103103
<span class="comment-footer-button" v-on:click="showReplyForm('{{ comment.id }}', '{{ comment.author.slug }}', true)"><i class="fas fa-reply"></i>&nbsp;ответить</span>
104104
{% endif %}
105105
</div>

frontend/html/posts/show/battle.html

+13-12
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<div class="post-comments" id="comments">
9090
{% battle_stats post comments %}
9191

92-
{% if me %}
92+
{% if me and me.is_active_membership %}
9393
<post-subscription
9494
url="{% url "toggle_post_subscription" post.slug %}"
9595
{% if subscription %}is-active-by-default{% endif %}
@@ -113,21 +113,22 @@
113113
</div>
114114
{% endif %}
115115

116-
{% if me and post.is_commentable and post.is_visible or me.is_moderator %}
116+
{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
117117
<div class="post-comments-form">
118118
{% include "comments/forms/battle.html" with post=post form=comment_form %}
119119
</div>
120+
121+
<div class="post-comments-rules">
122+
<strong>Этикет батлов:</strong>
123+
<ul>
124+
<li>💣 Батл — это схватка двух крайностей. Мы пытаемся выделить аргументы каждой из сторон чтобы потом по ним составить свою картину мира. Рекомендуется избегать аргументов типа «каждый хорош для своего».</li>
125+
<li>☝️ Один аргумент — один комментарий. Не делайте списков, так сложнее вести дискуссию и подсчитывать статистику.</li>
126+
<li>😎 Можно топить как за одну, так и за обе стороны сразу. Просто выберите за кого вы при постинге.</li>
127+
<li>💬 На аргументы можно отвечать. Реплаи никуда не засчитываются и нужны только для срача.</li>
128+
<li>👮‍♀️ Авторам батлов нужно удалять повторы и комментарии не по формату.</li>
129+
</ul>
130+
</div>
120131
{% endif %}
121132
</div>
122133

123-
<div class="post-comments-rules">
124-
<strong>Этикет батлов:</strong>
125-
<ul>
126-
<li>💣 Батл — это схватка двух крайностей. Мы пытаемся выделить аргументы каждой из сторон чтобы потом по ним составить свою картину мира. Рекомендуется избегать аргументов типа «каждый хорош для своего».</li>
127-
<li>☝️ Один аргумент — один комментарий. Не делайте списков, так сложнее вести дискуссию и подсчитывать статистику.</li>
128-
<li>😎 Можно топить как за одну, так и за обе стороны сразу. Просто выберите за кого вы при постинге.</li>
129-
<li>💬 На аргументы можно отвечать. Реплаи никуда не засчитываются и нужны только для срача.</li>
130-
<li>👮‍♀️ Авторам батлов нужно удалять повторы и комментарии не по формату.</li>
131-
</ul>
132-
</div>
133134
{% endblock %}

frontend/html/posts/show/event.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h1 class="post-title">
8484
</div>
8585

8686
<div class="post-event-rsvp">
87-
{% if me %}
87+
{% if me and me.is_active_membership %}
8888
<post-rsvp
8989
url="{% url "toggle_post_subscription" post.slug %}"
9090
{% if subscription %}is-active-by-default{% endif %}

frontend/html/posts/show/layout.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</div>
6464

6565
<div class="post-comments-title-left">
66-
{% if me %}
66+
{% if me and me.is_active_membership %}
6767
<post-subscription
6868
url="{% url "toggle_post_subscription" post.slug %}"
6969
{% if subscription %}is-active-by-default{% endif %}
@@ -81,7 +81,7 @@
8181
</div>
8282
{% endif %}
8383

84-
{% if me and post.is_commentable and post.is_visible or me.is_moderator %}
84+
{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
8585
<div class="post-comments-form" id="post-comments-form">
8686
{% include "comments/forms/comment.html" with post=post form=comment_form %}
8787
</div>
@@ -103,6 +103,10 @@
103103
{% include "posts/widgets/not_commentable.html" %}
104104
{% endif %}
105105

106+
{% if me and not me.is_active_membership %}
107+
{% include "posts/widgets/membership_expired.html" %}
108+
{% endif %}
109+
106110
{% if not me %}
107111
{% include "posts/widgets/join_the_club.html" %}
108112
{% endif %}

frontend/html/posts/show/post.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h1 class="post-title">
9797
{% endblock %}
9898

9999
{% block post_footer %}
100-
{% if me and collectible_tag %}
100+
{% if me and me.is_active_membership and collectible_tag %}
101101
{% include "posts/widgets/collectible_tag.html" %}
102102
{% endif %}
103103

frontend/html/posts/show/question.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1 class="post-inline-title p-name">{{ post.title | rutypography }}</h1>
8383
{% endblock %}
8484
</article>
8585

86-
{% if me and collectible_tag %}
86+
{% if me and me.is_active_membership and collectible_tag %}
8787
{% include "posts/widgets/collectible_tag.html" %}
8888
{% endif %}
8989
</section>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="block post-join">
2+
<p class="post-join-icon">😤</p>
3+
4+
<p class="post-join-message">
5+
Ваша клубная карта истекла, и комментирование больше недоступно
6+
</p>
7+
8+
<p>
9+
<br>&nbsp;&nbsp;<a href="{% url "membership_expired" %}" class="button">Продлить подписку</a>
10+
</p>
11+
</div>

frontend/html/posts/widgets/post_actions_line.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
{% endif %}
2323
{% endif %}
2424

25-
{% if post.author == me or me.is_moderator or me.slug in post.coauthors %}
25+
{% if post.author == me and me.is_active_membership or me.is_moderator or me.slug in post.coauthors %}
2626
<a href="{% url "edit_post" post.slug %}" class="post-actions-line-item"><i class="fas fa-edit"></i>&nbsp;Править</a>
2727
{% endif %}
2828

29-
{% if post.author == me and not post.is_visible %}
29+
{% if post.author == me and me.is_active_membership and not post.is_visible %}
3030
{% if not post.deleted_at %}
3131
<a href="{% url "delete_post" post.slug %}" onclick="return confirm('Действительно удалить?')" class="post-actions-line-item"><i class="fas fa-trash"></i>&nbsp;Удалить&nbsp;&nbsp;&nbsp;</a>
3232
{% else %}

payments/views/common.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
from datetime import datetime
2-
31
from django.shortcuts import redirect, render
42

53

64
def membership_expired(request):
75
if not request.me:
86
return redirect("index")
97

10-
if request.me.membership_expires_at >= datetime.utcnow():
8+
if request.me.is_active_membership:
119
return redirect("profile", request.me.slug)
1210

1311
return render(request, "payments/membership_expired.html")

posts/templatetags/posts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def link_summary(post):
101101

102102
@register.filter
103103
def can_upvote_post(user, post):
104-
return bool(user and user != post.author and user.slug not in post.coauthors)
104+
return bool(user and user.is_active_membership and user != post.author and user.slug not in post.coauthors)
105105

106106

107107
@register.filter
108108
def can_upvote_comment(user, comment):
109-
return bool(user and user != comment.author)
109+
return bool(user and user.is_active_membership and user != comment.author)
110110

111111

112112
@register.filter

users/models/user.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def to_dict(self):
137137
"membership_started_at": self.membership_started_at.isoformat(),
138138
"membership_expires_at": self.membership_expires_at.isoformat(),
139139
"moderation_status": self.moderation_status,
140-
"payment_status": "active" if self.membership_expires_at >= datetime.utcnow() else "inactive",
140+
"payment_status": "active" if self.is_active_membership else "inactive",
141141
"company": self.company,
142142
"position": self.position,
143143
"city": self.city,
@@ -195,7 +195,11 @@ def is_member(self):
195195

196196
@property
197197
def is_active_member(self):
198-
return self.is_member and self.membership_expires_at >= datetime.utcnow()
198+
return self.is_member and self.is_active_membership
199+
200+
@property
201+
def is_active_membership(self):
202+
return self.membership_expires_at >= datetime.utcnow()
199203

200204
@property
201205
def secret_auth_code(self):

0 commit comments

Comments
 (0)