add submit for approval for app
This commit is contained in:
parent
c3d57ed6e4
commit
a90fa49636
|
@ -26,7 +26,8 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<form method="post" enctype="multipart/form-data"
|
||||
action="{{ url_for('developer.client_detail', client_id=client.id, action="edit") }}">
|
||||
{{ form.csrf_token }}
|
||||
|
||||
<h3>App Info</h3>
|
||||
|
@ -36,13 +37,6 @@
|
|||
{{ render_field_errors(form.name) }}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Website URL</label>
|
||||
{{ form.home_url(class="form-control", type="url", value=client.home_url or "",
|
||||
placeholder="https://mywebsite.com") }}
|
||||
{{ render_field_errors(form.home_url) }}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-label">App Icon</div>
|
||||
<p>
|
||||
|
@ -55,6 +49,27 @@
|
|||
<img src="{{ client.icon.get_url() }}" class="client-icon">
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
<h3>Submit for approval</h3>
|
||||
<p>Before your app can be used by all SimpleLogin users, it needs to go through an approval process.</p>
|
||||
|
||||
<form method="post" enctype="multipart/form-data"
|
||||
action="{{ url_for('developer.client_detail', client_id=client.id, action="submit") }}">
|
||||
{{ approval_form.csrf_token }}
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">Tell us about your app</label>
|
||||
{{ approval_form.description(
|
||||
class="form-control", rows="10",
|
||||
placeholder="This information is used for approving your application. Please give us as much info as you can, for example where you plan to use SimpleLogin, for which community, etc."
|
||||
) }}
|
||||
{{ render_field_errors(approval_form.description) }}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -22,8 +22,12 @@
|
|||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a href="{{ url_for('developer.new_client') }}" class="btn btn-primary">Create new app</a>
|
||||
<a href="https://docs.simplelogin.io" target="_blank" class="ml-2 btn btn-secondary">Docs <i class="fe fe-external-link"></i></a>
|
||||
<a href="{{ url_for('developer.new_client') }}" class="btn btn-primary">
|
||||
Create new website/app
|
||||
</a>
|
||||
<a href="https://docs.simplelogin.io" target="_blank" class="ml-2 btn btn-secondary">
|
||||
Docs <i class="fe fe-external-link"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -37,12 +41,21 @@
|
|||
<div class="card-header">
|
||||
<div class="card-title d-flex align-items-center">
|
||||
{% if client.icon_id %}
|
||||
<span class="avatar" style="background-image: url({{ client.icon.get_url() }})"></span>
|
||||
<span class="avatar mr-2" style="background-image: url({{ client.icon.get_url() }})"></span>
|
||||
{% endif %}
|
||||
<span class="">
|
||||
<a href="{{ url_for('developer.client_detail', client_id=client.id) }}">
|
||||
{{ client.name }}
|
||||
</a>
|
||||
{% if client.approved %}
|
||||
<span class="cursor" data-toggle="tooltip" data-original-title="Approved">✅</span>
|
||||
{% else %}
|
||||
<span class="cursor" data-toggle="tooltip" data-original-title="In Dev mode">
|
||||
<a href="{{ url_for('developer.client_detail', client_id=client.id) }}"
|
||||
class="text-decoration-none">🚫
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@ from flask import request, render_template, redirect, url_for, flash
|
|||
from flask_login import current_user, login_required
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField
|
||||
from wtforms import StringField, validators
|
||||
from wtforms import StringField, validators, TextAreaField
|
||||
|
||||
from app import s3
|
||||
from app.config import ADMIN_EMAIL
|
||||
from app.developer.base import developer_bp
|
||||
from app.email_utils import send_email
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import Client, RedirectUri, File
|
||||
|
@ -17,7 +19,10 @@ from app.utils import random_string
|
|||
class EditClientForm(FlaskForm):
|
||||
name = StringField("Name", validators=[validators.DataRequired()])
|
||||
icon = FileField("Icon")
|
||||
home_url = StringField("Home Url")
|
||||
|
||||
|
||||
class ApprovalClientForm(FlaskForm):
|
||||
description = TextAreaField("Description", validators=[validators.DataRequired()])
|
||||
|
||||
|
||||
# basic info
|
||||
|
@ -25,21 +30,22 @@ class EditClientForm(FlaskForm):
|
|||
@login_required
|
||||
def client_detail(client_id):
|
||||
form = EditClientForm()
|
||||
approval_form = ApprovalClientForm()
|
||||
|
||||
is_new = "is_new" in request.args
|
||||
action = request.args.get("action")
|
||||
|
||||
client = Client.get(client_id)
|
||||
if not client:
|
||||
flash("no such client", "warning")
|
||||
return redirect(url_for("developer.index"))
|
||||
|
||||
if client.user_id != current_user.id:
|
||||
if not client or client.user_id != current_user.id:
|
||||
flash("you cannot see this app", "warning")
|
||||
return redirect(url_for("developer.index"))
|
||||
|
||||
if form.validate_on_submit():
|
||||
# can't set value for a textarea field in jinja
|
||||
if request.method == "GET":
|
||||
approval_form.description.data = client.description
|
||||
|
||||
if action == "edit" and form.validate_on_submit():
|
||||
client.name = form.name.data
|
||||
client.home_url = form.home_url.data
|
||||
|
||||
if form.icon.data:
|
||||
# todo: remove current icon if any
|
||||
|
@ -61,9 +67,34 @@ def client_detail(client_id):
|
|||
|
||||
return redirect(url_for("developer.client_detail", client_id=client.id))
|
||||
|
||||
if action == "submit" and approval_form.validate_on_submit():
|
||||
client.description = approval_form.description.data
|
||||
db.session.commit()
|
||||
|
||||
send_email(
|
||||
ADMIN_EMAIL,
|
||||
subject=f"{client.name} {client.id} submits for approval",
|
||||
plaintext="",
|
||||
html=f"""
|
||||
name: {client.name} <br>
|
||||
created: {client.created_at} <br>
|
||||
user: {current_user.email} <br>
|
||||
<br>
|
||||
{client.description}
|
||||
""",
|
||||
)
|
||||
|
||||
flash(
|
||||
f"Thanks for submitting, we are informed and will come back to you asap!",
|
||||
"success",
|
||||
)
|
||||
|
||||
return redirect(url_for("developer.client_detail", client_id=client.id))
|
||||
|
||||
return render_template(
|
||||
"developer/client_details/basic_info.html",
|
||||
form=form,
|
||||
approval_form=approval_form,
|
||||
client=client,
|
||||
is_new=is_new,
|
||||
)
|
||||
|
|
|
@ -238,10 +238,11 @@ def send_email(
|
|||
to_email = sanitize_email(to_email)
|
||||
if NOT_SEND_EMAIL:
|
||||
LOG.d(
|
||||
"send email with subject '%s' to '%s', plaintext: %s",
|
||||
"send email with subject '%s' to '%s', plaintext: %s, html: %s",
|
||||
subject,
|
||||
to_email,
|
||||
plaintext,
|
||||
html,
|
||||
)
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue