Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iambibhas committed Dec 23, 2020
1 parent f37d261 commit 2397618
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
11 changes: 8 additions & 3 deletions funnel/models/commentset_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def offered_roles(self):
Roles offered by this membership record.
It won't be used though because relationship below ignores it.
ref: https://github.com/hasgeek/funnel/pull/977#discussion_r544878851
"""
return {'document_subscriber'}

Expand Down Expand Up @@ -96,7 +95,8 @@ def update_last_seen_at(self, user: User):
if existing_ms is not None:
existing_ms.last_seen_at = db.func.utcnow()

def add_subscriber(self, actor: User, user: User) -> None:
def add_subscriber(self, actor: User, user: User) -> bool:
"""Return True is subscriber is added, False if already exists."""
existing_ms = CommentsetMembership.query.filter_by(
commentset=self, user=user, is_active=True
).one_or_none()
Expand All @@ -107,10 +107,15 @@ def add_subscriber(self, actor: User, user: User) -> None:
granted_by=actor,
)
db.session.add(new_ms)
return True
return False

def remove_subscriber(self, actor: User, user: User) -> None:
def remove_subscriber(self, actor: User, user: User) -> bool:
"""Return True is subscriber is removed, False if already removed."""
existing_ms = CommentsetMembership.query.filter_by(
commentset=self, user=user, is_active=True
).one_or_none()
if existing_ms is not None:
existing_ms.revoke(actor=actor)
return True
return False
5 changes: 3 additions & 2 deletions funnel/models/rsvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def rsvp_yes(self, subscribe_comments: bool = False):
message=__("Your response has been saved"),
type='dark',
)
def rsvp_no(self):
self.project.commentset.remove_subscriber(actor=self.user, user=self.user)
def rsvp_no(self, unsubscribe_comments: bool = False):
if unsubscribe_comments:
self.project.commentset.remove_subscriber(actor=self.user, user=self.user)

@with_roles(call={'owner'})
@state.transition(
Expand Down
2 changes: 1 addition & 1 deletion funnel/templates/project_comments.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
isuserloggedin: {% if current_auth.user -%}true{% else %}false{% endif %},
user: {% if current_auth.user -%}{{ { 'fullname': current_auth.user.fullname, 'avatar': current_auth.user.avatar, 'profile_url': current_auth.user.profile_url }|tojson }}{% else %}{}{% endif %},
loginUrl: "{{ url_for('login') }}",
lastSeenUrl: {% if project.commentset.current_roles.document_subscriber %}"{{ project.commentset.url_for('update_last_seen_at') }}"{% else %}false{% endif %},
lastSeenUrl: {% if project.commentset.current_roles.document_subscriber %}{{ project.commentset.url_for('update_last_seen_at')|tojson }}{% else %}false{% endif %},
};
window.Hasgeek.Comments(commentsConfig);
Expand Down
2 changes: 1 addition & 1 deletion funnel/templates/proposal.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
isuserloggedin: {% if current_auth.user -%}true{% else %}false{% endif %},
user: {% if current_auth.user -%}{{ { 'fullname': current_auth.user.fullname, 'avatar': current_auth.user.avatar, 'profile_url': current_auth.user.profile_url }|tojson }}{% else %}{}{% endif %},
loginUrl: "{{ url_for('login') }}",
lastSeenUrl: {% if proposal.commentset.current_roles.document_subscriber %}"{{ proposal.commentset.url_for('update_last_seen_at') }}"{% else %}false{% endif %},
lastSeenUrl: {% if proposal.commentset.current_roles.document_subscriber %}{{ proposal.commentset.url_for('update_last_seen_at')|tojson }}{% else %}false{% endif %},
};
window.Hasgeek.Comments(commentsConfig);
Expand Down
18 changes: 5 additions & 13 deletions funnel/views/commentvote.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,13 @@ def subscribe(self):
db.session.commit()
return {
'status': 'ok',
'message': _("You have successfully subscribed to this comment thread"),
'message': _("Successfully subscribed to this comment thread"),
}
else:
return {
'status': 'error',
'error_code': 'subscribe_error',
'error_description': _(
"Invalid CSRF token. Reload the page and try again"
),
'error_description': _("This page timed out. Reload and try again"),
'error_details': csrf_form.errors,
}, 422

Expand All @@ -209,17 +207,13 @@ def unsubscribe(self):
db.session.commit()
return {
'status': 'ok',
'message': _(
"You have successfully unsubscribed from this comment thread"
),
'message': _("Successfully unsubscribed from this comment thread"),
}
else:
return {
'status': 'error',
'error_code': 'unsubscribe_error',
'error_description': _(
"Invalid CSRF token. Reload the page and try again"
),
'error_description': _("This page timed out. Reload and try again"),
'error_details': csrf_form.errors,
}, 422

Expand All @@ -236,9 +230,7 @@ def update_last_seen_at(self):
return {
'status': 'error',
'error_code': 'update_seen_at_error',
'error_description': _(
"Invalid CSRF token. Reload the page and try again"
),
'error_description': _("This page timed out. Reload and try again"),
'error_details': csrf_form.errors,
}, 422

Expand Down
7 changes: 1 addition & 6 deletions migrations/versions/3d3df26524b7_commentset_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ def upgrade():
sa.Column('revoked_at', sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column('record_type', sa.Integer(), nullable=False),
sa.Column('commentset_id', sa.Integer(), nullable=False),
sa.Column(
'last_seen_at',
sa.TIMESTAMP(timezone=True),
nullable=False,
default=sa.func.utcnow(),
),
sa.Column('last_seen_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('revoked_by_id', sa.Integer(), nullable=True),
sa.Column('granted_by_id', sa.Integer(), nullable=True),
Expand Down

0 comments on commit 2397618

Please sign in to comment.