Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 24 commits into from
Apr 29, 2024

Conversation

wlorenzetti
Copy link
Member

@wlorenzetti wlorenzetti commented Apr 16, 2024

Related to: g3w-suite/g3w-client#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 :https:////// 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"
                }
                }
   ]
}

@wlorenzetti wlorenzetti added the feature New feature or request label Apr 16, 2024
@wlorenzetti wlorenzetti added this to the v3.8 milestone Apr 16, 2024
@wlorenzetti wlorenzetti self-assigned this Apr 16, 2024
@Raruto
Copy link
Contributor

Raruto commented Apr 18, 2024

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 Raruto changed the title Customer theme CRUD Allow fronted users to store custom map themes within project config Apr 18, 2024
@Raruto Raruto changed the title Allow fronted users to store custom map themes within project config Allow to store custom map themes Apr 18, 2024
@Raruto Raruto changed the title Allow to store custom map themes Allow to store custom map themes (authenticathed users) Apr 18, 2024
@Raruto
Copy link
Contributor

Raruto commented Apr 18, 2024

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:https://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>."
}

@Raruto Raruto changed the title Allow to store custom map themes (authenticathed users) ✨ Allow to store custom map themes (authenticathed users) Apr 18, 2024
@Raruto Raruto marked this pull request as ready for review April 18, 2024 13:17
@wlorenzetti
Copy link
Member Author

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:https://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
Copy link
Contributor

Raruto commented Apr 22, 2024

@wlorenzetti what am I doing wrong?

image

image

[g3wsdk.info]

  • g3w-admin: 3.8.customer_theme-20240422102126
  • g3w-client: 3.10.0-issue_539
    • editing: 3.8.0-fix_vector_relations
    • qplotly: 3.7.0
    • openrouteservice: 3.7.0
    • qtimeseries: 3.7.0
  • browser: Firefox 124.0
  • operating system: Windows 10 64-bit

@Raruto
Copy link
Contributor

Raruto commented Apr 22, 2024

#813 (comment)

pip3 install -r /code/requirements.txt

Ref: 3449515

@wlorenzetti wlorenzetti merged commit 4b50d5f into dev Apr 29, 2024
4 checks passed
@wlorenzetti wlorenzetti deleted the customer_theme branch April 29, 2024 09:30
wlorenzetti added a commit that referenced this pull request May 6, 2024
* Create model for customer themes.

* Implemented CRUD custom theme.

* Add constraint.

* Typo

* Add invalidation of project cache.

* Fix test.

* Remove CSFR check.

* ✨ Client
  g3w-suite/g3w-client@0e226b2

* 🐛 Client
  g3w-suite/g3w-client@37adf60

* Add pydantic validation data structure.

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: volterra79 <[email protected]>
Co-authored-by: Raruto <[email protected]>
wlorenzetti added a commit that referenced this pull request May 20, 2024
* Add 'other_info' (userdata) to user form.

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

* Create model for customer themes.

* Implemented CRUD custom theme.

* Add constraint.

* Typo

* Add invalidation of project cache.

* Fix test.

* Remove CSFR check.

* ✨ Client
  g3w-suite/g3w-client@0e226b2

* 🐛 Client
  g3w-suite/g3w-client@37adf60

* Add pydantic validation data structure.

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: volterra79 <[email protected]>
Co-authored-by: Raruto <[email protected]>

* 🐛 Fix `SameSite` cookie property. (#793)

* Fix `SameSite` cookie property.

* Fix samesite value.

* Add secure=True for samesite=None

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: Raruto <[email protected]>

* ✨ Client
  g3w-suite/g3w-client@19c1d71

* ⚡ Client
   g3w-suite/g3w-client@dc02f92

* Fix issue #838

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: Raruto <[email protected]>
Co-authored-by: volterra79 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Save customer toc theme
3 participants