def METHOD_NAME(user_id):
    METHOD_NAME = User.query.filter_by(id=user_id).one()
    permissions = Permission.query.all()
    class UserForm(Form):
        note = StringField("Check-in note (will be shown to check-in operator)")
        add_note = SubmitField("Save Note")
        change_permissions = SubmitField("Change")
    for permission in permissions:
        setattr(
            UserForm,
            "permission_" + permission.name,
            BooleanField(
                permission.name, default=METHOD_NAME.has_permission(permission.name, False)
            ),
        )
    form = UserForm()
    if form.validate_on_submit():
        if form.change_permissions.data:
            for permission in permissions:
                field = getattr(form, "permission_" + permission.name)
                if METHOD_NAME.has_permission(permission.name, False) != field.data:
                    app.logger.info(
                        "user %s (%s) %s: %s -> %s",
                        METHOD_NAME.name,
                        METHOD_NAME.id,
                        permission.name,
                        METHOD_NAME.has_permission(permission.name, False),
                        field.data,
                    )
                    if field.data:
                        METHOD_NAME.grant_permission(permission.name)
                    else:
                        METHOD_NAME.revoke_permission(permission.name)
                    db.session.commit()
        elif form.add_note.data:
            METHOD_NAME.checkin_note = form.note.data
            db.session.commit()
        return redirect(url_for(".user", user_id=METHOD_NAME.id))
    form.note.data = METHOD_NAME.checkin_note
    return render_template(
        "admin/users/user.html", METHOD_NAME=METHOD_NAME, form=form, permissions=permissions
    )