diff --git a/docs/install/debug.md b/docs/install/debug.md new file mode 100644 index 0000000..bf8b4b7 --- /dev/null +++ b/docs/install/debug.md @@ -0,0 +1,29 @@ + +# Debug + +You can activate the **debug mode** by manually editing the configuration file `lizmap/var/config/gobsapi.ini.php` +and modify the variable `log_api_calls' with the `debug` value: + +```ini +[gobsapi] +log_api_calls=debug +``` + +You will then be able to see the API calls log written in the file `lizmap/var/log/messages.log` + +```bash +tail -f lizmap/var/log/messages.log +``` + +Messages will be like + +``` +2021-02-09 17:18:52 127.0.0.1 default GOBSAPI - ################ +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - path: getProjectByKey +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - input_data: {"projectKey":"lizmapdemo~a_fake_project","module":"gobsapi","action":"project:getProjectByKey"} +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - http_code: 404 +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - status: error +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - message: The given project key does not refer to a known project +2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - ################ + +``` diff --git a/docs/install/index.md b/docs/install/index.md index 8e31db9..b95dd27 100644 --- a/docs/install/index.md +++ b/docs/install/index.md @@ -1,412 +1,4 @@ -# Installation -## Lizmap Web Client gobsapi module - -NB: all the path given are relative to your Lizmap Web Client instance folder. - -* Copy the `gobsapi` directory inside the `lizmap/lizmap-modules/` of a working - Lizmap Web Client instance to have a new `lizmap/lizmap-modules/gobsapi/` folder - containing the files `module.xml`, `events.xml`, and folders. - -* Then modify the file `lizmap/var/config/localconfig.ini.php` - to add `gobsapi.access=2` in the `[modules]` section, such as - -```ini -[modules] -gobsapi.access=2 - -``` - -### For Lizmap Web Client <= 3.4.x - -* You need to manually edit the file `lizmap/projects.xml` - and add the following content inside the `` section - -```xml - -``` - -Afterwards, you should have a content like this in the `entrypoints` section - -```xml - - - - - - -``` - -* Copy the folder `gobsapi/install/gobsapi` inside the Lizmap folder `lizmap/var/config/` - to have a new folder `lizmap/var/config/gobsapi` with a file `config.ini.php` inside - -```bash -cp -R lizmap/lizmap-modules/gobsapi/install/gobsapi lizmap/var/config/gobsapi -``` - -* Copy the file `gobsapi/install/gobsapi.php` inside the `lizmap/www/` folder - -```bash -cp -R lizmap/lizmap-modules/gobsapi/install/gobsapi.php lizmap/www/ -``` - -### For Lizmap Web Client >= 3.5.x - -You do not need to copy, modify or create files, everything is done by the module installer. - -### Run the Lizmap Web Client installer - -* Then you need to run the Lizmap installer - -```bash -lizmap/install/set_rights.sh -lizmap/install/clean_vartmp.sh -php lizmap/install/installer.php -``` - -## Authentication driver - -If your Lizmap Web Client uses **SAMLv2** to authenticate the users, -you need to force the `gobsapi` module to use another driver. -The `SAML` protocol is based on URL redirections, which are not suitable for the G-Obs API end point. - -You can override the configuration to force the `gobsapi.php` entry point to use another driver. -To do so, you must first edit the file `localconfig.ini.php` and change the `[module]` section into: - -```ini -[modules] -;; uncomment it if you want to use ldap for authentication -;; see documentation to complete the ldap configuration -ldapdao.access=0 -lizmap.installparam= -multiauth.access=0 - -;; we deactivate gobs & saml which must be activated -;; only for the entry points index and admin -;; by editing their configuration files lizmap/var/config/index/config.ini.php -;; and lizmap/var/config/admin/config.ini.php -gobs.access=0 -saml.access=0 -;; we then activate the gobsapi module -gobsapi.access=2 -``` - -We have deactivated gobs & saml in the main config (localconfig): -they must now be activated **only** for the entry points **index** and **admin** -by editing their configuration files `lizmap/var/config/index/config.ini.php` and `lizmap/var/config/admin/config.ini.php`. - -Example contents: - -* for the index entrypoint: - - -```ini -; -;for security reasons , don't remove or modify the first line - -startModule=view -startAction="default:index" - -[coordplugins] -jacl2=1 - -saml="saml/saml.coord.ini.php" -saml.name=auth - -[modules] -dataviz.access=2 -dynamicLayers.access=2 -jelix.access=2 -lizmap.access=2 -view.access=2 -filter.access=2 -action.access=2 - -jacl2db_admin.access=1 -jauthdb_admin.access=1 -master_admin.access=1 - -saml.access=2 -saml.installparam="localconfig;useradmin=mdouchin;emailadmin=mdouchin@3liz.com" -saml.path="app:my-packages/vendor/jelix/saml-module/saml" -gobs.access=2 - -[coordplugin_auth] -;; uncomment it if you want to use ldap for authentication -;; see documentation to complete the ldap configuration -driver=saml -``` - -* for the admin entrypoint: - -```ini -; -;for security reasons , don't remove or modify the first line - -startModule=master_admin -startAction="default:index" - -[responses] -html=adminHtmlResponse -htmlauth=adminLoginHtmlResponse - -[modules] -admin.access=2 -jauthdb_admin.access=2 -jacl2db_admin.access=2 -master_admin.access=2 -jcommunity.access=2 - -saml.access=2 -saml.installparam="localconfig;useradmin=mdouchin;emailadmin=mdouchin@3liz.com" -saml.path="app:my-packages/vendor/jelix/saml-module/saml" -gobs.access=2 - -[coordplugins] -jacl2=1 - -saml="saml/saml.coord.ini.php" -saml.name=auth - -[coordplugin_auth] -;; uncomment it if you want to use ldap for authentication -;; see documentation to complete the ldap configuration -driver=saml - -``` - -* for the gobsapi entrypoint: - -```ini -[modules] -jelix.access=1 -lizmap.access=1 -view.access=1 - -jacl2db_admin.access=1 -jauthdb_admin.access=1 -master_admin.access=1 - -;; on active le module gobsapi -gobsapi.access=2 - -;; et ldapdao -ldapdao.access=1 -jacl2.access=1 -jauth.access=1 -jauthdb.access=1 - -[coordplugins] -jacl2=1 -auth="gobsapi/auth.coord.ini.php" - -[coordplugin_jacl2] -on_error=2 -error_message="jacl2~errors.action.right.needed" -on_error_action="jelix~error:badright" - -``` - - -## Test the API - -Then you are ready to test. For example with curl (you need curl to pass JWT token in Authorization header). -Full API Documentation is available: https://docs.3liz.org/lizmap-gobsapi-module/api/ - -You can find examples in the [tests folder]() - -In the following examples, we use `http://lizmap.localhost/` as the base URL: - -* Define the API base URL: - -```bash -BASEURL="http://lizmap.localhost/gobsapi.php" -``` - -### User - -* Log in - -```bash -# login -# we get the authentication TOKEN variable by first log the user in -TOKEN=$(curl -s -X GET -H 'Content-Type: application/json' "$BASEURL/user/login?username=gobsapi_writer&password=al_password" | jq -r '.token') && echo $TOKEN -``` - -returns the token, for example - -``` -dacf5135c6686417c3916a649adbd146 -``` - -* Get the user projects - -```bash -# User Projects -# we use the $TOKEN variable in the Authorization header -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/user/projects) -``` - -* Log out - -```bash -# logUserOut -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/user/logout) -``` - - -### Project - -* Get a project details - -```bash -# getProjectByKey -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/test_project_a) -``` - -* Get the list of indicators - -```bash -# getProjectIndicators -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/test_project_a/indicators) -``` -returns - -* Get the project Geopackage - -```bash -# getProjectGeopackage -curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/geopackage --output /tmp/test.gpkg -``` -returns the binary file and save it to `/tmp/test.gpkg` - -### Indicator - -* Get an indicator data -* -```bash -# getIndicatorByCode -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/test_project_a/indicator/hiker_position) -``` -` - -* Get the observation of a given indicator between two dates - -```bash -# getObservationsByIndicator -# between seven days ago and now -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "lastSyncDate: $(date '+%Y-%m-%d %H:%M:%S' -d '7 days ago')" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/observations) -``` - -returns all the matching observations. - - -* Get the deleted observation on the server between two dates - -```bash -# getDeletedObservationsByIndicator -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "lastSyncDate: $(date '+%Y-%m-%d %H:%M:%S' -d '13 days ago')" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/deletedObservations) -``` - -returns a list of the deleted observation uids - -```json -["98020996-2dec-4cbe-93d7-c2ba1b43b871","230d5b17-96b3-4bad-8c78-6379f1e9b1c6","ced021b2-6eda-4a80-8903-b013291a6b2d","2d198922-5cd0-4d0f-bc96-dfcc17c01ced","1fc001b6-c147-49ef-ae6e-66f8ea5e0b39"] -``` - -* Get the indicator documents - -```bash -# getIndicatorDocument -curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/document/946fee64-e86c-40fa-a55e-8d9ad3579734 --output /tmp/test.jpeg -``` - -### Observation - -* Create a new observation -* -```bash -# createObservation -echo $(curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: application/json" -d "{\"id\":null,\"indicator\":\"hiker_position\",\"uuid\":null,\"start_timestamp\":\"2019-07-19 03:30:00\",\"end_timestamp\":null,\"coordinates\":{\"x\":-3.785956510771293,\"y\":48.4744332531894},\"wkt\":\"POINT(-3.78595651077129 48.4744332531894)\",\"values\":[125],\"photo\":null,\"created_at\":null,\"updated_at\":null}" "$BASEURL/project/test_project_a/indicator/hiker_position/observation") -``` - - -* Update an existing observation - -```bash -# updateObservation -echo $(curl -X PUT -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: application/json" -d "{\"id\":1,\"indicator\":\"hiker_position\",\"uuid\":\"e8f0a46c-1d24-456a-925a-387740ade1c6\",\"start_timestamp\":\"2019-07-16 03:35:00\",\"end_timestamp\":null,\"coordinates\":{\"x\":-3.785956510771293,\"y\":48.4744332531894},\"wkt\":\"POINT(-3.78595651077999 48.4744332531999)\",\"values\":[1.2],\"photo\":null,\"created_at\":\"2020-12-03 15:04:40\",\"updated_at\":\"2020-12-03 17:55:59\"}" "$BASEURL/project/test_project_a/indicator/hiker_position/observation") -``` - -* Get an observation data - -```bash -# getObservationById -echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6) -``` - - -* Delete an observation - -```bash -# deleteObservationById -echo $(curl -X DELETE -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6) -``` - - -### Observation media - -* Upload a media for a given observation - -```bash -# uploadObservationMedia -echo $(curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: multipart/form-data" -F "mediaFile=@/home/mdouchin/Documents/3liz/mdouchin_carre.jpeg;type=image/jpeg" $BASEURL/project/test_project_a/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/uploadMedia) -``` - - -* Delete an observation media - -```bash -# deleteObservationMedia -echo $(curl -X DELETE -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/deleteMedia) -``` - - -* Download an observation media - -```bash -# getObservationMedia -curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/test_project_a/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/media --output /tmp/test.jpeg -``` - -returns the media file in binary and save it to `/tmp/test.jpeg` - - -## Debug - -You can activate the **debug mode** by manually editing the configuration file `lizmap/var/config/gobsapi.ini.php` -and modify the variable `log_api_calls' with the `debug` value: - -```ini -[gobsapi] -log_api_calls=debug -``` - -You will then be able to see the API calls log written in the file `lizmap/var/log/messages.log` - -```bash -tail -f lizmap/var/log/messages.log -``` - -Messages will be like - -``` -2021-02-09 17:18:52 127.0.0.1 default GOBSAPI - ################ -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - path: getProjectByKey -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - input_data: {"projectKey":"lizmapdemo~a_fake_project","module":"gobsapi","action":"project:getProjectByKey"} -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - http_code: 404 -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - status: error -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - message: The given project key does not refer to a known project -2021-02-09 17:19:05 127.0.0.1 default GOBSAPI - ################ - -``` +- [Installing into Lizmap 3.6 and 3.7](lizmap-3.6.md) +- [Testing the API](test-api.md) +- [Enabling debug mode](debug.md) diff --git a/docs/install/lizmap-3.6.md b/docs/install/lizmap-3.6.md new file mode 100644 index 0000000..d87eb94 --- /dev/null +++ b/docs/install/lizmap-3.6.md @@ -0,0 +1,95 @@ +# Installation for Lizmap 3.6+ + + +## Lizmap Web Client gobsapi module + +NB: all the path given are relative to your Lizmap Web Client instance folder. + +### installing source code from a zip + +Copy the `gobsapi` directory inside the `lizmap/lizmap-modules/` of a working +Lizmap Web Client instance to have a new `lizmap/lizmap-modules/gobsapi/` folder +containing the files `module.xml`, `events.xml`, and folders. + +### installing source code with Composer + +If you have Composer (the package manager for PHP), `lizmap/my-packages/` and +create the composer.json file if it does not exist: + +```bash +cp lizmap/my-packages/composer.json.dist lizmap/my-packages/composer.json +``` + +Then declare the package of the gobsapi module: + +```bash +composer --working-dir=lizmap/my-packages/ require "lizmap/lizmap-gobsapi-module" +``` + +### Run the Lizmap Web Client installer + +* Enable the module by running the configurator of lizmap + +```bash +php lizmap/install/configurator.php gobsapi +``` + +* Then you need to run the Lizmap installer + +```bash +lizmap/install/set_rights.sh +lizmap/install/clean_vartmp.sh +php lizmap/install/installer.php +``` + +## Authentication driver + +If your Lizmap Web Client uses **SAMLv2** to authenticate the users, +you need to force the `gobsapi` module to use another driver. +The `SAML` protocol is based on URL redirections, which are not suitable for the G-Obs API end point. + +In the file `lizmap/var/config/gobsapi/config.ini.php`, set these parameters: + +```ini +[coordplugins] +auth="gobsapi/auth.coord.ini.php" +saml=0 +[coordplugin_auth] +driver=db +``` + +And create the file `lizmap/var/config/gobsapi/auth.coord.ini.php`, containing: + +```ini +; +;for security reasons , don't remove or modify the first line +driver=Db +session_name=JELIX_USER +secure_with_ip=0 +timeout=0 +auth_required=off +on_error=2 +error_message="jcommunity~login.error.notlogged" +on_error_action="jcommunity~login:out" +bad_ip_action="jcommunity~login:out" +on_error_sleep=0 +after_login="view~default:index" +after_logout="jcommunity~login:index" +enable_after_login_override=on +enable_after_logout_override=on +persistant_enable=on +persistant_cookie_name=LizmapSession +persistant_duration=1 +password_hash_method=1 +password_hash_options= + +[Db] +dao="lizmap~user" +profile=jauth +password_crypt_function=sha1 +form="lizmap~account_admin" +userform="lizmap~account" +uploadsDirectory= +``` + + diff --git a/docs/install/test-api.md b/docs/install/test-api.md new file mode 100644 index 0000000..4652b83 --- /dev/null +++ b/docs/install/test-api.md @@ -0,0 +1,174 @@ + +# Test the API + +Then you are ready to test. For example with curl (you need curl to pass JWT token in Authorization header). +Full API Documentation is available: https://docs.3liz.org/lizmap-gobsapi-module/api/ + +You can find examples in the [tests folder]() + +In the following examples, we use `http://lizmap.localhost/` as the base URL: + +* Define the API base URL: + +```bash +BASEURL="http://lizmap.localhost/gobsapi.php" +``` + +## User + +* Log in + +```bash +# login +# we get the authentication TOKEN variable by first log the user in +TOKEN=$(curl -s -X GET -H 'Content-Type: application/json' "$BASEURL/user/login?username=gobsapi_writer&password=al_password" | jq -r '.token') && echo $TOKEN +``` + +returns the token, for example + +``` +dacf5135c6686417c3916a649adbd146 +``` + +* Get the user projects + +```bash +# User Projects +# we use the $TOKEN variable in the Authorization header +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/user/projects) +``` + +* Log out + +```bash +# logUserOut +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/user/logout) +``` + + +## Project + +* Get a project details + +```bash +# getProjectByKey +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/gobsapi~gobsapi) +``` + +* Get the list of indicators + +```bash +# getProjectIndicators +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/gobsapi~gobsapi/indicators) +``` +returns + +* Get the project Geopackage + +```bash +# getProjectGeopackage +curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/geopackage --output /tmp/test.gpkg +``` +returns the binary file and save it to `/tmp/test.gpkg` + +## Indicator + +* Get an indicator data +* +```bash +# getIndicatorByCode +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position) +``` +` + +* Get the observation of a given indicator between two dates + +```bash +# getObservationsByIndicator +# between seven days ago and now +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "lastSyncDate: $(date '+%Y-%m-%d %H:%M:%S' -d '7 days ago')" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observations) +``` + +returns all the matching observations. + + +* Get the deleted observation on the server between two dates + +```bash +# getDeletedObservationsByIndicator +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "lastSyncDate: $(date '+%Y-%m-%d %H:%M:%S' -d '13 days ago')" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/deletedObservations) +``` + +returns a list of the deleted observation uids + +```json +["98020996-2dec-4cbe-93d7-c2ba1b43b871","230d5b17-96b3-4bad-8c78-6379f1e9b1c6","ced021b2-6eda-4a80-8903-b013291a6b2d","2d198922-5cd0-4d0f-bc96-dfcc17c01ced","1fc001b6-c147-49ef-ae6e-66f8ea5e0b39"] +``` + +* Get the indicator documents + +```bash +# getIndicatorDocument +curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/document/946fee64-e86c-40fa-a55e-8d9ad3579734 --output /tmp/test.jpeg +``` + +## Observation + +* Create a new observation +* +```bash +# createObservation +echo $(curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: application/json" -d "{\"id\":null,\"indicator\":\"hiker_position\",\"uuid\":null,\"start_timestamp\":\"2019-07-19 03:30:00\",\"end_timestamp\":null,\"coordinates\":{\"x\":-3.785956510771293,\"y\":48.4744332531894},\"wkt\":\"POINT(-3.78595651077129 48.4744332531894)\",\"values\":[125],\"photo\":null,\"created_at\":null,\"updated_at\":null}" "$BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation") +``` + + +* Update an existing observation + +```bash +# updateObservation +echo $(curl -X PUT -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: application/json" -d "{\"id\":1,\"indicator\":\"hiker_position\",\"uuid\":\"e8f0a46c-1d24-456a-925a-387740ade1c6\",\"start_timestamp\":\"2019-07-16 03:35:00\",\"end_timestamp\":null,\"coordinates\":{\"x\":-3.785956510771293,\"y\":48.4744332531894},\"wkt\":\"POINT(-3.78595651077999 48.4744332531999)\",\"values\":[1.2],\"photo\":null,\"created_at\":\"2020-12-03 15:04:40\",\"updated_at\":\"2020-12-03 17:55:59\"}" "$BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation") +``` + +* Get an observation data + +```bash +# getObservationById +echo $(curl -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6) +``` + + +* Delete an observation + +```bash +# deleteObservationById +echo $(curl -X DELETE -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6) +``` + + +## Observation media + +* Upload a media for a given observation + +```bash +# uploadObservationMedia +echo $(curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" -H "Content-Type: multipart/form-data" -F "mediaFile=@/home/mdouchin/Documents/3liz/mdouchin_carre.jpeg;type=image/jpeg" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/uploadMedia) +``` + + +* Delete an observation media + +```bash +# deleteObservationMedia +echo $(curl -X DELETE -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/deleteMedia) +``` + + +* Download an observation media + +```bash +# getObservationMedia +curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" -H "requestSyncDate: $(date '+%Y-%m-%d %H:%M:%S')" $BASEURL/project/gobsapi~gobsapi/indicator/hiker_position/observation/e8f0a46c-1d24-456a-925a-387740ade1c6/media --output /tmp/test.jpeg +``` + +returns the media file in binary and save it to `/tmp/test.jpeg` + diff --git a/gobsapi/controllers/observation.classic.php b/gobsapi/controllers/observation.classic.php index a00a3b5..fa642ae 100644 --- a/gobsapi/controllers/observation.classic.php +++ b/gobsapi/controllers/observation.classic.php @@ -152,6 +152,11 @@ private function checkBodyActions($from) { // Parameters $body = $this->request->readHttpBody(); + if ($body && !is_string($body)) { + // FIXME, Lizmap 3.6/jelix 1.8 decode automatically json data + // we should avoid to do this, by modifying Observation.... + $body = json_encode($body); + } $observation_uid = null; $gobs_observation = new Observation($this->user, $this->indicator, $observation_uid, $body); diff --git a/gobsapi/install/configure.php b/gobsapi/install/configure.php new file mode 100644 index 0000000..a44f8cb --- /dev/null +++ b/gobsapi/install/configure.php @@ -0,0 +1,52 @@ +havingName( + 'gobsapi', + array( + new MapInclude('urls.xml'), + ) + ) + ; + } + + public function getEntryPointsToCreate() + { + return array( + new \Jelix\Installer\Module\EntryPointToInstall( + 'gobsapi.php', + 'gobsapi/config.ini.php', + 'gobsapi.php', + 'gobsapi/config.ini.php' + ), + ); + } + + public function configure(Jelix\Installer\Module\API\ConfigurationHelpers $helpers) + { + $gobs_config_target = $helpers->configFilePath('gobsapi.ini.php'); + $helpers->copyFile('config/gobsapi.ini.php.dist', $gobs_config_target); + } +} diff --git a/gobsapi/install/gobsapi/config.ini.php b/gobsapi/install/gobsapi/config.ini.php index 625957c..63569bc 100644 --- a/gobsapi/install/gobsapi/config.ini.php +++ b/gobsapi/install/gobsapi/config.ini.php @@ -1,13 +1,5 @@ [modules] -jelix.access=1 -lizmap.access=1 -view.access=1 - -jacl2db_admin.access=1 -jauthdb_admin.access=1 -master_admin.access=1 - -gobsapi.access=2 +gobsapi.enabled=on [coordplugins] jacl2=1 diff --git a/gobsapi/install/install.php b/gobsapi/install/install.php index 5afe024..02abcc6 100644 --- a/gobsapi/install/install.php +++ b/gobsapi/install/install.php @@ -1,33 +1,15 @@ createEntryPoint('gobsapi.php', 'gobsapi/config.ini.php', 'gobsapi', 'classic'); - } else { - // Copy directory for Jelix configuration file related to new entry point - $gobsapi_jelix_config_target = jApp::configPath('gobsapi/config.ini.php'); - $this->copyFile('gobsapi/config.ini.php', $gobsapi_jelix_config_target); - - // Copy the new entry point PHP file in Lizmap www folder - // Deprecated and not safe ! - $this->copyFile('gobsapi.php', jApp::wwwPath('gobsapi.php')); - } - - // Copy configuration file for user defined options - // TODO: This file should be editable by the admin user in LWC admin panel - $gobs_config_target = jApp::configPath('gobsapi.ini.php'); - if (!file_exists($gobs_config_target)) { - $this->copyFile('config/gobsapi.ini.php.dist', $gobs_config_target); - } } } diff --git a/gobsapi/install/upgrade.php b/gobsapi/install/upgrade.php index 180a914..11a4372 100644 --- a/gobsapi/install/upgrade.php +++ b/gobsapi/install/upgrade.php @@ -1,57 +1,16 @@ createEntryPoint('gobsapi.php', 'gobsapi/config.ini.php', 'gobsapi', 'classic'); - } else { - $this->myUpdateEntryPointFile('gobsapi.php'); - } - } else { - // deprecated and not safe - $overwrite = true; - $this->copyFile('gobsapi.php', jApp::wwwPath('gobsapi.php'), $overwrite); - } - } - - /** - * Update the entry point (overwrite the file - * and adapt application init file. - * - * @param string $entryPointFile Entry point file - */ - protected function myUpdateEntryPointFile($entryPointFile) - { - $entryPointFileName = basename($entryPointFile); - $epPath = jApp::wwwPath($entryPointFileName); - if (!file_exists($epPath)) { - throw new \Exception('The entrypoint '.$entryPointFile.' cannot be updated, as it doesn\'t exist'); - } - - // copy the entrypoint and its configuration - $this->copyFile($entryPointFile, $epPath, true); - - // change the path to application.init.php into the entrypoint - // depending on the application, the path of www/ is not always at the same place, relatively to - // application.init.php - $appInitFile = jApp::applicationInitFile(); - $relativePath = \Jelix\FileUtilities\Path::shortestPath(jApp::wwwPath(), dirname($appInitFile).'/'); - - $epCode = file_get_contents($epPath); - $epCode = preg_replace('#(require\s*\(?\s*[\'"])(.*)(application\.init\.php)([\'"])#m', '\\1'.$relativePath.'/'.basename($appInitFile).'\\4', $epCode); - file_put_contents($epPath, $epCode); + $helpers->updateEntryPointFile('gobsapi.php', 'gobsapi', 'classic'); } } diff --git a/gobsapi/module.xml b/gobsapi/module.xml index 860b0f1..72f5ffe 100644 --- a/gobsapi/module.xml +++ b/gobsapi/module.xml @@ -5,12 +5,12 @@ Mozilla Public Licence (MPL) - 2017 3liz + 2017-2024 3liz http://3liz.com - + diff --git a/tests/Makefile b/tests/Makefile index b463c66..a9a002a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,13 +8,15 @@ LIZMAP_DIR=$(shell pwd)/lizmap LIZMAP_USER_ID:=$(shell id -u) LIZMAP_USER_GID:=$(shell id -g) -LIZMAP_VERSION_TAG:=3.5 +LIZMAP_USER:=userphp +LIZMAP_GROUP:=groupphp +LIZMAP_VERSION_TAG:=3.7 QGIS_VERSION_TAG:=ltr-rc -POSTGIS_VERSION_TAG:=11-2.5 +POSTGIS_VERSION_TAG:=13-3 QGIS_MAP_WORKERS:=1 -LIZMAP_PORT:=127.0.0.1:9095 +LIZMAP_PORT:=9095 OWS_PORT:=127.0.0.1:9096 LZMPGPORT:=127.0.0.1:9097 @@ -64,13 +66,14 @@ env: dirs run: stop env install-plugins docker compose up -d -stop: +stop: env docker compose down || true clean: stop docker compose down -v rm -rf $(LIZMAP_DIR)/www/* rm -rf $(LIZMAP_DIR)/var/* + rm -f .env # Pull images from github 3liz pull: @@ -79,7 +82,10 @@ pull: docker pull 3liz/postgis:${POSTGIS_VERSION_TAG} shell: - docker compose exec -u ${LIZMAP_USER_ID} lizmap /bin/sh -l + docker compose exec -u ${LIZMAP_USER} lizmap /bin/sh -l + +shell-root: + docker compose exec lizmap /bin/sh -l shellpg: docker compose exec -u ${LIZMAP_USER_ID} pgsql /bin/sh -l @@ -109,36 +115,9 @@ import-data: export PGPASSWORD=lizmap1234!; psql -h localhost -U lizmap -d lizmap -p 9097 -f sql/test_data.sql import-lizmap-acl: - @echo "Set repositories and users rights if needed" - @echo "Set view project" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add __anonymous "lizmap.repositories.view" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add users "lizmap.repositories.view" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add admins "lizmap.repositories.view" gobsapi' - @echo "Display WMS links" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add __anonymous "lizmap.tools.displayGetCapabilitiesLinks" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add users "lizmap.tools.displayGetCapabilitiesLinks" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add admins "lizmap.tools.displayGetCapabilitiesLinks" gobsapi' - @echo "Edition" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add __anonymous "lizmap.tools.edition.use" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add users "lizmap.tools.edition.use" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add admins "lizmap.tools.edition.use" gobsapi' - @echo "Export layers" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add __anonymous "lizmap.tools.layer.export" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add users "lizmap.tools.layer.export" gobsapi' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add admins "lizmap.tools.layer.export" gobsapi' - @echo "Add GobsAPI users" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/scripts/script.php jcommunity~user:create -v --no-error-if-exists --admin gobsapi_writer al@al.al al_password' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/scripts/script.php jcommunity~user:create -v --no-error-if-exists gobsapi_reader bob@bob.bob bob_password' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/scripts/script.php jcommunity~user:create -v --no-error-if-exists gobsapi_writer_filtered md@md.md md_password' - @echo "Add GobsAPI groups" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group create gobsapi_group "GobsAPI group"' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group create gobsapi_global_group "GobsAPI global group"' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group create gobsapi_filtered_group "GobsAPI filtered group"' - @echo "Put users in their groups" - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_group gobsapi_writer' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_group gobsapi_reader' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_group gobsapi_writer_filtered' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_global_group gobsapi_writer' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_global_group gobsapi_reader' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2group adduser gobsapi_filtered_group gobsapi_writer_filtered' - docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c 'php lizmap/cmd.php acl2right add gobsapi_group "lizmap.repositories.view" "gobsapi"' + docker compose exec -u $(LIZMAP_USER_ID) lizmap /bin/sh -c '/srv/etc/setup-lizmap.sh' + +setup-module: + docker compose exec -u ${LIZMAP_USER} lizmap php /www/lizmap/install/configurator.php -v gobsapi + docker compose exec -u ${LIZMAP_USER} lizmap php /www/lizmap/install/installer.php -v --no-clean-temp + docker compose exec lizmap /www/lizmap/install/clean_vartmp.sh diff --git a/tests/README.md b/tests/README.md index a6fe42a..bc245bc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,20 +2,34 @@ Steps: -- Launch Lizmap with docker compose - +- clean previous versions (optional) ```bash -# Clean previous versions (optional) make clean - -# Run the different services +``` +- Launch Lizmap with docker compose (Lizmap 3.5 by default) +```bash make run +``` + If you want to use a specific version of Lizmap (for example a local docker image), + indicate the version of the docker image into `LIZMAP_VERSION_TAG`: +```bash +make run LIZMAP_VERSION_TAG=3.6.0-rc.2 +``` +- If you are using Lizmap 3.6, execute: +```bash +make setup-module make import-data make import-lizmap-acl ``` +- If you are using Lizmap 3.5, execute: +```bash +make import-data +make import-lizmap-acl-35 +``` - Open your browser at http://localhost:9095 + Then you can try the [Lizmap test map](http://localhost:9095/index.php/view/map/?repository=gobsapi&project=gobsapi). For more information, refer to the [docker compose documentation](https://docs.docker.com/compose/) @@ -73,10 +87,17 @@ and add the modified file `tests/sql/test_data.sql` to your pull request. Before running manual or automatic tests, you also need to add some Lizmap groups, users and rights +With Lizmap 3.5, execute: +```bash +make import-lizmap-acl-35 +``` + +With Lizmap 3.6, execute: ```bash make import-lizmap-acl ``` + Create group: * `gobsapi_group`, label `GobsAPI group` * `gobsapi_global_group`, label `GobsAPI global group` @@ -140,3 +161,4 @@ pytest -v -k _with_spatial_layer # Deactivate env deactivate ``` + diff --git a/tests/lizmap/etc/conf/localconfig.d/localconfig.ini.php b/tests/lizmap/etc/conf/localconfig.d/localconfig.ini.php index a84c094..1bdcb82 100644 --- a/tests/lizmap/etc/conf/localconfig.d/localconfig.ini.php +++ b/tests/lizmap/etc/conf/localconfig.d/localconfig.ini.php @@ -1,2 +1,16 @@ -[modules] -gobsapi.access=2 + + +[jResponseHtml] +plugins = debugbar + + + +[logger] +default = file +error = file +warning = file +notice = file +deprecated = file +auth = file +echoproxy = file + diff --git a/tests/lizmap/etc/conf/localconfig.d/mailconfig.ini b/tests/lizmap/etc/conf/localconfig.d/mailconfig.ini new file mode 100644 index 0000000..6d4f745 --- /dev/null +++ b/tests/lizmap/etc/conf/localconfig.d/mailconfig.ini @@ -0,0 +1,6 @@ +[mailer] +mailerType = file +webmasterEmail="hosting-no-reply@lizmap.com" +webmasterName="Lizmap Docker" + + diff --git a/tests/lizmap/etc/mailconfig.ini b/tests/lizmap/etc/mailconfig.ini deleted file mode 100644 index 07349c7..0000000 --- a/tests/lizmap/etc/mailconfig.ini +++ /dev/null @@ -1,14 +0,0 @@ - -[mailer] -webmasterEmail="hosting-no-reply@lizmap.com" -webmasterName="Lizmap Docker" -mailerType=smtp -smtpHost=smtp.host.net -smtpPort=25 -smtpSecure=tls -smtpHelo= -smtpAuth=on -smtpUsername="hosting-no-reply@lizmap.com" -smtpPassword=mysecretpassword -smtpTimeout=10 - diff --git a/tests/lizmap/etc/setup-lizmap.sh b/tests/lizmap/etc/setup-lizmap.sh new file mode 100755 index 0000000..74ecef9 --- /dev/null +++ b/tests/lizmap/etc/setup-lizmap.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +# For lizmap 3.6+ + +echo "Set repositories and users rights if needed" +echo "Set view project" +cd /www/lizmap + +php console.php acl2:add __anonymous "lizmap.repositories.view" gobsapi +php console.php acl2:add users "lizmap.repositories.view" gobsapi +php console.php acl2:add admins "lizmap.repositories.view" gobsapi + +echo "Display WMS links" +php console.php acl2:add __anonymous "lizmap.tools.displayGetCapabilitiesLinks" gobsapi +php console.php acl2:add users "lizmap.tools.displayGetCapabilitiesLinks" gobsapi +php console.php acl2:add admins "lizmap.tools.displayGetCapabilitiesLinks" gobsapi + +echo "Edition" +php console.php acl2:add __anonymous "lizmap.tools.edition.use" gobsapi +php console.php acl2:add users "lizmap.tools.edition.use" gobsapi +php console.php acl2:add admins "lizmap.tools.edition.use" gobsapi + +echo "Export layers" +php console.php acl2:add __anonymous "lizmap.tools.layer.export" gobsapi +php console.php acl2:add users "lizmap.tools.layer.export" gobsapi +php console.php acl2:add admins "lizmap.tools.layer.export" gobsapi + +echo "Add GobsAPI users" +php console.php jcommunity:user:create -v --no-error-if-exist --admin gobsapi_writer al@al.al al_password +php console.php jcommunity:user:create -v --no-error-if-exist gobsapi_reader bob@bob.bob bob_password +php console.php jcommunity:user:create -v --no-error-if-exist gobsapi_writer_filtered md@md.md md_password + +echo "Add GobsAPI groups" +php console.php acl2group:create gobsapi_group "GobsAPI group" +php console.php acl2group:create gobsapi_global_group "GobsAPI global group" +php console.php acl2group:create gobsapi_filtered_group "GobsAPI filtered group" + +echo "Put users in their groups" +php console.php acl2user:addgroup gobsapi_reader gobsapi_group +php console.php acl2user:addgroup gobsapi_writer gobsapi_group +php console.php acl2user:addgroup gobsapi_writer_filtered gobsapi_group +php console.php acl2user:addgroup gobsapi_reader gobsapi_global_group +php console.php acl2user:addgroup gobsapi_writer gobsapi_global_group +php console.php acl2user:addgroup gobsapi_writer_filtered gobsapi_filtered_group + +php console.php acl2:add gobsapi_group "lizmap.repositories.view" "gobsapi" + +