Skip to content

Commit

Permalink
Add map library fetch and endpoint (performant-software/core-data-clo…
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Feb 12, 2025
1 parent 0a95609 commit 17df13b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/core_data_connector/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ def import_data
end
end

def map_library
project = Project.find(params[:id])
authorize project, :map_library?

library = MapLibrary.new(project.map_library_url)
json = library.fetch_library || []

render json: json, status: :ok
end

protected

# If we're not looking for "discoverable" projects, use base query defined by the policy. Otherwise, return
Expand Down
7 changes: 7 additions & 0 deletions app/policies/core_data_connector/project_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def import_data?
false
end

# A user can view any project's map library for which they are a member.
def map_library?
return true if current_user.admin?

project_member?
end

# A user can update a project if they are an admin or an owner of the project.
def update?
return true if current_user.admin?
Expand Down
16 changes: 16 additions & 0 deletions app/services/core_data_connector/map_library.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module CoreDataConnector
class MapLibrary
include Http::Requestable

def initialize(map_library_url)
@map_library_url = map_library_url
end

def fetch_library
params = {}
send_request(@map_library_url, method: :get, params: params) do |body|
JSON.parse(body)
end
end
end
end
1 change: 1 addition & 0 deletions config/routes/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def self.extended(router)
post :import_analyze, on: :member
post :import_configuration, on: :member
post :import_data, on: :member
get :map_library, on: :member
end

resources :record_merges, only: [:index, :destroy]
Expand Down

0 comments on commit 17df13b

Please sign in to comment.