sso: implement populate_obj, fix membership edit form

master
informatic 2022-04-29 22:48:21 +02:00
parent 576ff1b0ea
commit 682322c980
2 changed files with 23 additions and 2 deletions

View File

@ -86,3 +86,24 @@ class ClientForm(FlaskForm):
default=True,
description="User will be refused authorization to this client if their membership in Kasownik is not active",
)
def populate_obj(self, obj):
client_metadata_keys = [
"client_name",
"client_uri",
"redirect_uris",
"grant_types",
"response_types",
"token_endpoint_auth_method",
"scope",
]
metadata = {}
for name, field in self._fields.items():
if name in client_metadata_keys:
metadata[name] = self.data[name]
else:
field.populate_obj(obj, name)
obj.set_client_metadata(metadata)

View File

@ -96,7 +96,7 @@ def client_create():
client.client_id = str(uuid.uuid4())
client.client_secret = generate_token()
client.owner_id = current_user.get_user_id()
client.set_client_metadata(form.data)
form.populate_obj(client)
db.session.add(client)
db.session.commit()
@ -117,7 +117,7 @@ def client_edit(client_id):
form = ClientForm(obj=client)
if form.validate_on_submit():
client.set_client_metadata(form.data)
form.populate_obj(client)
db.session.commit()
flash("Client has been changed.", "success")
return redirect(url_for(".client_edit", client_id=client.id))