aboutsummaryrefslogtreecommitdiff
path: root/app/blueprints/api/tokens.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-01-24 19:26:00 +0000
committerrubenwardy <rw@rubenwardy.com>2020-01-24 19:26:00 +0000
commit6f1472addb401bf21b0d4feb9dd755d6e8892f09 (patch)
tree0c55498c14f018fcbb49f42e4cb2390cf82c543a /app/blueprints/api/tokens.py
parent2fa2c3afec496b5d29c610dd92f788c7fd99fa66 (diff)
downloadcheatdb-6f1472addb401bf21b0d4feb9dd755d6e8892f09.tar.xz
Add ability to limit APITokens to a package
Diffstat (limited to 'app/blueprints/api/tokens.py')
-rw-r--r--app/blueprints/api/tokens.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/app/blueprints/api/tokens.py b/app/blueprints/api/tokens.py
index fcc22bb..b8da78d 100644
--- a/app/blueprints/api/tokens.py
+++ b/app/blueprints/api/tokens.py
@@ -29,6 +29,8 @@ from wtforms.ext.sqlalchemy.fields import QuerySelectField
class CreateAPIToken(FlaskForm):
name = StringField("Name", [InputRequired(), Length(1, 30)])
+ package = QuerySelectField("Limit to package", allow_blank=True, \
+ get_pk=lambda a: a.id, get_label=lambda a: a.title)
submit = SubmitField("Save")
@@ -70,6 +72,8 @@ def create_edit_token(username, id=None):
access_token = session.pop("token_" + str(id), None)
form = CreateAPIToken(formdata=request.form, obj=token)
+ form.package.query_factory = lambda: Package.query.filter_by(author=user).all()
+
if request.method == "POST" and form.validate():
if is_new:
token = APIToken()