Implement set user role from admin panel
This commit is contained in:
@@ -466,6 +466,15 @@ class DB:
|
|||||||
(until, user_id)
|
(until, user_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_user_role(self, user_id, role):
|
||||||
|
return self.change_one('''
|
||||||
|
update users
|
||||||
|
set role = ?
|
||||||
|
where user_id = ?
|
||||||
|
''',
|
||||||
|
(role, user_id)
|
||||||
|
)
|
||||||
|
|
||||||
def change_one(self, query, values):
|
def change_one(self, query, values):
|
||||||
db = self._db()
|
db = self._db()
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
|||||||
13
main.py
13
main.py
@@ -530,6 +530,19 @@ def admin_new_user():
|
|||||||
flash(str(e), 'error')
|
flash(str(e), 'error')
|
||||||
return redirect(url_for('admin'))
|
return redirect(url_for('admin'))
|
||||||
|
|
||||||
|
@app.route('/admin/user/<int:user_id>/edit/role/', methods = ['POST'])
|
||||||
|
def admin_set_role(user_id):
|
||||||
|
try:
|
||||||
|
role = request.form['role']
|
||||||
|
if role not in ('0', '1', '2'):
|
||||||
|
flash(f'Invalid role type ({role})', 'error')
|
||||||
|
else:
|
||||||
|
db.set_user_role(user_id, role)
|
||||||
|
flash('Set user role', 'success')
|
||||||
|
except Exception as e:
|
||||||
|
flash(str(e), 'error')
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
|
||||||
@app.route('/admin/restart/', methods = ['POST'])
|
@app.route('/admin/restart/', methods = ['POST'])
|
||||||
def admin_restart():
|
def admin_restart():
|
||||||
chk, user = _admin_check()
|
chk, user = _admin_check()
|
||||||
|
|||||||
Reference in New Issue
Block a user