Browse Source

Rename "post_topic" permission to "topic.post"

This permission was a strange exception, with every other permission
being of a format like "topic.lock", "comment.remove", and so on.
merge-requests/126/merge
Deimos 4 years ago
parent
commit
a46283436d
  1. 28
      tildes/alembic/versions/82e9801eb2d6_update_post_topic_permission_to_topic_.py
  2. 8
      tildes/tildes/models/group/group.py
  3. 2
      tildes/tildes/templates/search.jinja2
  4. 4
      tildes/tildes/templates/topic_listing.jinja2
  5. 4
      tildes/tildes/views/topic.py

28
tildes/alembic/versions/82e9801eb2d6_update_post_topic_permission_to_topic_.py

@ -0,0 +1,28 @@
"""Update post_topic permission to topic.post
Revision ID: 82e9801eb2d6
Revises: 0435c46f64d8
Create Date: 2020-08-05 00:05:46.690188
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "82e9801eb2d6"
down_revision = "0435c46f64d8"
branch_labels = None
depends_on = None
def upgrade():
op.execute(
"update user_permissions set permission = 'topic.post' where permission = 'post_topic'"
)
def downgrade():
op.execute(
"update user_permissions set permission = 'post_topic' where permission = 'topic.post'"
)

8
tildes/tildes/models/group/group.py

@ -124,15 +124,15 @@ class Group(DatabaseModel):
# - all groups can be subscribed to by logged-in users # - all groups can be subscribed to by logged-in users
acl.append((Allow, Authenticated, "subscribe")) acl.append((Allow, Authenticated, "subscribe"))
# post_topic:
# topic.post:
# - only users with specifically-granted permission can post topics in groups # - only users with specifically-granted permission can post topics in groups
# that require permission to post # that require permission to post
# - otherwise, all logged-in users can post # - otherwise, all logged-in users can post
if self.requires_permission_to_post_topics: if self.requires_permission_to_post_topics:
acl.append((Allow, f"{self.group_id}:post_topic", "post_topic"))
acl.append((Deny, Everyone, "post_topic"))
acl.append((Allow, f"{self.group_id}:topic.post", "topic.post"))
acl.append((Deny, Everyone, "topic.post"))
acl.append((Allow, Authenticated, "post_topic"))
acl.append((Allow, Authenticated, "topic.post"))
# wiki_page_create: # wiki_page_create:
# - requires being granted the "wiki.edit" permission # - requires being granted the "wiki.edit" permission

2
tildes/tildes/templates/search.jinja2

@ -36,7 +36,7 @@
{% if request.user %} {% if request.user %}
<div class="divider"></div> <div class="divider"></div>
{% if request.has_permission('post_topic', group) %}
{% if request.has_permission("topic.post", group) %}
<a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a> <a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a>
{% endif %} {% endif %}

4
tildes/tildes/templates/topic_listing.jinja2

@ -148,7 +148,7 @@
<div class="empty"> <div class="empty">
{% if period %} {% if period %}
<h2 class="empty-title">No topics in the selected time period</h2> <h2 class="empty-title">No topics in the selected time period</h2>
{% if is_single_group and request.has_permission('post_topic', group) %}
{% if is_single_group and request.has_permission("topic.post", group) %}
<p class="empty-subtitle">Try choosing a longer time period, or break the silence by posting one yourself.</p> <p class="empty-subtitle">Try choosing a longer time period, or break the silence by posting one yourself.</p>
<div class="empty-action"> <div class="empty-action">
<a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a> <a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a>
@ -218,7 +218,7 @@
{{ render_group_subscription_box(group) }} {{ render_group_subscription_box(group) }}
{% if request.has_permission('post_topic', group) %}
{% if request.has_permission("topic.post", group) %}
<a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a> <a href="/~{{ group.path }}/new_topic" class="btn btn-primary">Post a new topic</a>
{% endif %} {% endif %}

4
tildes/tildes/views/topic.py

@ -45,7 +45,7 @@ from tildes.views.financials import get_financial_data
DefaultSettings = namedtuple("DefaultSettings", ["order", "period"]) DefaultSettings = namedtuple("DefaultSettings", ["order", "period"])
@view_config(route_name="group_topics", request_method="POST", permission="post_topic")
@view_config(route_name="group_topics", request_method="POST", permission="topic.post")
@use_kwargs(TopicSchema(only=("title", "markdown", "link")), location="form") @use_kwargs(TopicSchema(only=("title", "markdown", "link")), location="form")
@use_kwargs( @use_kwargs(
{"tags": String(missing=""), "confirm_repost": Boolean(missing=False)}, {"tags": String(missing=""), "confirm_repost": Boolean(missing=False)},
@ -379,7 +379,7 @@ def get_search(
@view_config( @view_config(
route_name="new_topic", renderer="new_topic.jinja2", permission="post_topic"
route_name="new_topic", renderer="new_topic.jinja2", permission="topic.post"
) )
def get_new_topic_form(request: Request) -> dict: def get_new_topic_form(request: Request) -> dict:
"""Form for entering a new topic to post.""" """Form for entering a new topic to post."""

Loading…
Cancel
Save