g3w-suite / g3w-admin

Server module for G3W-SUITE
https://g3w-suite.readthedocs.io/en/latest/g3wsuite_administration.html
Mozilla Public License 2.0
39 stars 31 forks source link

✨ Allow to store custom map themes (authenticathed users) #813

Closed wlorenzetti closed 2 months ago

wlorenzetti commented 2 months ago

Related to: https://github.com/g3w-suite/g3w-client/pull/540

Closes: #812

CRUD actions

Create/Update

POST /qdjango/api/prjtheme/<project_id>/<theme_name>/

Body request application/json content example:

{
    "layerstree": [
        {
            "name": "Geographical group",
            "checked": true,
            "expanded": true,
            "mutually-exclusive": false,
            "nodes": [
                {
                    "id": "points_b0a9c189_3dcf_48e8_a74e_42ed6d945e91",
                    "name": "points",
                    "visible": true,
                    "expanded": true
                },
                {
                    "id": "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4",
                    "name": "roads",
                    "visible": true,
                    "expanded": true
                },
                {
                    "id": "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a",
                    "name": "buildings: wfs( a :////// z )",
                    "visible": true,
                    "expanded": false
                },
                {
                    "id": "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63",
                    "name": "Maintenance works",
                    "visible": false,
                    "expanded": true
                },
                {
                    "id": "point_reprojected_7b238fe4_8fa3_4016_b98e_b65939ffafe0",
                    "name": "point_reprojected",
                    "visible": true,
                    "expanded": true
                },
                {
                    "id": "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe",
                    "name": "Work areas",
                    "visible": true,
                    "expanded": true
                },
                {
                    "name": "B",
                    "checked": false,
                    "expanded": false,
                    "mutually-exclusive": true,
                    "nodes": []
                },
                {
                    "name": "C",
                    "checked": false,
                    "expanded": false,
                    "mutually-exclusive": true,
                    "nodes": []
                },
                {
                    "id": "buildings_07994322_5660_4d3c_b6b0_b579dfc5aeb9",
                    "name": "buildings",
                    "visible": false,
                    "expanded": true
                },
                {
                    "id": "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1",
                    "name": "Type - Subtype",
                    "visible": false,
                    "expanded": true
                }
            ]
        },
        {
            "name": "1:N referencing tables",
            "checked": true,
            "expanded": true,
            "mutually-exclusive": false,
            "nodes": [
                {
                    "id": "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f",
                    "name": "Buildings rating",
                    "visible": true,
                    "expanded": true
                }
            ]
        }
    ],
    "styles": {
        "points_b0a9c189_3dcf_48e8_a74e_42ed6d945e91": "predefinito",
        "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4": "default",
        "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a": "cambio",
        "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63": "default",
        "point_reprojected_7b238fe4_8fa3_4016_b98e_b65939ffafe0": "default",
        "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe": "default",
        "buildings_07994322_5660_4d3c_b6b0_b579dfc5aeb9": "default",
        "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1": "default",
        "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f": "default"
    }
}

Response:

{
    "result": true
}

Delete

DELETE /qdjango/api/prjtheme/<project_id>/<theme_name>/

Response:

{
    "result": true
}

Project Config map_themes structure:

Refactoring of the /config/api/<group_id>/<project_type>/<project_id> API REST result map_themes property: I.e.:

{
   "project": [
                 {
                "theme": "Deafult",
                "styles": {
                    "cities10000eu_3857_728999c2_0883_4627_8df2_25224f71e3ea": "style_red_square",
                    "countries_3857_4f885888_b0df_4f87_88ed_17c907315fad": "default"
                }
                }
   ],
   "custom": [
                {
                "theme": "Custom theme 1",
                "styles": {
                    "cities10000eu_3857_728999c2_0883_4627_8df2_25224f71e3ea": "style_red_square",
                    "countries_3857_4f885888_b0df_4f87_88ed_17c907315fad": "other_style"
                }
                }
   ]
}
Raruto commented 2 months ago

KO: layer categories are not stored within custom theme

  1. create a style as follows:

image

  1. switch from Base map to administrative

  2. all the categories are enabled

image

Raruto commented 2 months ago

KO: no error message shown to anonymous user

Nothing happens when you try to create a new theme via an anonymous user:

image

Request:

POST http://localhost:8000/qdjango/api/prjtheme/3/foo/

{
  "layerstree": [
    {
      "name": "Geographical group",
      "checked": true,
      "expanded": true,
      "mutually-exclusive": false,
      "nodes": [
        {
          "id": "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a",
          "name": "buildings",
          "visible": true,
          "expanded": true
        },
        {
          "id": "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4",
          "name": "roads",
          "visible": true,
          "expanded": true
        },
        {
          "id": "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe",
          "name": "Work areas",
          "visible": true,
          "expanded": true
        },
        {
          "id": "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1",
          "name": "Type - Subtype",
          "visible": true,
          "expanded": true
        }
      ]
    },
    {
      "name": "1:N referencing tables",
      "checked": true,
      "expanded": true,
      "mutually-exclusive": false,
      "nodes": [
        {
          "id": "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63",
          "name": "Maintenance works",
          "visible": true,
          "expanded": true
        },
        {
          "id": "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f",
          "name": "Buildings rating",
          "visible": true,
          "expanded": true
        }
      ]
    }
  ],
  "styles": {
    "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a": "Categorized",
    "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4": "default",
    "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe": "default",
    "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1": "default",
    "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63": "default",
    "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f": "default"
  }
}

Response:

{
    "result": false,
    "error": "Field 'id' expected a number but got <django.contrib.auth.models.AnonymousUser object at 0x7f4826a353c0>."
}
wlorenzetti commented 2 months ago

KO: no error message shown to anonymous user

Nothing happens when you try to create a new theme via an anonymous user:

image

Request:

POST http://localhost:8000/qdjango/api/prjtheme/3/foo/

{
  "layerstree": [
    {
      "name": "Geographical group",
      "checked": true,
      "expanded": true,
      "mutually-exclusive": false,
      "nodes": [
        {
          "id": "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a",
          "name": "buildings",
          "visible": true,
          "expanded": true
        },
        {
          "id": "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4",
          "name": "roads",
          "visible": true,
          "expanded": true
        },
        {
          "id": "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe",
          "name": "Work areas",
          "visible": true,
          "expanded": true
        },
        {
          "id": "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1",
          "name": "Type - Subtype",
          "visible": true,
          "expanded": true
        }
      ]
    },
    {
      "name": "1:N referencing tables",
      "checked": true,
      "expanded": true,
      "mutually-exclusive": false,
      "nodes": [
        {
          "id": "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63",
          "name": "Maintenance works",
          "visible": true,
          "expanded": true
        },
        {
          "id": "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f",
          "name": "Buildings rating",
          "visible": true,
          "expanded": true
        }
      ]
    }
  ],
  "styles": {
    "buildings_2f43dc1d_6725_42d2_a09b_dd446220104a": "Categorized",
    "roads_ea006d6f_bd87_4635_aae0_4e9e7842b3f4": "default",
    "work_areas_f0ecbe28_cbd1_4a38_8a57_ab6da91473fe": "default",
    "type_subtype_caec4a0b_e7c4_4542_b59c_769f2033d6b1": "default",
    "maintenance_works_f8cbe34a_eebe_4cd1_9c78_5d420ab0af63": "default",
    "buildings_rating_3d535fae_fd04_4df6_b6ff_8cbd13df078f": "default"
  }
}

Response:

{
    "result": false,
    "error": "Field 'id' expected a number but got <django.contrib.auth.models.AnonymousUser object at 0x7f4826a353c0>."
}

The save of theme by anonymous user it is not allowed and makes no sense, no?

Raruto commented 2 months ago

@wlorenzetti what am I doing wrong?

image

image

[g3wsdk.info]

Raruto commented 2 months ago

https://github.com/g3w-suite/g3w-admin/pull/813#issuecomment-2069044558

pip3 install -r /code/requirements.txt

Ref: https://github.com/g3w-suite/g3w-admin/pull/813/commits/34495154e470a9740ca0ad9f68c9e5e086813422