mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
add submit for approval for app
This commit is contained in:
parent
c3d57ed6e4
commit
a90fa49636
@ -26,7 +26,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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 }}
|
{{ form.csrf_token }}
|
||||||
|
|
||||||
<h3>App Info</h3>
|
<h3>App Info</h3>
|
||||||
@ -36,13 +37,6 @@
|
|||||||
{{ render_field_errors(form.name) }}
|
{{ render_field_errors(form.name) }}
|
||||||
</div>
|
</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-group">
|
||||||
<div class="form-label">App Icon</div>
|
<div class="form-label">App Icon</div>
|
||||||
<p>
|
<p>
|
||||||
@ -55,6 +49,27 @@
|
|||||||
<img src="{{ client.icon.get_url() }}" class="client-icon">
|
<img src="{{ client.icon.get_url() }}" class="client-icon">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Update</button>
|
<button type="submit" class="btn btn-primary">Update</button>
|
||||||
</form>
|
</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 %}
|
{% endblock %}
|
@ -22,8 +22,12 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="btn-group" role="group" aria-label="Basic example">
|
<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="{{ url_for('developer.new_client') }}" class="btn btn-primary">
|
||||||
<a href="https://docs.simplelogin.io" target="_blank" class="ml-2 btn btn-secondary">Docs <i class="fe fe-external-link"></i></a>
|
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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -37,12 +41,21 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="card-title d-flex align-items-center">
|
<div class="card-title d-flex align-items-center">
|
||||||
{% if client.icon_id %}
|
{% 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 %}
|
{% endif %}
|
||||||
<span class="">
|
<span class="">
|
||||||
<a href="{{ url_for('developer.client_detail', client_id=client.id) }}">
|
<a href="{{ url_for('developer.client_detail', client_id=client.id) }}">
|
||||||
{{ client.name }}
|
{{ client.name }}
|
||||||
</a>
|
</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>
|
</span>
|
||||||
</div>
|
</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_login import current_user, login_required
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField
|
from flask_wtf.file import FileField
|
||||||
from wtforms import StringField, validators
|
from wtforms import StringField, validators, TextAreaField
|
||||||
|
|
||||||
from app import s3
|
from app import s3
|
||||||
|
from app.config import ADMIN_EMAIL
|
||||||
from app.developer.base import developer_bp
|
from app.developer.base import developer_bp
|
||||||
|
from app.email_utils import send_email
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import Client, RedirectUri, File
|
from app.models import Client, RedirectUri, File
|
||||||
@ -17,7 +19,10 @@ from app.utils import random_string
|
|||||||
class EditClientForm(FlaskForm):
|
class EditClientForm(FlaskForm):
|
||||||
name = StringField("Name", validators=[validators.DataRequired()])
|
name = StringField("Name", validators=[validators.DataRequired()])
|
||||||
icon = FileField("Icon")
|
icon = FileField("Icon")
|
||||||
home_url = StringField("Home Url")
|
|
||||||
|
|
||||||
|
class ApprovalClientForm(FlaskForm):
|
||||||
|
description = TextAreaField("Description", validators=[validators.DataRequired()])
|
||||||
|
|
||||||
|
|
||||||
# basic info
|
# basic info
|
||||||
@ -25,21 +30,22 @@ class EditClientForm(FlaskForm):
|
|||||||
@login_required
|
@login_required
|
||||||
def client_detail(client_id):
|
def client_detail(client_id):
|
||||||
form = EditClientForm()
|
form = EditClientForm()
|
||||||
|
approval_form = ApprovalClientForm()
|
||||||
|
|
||||||
is_new = "is_new" in request.args
|
is_new = "is_new" in request.args
|
||||||
|
action = request.args.get("action")
|
||||||
|
|
||||||
client = Client.get(client_id)
|
client = Client.get(client_id)
|
||||||
if not client:
|
if not client or client.user_id != current_user.id:
|
||||||
flash("no such client", "warning")
|
|
||||||
return redirect(url_for("developer.index"))
|
|
||||||
|
|
||||||
if client.user_id != current_user.id:
|
|
||||||
flash("you cannot see this app", "warning")
|
flash("you cannot see this app", "warning")
|
||||||
return redirect(url_for("developer.index"))
|
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.name = form.name.data
|
||||||
client.home_url = form.home_url.data
|
|
||||||
|
|
||||||
if form.icon.data:
|
if form.icon.data:
|
||||||
# todo: remove current icon if any
|
# 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))
|
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(
|
return render_template(
|
||||||
"developer/client_details/basic_info.html",
|
"developer/client_details/basic_info.html",
|
||||||
form=form,
|
form=form,
|
||||||
|
approval_form=approval_form,
|
||||||
client=client,
|
client=client,
|
||||||
is_new=is_new,
|
is_new=is_new,
|
||||||
)
|
)
|
||||||
|
@ -238,10 +238,11 @@ def send_email(
|
|||||||
to_email = sanitize_email(to_email)
|
to_email = sanitize_email(to_email)
|
||||||
if NOT_SEND_EMAIL:
|
if NOT_SEND_EMAIL:
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"send email with subject '%s' to '%s', plaintext: %s",
|
"send email with subject '%s' to '%s', plaintext: %s, html: %s",
|
||||||
subject,
|
subject,
|
||||||
to_email,
|
to_email,
|
||||||
plaintext,
|
plaintext,
|
||||||
|
html,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user