mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-25 15:31:37 +01:00
parent
5f2a399260
commit
ed88c61714
@ -99,7 +99,7 @@ class User(db.Model, UserMixin):
|
|||||||
self.rank = UserRank.NOT_JOINED
|
self.rank = UserRank.NOT_JOINED
|
||||||
|
|
||||||
def isClaimed(self):
|
def isClaimed(self):
|
||||||
return self.password is not None and self.password != ""
|
return self.rank.atLeast(UserRank.NEW_MEMBER)
|
||||||
|
|
||||||
def checkPerm(self, user, perm):
|
def checkPerm(self, user, perm):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
@ -111,7 +111,9 @@ class User(db.Model, UserMixin):
|
|||||||
raise Exception("Unknown permission given to User.checkPerm()")
|
raise Exception("Unknown permission given to User.checkPerm()")
|
||||||
|
|
||||||
# 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.CHANGE_RANK:
|
if perm == Permission.CHANGE_AUTHOR:
|
||||||
|
return user.rank.atLeast(UserRank.EDITOR)
|
||||||
|
elif perm == Permission.CHANGE_RANK:
|
||||||
return user.rank.atLeast(UserRank.MODERATOR)
|
return user.rank.atLeast(UserRank.MODERATOR)
|
||||||
else:
|
else:
|
||||||
raise Exception("Permission {} is not related to users".format(perm.name))
|
raise Exception("Permission {} is not related to users".format(perm.name))
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{{ package.title or "Create Package" }}
|
{{ package.title or "Create Package" }}
|
||||||
|
{% if not package and author != current_user %}
|
||||||
|
for {{ author.display_name }}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -74,6 +74,11 @@
|
|||||||
<li><i>No packages available</i></ul>
|
<li><i>No packages available</i></ul>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% if user == current_user or user.checkPerm(current_user, "CHANGE_AUTHOR") %}
|
||||||
|
<a href="{{ url_for('create_edit_package_page', author=user.username) }}">
|
||||||
|
Create
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if form %}
|
{% if form %}
|
||||||
|
@ -152,11 +152,26 @@ def create_edit_package_page(type=None, author=None, name=None):
|
|||||||
form = None
|
form = None
|
||||||
if type is None:
|
if type is None:
|
||||||
form = PackageForm(formdata=request.form)
|
form = PackageForm(formdata=request.form)
|
||||||
|
author = request.args.get("author")
|
||||||
|
if author is None or author == current_user.username:
|
||||||
|
author = current_user
|
||||||
|
else:
|
||||||
|
author = User.query.filter_by(username=author).first()
|
||||||
|
if author is None:
|
||||||
|
flash("Unable to find that user", "error")
|
||||||
|
return redirect(url_for("create_edit_package_page"))
|
||||||
|
|
||||||
|
if not author.checkPerm(current_user, Permission.CHANGE_AUTHOR):
|
||||||
|
flash("Permission denied", "error")
|
||||||
|
return redirect(url_for("create_edit_package_page"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
package = getPageByInfo(type, author, name)
|
package = getPageByInfo(type, author, name)
|
||||||
if not package.checkPerm(current_user, Permission.EDIT_PACKAGE):
|
if not package.checkPerm(current_user, Permission.EDIT_PACKAGE):
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
author = package.author
|
||||||
|
|
||||||
form = PackageForm(formdata=request.form, obj=package)
|
form = PackageForm(formdata=request.form, obj=package)
|
||||||
|
|
||||||
# Initial form class from post data and default data
|
# Initial form class from post data and default data
|
||||||
@ -164,18 +179,19 @@ def create_edit_package_page(type=None, author=None, name=None):
|
|||||||
# Successfully submitted!
|
# Successfully submitted!
|
||||||
if not package:
|
if not package:
|
||||||
package = Package()
|
package = Package()
|
||||||
package.author = current_user
|
package.author = author
|
||||||
# package.approved = package.checkPerm(current_user, Permission.APPROVE_NEW)
|
# package.approved = package.checkPerm(current_user, Permission.APPROVE_NEW)
|
||||||
|
|
||||||
|
form.populate_obj(package) # copy to row
|
||||||
|
|
||||||
package.tags.clear()
|
package.tags.clear()
|
||||||
for tag in form.tags.raw_data:
|
for tag in form.tags.raw_data:
|
||||||
package.tags.append(Tag.query.get(tag))
|
package.tags.append(Tag.query.get(tag))
|
||||||
|
|
||||||
form.populate_obj(package) # copy to row
|
|
||||||
db.session.commit() # save
|
db.session.commit() # save
|
||||||
return redirect(package.getDetailsURL()) # redirect
|
return redirect(package.getDetailsURL()) # redirect
|
||||||
|
|
||||||
return render_template("packages/create_edit.html", package=package, form=form)
|
return render_template("packages/create_edit.html", package=package, form=form, author=author)
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/approve/")
|
@app.route("/<type>s/<author>/<name>/approve/")
|
||||||
@login_required
|
@login_required
|
||||||
|
Loading…
Reference in New Issue
Block a user