Uppercase the Visibility enum keys

There is currently a mismatch, causing for example project creation via
the web interface to fail, because the validation code is using the enum
keys, which are lowercase, but everything else uses uppercase.

Simply use uppercase everywhere, like already the case in other
services.
master 0.14.18
Conrad Hoffmann 3 months ago committed by Drew DeVault
parent 7e78dc04d9
commit d637723564
  1. 8
      hubsrht/alembic/versions/7f512cdfc2f5_add_visibility_to_resources.py
  2. 10
      hubsrht/blueprints/mailing_lists.py
  3. 16
      hubsrht/blueprints/projects.py
  4. 8
      hubsrht/blueprints/public.py
  5. 2
      hubsrht/blueprints/sources.py
  6. 6
      hubsrht/blueprints/trackers.py
  7. 12
      hubsrht/blueprints/users.py
  8. 8
      hubsrht/blueprints/webhooks.py
  9. 4
      hubsrht/projects.py
  10. 6
      hubsrht/types/__init__.py
  11. 5
      hubsrht/types/mailinglist.py
  12. 5
      hubsrht/types/project.py
  13. 5
      hubsrht/types/repository.py
  14. 5
      hubsrht/types/sourcerepo.py
  15. 5
      hubsrht/types/tracker.py

@ -42,16 +42,16 @@ def upgrade():
for ml in session.query(MailingList).all():
m = lists.get_list(ml.owner, ml.name)
if any(m["permissions"]["nonsubscriber"]):
ml.visibility = Visibility.public
ml.visibility = Visibility.PUBLIC
else:
ml.visibility = Visibility.unlisted
ml.visibility = Visibility.UNLISTED
for tracker in session.query(Tracker).all():
t = todo.get_tracker(tracker.owner, tracker.name)
if any(t["default_permissions"]["anonymous"]):
tracker.visibility = Visibility.public
tracker.visibility = Visibility.PUBLIC
else:
tracker.visibility = Visibility.unlisted
tracker.visibility = Visibility.UNLISTED
session.commit()

@ -21,7 +21,7 @@ def lists_GET(owner, project_name):
.order_by(MailingList.updated.desc()))
if not current_user or current_user.id != owner.id:
mailing_lists = mailing_lists.filter(
MailingList.visibility == Visibility.public)
MailingList.visibility == Visibility.PUBLIC)
terms = request.args.get("search")
search_error = None
@ -116,9 +116,9 @@ Mailing list for end-user discussion and questions related to the
ml.name = mailing_list["name"]
ml.description = mailing_list["description"]
if any(mailing_list["permissions"]["nonsubscriber"]):
ml.visibility = Visibility.public
ml.visibility = Visibility.PUBLIC
else:
ml.visibility = Visibility.unlisted
ml.visibility = Visibility.UNLISTED
db.session.add(ml)
db.session.flush()
@ -190,9 +190,9 @@ def new_POST(owner, project_name):
ml.name = mailing_list["name"]
ml.description = mailing_list["description"]
if any(mailing_list["permissions"]["nonsubscriber"]):
ml.visibility = Visibility.public
ml.visibility = Visibility.PUBLIC
else:
ml.visibility = Visibility.unlisted
ml.visibility = Visibility.UNLISTED
db.session.add(ml)
db.session.flush()

@ -50,7 +50,7 @@ def summary_GET(owner, project_name):
sources = (SourceRepo.query
.filter(SourceRepo.project_id == project.id)
.filter(SourceRepo.repo_type == RepoType.hg)
.filter(SourceRepo.visibility == Visibility.public)
.filter(SourceRepo.visibility == Visibility.PUBLIC)
.order_by(SourceRepo.updated.desc())
.limit(5))
@ -81,9 +81,9 @@ def summary_GET(owner, project_name):
.outerjoin(SourceRepo)
.outerjoin(MailingList)
.outerjoin(Tracker)
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.public),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.public),
or_(Event.tracker == None, Tracker.visibility == Visibility.public)))
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.PUBLIC),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.PUBLIC),
or_(Event.tracker == None, Tracker.visibility == Visibility.PUBLIC)))
events = events.limit(2).all()
return render_template("project-summary.html", view="summary",
@ -99,7 +99,7 @@ def summary_refs(owner, project_name):
sources = (SourceRepo.query
.filter(SourceRepo.project_id == project.id)
.filter(SourceRepo.repo_type == RepoType.git)
.filter(SourceRepo.visibility == Visibility.public)
.filter(SourceRepo.visibility == Visibility.PUBLIC)
.order_by(SourceRepo.updated.desc())
.limit(5))
@ -125,9 +125,9 @@ def feed_GET(owner, project_name):
.outerjoin(SourceRepo)
.outerjoin(MailingList)
.outerjoin(Tracker)
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.public),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.public),
or_(Event.tracker == None, Tracker.visibility == Visibility.public)))
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.PUBLIC),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.PUBLIC),
or_(Event.tracker == None, Tracker.visibility == Visibility.PUBLIC)))
events, pagination = paginate_query(events)

@ -29,7 +29,7 @@ def index():
features = (Feature.query
.join(Project, Feature.project_id == Project.id)
.join(User, Project.owner_id == User.id)
.filter(Project.visibility == Visibility.public)
.filter(Project.visibility == Visibility.PUBLIC)
.order_by(Feature.created.desc())
.limit(6)).all()
return render_template("index.html", features=features)
@ -42,7 +42,7 @@ def getting_started():
@public.route("/projects")
def project_index():
projects = Project.query.filter(Project.visibility == Visibility.public)
projects = Project.query.filter(Project.visibility == Visibility.PUBLIC)
search = request.args.get("search")
search_error = None
@ -69,7 +69,7 @@ def project_index():
features = (Feature.query
.join(Project, Feature.project_id == Project.id)
.join(User, Project.owner_id == User.id)
.filter(Project.visibility == Visibility.public)
.filter(Project.visibility == Visibility.PUBLIC)
.order_by(Feature.created.desc())
.limit(5)).all()
@ -82,7 +82,7 @@ def featured_projects():
features = (Feature.query
.join(Project, Feature.project_id == Project.id)
.join(User, Project.owner_id == User.id)
.filter(Project.visibility == Visibility.public)
.filter(Project.visibility == Visibility.PUBLIC)
.order_by(Feature.created.desc()))
features, pagination = paginate_query(features)
return render_template("featured-projects.html",

@ -19,7 +19,7 @@ def sources_GET(owner, project_name):
.filter(SourceRepo.project_id == project.id)
.order_by(SourceRepo.updated.desc()))
if not current_user or current_user.id != owner.id:
sources = sources.filter(SourceRepo.visibility == Visibility.public)
sources = sources.filter(SourceRepo.visibility == Visibility.PUBLIC)
terms = request.args.get("search")
search_error = None

@ -18,7 +18,7 @@ def trackers_GET(owner, project_name):
.filter(Tracker.project_id == project.id)
.order_by(Tracker.updated.desc()))
if not current_user or current_user.id != owner.id:
trackers = trackers.filter(Tracker.visibility == Visibility.public)
trackers = trackers.filter(Tracker.visibility == Visibility.PUBLIC)
terms = request.args.get("search")
search_error = None
@ -90,9 +90,9 @@ def new_POST(owner, project_name):
tracker.name = remote_tracker["name"]
tracker.description = remote_tracker["description"]
if any(remote_tracker["default_access"]):
tracker.visibility = Visibility.public
tracker.visibility = Visibility.PUBLIC
else:
tracker.visibility = Visibility.unlisted
tracker.visibility = Visibility.UNLISTED
db.session.add(tracker)
db.session.flush()

@ -23,17 +23,17 @@ def summary_GET(username):
if not current_user or current_user.id != user.id:
# TODO: ACLs
projects = projects.filter(Project.visibility == Visibility.public)
projects = projects.filter(Project.visibility == Visibility.PUBLIC)
events = (events
.join(Project, Event.project_id == Project.id)
.filter(Project.visibility == Visibility.public))
.filter(Project.visibility == Visibility.PUBLIC))
events = (events
.outerjoin(SourceRepo, Event.source_repo_id == SourceRepo.id)
.outerjoin(MailingList, Event.source_repo_id == MailingList.id)
.outerjoin(Tracker, Event.source_repo_id == Tracker.id)
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.public),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.public),
or_(Event.tracker == None, Tracker.visibility == Visibility.public)))
.filter(or_(Event.source_repo == None, SourceRepo.visibility == Visibility.PUBLIC),
or_(Event.mailing_list == None, MailingList.visibility == Visibility.PUBLIC),
or_(Event.tracker == None, Tracker.visibility == Visibility.PUBLIC)))
projects = projects.limit(5).all()
events, pagination = paginate_query(events)
@ -53,7 +53,7 @@ def projects_GET(owner):
.filter(Project.owner_id == owner.id))
if not current_user or current_user.id != owner.id:
# TODO: ACLs
projects = projects.filter(Project.visibility == Visibility.public)
projects = projects.filter(Project.visibility == Visibility.PUBLIC)
search = request.args.get("search")
search_error = None

@ -226,9 +226,9 @@ def mailing_list(list_id):
ml.name = payload["name"]
ml.description = payload["description"]
if any(payload["permissions"]["nonsubscriber"]):
ml.visibility = Visibility.public
ml.visibility = Visibility.PUBLIC
else:
ml.visibility = Visibility.unlisted
ml.visibility = Visibility.UNLISTED
ml.project.updated = datetime.utcnow()
db.session.commit()
return f"Updated local:{ml.id}/remote:{ml.remote_id}. Thanks!", 200
@ -293,9 +293,9 @@ def todo_user(user_id):
tracker.name = payload["name"]
tracker.description = payload["description"]
if any(payload["default_access"]):
tracker.visibility = Visibility.public
tracker.visibility = Visibility.PUBLIC
else:
tracker.visibility = Visibility.unlisted
tracker.visibility = Visibility.UNLISTED
tracker.project.updated = datetime.utcnow()
summary += f"Updated local:{tracker.id}/remote:{tracker.remote_id}\n"
db.session.commit()

@ -22,8 +22,8 @@ def get_project(owner, project_name, access, user=current_user):
if access == ProjectAccess.write:
abort(401)
# TODO: ACLs
if project.visibility in (Visibility.public, Visibility.unlisted):
if project.visibility in (Visibility.PUBLIC, Visibility.UNLISTED):
return project.owner, project
elif project.visibility == Visibility.private:
elif project.visibility == Visibility.PRIVATE:
abort(401)
assert False

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

@ -1,5 +1,6 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from sqlalchemy.dialects import postgresql
from hubsrht.types import Visibility
from srht.config import get_origin
from srht.database import Base
@ -27,8 +28,8 @@ class MailingList(Base):
name = sa.Column(sa.Unicode(128), nullable=False)
description = sa.Column(sa.Unicode)
visibility = sa.Column(sau.ChoiceType(Visibility, impl=sa.String()),
nullable=False, server_default="unlisted")
visibility = sa.Column(postgresql.ENUM(Visibility),
nullable=False, server_default="UNLISTED")
def url(self):
return f"{_listsrht}/{self.owner.canonical_name}/{self.name}"

@ -1,5 +1,6 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from sqlalchemy.dialects import postgresql
from hubsrht.types import Visibility
from srht.database import Base
@ -20,8 +21,8 @@ class Project(Base):
tags = sa.Column(sa.ARRAY(sa.String(16), dimensions=1),
nullable=False, server_default="{}")
website = sa.Column(sa.Unicode)
visibility = sa.Column(sau.ChoiceType(Visibility, impl=sa.String()),
nullable=False, server_default="unlisted")
visibility = sa.Column(postgresql.ENUM(Visibility),
nullable=False, server_default="UNLISTED")
checklist_complete = sa.Column(sa.Boolean,
nullable=False, server_default='f')

@ -1,5 +1,6 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from sqlalchemy.dialects import postgresql
from hubsrht.types import Visibility
from srht.database import Base
from enum import Enum
@ -20,5 +21,5 @@ class Repository(Base):
name = sa.Column(sa.Unicode(128), nullable=False)
description = sa.Column(sa.Unicode(512), nullable=False)
visibility = sa.Column(sau.ChoiceType(Visibility, impl=sa.String()),
nullable=False, server_default="unlisted")
visibility = sa.Column(postgresql.ENUM(Visibility),
nullable=False, server_default="UNLISTED")

@ -1,5 +1,6 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from sqlalchemy.dialects import postgresql
from enum import Enum
from hubsrht.types import Visibility
from srht.config import get_origin
@ -40,8 +41,8 @@ class SourceRepo(Base):
description = sa.Column(sa.Unicode)
repo_type = sa.Column(sau.ChoiceType(RepoType, impl=sa.String()),
nullable=False)
visibility = sa.Column(sau.ChoiceType(Visibility, impl=sa.String()),
nullable=False, server_default="unlisted")
visibility = sa.Column(postgresql.ENUM(Visibility),
nullable=False, server_default="UNLISTED")
def url(self):
origin = _gitsrht if self.repo_type == RepoType.git else _hgsrht

@ -1,5 +1,6 @@
import sqlalchemy as sa
import sqlalchemy_utils as sau
from sqlalchemy.dialects import postgresql
from hubsrht.types import Visibility
from srht.config import get_origin
from srht.database import Base
@ -26,8 +27,8 @@ class Tracker(Base):
name = sa.Column(sa.Unicode(128), nullable=False)
description = sa.Column(sa.Unicode)
visibility = sa.Column(sau.ChoiceType(Visibility, impl=sa.String()),
nullable=False, server_default="unlisted")
visibility = sa.Column(postgresql.ENUM(Visibility),
nullable=False, server_default="UNLISTED")
def url(self):
return f"{_todosrht}/{self.owner.canonical_name}/{self.name}"

Loading…
Cancel
Save