remove Client.published

This commit is contained in:
Son NK 2021-04-06 19:46:21 +02:00
parent e42fb0816d
commit f8540808bc
7 changed files with 43 additions and 37 deletions

View File

@ -7,13 +7,17 @@ RUN cd /code/static && npm install
# Main image
FROM python:3.7
RUN pip3 install poetry==1.0.10
# install poetry, "pip3 install poetry==1.1.5" doesn't work
# poetry will be available at /root/.poetry/bin/poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
WORKDIR /code
# install dependencies
WORKDIR /code
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false \
&& poetry install --no-root
RUN /root/.poetry/bin/poetry config virtualenvs.create false \
&& /root/.poetry/bin/poetry install --no-root
# copy npm packages
COPY --from=npm /code /code

View File

@ -35,9 +35,7 @@ def export_data():
data["custom_domains"].append(custom_domain.domain)
for app in Client.filter_by(user_id=user.id): # type: Client
data["apps"].append(
dict(name=app.name, home_url=app.home_url, published=app.published)
)
data["apps"].append(dict(name=app.name, home_url=app.home_url))
return jsonify(data)

View File

@ -1,38 +1,14 @@
"""List of clients"""
from flask import render_template, request, flash, redirect, url_for
from flask import render_template
from flask_login import current_user, login_required
from app.developer.base import developer_bp
from app.extensions import db
from app.log import LOG
from app.models import Client
@developer_bp.route("/", methods=["GET", "POST"])
@login_required
def index():
if request.method == "POST":
if request.form.get("form-name") == "switch-client-publish":
client_id = int(request.form.get("client-id"))
client = Client.get(client_id)
if client.user_id != current_user.id:
flash("You cannot modify this client", "warning")
else:
client.published = not client.published
db.session.commit()
LOG.d("Switch client.published %s", client)
if client.published:
flash(
f"Client {client.name} has been published on Discover",
"success",
)
else:
flash(f"Client {client.name} has been un-published", "success")
return redirect(url_for("developer.index"))
clients = Client.filter_by(user_id=current_user.id).all()
return render_template("developer/index.html", clients=clients)

View File

@ -842,7 +842,6 @@ class Client(db.Model, ModelMixin):
name = db.Column(db.String(128), nullable=False)
home_url = db.Column(db.String(1024))
published = db.Column(db.Boolean, default=False, nullable=False)
# user who created this client
user_id = db.Column(db.ForeignKey(User.id, ondelete="cascade"), nullable=False)
@ -853,6 +852,7 @@ class Client(db.Model, ModelMixin):
description = db.Column(db.Text, nullable=True)
icon = db.relationship(File)
user = db.relationship(User)
def nb_user(self):
return ClientUser.filter_by(client_id=self.id).count()

View File

@ -0,0 +1,29 @@
"""empty message
Revision ID: f5133dc851ee
Revises: 4912f3bd5ba2
Create Date: 2021-04-06 19:45:50.595838
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f5133dc851ee'
down_revision = '4912f3bd5ba2'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('client', 'published')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('client', sa.Column('published', sa.BOOLEAN(), autoincrement=False, nullable=False))
# ### end Alembic commands ###

View File

@ -359,15 +359,15 @@ def fake_data():
client1 = Client.create_new(name="Demo", user_id=user.id)
client1.oauth_client_id = "client-id"
client1.oauth_client_secret = "client-secret"
client1.published = True
db.session.commit()
RedirectUri.create(client_id=client1.id, uri="https://ab.com")
RedirectUri.create(
client_id=client1.id, uri="https://your-website.com/oauth-callback"
)
client2 = Client.create_new(name="Demo 2", user_id=user.id)
client2.oauth_client_id = "client-id2"
client2.oauth_client_secret = "client-secret2"
client2.published = True
db.session.commit()
ClientUser.create(user_id=user.id, client_id=client1.id, name="Fake Name")

View File

@ -13,7 +13,6 @@ def test_encode_decode(flask_app):
client1 = Client.create_new(name="Demo", user_id=user.id)
client1.oauth_client_id = "client-id"
client1.oauth_client_secret = "client-secret"
client1.published = True
db.session.commit()
client_user = ClientUser.create(client_id=client1.id, user_id=user.id)