mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 11:47:28 +01:00
Add package releases
This commit is contained in:
parent
623ca3da07
commit
596f725d59
@ -30,6 +30,7 @@ class Permission(enum.Enum):
|
|||||||
APPROVE_CHANGES = "APPROVE_CHANGES"
|
APPROVE_CHANGES = "APPROVE_CHANGES"
|
||||||
DELETE_PACKAGE = "DELETE_PACKAGE"
|
DELETE_PACKAGE = "DELETE_PACKAGE"
|
||||||
CHANGE_AUTHOR = "CHANGE_AUTHOR"
|
CHANGE_AUTHOR = "CHANGE_AUTHOR"
|
||||||
|
MAKE_RELEASE = "MAKE_RELEASE"
|
||||||
APPROVE_RELEASE = "APPROVE_RELEASE"
|
APPROVE_RELEASE = "APPROVE_RELEASE"
|
||||||
APPROVE_NEW = "APPROVE_NEW"
|
APPROVE_NEW = "APPROVE_NEW"
|
||||||
|
|
||||||
@ -106,6 +107,9 @@ class Package(db.Model):
|
|||||||
issueTracker = db.Column(db.String(200), nullable=True)
|
issueTracker = db.Column(db.String(200), nullable=True)
|
||||||
forums = db.Column(db.String(200), nullable=False)
|
forums = db.Column(db.String(200), nullable=False)
|
||||||
|
|
||||||
|
# Releases
|
||||||
|
releases = db.relationship('PackageRelease', backref='package', lazy='dynamic')
|
||||||
|
|
||||||
def getDetailsURL(self):
|
def getDetailsURL(self):
|
||||||
return url_for("package_page",
|
return url_for("package_page",
|
||||||
type=self.type.toName(),
|
type=self.type.toName(),
|
||||||
@ -128,6 +132,9 @@ class Package(db.Model):
|
|||||||
isOwner = user == self.author
|
isOwner = user == self.author
|
||||||
|
|
||||||
# Members can edit their own packages, and editors can edit any packages
|
# Members can edit their own packages, and editors can edit any packages
|
||||||
|
if perm == Permission.MAKE_RELEASE:
|
||||||
|
return isOwner or user.rank.atLeast(UserRank.EDITOR)
|
||||||
|
|
||||||
if perm == Permission.EDIT_PACKAGE or perm == Permission.APPROVE_CHANGES:
|
if perm == Permission.EDIT_PACKAGE or perm == Permission.APPROVE_CHANGES:
|
||||||
return user.rank.atLeast(UserRank.MEMBER if isOwner else UserRank.EDITOR)
|
return user.rank.atLeast(UserRank.MEMBER if isOwner else UserRank.EDITOR)
|
||||||
|
|
||||||
@ -143,6 +150,18 @@ class Package(db.Model):
|
|||||||
else:
|
else:
|
||||||
raise Exception("Permission {} is not related to packages".format(perm.name))
|
raise Exception("Permission {} is not related to packages".format(perm.name))
|
||||||
|
|
||||||
|
class PackageRelease(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
|
package_id = db.Column(db.Integer, db.ForeignKey('package.id'))
|
||||||
|
title = db.Column(db.String(100), nullable=False)
|
||||||
|
releaseDate = db.Column(db.Date, nullable=False)
|
||||||
|
url = db.Column(db.String(100), nullable=False)
|
||||||
|
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.releaseDate = datetime.now()
|
||||||
|
|
||||||
# Setup Flask-User
|
# Setup Flask-User
|
||||||
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
||||||
user_manager = UserManager(db_adapter, app) # Initialize Flask-User
|
user_manager = UserManager(db_adapter, app) # Initialize Flask-User
|
||||||
|
@ -43,4 +43,27 @@
|
|||||||
<p class="package-short-large">{{ package.shortDesc }}</p>
|
<p class="package-short-large">{{ package.shortDesc }}</p>
|
||||||
|
|
||||||
{{ package.desc | markdown }}
|
{{ package.desc | markdown }}
|
||||||
|
|
||||||
|
<h3>Releases</h3>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for rel in releases %}
|
||||||
|
<li>
|
||||||
|
{% if not rel.approved %}<i>{% endif %}
|
||||||
|
|
||||||
|
<a href="{{ rel.url }}">{{ rel.title }}</a>,
|
||||||
|
created {{ rel.releaseDate }}.
|
||||||
|
{% if not rel.approved %}
|
||||||
|
Waiting for approval.
|
||||||
|
{% if package.checkPerm(current_user, "APPROVE_RELEASE") %}
|
||||||
|
<a href="">Approve</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not rel.approved %}</i>{% endif %}
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li>No releases available.</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -42,11 +42,19 @@ def getPageByInfo(type, author, name):
|
|||||||
|
|
||||||
return package
|
return package
|
||||||
|
|
||||||
|
def getReleases(package):
|
||||||
|
if package.checkPerm(current_user, Permission.MAKE_RELEASE):
|
||||||
|
return package.releases
|
||||||
|
else:
|
||||||
|
return [rel for rel in package.releases if rel.approved]
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/")
|
@app.route("/<type>s/<author>/<name>/")
|
||||||
def package_page(type, author, name):
|
def package_page(type, author, name):
|
||||||
package = getPageByInfo(type, author, name)
|
package = getPageByInfo(type, author, name)
|
||||||
return render_template('package_details.html', package=package)
|
releases = getReleases(package)
|
||||||
|
|
||||||
|
return render_template('package_details.html', package=package, releases=releases)
|
||||||
|
|
||||||
|
|
||||||
class PackageForm(FlaskForm):
|
class PackageForm(FlaskForm):
|
||||||
|
8
setup.py
8
setup.py
@ -14,7 +14,7 @@ if not os.path.isfile("db.sqlite"):
|
|||||||
|
|
||||||
ruben = User("rubenwardy")
|
ruben = User("rubenwardy")
|
||||||
ruben.github_username = "rubenwardy"
|
ruben.github_username = "rubenwardy"
|
||||||
ruben.rank = UserRank.MEMBER
|
ruben.rank = UserRank.EDITOR
|
||||||
db.session.add(ruben)
|
db.session.add(ruben)
|
||||||
|
|
||||||
jeija = User("Jeija")
|
jeija = User("Jeija")
|
||||||
@ -46,6 +46,12 @@ awards.register_achievement("award_mesefind",{
|
|||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
rel = PackageRelease()
|
||||||
|
rel.package = mod1
|
||||||
|
rel.title = "v1.0.0"
|
||||||
|
rel.url = "https://github.com/rubenwardy/awards/archive/master.zip"
|
||||||
|
db.session.add(rel)
|
||||||
|
|
||||||
mod2 = Package()
|
mod2 = Package()
|
||||||
mod2.name = "mesecons"
|
mod2.name = "mesecons"
|
||||||
mod2.title = "Mesecons"
|
mod2.title = "Mesecons"
|
||||||
|
Loading…
Reference in New Issue
Block a user