hubsrht: Add visibility enum

This commit is contained in:
Adnan Maolood 2022-06-29 08:25:16 -04:00 committed by Drew DeVault
parent db74624e2a
commit ab821d423a
8 changed files with 67 additions and 26 deletions

View File

@ -0,0 +1,41 @@
"""Add visibility enum
Revision ID: de4adc3cc306
Revises: 5b1ac5bdb471
Create Date: 2022-06-16 01:32:20.691725
"""
# revision identifiers, used by Alembic.
revision = 'de4adc3cc306'
down_revision = '5b1ac5bdb471'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.execute("""
CREATE TYPE visibility AS ENUM (
'PUBLIC',
'PRIVATE',
'UNLISTED'
);
ALTER TABLE project
ALTER COLUMN visibility DROP DEFAULT;
ALTER TABLE project
ALTER COLUMN visibility TYPE visibility USING upper(visibility)::visibility;
ALTER TABLE project
ALTER COLUMN visibility SET DEFAULT 'UNLISTED'::visibility;
""")
def downgrade():
op.execute("""
ALTER TABLE project
ALTER COLUMN visibility TYPE varchar USING lower(visibility::varchar);
ALTER TABLE project
ALTER COLUMN visibility SET DEFAULT 'unlisted';
DROP TYPE visibility;
""")

View File

@ -48,8 +48,8 @@
{% for project in projects %}
<div class="event">
<h4>
{% if project.visibility.value != 'public' %}
<small class="text-muted pull-right">{{project.visibility.value}}</small>
{% if project.visibility.value != 'PUBLIC' %}
<small class="text-muted pull-right">{{project.visibility.value.lower()}}</small>
{% endif %}
<a href="{{url_for("projects.summary_GET",
owner=project.owner.canonical_name,

View File

@ -60,8 +60,8 @@
{% for project in projects %}
<div class="event">
<h4>
{% if project.visibility.value != 'public' %}
<small class="text-muted pull-right">{{project.visibility.value}}</small>
{% if project.visibility.value != 'PUBLIC' %}
<small class="text-muted pull-right">{{project.visibility.value.lower()}}</small>
{% endif %}
<a href="{{url_for("projects.summary_GET",
owner=project.owner.canonical_name,

View File

@ -72,10 +72,10 @@
class="form-check-input"
type="radio"
name="visibility"
{% if (visibility and visibility == "public") or project.visibility.value == "public" %}
{% if (visibility and visibility == "PUBLIC") or project.visibility.value == "PUBLIC" %}
checked
{% endif %}
value="public"> Public
value="PUBLIC"> Public
<small id="visibility-public-help" class="form-text text-muted">
Shown on your profile and listed in the public project index
</small>
@ -90,10 +90,10 @@
class="form-check-input"
type="radio"
name="visibility"
{% if (visibility and visibility == "unlisted") or project.visibility.value == "unlisted" %}
{% if (visibility and visibility == "UNLISTED") or project.visibility.value == "UNLISTED" %}
checked
{% endif %}
value="unlisted"> Unlisted
value="UNLISTED"> Unlisted
<small id="visibility-unlisted-help" class="form-text text-muted">
Visible to anyone who knows the URL, but not shown on your profile
</small>
@ -108,10 +108,10 @@
class="form-check-input"
type="radio"
name="visibility"
{% if (visibility and visibility == "private") or project.visibility.value == "private" %}
{% if (visibility and visibility == "PRIVATE") or project.visibility.value == "PRIVATE" %}
checked
{% endif %}
value="private"> Private
value="PRIVATE"> Private
<small id="visibility-unlisted-help" class="form-text text-muted">
Only visible to you and your collaborators
</small>

View File

@ -76,8 +76,8 @@
class="form-check-input"
type="radio"
name="visibility"
value="public"
{% if not visibility or visibility == "public" %}
value="PUBLIC"
{% if not visibility or visibility == "PUBLIC" %}
checked
{% endif %}
> Public
@ -95,8 +95,8 @@
class="form-check-input"
type="radio"
name="visibility"
value="unlisted"
{% if visibility and visibility == "unlisted" %}
value="UNLISTED"
{% if visibility and visibility == "UNLISTED" %}
checked
{% endif %}
> Unlisted
@ -114,8 +114,8 @@
class="form-check-input"
type="radio"
name="visibility"
value="private"
{% if visibility and visibility == "private" %}
value="PRIVATE"
{% if visibility and visibility == "PRIVATE" %}
checked
{% endif %}
> Private

View File

@ -9,18 +9,18 @@
href="{{ path }}">{{ title }}</a>
{% endmacro %}
<ul class="nav nav-tabs">
{% if project.visibility.value != "public" %}
{% if project.visibility.value != "PUBLIC" %}
<li
class="nav-item nav-text vis-{{project.visibility.value.lower()}}"
{% if project.visibility.value == "unlisted" %}
{% if project.visibility.value == "UNLISTED" %}
title="This project is only visible to those who know the URL."
{% elif project.visibility.value == "private" %}
{% elif project.visibility.value == "PRIVATE" %}
title="This project is only visible to those who were invited to view it."
{% endif %}
>
{% if project.visibility.value == "unlisted" %}
{% if project.visibility.value == "UNLISTED" %}
Unlisted
{% elif project.visibility.value == "private" %}
{% elif project.visibility.value == "PRIVATE" %}
Private
{% endif %}
</li>

View File

@ -45,8 +45,8 @@
{% for project in projects %}
<div class="event">
<h4>
{% if project.visibility.value != 'public' %}
<small class="text-muted pull-right">{{project.visibility.value}}</small>
{% if project.visibility.value != 'PUBLIC' %}
<small class="text-muted pull-right">{{project.visibility.value.lower()}}</small>
{% endif %}
<a href="{{url_for("projects.summary_GET",
owner=project.owner.canonical_name,

View File

@ -6,9 +6,9 @@ class User(Base, ExternalUserMixin):
pass
class Visibility(Enum):
public = "public"
unlisted = "unlisted"
private = "private"
public = "PUBLIC"
private = "PRIVATE"
unlisted = "UNLISTED"
from hubsrht.types.event import Event, EventType
from hubsrht.types.feature import Feature