mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
Add new package approval
This commit is contained in:
parent
49a2a9192f
commit
aed805da6e
@ -35,6 +35,12 @@ class Permission(enum.Enum):
|
||||
APPROVE_NEW = "APPROVE_NEW"
|
||||
CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL"
|
||||
|
||||
def check(self, user):
|
||||
if self == Permission.APPROVE_NEW:
|
||||
return user.rank.atLeast(UserRank.EDITOR)
|
||||
else:
|
||||
raise Exception("Non-global permission checked globally. Use Package.checkPerm or User.checkPerm instead.")
|
||||
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
@ -102,6 +108,8 @@ class Package(db.Model):
|
||||
desc = db.Column(db.Text, nullable=True)
|
||||
type = db.Column(db.Enum(PackageType))
|
||||
|
||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
# Downloads
|
||||
repo = db.Column(db.String(200), nullable=True)
|
||||
website = db.Column(db.String(200), nullable=True)
|
||||
@ -122,6 +130,11 @@ class Package(db.Model):
|
||||
type=self.type.toName(),
|
||||
author=self.author.username, name=self.name)
|
||||
|
||||
def getApproveURL(self):
|
||||
return url_for("approve_package_page",
|
||||
type=self.type.toName(),
|
||||
author=self.author.username, name=self.name)
|
||||
|
||||
def getCreateReleaseURL(self):
|
||||
return url_for("create_release_page",
|
||||
type=self.type.toName(),
|
||||
|
@ -5,6 +5,17 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if not package.approved %}
|
||||
<div class="box box_grey alert alert-warning">
|
||||
<span class="icon_message"></span>
|
||||
This package needs to be approved before it can be found.
|
||||
{% if package.checkPerm(current_user, "APPROVE_NEW") %}
|
||||
<a href="{{ package.getApproveURL() }}">Approve</a>
|
||||
{% endif %}
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<h1>{{ package.title }} by {{ package.author.display_name }}</h1>
|
||||
|
||||
<aside class="asideright box box_grey">
|
||||
|
@ -15,19 +15,19 @@ from wtforms.validators import *
|
||||
@app.route('/mods/')
|
||||
@menu.register_menu(app, '.mods', 'Mods', order=10)
|
||||
def mods_page():
|
||||
packages = Package.query.filter_by(type=PackageType.MOD).all()
|
||||
packages = Package.query.filter_by(type=PackageType.MOD, approved=True).all()
|
||||
return render_template('packages.html', title="Mods", packages=packages)
|
||||
|
||||
@app.route('/games/')
|
||||
@menu.register_menu(app, '.games', 'Games', order=11)
|
||||
def games_page():
|
||||
packages = Package.query.filter_by(type=PackageType.GAME).all()
|
||||
packages = Package.query.filter_by(type=PackageType.GAME, approved=True).all()
|
||||
return render_template('packages.html', title="Games", packages=packages)
|
||||
|
||||
@app.route('/texturepacks/')
|
||||
@menu.register_menu(app, '.txp', 'Texture Packs', order=12)
|
||||
def txp_page():
|
||||
packages = Package.query.filter_by(type=PackageType.TXP).all()
|
||||
packages = Package.query.filter_by(type=PackageType.TXP, approved=True).all()
|
||||
return render_template('packages.html', title="Texture Packs", packages=packages)
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ def create_edit_package_page(type=None, author=None, name=None):
|
||||
if not package:
|
||||
package = Package()
|
||||
package.author = current_user
|
||||
# package.approved = package.checkPerm(current_user, Permission.APPROVE_NEW)
|
||||
|
||||
form.populate_obj(package) # copy to row
|
||||
db.session.commit() # save
|
||||
@ -99,6 +100,23 @@ def create_edit_package_page(type=None, author=None, name=None):
|
||||
|
||||
return render_template('package_create_edit.html', package=package, form=form)
|
||||
|
||||
@app.route("/<type>s/<author>/<name>/approve/")
|
||||
@login_required
|
||||
def approve_package_page(type=None, author=None, name=None):
|
||||
package = getPageByInfo(type, author, name)
|
||||
|
||||
if not package.checkPerm(current_user, Permission.APPROVE_NEW):
|
||||
flash("You don't have permission to do that.", "error")
|
||||
|
||||
elif package.approved:
|
||||
flash("Package has already been approved", "error")
|
||||
|
||||
else:
|
||||
package.approved = True
|
||||
db.session.commit()
|
||||
|
||||
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
class CreatePackageReleaseForm(FlaskForm):
|
||||
name = StringField("Name")
|
||||
|
3
setup.py
3
setup.py
@ -22,6 +22,7 @@ if not os.path.isfile("db.sqlite"):
|
||||
db.session.add(jeija)
|
||||
|
||||
mod1 = Package()
|
||||
mod1.approved = True
|
||||
mod1.name = "awards"
|
||||
mod1.title = "Awards"
|
||||
mod1.type = PackageType.MOD
|
||||
@ -53,6 +54,7 @@ awards.register_achievement("award_mesefind",{
|
||||
db.session.add(rel)
|
||||
|
||||
mod2 = Package()
|
||||
mod2.approved = True
|
||||
mod2.name = "mesecons"
|
||||
mod2.title = "Mesecons"
|
||||
mod2.type = PackageType.MOD
|
||||
@ -149,6 +151,7 @@ No warranty is provided, express or implied, for any part of the project.
|
||||
|
||||
|
||||
game1 = Package()
|
||||
game1.approved = True
|
||||
game1.name = "capturetheflag"
|
||||
game1.title = "Capture The Flag"
|
||||
game1.type = PackageType.GAME
|
||||
|
Loading…
Reference in New Issue
Block a user