From 8c134c7f1b790952321beca71e98c27b840a48eb Mon Sep 17 00:00:00 2001 From: Chad Burt Date: Fri, 8 Dec 2023 13:32:55 -0800 Subject: [PATCH] Update migrations --- packages/api/generated-schema-clean.gql | 19 ++ packages/api/migrations/committed/000282.sql | 275 +++++++++++++++++++ packages/api/migrations/current.sql | 271 ------------------ packages/api/schema.sql | 101 ++++++- 4 files changed, 387 insertions(+), 279 deletions(-) create mode 100644 packages/api/migrations/committed/000282.sql diff --git a/packages/api/generated-schema-clean.gql b/packages/api/generated-schema-clean.gql index e7852d97b..9e7e66994 100644 --- a/packages/api/generated-schema-clean.gql +++ b/packages/api/generated-schema-clean.gql @@ -320,6 +320,7 @@ type Basemap implements Node { """The method to use when ordering `MapBookmark`.""" orderBy: [MapBookmarksOrderBy!] = [NATURAL] ): MapBookmarksConnection! + maxzoom: Int """Label shown in the basemap picker interface""" name: String! @@ -486,6 +487,7 @@ input BasemapInput { Identify the labels layer lowest in the stack so that overlay layers may be placed underneath. """ labelsLayerId: String + maxzoom: Int """Label shown in the basemap picker interface""" name: String! @@ -558,6 +560,7 @@ input BasemapPatch { Identify the labels layer lowest in the stack so that overlay layers may be placed underneath. """ labelsLayerId: String + maxzoom: Int """Label shown in the basemap picker interface""" name: String @@ -2760,6 +2763,8 @@ input DataSourceInput { Represents an update to a `DataSource`. Fields that are set will be updated. """ input DataSourcePatch { + arcgisFetchStrategy: ArcgisFeatureLayerFetchStrategy + """ Contains an attribution to be displayed when the map is shown to a user. """ @@ -6566,6 +6571,7 @@ input InteractivitySettingPatch { } enum InteractivityType { + ALL_PROPERTIES_POPUP BANNER FIXED_BLOCK NONE @@ -9350,6 +9356,12 @@ enum OptionalBasemapLayersOrderBy { PRIMARY_KEY_DESC } +type OutstandingSurveyInvites { + projectId: Int! + surveyId: Int! + token: String! +} + """Information about pagination in a connection.""" type PageInfo { """When paginating forwards, the cursor to continue.""" @@ -13190,6 +13202,7 @@ type TableOfContentsItem implements Node { their children. Toggles can only be used to toggle children off """ isClickOffOnly: Boolean! + isCustomGlSource: Boolean """ Identifies whether this item is part of the draft table of contents edited by @@ -13245,6 +13258,7 @@ type TableOfContentsItem implements Node { """Name used in the table of contents rendering""" title: String! translatedProps: JSON! + usesDynamicMetadata: Boolean } """ @@ -13435,6 +13449,11 @@ enum TileScheme { XYZ } +type TocItemDetails { + id: Int! + type: SketchChildType! +} + """All input for the `toggleAdminAccess` mutation.""" input ToggleAdminAccessInput { """ diff --git a/packages/api/migrations/committed/000282.sql b/packages/api/migrations/committed/000282.sql new file mode 100644 index 000000000..1699589ba --- /dev/null +++ b/packages/api/migrations/committed/000282.sql @@ -0,0 +1,275 @@ +--! Previous: sha1:077e1ed1e4f045a9336afed1444ff35444bcd3db +--! Hash: sha1:6284aa014c05f12ad1b5920e5686ba8fa4be3ad4 + +-- Enter migration here +CREATE OR REPLACE FUNCTION public.before_insert_or_update_data_sources_trigger() RETURNS trigger + LANGUAGE plpgsql + AS $$ + declare + bucket_id text; + begin + if new.minzoom is not null and (new.type != 'vector' and new.type != 'raster' and new.type != 'raster-dem' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' and new.type != 'arcgis-raster-tiles' ) then + raise 'minzoom may only be set for tiled sources (vector, raster, raster-dem)'; + end if; + if new.coordinates is null and (new.type = 'video' or new.type = 'image') then + raise 'coordinates must be set on image and video sources'; + end if; + if new.coordinates is not null and (new.type != 'video' and new.type != 'image') then + raise 'coordinates property can only be set on image and video sources'; + end if; + if new.maxzoom is not null and (new.type = 'image' or new.type = 'video') then + raise 'maxzoom cannot be set for image and video sources'; + end if; + if new.url is null and (new.type = 'geojson' or new.type = 'image' or new.type = 'arcgis-dynamic-mapserver' or new.type = 'arcgis-vector' or new.type = 'seasketch-mvt') then + raise 'url must be set for "%" sources', (new.type); + end if; + if new.scheme is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-mvt') then + raise 'scheme property is not allowed for "%" sources', (new.type); + end if; + if new.tiles is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-vector') then + raise 'tiles property is not allowed for "%" sources', (new.type); + end if; + if new.encoding is not null and new.type != 'raster-dem' then + raise 'encoding property only allowed on raster-dem sources'; + end if; + if new.tile_size is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster') then + raise 'tile_size property is not allowed for "%" sources', (new.type); + end if; + if (new.type != 'geojson' and new.type != 'seasketch-vector') and (new.buffer is not null or new.cluster is not null or new.cluster_max_zoom is not null or new.cluster_properties is not null or new.cluster_radius is not null or new.generate_id is not null or new.line_metrics is not null or new.promote_id is not null or new.tolerance is not null) then + raise 'geojson props such as buffer, cluster, generate_id, etc not allowed on % sources', (new.type); + end if; + if (new.byte_length is not null and new.type != 'seasketch-vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster') then + raise 'byte_length can only be set on seasketch-vector, seasketch_mvt and seasketch-raster sources'; + end if; + if (new.type = 'seasketch-vector' and new.type != 'seasketch-mvt' and new.byte_length is null) then + raise 'seasketch-vector and mvt sources must have byte_length set to an approximate value'; + end if; + if new.urls is not null and new.type != 'video' then + raise 'urls property not allowed on % sources', (new.type); + end if; + if new.query_parameters is not null and (new.type != 'arcgis-vector' and new.type != 'arcgis-dynamic-mapserver') then + raise 'query_parameters property not allowed on % sources', (new.type); + end if; + if new.use_device_pixel_ratio is not null and new.type != 'arcgis-dynamic-mapserver' then + raise 'use_device_pixel_ratio property not allowed on % sources', (new.type); + end if; + if new.import_type is not null and new.type != 'seasketch-vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' then + raise 'import_type property is only allowed for seasketch-vector, seasketch-mvt, and seasketch-raster sources'; + end if; + if new.import_type is null and (new.type = 'seasketch-vector' or new.type = 'seasketch-mvt') then + raise 'import_type property is required for seasketch-vector sources'; + end if; + if new.original_source_url is not null and new.type != 'seasketch-vector' then + raise 'original_source_url may only be set on seasketch-vector sources'; + end if; + if new.enhanced_security is not null and new.type != 'seasketch-vector' then + raise 'enhanced_security may only be set on seasketch-vector sources'; + end if; + if old is null and new.type = 'seasketch-vector' then + if new.bucket_id is null then + new.bucket_id = (select data_sources_bucket_id from projects where id = new.project_id); + end if; + if new.object_key is null then + new.object_key = (select gen_random_uuid()); + end if; + new.tiles = null; + end if; + return new; + end; +$$; + +drop policy if exists data_sources_update on data_sources; +CREATE POLICY data_sources_update ON public.data_sources FOR UPDATE USING ((public.session_is_admin(project_id) AND ( SELECT (( SELECT 1 + FROM public.table_of_contents_items + WHERE ((table_of_contents_items.data_layer_id in ( SELECT data_layers.id + FROM public.data_layers + WHERE (data_layers.data_source_id = data_sources.id))) AND (table_of_contents_items.is_draft = false))) IS NULL)))) WITH CHECK (public.session_is_admin(project_id)); + + +create or replace function import_arcgis_services("projectId" int, items arcgis_import_item[], sources arcgis_import_source[]) + returns setof table_of_contents_items + language plpgsql + security definer + as $$ + declare + folder_id int; + source arcgis_import_source; + source_id int; + layer_id int; + item_id int; + source_id_map jsonb; + layer_id_map jsonb; + item_id_map jsonb; + interactive_layers int[]; + begin + source_id_map = '{}'::jsonb; + layer_id_map = '{}'::jsonb; + item_id_map = '{}'::jsonb; + if session_is_admin("projectId") then + for i in array_lower(sources, 1)..array_upper(sources, 1) loop + source = sources[i]; + if source.type = 'arcgis-vector' then + insert into data_sources ( + project_id, + type, + url, + arcgis_fetch_strategy + ) values ( + "projectId", + 'arcgis-vector', + source.url, + source.fetch_strategy + ) returning id into source_id; + select + id_lookup_set_key(source_id_map, source.id, source_id) + into source_id_map; + + insert into data_layers ( + project_id, + data_source_id + ) values ( + "projectId", + source_id + ) returning id into layer_id; + select + id_lookup_set_key(layer_id_map, source.id, layer_id) + into layer_id_map; + interactive_layers = array_append(interactive_layers, layer_id); + elsif source.type = 'arcgis-raster-tiles' then + insert into data_sources ( + project_id, + type, + url, + use_device_pixel_ratio + ) values ( + "projectId", + 'arcgis-raster-tiles', + source.url, + true + ) returning id into source_id; + insert into data_layers ( + project_id, + data_source_id + ) values ( + "projectId", + source_id + ) returning id into layer_id; + elsif source.type = 'arcgis-dynamic-mapserver' then + insert into data_sources ( + project_id, + type, + url, + use_device_pixel_ratio + ) values ( + "projectId", + 'arcgis-dynamic-mapserver', + source.url, + true + ) returning id into source_id; + -- create data layers for each sublayer + for i in array_lower(items, 1)..array_upper(items, 1) loop + if items[i].sublayer_id is not null then + insert into data_layers ( + project_id, + data_source_id, + sublayer + ) values ( + "projectId", + source_id, + items[i].sublayer_id + ) returning id into layer_id; + interactive_layers = array_append(interactive_layers, layer_id); + select + id_lookup_set_key(layer_id_map, items[i].id, layer_id) + into layer_id_map; + end if; + end loop; + else + raise exception 'Source type % not supported', source.type; + end if; + end loop; + if array_length(items, 1) > 1 then + perform import_subtree("projectId", items, layer_id_map, null); + else + insert into table_of_contents_items ( + project_id, + is_draft, + is_folder, + data_layer_id, + title, + stable_id, + path + ) values ( + "projectId", + true, + false, + layer_id, + items[1].title, + items[1].stable_id, + items[1].stable_id::ltree + ); + end if; + update interactivity_settings + set type = 'ALL_PROPERTIES_POPUP' + where id = any( + ( + select + interactivity_settings_id + from + data_layers + where + id = any(interactive_layers) + ) + ); + else + raise exception 'Only admins can import ArcGIS services'; + end if; + end; + $$; + +grant update (arcgis_fetch_strategy) on data_sources to seasketch_user; + +alter table basemaps add column if not exists maxzoom int; + +create or replace function table_of_contents_items_uses_dynamic_metadata(t table_of_contents_items) + returns boolean + language plpgsql + security definer + stable + as $$ + declare + uses_dynamic_metadata boolean; + begin + if t.metadata is not null then + return false; + end if; + if t.data_layer_id is null then + return false; + end if; + select type = 'arcgis-dynamic-mapserver' or type = 'arcgis-vector' or type = 'arcgis-raster-tiles' into uses_dynamic_metadata from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); + return uses_dynamic_metadata; + end; + $$; + +grant execute on function table_of_contents_items_uses_dynamic_metadata(table_of_contents_items) to anon; + +create or replace function table_of_contents_items_is_custom_gl_source(t table_of_contents_items) + returns boolean + language plpgsql + security definer + stable + as $$ + declare + source_type text; + begin + if t.data_layer_id is null then + return null; + end if; + select type into source_type from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); + return source_type = 'arcgis-dynamic-mapserver' or source_type = 'arcgis-vector' or source_type = 'arcgis-raster-tiles'; + end; + $$; + +grant execute on function table_of_contents_items_is_custom_gl_source(table_of_contents_items) to anon; + +ALTER TYPE interactivity_type ADD VALUE IF NOT EXISTS 'ALL_PROPERTIES_POPUP'; diff --git a/packages/api/migrations/current.sql b/packages/api/migrations/current.sql index 752cc2389..8da533983 100644 --- a/packages/api/migrations/current.sql +++ b/packages/api/migrations/current.sql @@ -1,272 +1 @@ -- Enter migration here -CREATE OR REPLACE FUNCTION public.before_insert_or_update_data_sources_trigger() RETURNS trigger - LANGUAGE plpgsql - AS $$ - declare - bucket_id text; - begin - if new.minzoom is not null and (new.type != 'vector' and new.type != 'raster' and new.type != 'raster-dem' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' and new.type != 'arcgis-raster-tiles' ) then - raise 'minzoom may only be set for tiled sources (vector, raster, raster-dem)'; - end if; - if new.coordinates is null and (new.type = 'video' or new.type = 'image') then - raise 'coordinates must be set on image and video sources'; - end if; - if new.coordinates is not null and (new.type != 'video' and new.type != 'image') then - raise 'coordinates property can only be set on image and video sources'; - end if; - if new.maxzoom is not null and (new.type = 'image' or new.type = 'video') then - raise 'maxzoom cannot be set for image and video sources'; - end if; - if new.url is null and (new.type = 'geojson' or new.type = 'image' or new.type = 'arcgis-dynamic-mapserver' or new.type = 'arcgis-vector' or new.type = 'seasketch-mvt') then - raise 'url must be set for "%" sources', (new.type); - end if; - if new.scheme is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-mvt') then - raise 'scheme property is not allowed for "%" sources', (new.type); - end if; - if new.tiles is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-vector') then - raise 'tiles property is not allowed for "%" sources', (new.type); - end if; - if new.encoding is not null and new.type != 'raster-dem' then - raise 'encoding property only allowed on raster-dem sources'; - end if; - if new.tile_size is not null and (new.type != 'raster' and new.type != 'raster-dem' and new.type != 'vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster') then - raise 'tile_size property is not allowed for "%" sources', (new.type); - end if; - if (new.type != 'geojson' and new.type != 'seasketch-vector') and (new.buffer is not null or new.cluster is not null or new.cluster_max_zoom is not null or new.cluster_properties is not null or new.cluster_radius is not null or new.generate_id is not null or new.line_metrics is not null or new.promote_id is not null or new.tolerance is not null) then - raise 'geojson props such as buffer, cluster, generate_id, etc not allowed on % sources', (new.type); - end if; - if (new.byte_length is not null and new.type != 'seasketch-vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster') then - raise 'byte_length can only be set on seasketch-vector, seasketch_mvt and seasketch-raster sources'; - end if; - if (new.type = 'seasketch-vector' and new.type != 'seasketch-mvt' and new.byte_length is null) then - raise 'seasketch-vector and mvt sources must have byte_length set to an approximate value'; - end if; - if new.urls is not null and new.type != 'video' then - raise 'urls property not allowed on % sources', (new.type); - end if; - if new.query_parameters is not null and (new.type != 'arcgis-vector' and new.type != 'arcgis-dynamic-mapserver') then - raise 'query_parameters property not allowed on % sources', (new.type); - end if; - if new.use_device_pixel_ratio is not null and new.type != 'arcgis-dynamic-mapserver' then - raise 'use_device_pixel_ratio property not allowed on % sources', (new.type); - end if; - if new.import_type is not null and new.type != 'seasketch-vector' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' then - raise 'import_type property is only allowed for seasketch-vector, seasketch-mvt, and seasketch-raster sources'; - end if; - if new.import_type is null and (new.type = 'seasketch-vector' or new.type = 'seasketch-mvt') then - raise 'import_type property is required for seasketch-vector sources'; - end if; - if new.original_source_url is not null and new.type != 'seasketch-vector' then - raise 'original_source_url may only be set on seasketch-vector sources'; - end if; - if new.enhanced_security is not null and new.type != 'seasketch-vector' then - raise 'enhanced_security may only be set on seasketch-vector sources'; - end if; - if old is null and new.type = 'seasketch-vector' then - if new.bucket_id is null then - new.bucket_id = (select data_sources_bucket_id from projects where id = new.project_id); - end if; - if new.object_key is null then - new.object_key = (select gen_random_uuid()); - end if; - new.tiles = null; - end if; - return new; - end; -$$; - -drop policy if exists data_sources_update on data_sources; -CREATE POLICY data_sources_update ON public.data_sources FOR UPDATE USING ((public.session_is_admin(project_id) AND ( SELECT (( SELECT 1 - FROM public.table_of_contents_items - WHERE ((table_of_contents_items.data_layer_id in ( SELECT data_layers.id - FROM public.data_layers - WHERE (data_layers.data_source_id = data_sources.id))) AND (table_of_contents_items.is_draft = false))) IS NULL)))) WITH CHECK (public.session_is_admin(project_id)); - - -create or replace function import_arcgis_services("projectId" int, items arcgis_import_item[], sources arcgis_import_source[]) - returns setof table_of_contents_items - language plpgsql - security definer - as $$ - declare - folder_id int; - source arcgis_import_source; - source_id int; - layer_id int; - item_id int; - source_id_map jsonb; - layer_id_map jsonb; - item_id_map jsonb; - interactive_layers int[]; - begin - source_id_map = '{}'::jsonb; - layer_id_map = '{}'::jsonb; - item_id_map = '{}'::jsonb; - if session_is_admin("projectId") then - for i in array_lower(sources, 1)..array_upper(sources, 1) loop - source = sources[i]; - if source.type = 'arcgis-vector' then - insert into data_sources ( - project_id, - type, - url, - arcgis_fetch_strategy - ) values ( - "projectId", - 'arcgis-vector', - source.url, - source.fetch_strategy - ) returning id into source_id; - select - id_lookup_set_key(source_id_map, source.id, source_id) - into source_id_map; - - insert into data_layers ( - project_id, - data_source_id - ) values ( - "projectId", - source_id - ) returning id into layer_id; - select - id_lookup_set_key(layer_id_map, source.id, layer_id) - into layer_id_map; - interactive_layers = array_append(interactive_layers, layer_id); - elsif source.type = 'arcgis-raster-tiles' then - insert into data_sources ( - project_id, - type, - url, - use_device_pixel_ratio - ) values ( - "projectId", - 'arcgis-raster-tiles', - source.url, - true - ) returning id into source_id; - insert into data_layers ( - project_id, - data_source_id - ) values ( - "projectId", - source_id - ) returning id into layer_id; - elsif source.type = 'arcgis-dynamic-mapserver' then - insert into data_sources ( - project_id, - type, - url, - use_device_pixel_ratio - ) values ( - "projectId", - 'arcgis-dynamic-mapserver', - source.url, - true - ) returning id into source_id; - -- create data layers for each sublayer - for i in array_lower(items, 1)..array_upper(items, 1) loop - if items[i].sublayer_id is not null then - insert into data_layers ( - project_id, - data_source_id, - sublayer - ) values ( - "projectId", - source_id, - items[i].sublayer_id - ) returning id into layer_id; - interactive_layers = array_append(interactive_layers, layer_id); - select - id_lookup_set_key(layer_id_map, items[i].id, layer_id) - into layer_id_map; - end if; - end loop; - else - raise exception 'Source type % not supported', source.type; - end if; - end loop; - if array_length(items, 1) > 1 then - perform import_subtree("projectId", items, layer_id_map, null); - else - insert into table_of_contents_items ( - project_id, - is_draft, - is_folder, - data_layer_id, - title, - stable_id, - path - ) values ( - "projectId", - true, - false, - layer_id, - items[1].title, - items[1].stable_id, - items[1].stable_id::ltree - ); - end if; - update interactivity_settings - set type = 'ALL_PROPERTIES_POPUP' - where id = any( - ( - select - interactivity_settings_id - from - data_layers - where - id = any(interactive_layers) - ) - ); - else - raise exception 'Only admins can import ArcGIS services'; - end if; - end; - $$; - -grant update (arcgis_fetch_strategy) on data_sources to seasketch_user; - -alter table basemaps add column if not exists maxzoom int; - -create or replace function table_of_contents_items_uses_dynamic_metadata(t table_of_contents_items) - returns boolean - language plpgsql - security definer - stable - as $$ - declare - uses_dynamic_metadata boolean; - begin - if t.metadata is not null then - return false; - end if; - if t.data_layer_id is null then - return false; - end if; - select type = 'arcgis-dynamic-mapserver' or type = 'arcgis-vector' or type = 'arcgis-raster-tiles' into uses_dynamic_metadata from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); - return uses_dynamic_metadata; - end; - $$; - -grant execute on function table_of_contents_items_uses_dynamic_metadata(table_of_contents_items) to anon; - -create or replace function table_of_contents_items_is_custom_gl_source(t table_of_contents_items) - returns boolean - language plpgsql - security definer - stable - as $$ - declare - source_type text; - begin - if t.data_layer_id is null then - return null; - end if; - select type into source_type from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); - return source_type = 'arcgis-dynamic-mapserver' or source_type = 'arcgis-vector' or source_type = 'arcgis-raster-tiles'; - end; - $$; - -grant execute on function table_of_contents_items_is_custom_gl_source(table_of_contents_items) to anon; - -ALTER TYPE interactivity_type ADD VALUE IF NOT EXISTS 'ALL_PROPERTIES_POPUP'; \ No newline at end of file diff --git a/packages/api/schema.sql b/packages/api/schema.sql index e8b0ce977..5e9f3d415 100644 --- a/packages/api/schema.sql +++ b/packages/api/schema.sql @@ -444,7 +444,8 @@ CREATE TYPE public.interactivity_type AS ENUM ( 'TOOLTIP', 'POPUP', 'FIXED_BLOCK', - 'NONE' + 'NONE', + 'ALL_PROPERTIES_POPUP' ); @@ -2628,7 +2629,8 @@ CREATE TABLE public.basemaps ( surveys_only boolean DEFAULT false NOT NULL, use_default_offline_tile_settings boolean DEFAULT true NOT NULL, translated_props jsonb DEFAULT '{}'::jsonb NOT NULL, - is_arcgis_tiled_mapservice boolean DEFAULT false NOT NULL + is_arcgis_tiled_mapservice boolean DEFAULT false NOT NULL, + maxzoom integer ); @@ -3045,7 +3047,7 @@ CREATE FUNCTION public.before_insert_or_update_data_sources_trigger() RETURNS tr declare bucket_id text; begin - if new.minzoom is not null and (new.type != 'vector' and new.type != 'raster' and new.type != 'raster-dem' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' ) then + if new.minzoom is not null and (new.type != 'vector' and new.type != 'raster' and new.type != 'raster-dem' and new.type != 'seasketch-mvt' and new.type != 'seasketch-raster' and new.type != 'arcgis-raster-tiles' ) then raise 'minzoom may only be set for tiled sources (vector, raster, raster-dem)'; end if; if new.coordinates is null and (new.type = 'video' or new.type = 'image') then @@ -8273,6 +8275,7 @@ CREATE FUNCTION public.import_arcgis_services("projectId" integer, items public. source_id_map jsonb; layer_id_map jsonb; item_id_map jsonb; + interactive_layers int[]; begin source_id_map = '{}'::jsonb; layer_id_map = '{}'::jsonb; @@ -8306,15 +8309,18 @@ CREATE FUNCTION public.import_arcgis_services("projectId" integer, items public. select id_lookup_set_key(layer_id_map, source.id, layer_id) into layer_id_map; + interactive_layers = array_append(interactive_layers, layer_id); elsif source.type = 'arcgis-raster-tiles' then insert into data_sources ( project_id, type, - url + url, + use_device_pixel_ratio ) values ( "projectId", 'arcgis-raster-tiles', - source.url + source.url, + true ) returning id into source_id; insert into data_layers ( project_id, @@ -8327,11 +8333,13 @@ CREATE FUNCTION public.import_arcgis_services("projectId" integer, items public. insert into data_sources ( project_id, type, - url + url, + use_device_pixel_ratio ) values ( "projectId", 'arcgis-dynamic-mapserver', - source.url + source.url, + true ) returning id into source_id; -- create data layers for each sublayer for i in array_lower(items, 1)..array_upper(items, 1) loop @@ -8345,6 +8353,7 @@ CREATE FUNCTION public.import_arcgis_services("projectId" integer, items public. source_id, items[i].sublayer_id ) returning id into layer_id; + interactive_layers = array_append(interactive_layers, layer_id); select id_lookup_set_key(layer_id_map, items[i].id, layer_id) into layer_id_map; @@ -8375,6 +8384,18 @@ CREATE FUNCTION public.import_arcgis_services("projectId" integer, items public. items[1].stable_id::ltree ); end if; + update interactivity_settings + set type = 'ALL_PROPERTIES_POPUP' + where id = any( + ( + select + interactivity_settings_id + from + data_layers + where + id = any(interactive_layers) + ) + ); else raise exception 'Only admins can import ArcGIS services'; end if; @@ -12609,6 +12630,25 @@ CREATE FUNCTION public.table_of_contents_items_has_metadata(toc public.table_of_ $$; +-- +-- Name: table_of_contents_items_is_custom_gl_source(public.table_of_contents_items); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION public.table_of_contents_items_is_custom_gl_source(t public.table_of_contents_items) RETURNS boolean + LANGUAGE plpgsql STABLE SECURITY DEFINER + AS $$ + declare + source_type text; + begin + if t.data_layer_id is null then + return null; + end if; + select type into source_type from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); + return source_type = 'arcgis-dynamic-mapserver' or source_type = 'arcgis-vector' or source_type = 'arcgis-raster-tiles'; + end; + $$; + + -- -- Name: table_of_contents_items_primary_download_url(public.table_of_contents_items); Type: FUNCTION; Schema: public; Owner: - -- @@ -12663,6 +12703,28 @@ CREATE FUNCTION public.table_of_contents_items_project_update() RETURNS trigger $$; +-- +-- Name: table_of_contents_items_uses_dynamic_metadata(public.table_of_contents_items); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION public.table_of_contents_items_uses_dynamic_metadata(t public.table_of_contents_items) RETURNS boolean + LANGUAGE plpgsql STABLE SECURITY DEFINER + AS $$ + declare + uses_dynamic_metadata boolean; + begin + if t.metadata is not null then + return false; + end if; + if t.data_layer_id is null then + return false; + end if; + select type = 'arcgis-dynamic-mapserver' or type = 'arcgis-vector' or type = 'arcgis-raster-tiles' into uses_dynamic_metadata from data_sources where id = (select data_source_id from data_layers where id = t.data_layer_id); + return uses_dynamic_metadata; + end; + $$; + + -- -- Name: template_forms(); Type: FUNCTION; Schema: public; Owner: - -- @@ -17707,7 +17769,7 @@ CREATE POLICY data_sources_select ON public.data_sources FOR SELECT USING ((publ CREATE POLICY data_sources_update ON public.data_sources FOR UPDATE USING ((public.session_is_admin(project_id) AND ( SELECT (( SELECT 1 FROM public.table_of_contents_items - WHERE ((table_of_contents_items.data_layer_id = ( SELECT data_layers.id + WHERE ((table_of_contents_items.data_layer_id IN ( SELECT data_layers.id FROM public.data_layers WHERE (data_layers.data_source_id = data_sources.id))) AND (table_of_contents_items.is_draft = false))) IS NULL)))) WITH CHECK (public.session_is_admin(project_id)); @@ -21441,6 +21503,13 @@ GRANT SELECT(translated_props) ON TABLE public.data_sources TO anon; GRANT UPDATE(translated_props) ON TABLE public.data_sources TO seasketch_user; +-- +-- Name: COLUMN data_sources.arcgis_fetch_strategy; Type: ACL; Schema: public; Owner: - +-- + +GRANT UPDATE(arcgis_fetch_strategy) ON TABLE public.data_sources TO seasketch_user; + + -- -- Name: FUNCTION data_sources_uploaded_by(data_source public.data_sources); Type: ACL; Schema: public; Owner: - -- @@ -28096,6 +28165,14 @@ REVOKE ALL ON FUNCTION public.table_of_contents_items_has_metadata(toc public.ta GRANT ALL ON FUNCTION public.table_of_contents_items_has_metadata(toc public.table_of_contents_items) TO anon; +-- +-- Name: FUNCTION table_of_contents_items_is_custom_gl_source(t public.table_of_contents_items); Type: ACL; Schema: public; Owner: - +-- + +REVOKE ALL ON FUNCTION public.table_of_contents_items_is_custom_gl_source(t public.table_of_contents_items) FROM PUBLIC; +GRANT ALL ON FUNCTION public.table_of_contents_items_is_custom_gl_source(t public.table_of_contents_items) TO anon; + + -- -- Name: FUNCTION table_of_contents_items_primary_download_url(item public.table_of_contents_items); Type: ACL; Schema: public; Owner: - -- @@ -28119,6 +28196,14 @@ GRANT ALL ON FUNCTION public.table_of_contents_items_project(t public.table_of_c REVOKE ALL ON FUNCTION public.table_of_contents_items_project_update() FROM PUBLIC; +-- +-- Name: FUNCTION table_of_contents_items_uses_dynamic_metadata(t public.table_of_contents_items); Type: ACL; Schema: public; Owner: - +-- + +REVOKE ALL ON FUNCTION public.table_of_contents_items_uses_dynamic_metadata(t public.table_of_contents_items) FROM PUBLIC; +GRANT ALL ON FUNCTION public.table_of_contents_items_uses_dynamic_metadata(t public.table_of_contents_items) TO anon; + + -- -- Name: FUNCTION template_forms(); Type: ACL; Schema: public; Owner: - --