diff --git a/app/models.py b/app/models.py index 70056d21..531737da 100644 --- a/app/models.py +++ b/app/models.py @@ -26,13 +26,14 @@ class UserRank(enum.Enum): class Permission(enum.Enum): - EDIT_PACKAGE = "EDIT_PACKAGE" - APPROVE_CHANGES = "APPROVE_CHANGES" - DELETE_PACKAGE = "DELETE_PACKAGE" - CHANGE_AUTHOR = "CHANGE_AUTHOR" - MAKE_RELEASE = "MAKE_RELEASE" - APPROVE_RELEASE = "APPROVE_RELEASE" - APPROVE_NEW = "APPROVE_NEW" + EDIT_PACKAGE = "EDIT_PACKAGE" + APPROVE_CHANGES = "APPROVE_CHANGES" + DELETE_PACKAGE = "DELETE_PACKAGE" + CHANGE_AUTHOR = "CHANGE_AUTHOR" + MAKE_RELEASE = "MAKE_RELEASE" + APPROVE_RELEASE = "APPROVE_RELEASE" + APPROVE_NEW = "APPROVE_NEW" + CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL" class User(db.Model, UserMixin): @@ -150,7 +151,7 @@ class Package(db.Model): return user.rank.atLeast(UserRank.EDITOR) # Moderators can delete packages - elif perm == Permission.DELETE_PACKAGE: + elif perm == Permission.DELETE_PACKAGE or perm == Permission.CHANGE_RELEASE_URL: return user.rank.atLeast(UserRank.MODERATOR) else: @@ -165,6 +166,14 @@ class PackageRelease(db.Model): url = db.Column(db.String(100), nullable=False) approved = db.Column(db.Boolean, nullable=False, default=False) + + def getEditURL(self): + return url_for("edit_release_page", + type=self.package.type.toName(), + author=self.package.author.username, + name=self.package.name, + id=self.id) + def __init__(self): self.releaseDate = datetime.now() diff --git a/app/templates/package_details.html b/app/templates/package_details.html index a2db8759..ec54f5f3 100644 --- a/app/templates/package_details.html +++ b/app/templates/package_details.html @@ -58,9 +58,14 @@ created {{ rel.releaseDate }}. {% if not rel.approved %} Waiting for approval. - {% if package.checkPerm(current_user, "APPROVE_RELEASE") %} - Approve + {% endif %} + + {% if package.checkPerm(current_user, "MAKE_RELEASE") or package.checkPerm(current_user, "APPROVE_RELEASE") %} + Edit + {% if not rel.approved and package.checkPerm(current_user, "APPROVE_RELEASE") %} + / Approve {% endif %} + {% endif %} {% if not rel.approved %}{% endif %} diff --git a/app/templates/package_release_edit.html b/app/templates/package_release_edit.html new file mode 100644 index 00000000..451fc81d --- /dev/null +++ b/app/templates/package_release_edit.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} + +{% block title %} + Create a release | {{ package.title }} +{% endblock %} + +{% block content %} + {% from "macros/forms.html" import render_field, render_submit_field %} +
+{% endblock %} diff --git a/app/views/packages.py b/app/views/packages.py index 4543503f..a6b68942 100644 --- a/app/views/packages.py +++ b/app/views/packages.py @@ -87,7 +87,7 @@ def edit_package_page(type, author, name): return render_template('package_edit.html', package=package, form=form) -class PackageReleaseForm(FlaskForm): +class CreatePackageReleaseForm(FlaskForm): name = StringField("Name") title = StringField("Title") uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")]) @@ -95,6 +95,13 @@ class PackageReleaseForm(FlaskForm): fileUpload = FileField("File Upload") submit = SubmitField('Save') +class EditPackageReleaseForm(FlaskForm): + name = StringField("Name") + title = StringField("Title") + url = StringField("URL") + approved = BooleanField("Is Approved") + submit = SubmitField('Save') + @app.route("/