mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 14:37:36 +01:00
Add ability for moderators to change linked accounts
This commit is contained in:
parent
b9e1be57e4
commit
c490df7f50
@ -24,14 +24,16 @@ from app.models import *
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
from wtforms.validators import *
|
from wtforms.validators import *
|
||||||
from app.utils import randomString, loginUser, rank_required
|
from app.utils import randomString, loginUser, rank_required, nonEmptyOrNone
|
||||||
from app.tasks.forumtasks import checkForumAccount
|
from app.tasks.forumtasks import checkForumAccount
|
||||||
from app.tasks.emails import sendVerifyEmail, sendEmailRaw
|
from app.tasks.emails import sendVerifyEmail, sendEmailRaw
|
||||||
from app.tasks.phpbbparser import getProfile
|
from app.tasks.phpbbparser import getProfile
|
||||||
|
|
||||||
# Define the User profile form
|
# Define the User profile form
|
||||||
class UserProfileForm(FlaskForm):
|
class UserProfileForm(FlaskForm):
|
||||||
display_name = StringField("Display name", [Optional(), Length(2, 20)])
|
display_name = StringField("Display name", [Optional(), Length(2, 100)])
|
||||||
|
forums_username = StringField("Forums Username", [Optional(), Length(2, 50)])
|
||||||
|
github_username = StringField("GitHub Username", [Optional(), Length(2, 50)])
|
||||||
email = StringField("Email", [Optional(), Email()], filters = [lambda x: x or None])
|
email = StringField("Email", [Optional(), Email()], filters = [lambda x: x or None])
|
||||||
website_url = StringField("Website URL", [Optional(), URL()], filters = [lambda x: x or None])
|
website_url = StringField("Website URL", [Optional(), URL()], filters = [lambda x: x or None])
|
||||||
donate_url = StringField("Donation URL", [Optional(), URL()], filters = [lambda x: x or None])
|
donate_url = StringField("Donation URL", [Optional(), URL()], filters = [lambda x: x or None])
|
||||||
@ -52,7 +54,7 @@ def profile(username):
|
|||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
form = None
|
form = None
|
||||||
if user.checkPerm(current_user, Permission.CHANGE_DNAME) or \
|
if user.checkPerm(current_user, Permission.CHANGE_USERNAMES) or \
|
||||||
user.checkPerm(current_user, Permission.CHANGE_EMAIL) or \
|
user.checkPerm(current_user, Permission.CHANGE_EMAIL) or \
|
||||||
user.checkPerm(current_user, Permission.CHANGE_RANK):
|
user.checkPerm(current_user, Permission.CHANGE_RANK):
|
||||||
# Initialize form
|
# Initialize form
|
||||||
@ -61,8 +63,10 @@ def profile(username):
|
|||||||
# Process valid POST
|
# Process valid POST
|
||||||
if request.method=="POST" and form.validate():
|
if request.method=="POST" and form.validate():
|
||||||
# Copy form fields to user_profile fields
|
# Copy form fields to user_profile fields
|
||||||
if user.checkPerm(current_user, Permission.CHANGE_DNAME):
|
if user.checkPerm(current_user, Permission.CHANGE_USERNAMES):
|
||||||
user.display_name = form["display_name"].data
|
user.display_name = form.display_name.data
|
||||||
|
user.forums_username = nonEmptyOrNone(form.forums_username.data)
|
||||||
|
user.github_username = nonEmptyOrNone(form.github_username.data)
|
||||||
|
|
||||||
if user.checkPerm(current_user, Permission.CHANGE_PROFILE_URLS):
|
if user.checkPerm(current_user, Permission.CHANGE_PROFILE_URLS):
|
||||||
user.website_url = form["website_url"].data
|
user.website_url = form["website_url"].data
|
||||||
|
@ -84,7 +84,7 @@ class Permission(enum.Enum):
|
|||||||
APPROVE_RELEASE = "APPROVE_RELEASE"
|
APPROVE_RELEASE = "APPROVE_RELEASE"
|
||||||
APPROVE_NEW = "APPROVE_NEW"
|
APPROVE_NEW = "APPROVE_NEW"
|
||||||
CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL"
|
CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL"
|
||||||
CHANGE_DNAME = "CHANGE_DNAME"
|
CHANGE_USERNAMES = "CHANGE_USERNAMES"
|
||||||
CHANGE_RANK = "CHANGE_RANK"
|
CHANGE_RANK = "CHANGE_RANK"
|
||||||
CHANGE_EMAIL = "CHANGE_EMAIL"
|
CHANGE_EMAIL = "CHANGE_EMAIL"
|
||||||
EDIT_EDITREQUEST = "EDIT_EDITREQUEST"
|
EDIT_EDITREQUEST = "EDIT_EDITREQUEST"
|
||||||
@ -192,7 +192,7 @@ class User(db.Model, UserMixin):
|
|||||||
# 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_AUTHOR:
|
if perm == Permission.CHANGE_AUTHOR:
|
||||||
return user.rank.atLeast(UserRank.EDITOR)
|
return user.rank.atLeast(UserRank.EDITOR)
|
||||||
elif perm == Permission.CHANGE_RANK or perm == Permission.CHANGE_DNAME:
|
elif perm == Permission.CHANGE_RANK or perm == Permission.CHANGE_USERNAMES:
|
||||||
return user.rank.atLeast(UserRank.MODERATOR)
|
return user.rank.atLeast(UserRank.MODERATOR)
|
||||||
elif perm == Permission.CHANGE_EMAIL or perm == Permission.CHANGE_PROFILE_URLS:
|
elif perm == Permission.CHANGE_EMAIL or perm == Permission.CHANGE_PROFILE_URLS:
|
||||||
return user == self or (user.rank.atLeast(UserRank.MODERATOR) and user.rank.atLeast(self.rank))
|
return user == self or (user.rank.atLeast(UserRank.MODERATOR) and user.rank.atLeast(self.rank))
|
||||||
|
@ -162,8 +162,10 @@
|
|||||||
<form action="" method="POST" class="form box-body" role="form">
|
<form action="" method="POST" class="form box-body" role="form">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
{% if user.checkPerm(current_user, "CHANGE_DNAME") %}
|
{% if user.checkPerm(current_user, "CHANGE_USERNAMES") %}
|
||||||
{{ render_field(form.display_name, tabindex=230) }}
|
{{ render_field(form.display_name, tabindex=230) }}
|
||||||
|
{{ render_field(form.forums_username, tabindex=230) }}
|
||||||
|
{{ render_field(form.github_username, tabindex=230) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.checkPerm(current_user, "CHANGE_PROFILE_URLS") %}
|
{% if user.checkPerm(current_user, "CHANGE_PROFILE_URLS") %}
|
||||||
|
@ -218,3 +218,9 @@ def isYes(val):
|
|||||||
|
|
||||||
def isNo(val):
|
def isNo(val):
|
||||||
return val and not isYes(val)
|
return val and not isYes(val)
|
||||||
|
|
||||||
|
def nonEmptyOrNone(str):
|
||||||
|
if str is None or str == "":
|
||||||
|
return None
|
||||||
|
|
||||||
|
return str
|
||||||
|
Loading…
Reference in New Issue
Block a user