sso: implement populate_obj, fix membership edit form
parent
576ff1b0ea
commit
682322c980
21
sso/forms.py
21
sso/forms.py
|
@ -86,3 +86,24 @@ class ClientForm(FlaskForm):
|
||||||
default=True,
|
default=True,
|
||||||
description="User will be refused authorization to this client if their membership in Kasownik is not active",
|
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)
|
||||||
|
|
|
@ -96,7 +96,7 @@ def client_create():
|
||||||
client.client_id = str(uuid.uuid4())
|
client.client_id = str(uuid.uuid4())
|
||||||
client.client_secret = generate_token()
|
client.client_secret = generate_token()
|
||||||
client.owner_id = current_user.get_user_id()
|
client.owner_id = current_user.get_user_id()
|
||||||
client.set_client_metadata(form.data)
|
form.populate_obj(client)
|
||||||
|
|
||||||
db.session.add(client)
|
db.session.add(client)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -117,7 +117,7 @@ def client_edit(client_id):
|
||||||
form = ClientForm(obj=client)
|
form = ClientForm(obj=client)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
client.set_client_metadata(form.data)
|
form.populate_obj(client)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Client has been changed.", "success")
|
flash("Client has been changed.", "success")
|
||||||
return redirect(url_for(".client_edit", client_id=client.id))
|
return redirect(url_for(".client_edit", client_id=client.id))
|
||||||
|
|
Loading…
Reference in New Issue