Skip to content

Commit

Permalink
Merge pull request #95 from zemfrog/dev
Browse files Browse the repository at this point in the history
Merge 'dev' to 'master'
  • Loading branch information
aprilahijriyan committed Apr 7, 2021
2 parents 39b5db0 + 138c0e9 commit 462049c
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 37 deletions.
6 changes: 4 additions & 2 deletions .pyup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# autogenerated pyup.io config file
# see https://pyup.io/docs/configuration/ for all available options

schedule: ''
update: false
schedule: 'every day'
update: insecure
branch: dev
label_prs: pyup-update
16 changes: 0 additions & 16 deletions docs/fileupload.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Welcome to zemfrog's documentation!
installation
usage
auth
fileupload
user_management
rbac
contributing
Expand Down
6 changes: 3 additions & 3 deletions docs/rbac.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ All you need is to add an authenticate decorator with a roles to the view, like
@authenticate(roles={"admin": []})
# your view here...

For example, edit the ``read`` view decorator in the ``apis/user.py`` file, as follows::
For example, edit the ``read`` view in the ``apis/user.py`` file and add the ``authenticate`` decorator, as follows::

@authenticate(roles={"admin": []})
@marshal_with(ReadUserSchema(many=True), 200)
@marshal_with(200, ReadUserSchema(many=True))
def read():
"""
Read all data.
Expand All @@ -65,7 +65,7 @@ First you have to create role permissions first::
And add permission to the ``authenticate`` decorator, for example::

@authenticate(roles={"admin": ["can_all"]})
@marshal_with(ReadUserSchema(many=True), 200)
@marshal_with(200, ReadUserSchema(many=True))
def read():
"""
Read all data.
Expand Down
21 changes: 9 additions & 12 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ The application structure is as follows::
├── Procfile
├── README.rst
├── requirements.txt
├── urls.py
├── views.py
└── wsgi.py

* ``apis`` - This directory is for all REST API resources.
Expand All @@ -44,8 +42,6 @@ The application structure is as follows::
* ``Procfile`` - Configuration file for deploying on heroku.
* ``README.rst`` - A short description of how to run zemfrog applications.
* ``requirements.txt`` - List of application dependencies.
* ``urls.py`` - List your application endpoints.
* ``views.py`` - List of your app view functions.
* ``wsgi.py`` - Flask application here.

Assume if you already installed virtualenv and go run the application::
Expand All @@ -68,10 +64,12 @@ There are several configurations in the zemfrog application, including:
* ``ERROR_HANDLERS`` - List of error handlers.
* ``MIDDLEWARES`` - List of middleware here.
* ``APIS`` - List your REST API resources here.
* ``API_DOCS`` - Configuration for automation creates REST API documentation using ``flask-apispec``. Default value is ``True``.
* ``API_DOCS`` - Configuration for automation creates REST API documentation using ``flask-smorest``. Default value is ``True``.
* ``CREATE_DB`` - Configuration for automation creates tables of all models. Default value is ``True``, but I will remove this configuration in the future.
* ``APISPEC_SECURITY_DEFINITIONS`` - Follow this https://swagger.io/docs/specification/authentication/.
* ``APISPEC_SECURITY_PARAMS`` - Follow this https://swagger.io/docs/specification/authentication/
* ``API_PREFIX`` - URL prefix for all endpoints in the ``apis`` directory.
* ``API_SECURITY_DEFINITIONS`` - Follow this https://swagger.io/docs/specification/authentication/.
* ``API_SECURITY_PARAMS`` - Follow this https://swagger.io/docs/specification/authentication/
* ``API_SPEC_OPTIONS`` - See here https://flask-smorest.readthedocs.io/en/latest/openapi.html#populate-the-root-document-object
* ``APPS`` - List of sub applications.
* ``TASKS`` - Celery task list.
* ``STATICFILES`` - List of static files to serve.
Expand Down Expand Up @@ -259,15 +257,14 @@ Let's start by creating an API resource::

Now you have the article API resource::

api
apis
├── article.py
├── __init__.py

In the article API resource there are variables ``docs``, ``endpoint``, ``url_prefix`` and ``routes``.

The following are the variables in the API article (on the last line):

* ``docs`` - For your REST API documentation, see `here <https://flask-apispec.readthedocs.io/en/latest/api_reference.html#flask_apispec.annotations.doc>`_.
* ``endpoint`` - For naming your view function. So if the view name is ``add`` then it will become ``article_add``.
* ``tag`` - API name (which is the name of the blueprint).
* ``description`` - API description.
* ``url_prefix`` - URL prefix for the API resource.
* ``routes`` - All of your API endpoints.

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ flask-mail
flask-shell-ipython
marshmallow-sqlalchemy
python-dotenv
click
celery==5.0.2
marshmallow
sqlalchemy-utils
Expand Down
4 changes: 4 additions & 0 deletions zemfrog/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def create_app(*args, **kwds) -> Scaffold:
prefix = dirname + "."
with app.app_context():
load_config(app)
api_docs = app.config.get("API_DOCS", True)
if not api_docs:
app.config["OPENAPI_URL_PREFIX"] = None

for name in app.config.get(dirname.upper(), []):
yourloader = name
if not name.startswith(prefix):
Expand Down
2 changes: 1 addition & 1 deletion zemfrog/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def marshal_with(*args, **kwds) -> Callable:
See here https://flask-smorest.readthedocs.io/en/latest/response.html#
"""

wrapper = ResponseMixin().response(*args, **kwds)
wrapper = ResponseMixin().alt_response(*args, **kwds)
return wrapper


Expand Down
5 changes: 3 additions & 2 deletions zemfrog/loaders/multiapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
from typing import Dict, List

import click
Expand All @@ -22,7 +23,7 @@ def loader(app: Flask):

name = a["name"]
path = a.get("path", "/" + name)
help = a.get("help", "")
help = a.get("help", f"{name.title()} App")
yourapp: Flask = import_attr(name + ".wsgi.app")

@click.command(name, context_settings=dict(ignore_unknown_options=True))
Expand All @@ -33,7 +34,7 @@ def cli(repl, args):
if repl:
build_repl(yourapp)
else:
os.system("flask " + " ".join(args))
subprocess.call(["flask"] + list(args))

cli.help = help
app.cli.add_command(cli)
Expand Down

0 comments on commit 462049c

Please sign in to comment.