Create a CMS for our project

The CMS will allow instructors to create courses and manage their content. We need to provide the following functionality:

Login to CMS
List the courses created by the instructor
Create, Edit and Delete courses
Add modules to a course and reorder them
Add different types of content to each module and reorder contents

There is an issue so far, When user is logging in the app doesn't redirect to the proper url page, witch is something like http://<IP_ADDRESS>:8000/course/mine/

Another issue: check the functionality of edit modules. There is an error that prevents edit form form saving Course Info

The last thing we need to do is to add Reordering Modules and contents ability to our CMS

This has been merge to master so i am closing it


Date format parameter not validated

Description
When defining an endpoint with a parameter in the date format, is not validated.
Expected behaviour
Should return 400 status code.
Actual behaviour
The code function is executed.
Steps to reproduce

Define an endpoint like:

   get:
     operationId: business_kpi.get_summary
     summary: Retrieves the summary of kpis for month
     parameters:
       - $ref: '#/parameters/date'
       - $ref: '#/parameters/comp_date'
     responses:
    ...

 date:
   name: date
   description: Date to query kpis
   in: query
   required: true
   type: string
   format: date

Make a request with an invalid date (ej. 123)

Additional info:
Output of the commands:

python 3.6.1
1.1.9 and 1.1.10

We have remove this because the code which implements date/time validation is not compatible with Apache license.
You can activate this validation for your application by installing pip install strict-rfc3339>=0.6. Please keep in mind that the library "strict-rfc3339" is under GPLv3. You can read more on this topic in https://github.com/zalando/connexion/pull/404.

@chimeno Please close this issue if that answer your question.

Well, after installing pip install strict-rfc3339>=0.6, date-time format is working but format date it does not work either.
Indeed there is a log:
ValueError: time data '12----' does not match format '%Y-%m-%d'
but not error is raised.

Could you send the full stack trace? Impossible to help just with this line. :)

Yep, for sure:
[2017-06-30 09:23:44,521] ERROR in app: Exception on /api/v0.5.0/kpis/summary [GET]
Traceback (most recent call last):
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/connexion/decorators/decorator.py", line 66, in wrapper
    response = function(request)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/connexion/decorators/validation.py", line 293, in wrapper
    return function(request)
  File "/Users/daniel.chimeno/Documents/projects/venv-api/lib/python3.6/site-packages/connexion/decorators/response.py", line 85, in wrapper
    response = function(request)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/connexion/decorators/decorator.py", line 42, in wrapper
    response = function(request)
  File "/Users/a/Documents/projects/venv-api/lib/python3.6/site-packages/connexion/decorators/parameter.py", line 195, in wrapper
    return function(**kwargs)
  File "/Users/a/Documents/projects/analytics-smartcomms/api/src/business_kpi.py", line 149, in get_summary
    comp_date = previous_month(date, 1)
  File "/Users/a/Documents/projects/analytics-smartcomms/api/src/utils/date.py", line 60, in previous_month
    curr = datetime.strptime(day, "%Y-%m-%d")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data '12----' does not match format '%Y-%m-%d'
2017-06-30;09:23:44;utils.logging;INFO;{'message': 'Ending FPA request', 'path': '/api/v0.5.0/kpis/summary', 'method': 'GET', 'authorization': '', 'status_code': 500, 'response': '{  "detail": "The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.",  "status": 500,  "title": "Internal Server Error",  "type": "about:blank"}'}
2017-06-30;09:23:44;tornado.access;ERROR;500 GET /api/v0.5.0/kpis/summary?date=12---- (<IP_ADDRESS>) 5.34ms

This happens with strict-rfc3339>=0.6 installed or not.

It is possible to workaround this by creating a custom format:
@draft4_format_checker.checks('customdate')
def is_custom_date(val):
    from datetime import datetime
    try:
        _ = datetime.strptime(val, '%Y-%m-%d')
    except ValueError:
        return False
    return True

Cool! Thanks for posting your solution. Maybe now we can close this issue?

Yes, we can close, but there is still an issue regarding dates and datetimes...
Feel free to close it. Thanks!

What is the issue regarding dates and datetimes?

date format is not validating either with strict-rfc3339 installed

Ok, I will investigate this later. I will leave this open for now then.

@chimeno Could you please post a snippet of your OpenAPI spec with the datetime  format parameter?

Looks like this bug is still actual.

But in mininal example it works fine:
cat openapi.yaml
openapi: 3.0.2
info:
  title: Test date
  version: 4.0.0

servers:
  - url: /4

paths:
  /alerts:
    post:
      summary: Post a new alerts
      operationId: api.post_alerts

      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Date'

      responses:
        '200':
          description: OK

components:
  schemas:
    Date:
      type: object
      properties:
        date:
          type: string
          format: date-time

cat ex.json
{"date": "sjkahdfkasjhdk"}
run
$ http POST localhost:8080/4/alerts < ex.json
HTTP/1.0 400 BAD REQUEST
Content-Length: 124
Content-Type: application/problem+json
Date: Fri, 24 May 2019 08:20:22 GMT
Server: Werkzeug/0.15.4 Python/3.6.7

{
    "detail": "'sjkahdfkasjhdk' is not a 'date-time'",
    "status": 400,
    "title": "Bad Request",
    "type": "about:blank"
}

strange

openapi: 3.0.2
info:
  title: Prometheus alerts acceptor
  version: 4.0.0

servers:
  - url: /4
    description: Same version as webhook

paths:
  /alerts:
    post:
      summary: Post a new alerts
      operationId: api.post_alerts

      requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Alert'

      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string

components:
  schemas:
    Status:
      type: string
      enum:
        - resolved
        - firing
    Alert:
      type: object
      properties:
        status:
          $ref: '#/components/schemas/Status'
        labels:
          type: object
        annotations:
          type: object
        startsAt:
          type: string
          format: date-time
        endsAt:
          type: string
          format: date-time
        generatorURL:
          type: string
          description: identifies the entity that caused the alert
      required:
        - status
# not works, investigation needed
#        - labels
#        - annotations
#        - startsAt
#        - endsAt
#        - generatorURL

    Alerts:
      type: object
      properties:
        version:
          description: API version.
          type: string
        groupKey:
          description: key identifying the group of alerts (e.g. to deduplicate)
          type: string
        status:
          $ref: "#/components/schemas/Status"
        receiver:
          description: receiver
          type: string
        groupLabels:
          description: groupLabels
          type: object
        commonLabels:
          description: commonLabels
          type: object
        commonAnnotations:
          description: commonAnnotations
          type: object
        externalURL:
          description: backlink to the Alertmanager
          type: string
        alerts:
          description: Alerts
          type: array
          items:
            $ref: "#/components/schemas/Alert"
      required:
        - version
        - groupKey
        - status
        - receiver
        - groupLabels
        - commonLabels
        - commonAnnotations
        - externalURL
        - alerts

json
{
  "version": "4",
  "groupKey": "<string>",
  "status": "resolved",
  "receiver": "<string>",
  "groupLabels": {},
  "commonLabels": {},
  "commonAnnotations": {},
  "externalURL": "<string>",
  "alerts": [
    {
     "status": "firing",
     "labels": ["ss", "ww"],
     "annotations": {},
     "startsAt": "2019-05-24T03:54:44+00:00",
     "endsAt": "ssdd",
     "generatorURL": "url://here.need"
     }
  ]
}

run
$ http POST localhost:8080/4/alerts < example.json
HTTP/1.0 200 OK
Content-Length: 2
Content-Type: text/plain; charset=utf-8
Date: Fri, 24 May 2019 08:38:27 GMT
Server: Werkzeug/0.15.4 Python/3.6.7

OK

But "endsAt" is invalid date, I can not understood what the difference

Sorry, possible my error, I will recheck an return.

As I understood it is require strict-rfc3339 module that not installs automatically from connexion deps.

I found a solution under the MIT license.
https://github.com/Julian/jsonschema/blob/9d5edb4749ab1f6194aa5c7c099c6e6fd402c4cf/jsonschema/_format.py#L305-L324
We can install the rfc3339_validator library (MIT), which is a fallback for strict-rfc3339 (GPL).

This can be done using jsonschema.


Keys

Hello,
is it possible to manage the keys separately?

Yes it is! First you need to generate a key pair using keyGen(). Both a private and a public key will be generated. If you want to save them in a file, use the functions savepublicKey(str filename) and savesecretKey(str filename). In order to recover them in a different context, just use restorepublicKey(str filename) and restoresecretKey(str filename) respectively.
FYI, the relinearization keys (required when performing a lot of multiplications without decrypting) and the rotation keys (only applicable in batch mode, to rotate values inside a ciphertext) can also be treated the same way using their respective save and restore functions.
Thanks to your question, I will be producing a Demo about key management wiht Pyfhel.