mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Prevent users from changing the name of approved packages
This commit is contained in:
parent
b36273a848
commit
e87db8b87f
@ -76,6 +76,7 @@ class Permission(enum.Enum):
|
||||
APPROVE_CHANGES = "APPROVE_CHANGES"
|
||||
DELETE_PACKAGE = "DELETE_PACKAGE"
|
||||
CHANGE_AUTHOR = "CHANGE_AUTHOR"
|
||||
CHANGE_NAME = "CHANGE_NAME"
|
||||
MAKE_RELEASE = "MAKE_RELEASE"
|
||||
ADD_SCREENSHOTS = "ADD_SCREENSHOTS"
|
||||
APPROVE_SCREENSHOT = "APPROVE_SCREENSHOT"
|
||||
@ -572,6 +573,10 @@ class Package(db.Model):
|
||||
else:
|
||||
return user.rank.atLeast(UserRank.EDITOR)
|
||||
|
||||
# Anyone can change the package name when not approved, but only editors when approved
|
||||
elif perm == Permission.CHANGE_NAME:
|
||||
return not self.approved or user.rank.atLeast(UserRank.EDITOR)
|
||||
|
||||
# Editors can change authors and approve new packages
|
||||
elif perm == Permission.APPROVE_NEW or perm == Permission.CHANGE_AUTHOR:
|
||||
return user.rank.atLeast(UserRank.EDITOR)
|
||||
|
@ -47,7 +47,7 @@
|
||||
<div class="row">
|
||||
{{ render_field(form.type, class_="pkg_meta col-sm-2") }}
|
||||
{{ render_field(form.title, class_="pkg_meta col-sm-7") }}
|
||||
{{ render_field(form.name, class_="pkg_meta col-sm-3") }}
|
||||
{{ render_field(form.name, class_="pkg_meta col-sm-3", readonly=package.approved and not package.checkPerm(current_user, "CHANGE_NAME")) }}
|
||||
</div>
|
||||
{{ render_field(form.short_desc, class_="pkg_meta") }}
|
||||
{{ render_multiselect_field(form.tags, class_="pkg_meta") }}
|
||||
|
@ -243,6 +243,12 @@ def create_edit_package_page(author=None, name=None):
|
||||
package = Package()
|
||||
package.author = author
|
||||
wasNew = True
|
||||
|
||||
elif package.approved and package.name != form.name.data and \
|
||||
not package.checkPerm(current_user, Permission.CHANGE_NAME):
|
||||
flash("Unable to change package name", "danger")
|
||||
return redirect(url_for("create_edit_package_page", author=author, name=name))
|
||||
|
||||
else:
|
||||
triggerNotif(package.author, current_user,
|
||||
"{} edited".format(package.title), package.getDetailsURL())
|
||||
|
Loading…
Reference in New Issue
Block a user