Changeset be25db1 for src/mapservice


Ignore:
Timestamp:
Apr 22, 2019, 5:39:46 PM (8 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
041e464
Parents:
5e4cb73
Message:

Improved adding Water UI in mapservice-webclient

Location:
src/mapservice
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/codegen/code_generator

    r5e4cb73 rbe25db1  
    99fi
    1010
    11 echo "Copying static files"
    12 cp -a ../../src/templates ./
    13 cp -a ../../src/static ./
    14 mkdir -p static/css/
    15 mkdir -p static/js/
    16 mkdir -p static/resources/
    17 cp -a ../../../common/css/* static/css/
    18 cp -a ../../../common/js/* static/js/
    19 cp -a ../../../common/resources/* static/resources/
    20 cp -a ../../../../icon/gnuboat-256-256-transparent.png static/resources/
     11#echo "Copying static files"
     12#cp -a ../../src/templates ./
     13#cp -a ../../src/static ./
     14#mkdir -p static/css/
     15#mkdir -p static/js/
     16#mkdir -p static/resources/
     17#cp -a ../../common/css/* static/css/
     18#cp -a ../../common/js/* static/js/
     19#cp -a ../../common/resources/* static/resources/
     20#cp -a ../../common/icon/gnuboat-256-256-transparent.png static/resources/
    2121
     22echo "Generating backend and client API code"
    2223cd ../../
     24# backend
    2325codegen/openapi-generator-cli generate -i openapi.yaml -g python-flask -t codegen/templates/ -o src-gen
     26# client
     27#codegen/openapi-generator-cli generate -i openapi.yaml -g javascript -o src-gen/openapi_server/static/
     28#rm -R src-gen/openapi_server/static/.openapi*
     29
    2430
    2531cd src-gen/
     32tox > /tmp/openapi_tox.log
    2633python3 -m openapi_server
  • src/mapservice/codegen/templates/__init__test.mustache

    r5e4cb73 rbe25db1  
    22
    33import connexion
     4from flask_cors import CORS
    45from flask_testing import TestCase
    56
    67from {{packageName}}.encoder import JSONEncoder
    78
     9from {{packageName}}.server_impl.database.Model import db, db_test_setup
    810
    911class BaseTestCase(TestCase):
     12        def create_app(self):
     13                logging.getLogger('connexion.operation').setLevel('ERROR')
     14                app = connexion.App(__name__, specification_dir='../openapi/')
     15                application = app.app
     16                CORS(application)
     17                application.json_encoder = JSONEncoder
     18                app.add_api('openapi.yaml')
    1019
    11     def create_app(self):
    12         logging.getLogger('connexion.operation').setLevel('ERROR')
    13         app = connexion.App(__name__, specification_dir='../openapi/')
    14         app.app.json_encoder = JSONEncoder
    15         app.add_api('openapi.yaml')
    16         return app.app
     20                application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
     21                db.init_app(application)
     22                application.app_context().push()
     23               
     24                return application
     25
     26        def setUp(self):
     27                db.drop_all()
     28                db_test_setup()
     29       
     30        def tearDown(self):
     31                db.session.remove()
     32                db.drop_all()
  • src/mapservice/codegen/templates/controller_test.mustache

    r5e4cb73 rbe25db1  
    2828        {{/bodyParam}}
    2929        {{#queryParams}}
    30         {{#-first}}query_string = [{{/-first}}{{^-first}}                {{/-first}}('{{paramName}}', {{{example}}}){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}}
     30        {{#-first}}query_string = [{{/-first}}{{^-first}}                {{/-first}}('{{paramName}}', '{{{example}}}'){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}}
    3131        {{/queryParams}}
    3232        headers = { {{#vendorExtensions.x-prefered-produce}}
    3333            'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}}
    3434            'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-consume}}{{#headerParams}}
    35             '{{paramName}}': {{{example}}},{{/headerParams}}{{#authMethods}}
    36             {{#isOAuth}}'Authorization': 'Bearer special-key',{{/isOAuth}}{{#isApiKey}}'{{name}}': 'special-key',{{/isApiKey}}{{#isBasicBasic}}'Authorization': 'BasicZm9vOmJhcg==',{{/isBasicBasic}}{{#isBasicBearer}}'Authorization': 'Bearer special-key',{{/isBasicBearer}}{{/authMethods}}
     35            '{{paramName}}': '{{{example}}}',{{/headerParams}}{{#authMethods}}
     36            {{#isOAuth}}'Authorization': 'Bearer special-key',{{/isOAuth}}{{#isApiKey}}'X-API-KEY': 'test_key',{{/isApiKey}}{{#isBasicBasic}}'Authorization': 'BasicZm9vOmJhcg==',{{/isBasicBasic}}{{#isBasicBearer}}'Authorization': 'Bearer special-key',{{/isBasicBearer}}{{/authMethods}}
    3737        }
    3838        {{#formParams}}
    … …  
    4040        {{/formParams}}
    4141        response = self.client.open(
    42             '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}={{{example}}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}},
     42            '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}='{{{example}}}'{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}},
    4343            method='{{httpMethod}}',
    4444            headers=headers{{#bodyParam}},
  • src/mapservice/codegen/templates/requirements.mustache

    r5e4cb73 rbe25db1  
    66{{/supportPython2}}
    77setuptools >= 21.0.0
     8flask-sqlalchemy
     9flask-cors
  • src/mapservice/openapi.yaml

    r5e4cb73 rbe25db1  
    2323        default: v1
    2424paths:
     25  '/user':
     26    get:
     27      description: Returns information for a user
     28      tags:
     29        - users
     30      summary: Returns info of a user
     31      operationId: usersGet
     32      security:
     33        - basicAuth: []
     34        - apiKeyAuth: []
     35      responses:
     36        '200':
     37          description: OK
     38          content:
     39            application/json:
     40              schema:
     41                $ref: '#/components/schemas/User'
     42              examples:
     43                User:
     44                  $ref: '#/components/examples/User'
     45        '400':
     46          $ref: '#/components/responses/BadRequest'
     47        '401':
     48          $ref: '#/components/responses/Unauthorized'
     49    post:
     50      description: Registers a new user
     51      tags:
     52        - users
     53      summary: Registers a new user
     54      operationId: usersRegister
     55      requestBody:
     56        content:
     57          application/json:
     58            schema:
     59              $ref: '#/components/schemas/UserCreation'
     60            examples:
     61              Water:
     62                $ref: '#/components/examples/UserCreation'
     63      responses:
     64        '201':
     65          description: Userr created
     66          content:
     67            application/json:
     68              schema:
     69                $ref: '#/components/schemas/User'
     70              examples:
     71                Water:
     72                  $ref: '#/components/examples/User'
     73        '400':
     74          $ref: '#/components/responses/BadRequest'
     75    options:
     76      description: Used by CORS preflight
     77      tags:
     78        - users
     79      responses:
     80        '200':
     81          description: CORS prefilght requests should return 200 as status code
     82          content:
     83           application/json: {}
     84  '/user/apikey_create':
     85    get:
     86      description: Generates and returns a new API key for current user
     87      tags:
     88        - users
     89      summary: Returns a new API key
     90      operationId: usersApiKeyCreate
     91      security:
     92        - basicAuth: []
     93        - apiKeyAuth: []
     94      responses:
     95        '200':
     96          description: OK
     97          content:
     98            application/json:
     99              schema:
     100                $ref: '#/components/schemas/apiKeys'
     101              example: 'NewApiKey4711'
     102        '400':
     103          $ref: '#/components/responses/BadRequest'
     104        '401':
     105          $ref: '#/components/responses/Unauthorized'
     106  '/user/{api_key}':
     107    delete:
     108      description: Deletes given API key and returns remaining API keys of the user
     109      tags:
     110        - users
     111      summary: Deletes API key
     112      operationId: usersApiKeyDelete
     113      security:
     114        - basicAuth: []
     115        - apiKeyAuth: []
     116      parameters:
     117        - name: api_key
     118          in: path
     119          description: API key
     120          required: true
     121          schema:
     122            $ref: '#/components/schemas/apiKey'
     123          example: 'DelApiKey4711'
     124      responses:
     125        '200':
     126          description: OK
     127          content:
     128            application/json:
     129              schema:
     130                $ref: '#/components/schemas/apiKeys'
     131              example: 'ApiKey4711'
     132        '400':
     133          $ref: '#/components/responses/BadRequest'
     134        '401':
     135          $ref: '#/components/responses/Unauthorized'
     136  '/user/activate/{activation_code}':
     137    get:
     138      description: Activates a user account
     139      tags:
     140        - users
     141      summary: Activates a user account
     142      operationId: usersActivate
     143      parameters:
     144        - name: activation_code
     145          in: path
     146          description: Activation code
     147          required: true
     148          schema:
     149            $ref: '#/components/schemas/activationCode'
     150          example: 'dac9630aec642a428cd73f4be0a03569'
     151      responses:
     152        '302':
     153          description: OK or not OK
     154          headers:
     155            Location:
     156              schema:
     157                type: string
     158              description: URL to the website, showing the result of the activation
    25159  /waters:
    26160    get:
    … …  
    32166      parameters:
    33167        - name: name
    34           in: header
     168          in: query
    35169          schema:
    36170            $ref: '#/components/schemas/item_name'
     171          example: 'Missi'
    37172        - name: manager
    38           in: header
     173          in: query
    39174          schema:
    40175            $ref: '#/components/schemas/username'
     176          example: 'jane'
    41177        - $ref: '#/components/parameters/orderBy'
    42178        - $ref: '#/components/parameters/offset'
    … …  
    57193        - waters
    58194      summary: Add a new water
     195      operationId: watersCreate
    59196      security:
    60197        - basicAuth: []
    61198        - apiKeyAuth: []
    62199      requestBody:
    63         description: item id of water is going to be ignored
    64200        content:
    65201          application/json:
    … …  
    124260      title: Username
    125261      type: string
     262    apiKey:
     263      title: API Key
     264      type: string
     265    apiKeys:
     266      title: Array of API keys
     267      type: array
     268      items:
     269        $ref: '#/components/schemas/apiKey'
     270    activationCode:
     271      title: Activation code for a User
     272      type: string
    126273    item_id:
    127274      title: Item ID
    … …  
    131278      title: Item Name
    132279      type: string
    133     osm_type:
     280    osmType:
    134281      maxLength: 1
    135282      minLength: 1
    136283      type: string
     284    User:
     285      title: User
     286      type: object
     287      properties:
     288        username:
     289          $ref: '#/components/schemas/username'
     290        email:
     291          type: string
     292        firstName:
     293          type: string
     294        lastName:
     295          type: string
     296        activated:
     297          type: boolean
     298        apiKeys:
     299          $ref: '#/components/schemas/apiKeys'
     300    UserCreation:
     301      title: User
     302      type: object
     303      properties:
     304        username:
     305          $ref: '#/components/schemas/username'
     306        email:
     307          type: string
     308        firstName:
     309          type: string
     310        lastName:
     311          type: string
     312        password:
     313          type: string
     314      required:
     315        - username
     316        - email
     317        - firstName
     318        - lastName
     319        - password
    137320    Water:
    138321      title: Water
    139322      type: object
    140323      properties:
    141         water_id:
     324        waterId:
    142325          $ref: '#/components/schemas/item_id'
    143326        name:
    … …  
    145328        manager:
    146329          $ref: '#/components/schemas/username'
    147         osm_id:
     330        osmId:
    148331          $ref: '#/components/schemas/item_id'
    149         osm_type:
    150           $ref: '#/components/schemas/osm_type'
     332        osmType:
     333          $ref: '#/components/schemas/osmType'
    151334        osm_class:
    152           $ref: '#/components/schemas/osm_type'
     335          $ref: '#/components/schemas/osmType'
    153336      required:
    154         - water_id
     337        - waterId
    155338        - name
    156339    WaterCreation:
    … …  
    160343        name:
    161344          $ref: '#/components/schemas/item_name'
    162         osm_id:
     345        osmId:
    163346          $ref: '#/components/schemas/item_id'
    164         osm_type:
    165           $ref: '#/components/schemas/osm_type'
     347        osmType:
     348          $ref: '#/components/schemas/osmType'
    166349      required:
    167350        - name
    … …  
    202385        type: string
    203386        default: name
     387        example: 'name'
    204388    order:
    205389      name: order
    … …  
    208392      schema:
    209393        $ref: '#/components/schemas/order'
     394      example: ''
    210395    offset:
    211396      name: offset
    … …  
    231416        example: 10
    232417  examples:
     418    User:
     419      value:
     420        username: jane
     421        email: jane@example.org
     422        firstName: Jane
     423        lastName: Doe
     424        activated: true
     425        apiKeys:
     426          - ApiKey4701
     427    UserCreation:
     428      value:
     429        username: richard
     430        email: richard@examle.org
     431        firstName: Richard
     432        lastName: Roe
     433        password: sdfl.1238_ASDkeil?
    233434    Water:
    234435      value:
    235         water_id: 1
     436        waterId: 1
    236437        name: Mississippi
    237         osm_id: 1756854
    238         osm_type: R
     438        osmId: 1756854
     439        osmType: R
    239440        link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1'
    240441      summary: A water example object
    … …  
    242443      value:
    243444        name: Mississippi
    244         osm_id: 1756854
    245         osm_type: R
     445        osmId: 1756854
     446        osmType: R
    246447      summary: A water example object for creation of a water
    247448    waters:
    248449      value:
    249         - water_id: 1
     450        - waterId: 1
    250451          name: Mississippi
    251           osm_id: 1756854
    252           osm_type: R
     452          osmId: 1756854
     453          osmType: R
    253454          link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1'
    254         - water_id: 2
     455        - waterId: 2
    255456          name: Bodensee
    256457          link: 'http://gnuboat.engsas.com/mapservice/v1/waters/2'
    … …  
    293494      A water is a river (like Mississippi, lake (Lake Ontario), or a sea (North
    294495      Sea)
     496  - name: users
     497    description: >-
     498      All actions used to manage users and api keys
  • src/mapservice/src-gen/openapi_server/controllers/waters_controller.py

    r5e4cb73 rbe25db1  
    2323from openapi_server.server_impl.controllers import WatersController
    2424
     25def waters_create(water_creation=None):  # noqa: E501
     26    """Add a new water
     27
     28    Adds a new water to the database # noqa: E501
     29
     30    :param water_creation:
     31    :type water_creation: dict | bytes
     32
     33    :rtype: Water
     34    """
     35    if connexion.request.is_json:
     36        water_creation = WaterCreation.from_dict(connexion.request.get_json())  # noqa: E501
     37    return WatersController.waters_create(water_creation=water_creation)
     38
     39from openapi_server.server_impl.controllers import WatersController
     40
    2541def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None):  # noqa: E501
    2642    """Find waters by id
    … …  
    4258    """
    4359    return WatersController.waters_get(name=name, manager=manager, order_by=order_by, offset=offset, limit=limit)
    44 
    45 from openapi_server.server_impl.controllers import WatersController
    46 
    47 def waters_post(water_creation=None):  # noqa: E501
    48     """Add a new water
    49 
    50     Adds a new water to the database # noqa: E501
    51 
    52     :param water_creation: item id of water is going to be ignored
    53     :type water_creation: dict | bytes
    54 
    55     :rtype: Water
    56     """
    57     if connexion.request.is_json:
    58         water_creation = WaterCreation.from_dict(connexion.request.get_json())  # noqa: E501
    59     return WatersController.waters_post(water_creation=water_creation)
  • src/mapservice/src-gen/openapi_server/models/__init__.py

    r5e4cb73 rbe25db1  
    66from openapi_server.models.http_error import HttpError
    77from openapi_server.models.order import Order
     8from openapi_server.models.user import User
     9from openapi_server.models.user_creation import UserCreation
    810from openapi_server.models.water import Water
    911from openapi_server.models.water_creation import WaterCreation
  • src/mapservice/src-gen/openapi_server/models/water.py

    r5e4cb73 rbe25db1  
    4242
    4343        self.attribute_map = {
    44             'water_id': 'water_id',
     44            'water_id': 'waterId',
    4545            'name': 'name',
    4646            'manager': 'manager',
    47             'osm_id': 'osm_id',
    48             'osm_type': 'osm_type',
     47            'osm_id': 'osmId',
     48            'osm_type': 'osmType',
    4949            'osm_class': 'osm_class'
    5050        }
  • src/mapservice/src-gen/openapi_server/models/water_creation.py

    r5e4cb73 rbe25db1  
    3434        self.attribute_map = {
    3535            'name': 'name',
    36             'osm_id': 'osm_id',
    37             'osm_type': 'osm_type'
     36            'osm_id': 'osmId',
     37            'osm_type': 'osmType'
    3838        }
    3939
  • src/mapservice/src-gen/openapi_server/openapi/openapi.yaml

    r5e4cb73 rbe25db1  
    2525- description: A water is a river (like Mississippi, lake (Lake Ontario), or a sea (North Sea)
    2626  name: waters
     27- description: All actions used to manage users and api keys
     28  name: users
    2729paths:
     30  /user:
     31    get:
     32      description: Returns information for a user
     33      operationId: users_get
     34      responses:
     35        200:
     36          content:
     37            application/json:
     38              examples:
     39                User:
     40                  $ref: '#/components/examples/User'
     41              schema:
     42                $ref: '#/components/schemas/User'
     43          description: OK
     44        400:
     45          content:
     46            application/json:
     47              examples:
     48                HttpError:
     49                  $ref: '#/components/examples/HttpError'
     50              schema:
     51                $ref: '#/components/schemas/HttpError'
     52          description: Bad Request (400)
     53        401:
     54          content:
     55            application/json:
     56              examples:
     57                HttpError:
     58                  $ref: '#/components/examples/HttpError'
     59              schema:
     60                $ref: '#/components/schemas/HttpError'
     61          description: Unauthorized (401) acces to resource
     62      security:
     63      - basicAuth: []
     64      - apiKeyAuth: []
     65      summary: Returns info of a user
     66      tags:
     67      - users
     68      x-openapi-router-controller: openapi_server.controllers.users_controller
     69    options:
     70      description: Used by CORS preflight
     71      operationId: user_options
     72      responses:
     73        200:
     74          content:
     75            application/json: {}
     76          description: CORS prefilght requests should return 200 as status code
     77      tags:
     78      - users
     79      x-openapi-router-controller: openapi_server.controllers.users_controller
     80    post:
     81      description: Registers a new user
     82      operationId: users_register
     83      requestBody:
     84        content:
     85          application/json:
     86            examples:
     87              Water:
     88                $ref: '#/components/examples/UserCreation'
     89            schema:
     90              $ref: '#/components/schemas/UserCreation'
     91      responses:
     92        201:
     93          content:
     94            application/json:
     95              examples:
     96                Water:
     97                  $ref: '#/components/examples/User'
     98              schema:
     99                $ref: '#/components/schemas/User'
     100          description: Userr created
     101        400:
     102          content:
     103            application/json:
     104              examples:
     105                HttpError:
     106                  $ref: '#/components/examples/HttpError'
     107              schema:
     108                $ref: '#/components/schemas/HttpError'
     109          description: Bad Request (400)
     110      summary: Registers a new user
     111      tags:
     112      - users
     113      x-openapi-router-controller: openapi_server.controllers.users_controller
     114  /user/apikey_create:
     115    get:
     116      description: Generates and returns a new API key for current user
     117      operationId: users_api_key_create
     118      responses:
     119        200:
     120          content:
     121            application/json:
     122              example: NewApiKey4711
     123              schema:
     124                $ref: '#/components/schemas/apiKeys'
     125          description: OK
     126        400:
     127          content:
     128            application/json:
     129              examples:
     130                HttpError:
     131                  $ref: '#/components/examples/HttpError'
     132              schema:
     133                $ref: '#/components/schemas/HttpError'
     134          description: Bad Request (400)
     135        401:
     136          content:
     137            application/json:
     138              examples:
     139                HttpError:
     140                  $ref: '#/components/examples/HttpError'
     141              schema:
     142                $ref: '#/components/schemas/HttpError'
     143          description: Unauthorized (401) acces to resource
     144      security:
     145      - basicAuth: []
     146      - apiKeyAuth: []
     147      summary: Returns a new API key
     148      tags:
     149      - users
     150      x-openapi-router-controller: openapi_server.controllers.users_controller
     151  /user/{api_key}:
     152    delete:
     153      description: Deletes given API key and returns remaining API keys of the user
     154      operationId: users_api_key_delete
     155      parameters:
     156      - description: API key
     157        example: DelApiKey4711
     158        explode: false
     159        in: path
     160        name: api_key
     161        required: true
     162        schema:
     163          $ref: '#/components/schemas/apiKey'
     164        style: simple
     165      responses:
     166        200:
     167          content:
     168            application/json:
     169              example: ApiKey4711
     170              schema:
     171                $ref: '#/components/schemas/apiKeys'
     172          description: OK
     173        400:
     174          content:
     175            application/json:
     176              examples:
     177                HttpError:
     178                  $ref: '#/components/examples/HttpError'
     179              schema:
     180                $ref: '#/components/schemas/HttpError'
     181          description: Bad Request (400)
     182        401:
     183          content:
     184            application/json:
     185              examples:
     186                HttpError:
     187                  $ref: '#/components/examples/HttpError'
     188              schema:
     189                $ref: '#/components/schemas/HttpError'
     190          description: Unauthorized (401) acces to resource
     191      security:
     192      - basicAuth: []
     193      - apiKeyAuth: []
     194      summary: Deletes API key
     195      tags:
     196      - users
     197      x-openapi-router-controller: openapi_server.controllers.users_controller
     198  /user/activate/{activation_code}:
     199    get:
     200      description: Activates a user account
     201      operationId: users_activate
     202      parameters:
     203      - description: Activation code
     204        example: dac9630aec642a428cd73f4be0a03569
     205        explode: false
     206        in: path
     207        name: activation_code
     208        required: true
     209        schema:
     210          $ref: '#/components/schemas/activationCode'
     211        style: simple
     212      responses:
     213        302:
     214          description: OK or not OK
     215          headers:
     216            Location:
     217              description: URL to the website, showing the result of the activation
     218              explode: false
     219              schema:
     220                type: string
     221              style: simple
     222      summary: Activates a user account
     223      tags:
     224      - users
     225      x-openapi-router-controller: openapi_server.controllers.users_controller
    28226  /waters:
    29227    get:
    … …  
    31229      operationId: waters_get
    32230      parameters:
    33       - explode: false
    34         in: header
     231      - example: Missi
     232        explode: true
     233        in: query
    35234        name: name
    36235        required: false
    37236        schema:
    38237          $ref: '#/components/schemas/item_name'
    39         style: simple
    40       - explode: false
    41         in: header
     238        style: form
     239      - example: jane
     240        explode: true
     241        in: query
    42242        name: manager
    43243        required: false
    44244        schema:
    45245          $ref: '#/components/schemas/username'
    46         style: simple
     246        style: form
    47247      - description: 'Order by field: name'
    48248        explode: true
    … …  
    52252        schema:
    53253          default: name
     254          example: name
    54255          type: string
    55256        style: form
    … …  
    92293    post:
    93294      description: Adds a new water to the database
    94       operationId: waters_post
     295      operationId: waters_create
    95296      requestBody:
    96297        content:
    … …  
    101302            schema:
    102303              $ref: '#/components/schemas/WaterCreation'
    103         description: item id of water is going to be ignored
    104304      responses:
    105305        201:
    … …  
    175375components:
    176376  examples:
     377    User:
     378      value:
     379        username: jane
     380        email: jane@example.org
     381        firstName: Jane
     382        lastName: Doe
     383        activated: true
     384        apiKeys:
     385        - ApiKey4701
     386    UserCreation:
     387      value:
     388        username: richard
     389        email: richard@examle.org
     390        firstName: Richard
     391        lastName: Roe
     392        password: sdfl.1238_ASDkeil?
    177393    Water:
    178394      summary: A water example object
    179395      value:
    180         water_id: 1
     396        waterId: 1
    181397        name: Mississippi
    182         osm_id: 1756854
    183         osm_type: R
     398        osmId: 1756854
     399        osmType: R
    184400        link: http://gnuboat.engsas.com/mapservice/v1/waters/1
    185401    WaterCreation:
    … …  
    187403      value:
    188404        name: Mississippi
    189         osm_id: 1756854
    190         osm_type: R
     405        osmId: 1756854
     406        osmType: R
    191407    waters:
    192408      summary: A sample list with waters
    193409      value:
    194       - water_id: 1
     410      - waterId: 1
    195411        name: Mississippi
    196         osm_id: 1756854
    197         osm_type: R
     412        osmId: 1756854
     413        osmType: R
    198414        link: http://gnuboat.engsas.com/mapservice/v1/waters/1
    199       - water_id: 2
     415      - waterId: 2
    200416        name: Bodensee
    201417        link: http://gnuboat.engsas.com/mapservice/v1/waters/2
    … …  
    213429      schema:
    214430        default: name
     431        example: name
    215432        type: string
    216433      style: form
    … …  
    280497      title: Username
    281498      type: string
     499    apiKey:
     500      title: API Key
     501      type: string
     502    apiKeys:
     503      items:
     504        $ref: '#/components/schemas/apiKey'
     505      title: Array of API keys
     506      type: array
     507    activationCode:
     508      title: Activation code for a User
     509      type: string
    282510    item_id:
    283511      format: int32
    … …  
    287515      title: Item Name
    288516      type: string
    289     osm_type:
     517    osmType:
    290518      maxLength: 1
    291519      minLength: 1
    292520      type: string
     521    User:
     522      example:
     523        firstName: firstName
     524        lastName: lastName
     525        apiKeys:
     526        - null
     527        - null
     528        email: email
     529        username: username
     530        activated: true
     531      properties:
     532        username:
     533          title: Username
     534          type: string
     535        email:
     536          type: string
     537        firstName:
     538          type: string
     539        lastName:
     540          type: string
     541        activated:
     542          type: boolean
     543        apiKeys:
     544          items:
     545            $ref: '#/components/schemas/apiKey'
     546          title: Array of API keys
     547          type: array
     548      title: User
     549      type: object
     550    UserCreation:
     551      example:
     552        firstName: firstName
     553        lastName: lastName
     554        password: password
     555        email: email
     556        username: username
     557      properties:
     558        username:
     559          title: Username
     560          type: string
     561        email:
     562          type: string
     563        firstName:
     564          type: string
     565        lastName:
     566          type: string
     567        password:
     568          type: string
     569      required:
     570      - email
     571      - firstName
     572      - lastName
     573      - password
     574      - username
     575      title: User
     576      type: object
    293577    Water:
    294578      example:
    295         osm_id: 6
    296         osm_type: osm_type
    297579        manager: manager
     580        osmId: 6
    298581        name: name
    299         water_id: 0
     582        osmType: osmType
    300583        osm_class: osm_class
     584        waterId: 0
    301585      properties:
    302         water_id:
     586        waterId:
    303587          format: int32
    304588          title: Item ID
    … …  
    310594          title: Username
    311595          type: string
    312         osm_id:
     596        osmId:
    313597          format: int32
    314598          title: Item ID
    315599          type: integer
    316         osm_type:
     600        osmType:
    317601          maxLength: 1
    318602          minLength: 1
    … …  
    324608      required:
    325609      - name
    326       - water_id
     610      - waterId
    327611      title: Water
    328612      type: object
    329613    WaterCreation:
    330614      example:
    331         osm_id: 0
    332         osm_type: osm_type
     615        osmId: 0
    333616        name: name
     617        osmType: osmType
    334618      properties:
    335619        name:
    336620          title: Item Name
    337621          type: string
    338         osm_id:
     622        osmId:
    339623          format: int32
    340624          title: Item ID
    341625          type: integer
    342         osm_type:
     626        osmType:
    343627          maxLength: 1
    344628          minLength: 1
  • src/mapservice/src-gen/openapi_server/static/js/GnuBoat.Webserver.js

    r5e4cb73 rbe25db1  
    111111        // getting my waters
    112112        $.ajax({
    113                 headers: {
    114 //                      manager: Cookies.get('username')
    115                         manager: "bla"
    116                 },
    117113                dataType: "json",
    118                 url: GnuBoat.Webserver.private.serverBaseUrl +'waters',
     114                url: GnuBoat.Webserver.private.serverBaseUrl +'waters?manager='+ encodeURIComponent(Cookies.get('username')),
    119115        }).done(function(data) {
    120116                GnuBoat.Webserver.private.loggedin = true;
  • src/mapservice/src-gen/openapi_server/test/__init__.py

    r5e4cb73 rbe25db1  
    22
    33import connexion
     4from flask_cors import CORS
    45from flask_testing import TestCase
    56
    67from openapi_server.encoder import JSONEncoder
    78
     9from openapi_server.server_impl.database.Model import db, db_test_setup
    810
    911class BaseTestCase(TestCase):
     12        def create_app(self):
     13                logging.getLogger('connexion.operation').setLevel('ERROR')
     14                app = connexion.App(__name__, specification_dir='../openapi/')
     15                application = app.app
     16                CORS(application)
     17                application.json_encoder = JSONEncoder
     18                app.add_api('openapi.yaml')
    1019
    11     def create_app(self):
    12         logging.getLogger('connexion.operation').setLevel('ERROR')
    13         app = connexion.App(__name__, specification_dir='../openapi/')
    14         app.app.json_encoder = JSONEncoder
    15         app.add_api('openapi.yaml')
    16         return app.app
     20                application.config.from_object('openapi_server.server_impl.Config.TestingConfig')
     21                db.init_app(application)
     22                application.app_context().push()
     23               
     24                return application
     25
     26        def setUp(self):
     27                db.drop_all()
     28                db_test_setup()
     29       
     30        def tearDown(self):
     31                db.session.remove()
     32                db.drop_all()
  • src/mapservice/src-gen/openapi_server/test/test_default_controller.py

    r5e4cb73 rbe25db1  
    77from six import BytesIO
    88
    9 from openapi_server.models.water import Water  # noqa: E501
    109from openapi_server.test import BaseTestCase
    1110
    … …  
    1413    """DefaultController integration test stubs"""
    1514
    16     def test_water_get_by_id(self):
    17         """Test case for water_get_by_id
     15    def test_user_options(self):
     16        """Test case for user_options
    1817
    19         Represents a water
     18       
    2019        """
    2120        headers = {
    2221        }
    2322        response = self.client.open(
    24             '/mapservice/v1/waters/{id}'.format(id=56),
    25             method='GET',
     23            '/mapservice/v1/user',
     24            method='OPTIONS',
    2625            headers=headers)
    2726        self.assert200(response,
  • src/mapservice/src-gen/openapi_server/test/test_waters_controller.py

    r5e4cb73 rbe25db1  
    22
    33from __future__ import absolute_import
     4import unittest
    45
    56from flask import json
    67from six import BytesIO
    78
    8 from openapi_server.models.order import Order  # noqa: E501
     9from openapi_server.models.http_error import HttpError  # noqa: E501
     10from openapi_server.models.water import Water  # noqa: E501
     11from openapi_server.models.water_creation import WaterCreation  # noqa: E501
    912from openapi_server.test import BaseTestCase
    1013
    … …  
    1316    """WatersController integration test stubs"""
    1417
     18    def test_water_get_by_id(self):
     19        """Test case for water_get_by_id
     20
     21        Represents a water
     22        """
     23        headers = {
     24        }
     25        response = self.client.open(
     26            '/mapservice/v1/waters/{id}'.format(id='56'),
     27            method='GET',
     28            headers=headers)
     29        self.assert200(response,
     30                       'Response body is : ' + response.data.decode('utf-8'))
     31
     32    def test_waters_create(self):
     33        """Test case for waters_create
     34
     35        Add a new water
     36        """
     37        water_creation = WaterCreation()
     38        headers = {
     39            'X-API-KEY': 'test_key',
     40           
     41        }
     42        response = self.client.open(
     43            '/mapservice/v1/waters',
     44            method='POST',
     45            headers=headers,
     46            data=json.dumps(water_creation),
     47            content_type='application/json')
     48        self.assert200(response,
     49                       'Response body is : ' + response.data.decode('utf-8'))
     50
    1551    def test_waters_get(self):
    1652        """Test case for waters_get
    1753
    18         Waters_GET
     54        Find waters by id
    1955        """
    20         query_string = [('order_by', 'order_by_example'),
    21                         ('order', Order()),
    22                         ('offset', 0),
    23                         ('limit', 10)]
     56        query_string = [('name', 'Missi'),
     57                        ('manager', 'jane'),
     58                        ('order_by', 'name'),
     59                        ('offset', '0'),
     60                        ('limit', '10')]
     61        headers = {
     62        }
    2463        response = self.client.open(
    2564            '/mapservice/v1/waters',
    2665            method='GET',
     66            headers=headers,
    2767            query_string=query_string)
    2868        self.assert200(response,
    … …  
    3171
    3272if __name__ == '__main__':
    33     import unittest
    3473    unittest.main()
  • src/mapservice/src-gen/requirements.txt

    r5e4cb73 rbe25db1  
    33python_dateutil == 2.6.0
    44setuptools >= 21.0.0
     5flask-sqlalchemy
     6flask-cors
  • src/mapservice/src/server_impl/controllers/UsersController.py

    r5e4cb73 rbe25db1  
    2020import hashlib
    2121
    22 from ..database.Model import User, ApiKey
     22from ..database.Model import User, ApiKey, db
    2323from ..HttpErrors import BadRequest, Unauthorized, NotFound
    2424
    … …  
    5050        api_key = hashlib.md5("{}{}".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S"), user.salt).encode()).hexdigest()
    5151        user.apikeys.append(ApiKey(user=user, key=api_key))
    52                
    53         return api_key
     52        db.session.commit()
     53
     54        result = []
     55        for apiKey in user.apikeys:
     56                result.append(apiKey.key)
     57        return result
    5458
    5559def users_api_key_delete(api_key):
    … …  
    5862                return Unauthorized
    5963       
    60         if not ApiKey.query.filter_by(user=user, key=api_key).delete():
     64        if not ApiKey.query.filter_by(key=api_key).delete():
    6165                return BadRequest
     66        db.session.commit()
    6267       
    6368        result = []
    … …  
    7883       
    7984        # add api keys of the user to the result dict
    80 
    8185        result['apiKeys'] = []
    8286        for apiKey in user.apikeys:
  • src/mapservice/src/server_impl/controllers/WatersController.py

    r5e4cb73 rbe25db1  
    1818
    1919from ..database.Model import User, Water
     20from ..HttpErrors import BadRequest, Unauthorized, NotFound
    2021
    2122def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None):
    2223        query = None
     24       
    2325        if manager is not None:
    2426                manager = User.query.filter_by(username=manager).all()
    2527                if len(manager) != 1:
    26                         return NoContent, 404
     28                        return NotFound
     29                manager = manager[0]
    2730
    2831        query = None
    2932        if manager is not None:
    30                 if len(manager) == 1 and name is not None:
    31                         query = Water.query.filter_by(name = name, manager = manager[0])
    32                 elif len(manager) == 1:
    33                         query = Water.query.filter_by(manager = manager[0])
     33                if manager and name is not None:
     34                        query = Water.query.filter_by(manager = manager).filter(Water.name.like('%{}%'.format(name)))
     35                elif manager:
     36                        query = Water.query.filter_by(manager = manager)
    3437        elif name is not None:
    35                 query = Water.query.filter_by(name = name)
     38                query = Water.query.filter(Water.name.like('%{}%'.format(name)))
    3639       
    3740        if query is None:
    38                 query = Water.query.filter_by(name = '*')
     41                print("5")
     42                query = Water.query
    3943       
    4044        result = []
    41         for water in query:
     45        for water in query.offset(offset).limit(limit):
    4246                result.append(water.to_dict())
    4347        return result
  • src/mapservice/src/server_impl/database/Model.py

    r5e4cb73 rbe25db1  
    5757                return result
    5858       
    59         def password_set(self, password):
    60                 self.salt = hashlib.md5('{}{}'.format(self.username, datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest()
    61                 self.password = hashlib.md5('{}{}'.format(password, self.salt).encode()).hexdigest()
     59        def factory(username, password, email):
     60                salt = hashlib.md5('{}{}'.format(username, datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest()
     61                password = hashlib.md5('{}{}'.format(password, salt).encode()).hexdigest()
     62                activation_code = hashlib.md5('{}'.format(datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')).encode()).hexdigest()
     63                return User(username=username, password=password, email=email, salt=salt, activated=False, activation_code=activation_code)
    6264       
    6365        def password_verify(self, password):
    … …  
    8587       
    8688        def to_dict(obj):
    87                 result = { 'water_id': obj.id, 'name': obj.name }
     89                result = { 'waterId': obj.id, 'name': obj.name }
    8890                if obj.manager:
    8991                        result['manager'] = obj.manager.username
    9092                if obj.osm_id:
    91                         result['osm_id'] = obj.osm_id
     93                        result['osmId'] = obj.osm_id
    9294                if obj.osm_type:
    93                         result['osm_type'] = obj.osm_type
     95                        result['osmType'] = obj.osm_type
    9496                if obj.osm_class:
    95                         result['osm_class'] = obj.osm_class
     97                        result['osmClass'] = obj.osm_class
    9698                return result
    9799
    … …  
    118120                with db.session.no_autoflush:
    119121                        if len(User.query.filter_by(username='john').all()) < 1:
    120                                 test_user_john = User(username='john', email='john@example.org', activated=False, activation_code='dac9630aec642a428cd73f4be0a03569')
    121                                 test_user_john.password_set('testpass2')
     122                                test_user_john = User.factory('john', 'testpass2', 'john@example.org')
     123                                test_user_john.activation_code = 'dac9630aec642a428cd73f4be0a03569'
    122124                                db.session.add(test_user_john)
    123125                       
    124                         test_user_jane = User(username='jane', email='jane@example.org', activated=True)
    125                         test_user_jane.password_set('testpass')
     126                        test_user_jane = User.factory('jane', 'testpass', 'jane@example.org')
     127                        test_user_jane.activated = True
     128                        test_user_jane.first_name = 'Jane'
    126129                        test_key_del = ApiKey(user=test_user_jane, key='DelApiKey4711')
    127130                        db.session.add(test_key_del)
  • src/mapservice/src/server_impl/tests/test_users.py

    r5e4cb73 rbe25db1  
    2121from openapi_server.test import BaseTestCase
    2222
    23 class TestDefaultController(BaseTestCase):
     23class TestUsers(BaseTestCase):
    2424        def test_users_get(self):
    2525                headers = {}
    … …  
    3636                assert response.status_code == 200
    3737                data = json.loads(response.data)
    38                 self.check_key("user_id", 2, data)
    3938                self.check_key("username", "jane", data)
    40                 self.check_key("first_name", "", data)
    41                 self.check_key("last_name", "", data)
     39                self.check_key("firstName", "Jane", data)
     40                self.check_key("lastName", "", data)
    4241                self.check_key("email", "jane@example.org", data)
    4342                self.check_key("activated", True, data)
    4443               
    45                 assert "api_keys" in data
    46                 assert data["api_keys"][0] == "test_key"
    47                 assert data["api_keys"][1] == "ApiKey4712"
     44                assert "apiKeys" in data
     45                assert data["apiKeys"][0] == "DelApiKey4711"
     46                assert data["apiKeys"][1] == "test_key"
     47                assert data["apiKeys"][2] == "ApiKey4712"
    4848               
    4949                assert "password" not in data
    … …  
    5555               
    5656        def check_key(self, key, value, data):
    57                 assert key in data
    58                 assert data[key] == value
     57                if not key in data: raise AssertionError(print("{} not in data {}".format(key, data)))
     58                if data[key] != value: raise AssertionError(print("{} = {}".format(value, data[key])))
    5959
    6060if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.