From 8e621140d00700fcb24126c12042c75af07e5205 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Tue, 19 Nov 2024 14:14:17 +0000 Subject: [PATCH] Refs #37989 - Pluralize api docs endpoint and other changes (cherry picked from commit 5e0e19a3140111c54a338ae67b05030b749f67e6) --- .../api/v2/flatpak_remote_repositories_controller.rb | 8 ++++---- .../katello/api/v2/flatpak_remotes_controller.rb | 9 +++++---- app/models/katello/flatpak_remote.rb | 1 + config/routes/api/v2.rb | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/katello/api/v2/flatpak_remote_repositories_controller.rb b/app/controllers/katello/api/v2/flatpak_remote_repositories_controller.rb index 8cf192f09da..8593b386878 100644 --- a/app/controllers/katello/api/v2/flatpak_remote_repositories_controller.rb +++ b/app/controllers/katello/api/v2/flatpak_remote_repositories_controller.rb @@ -35,7 +35,7 @@ def index_relation end def index_remote_relation(query) - query = query.joins(:flatpak_remote_id => :remote).where("#{FlatpakRemote.table_name}.organization_id" => @organization) if @organization + query = query.joins(:flatpak_remote).where("#{FlatpakRemote.table_name}.organization_id" => @organization) if @organization if params[:flatpak_remote_id] query.where(flatpak_remote_id: params[:flatpak_remote_id]) else @@ -44,15 +44,15 @@ def index_remote_relation(query) end api :GET, "/flatpak_remote_repositories/:id", N_("Show a flatpak remote repository") - param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true + param :id, :number, :desc => N_("Flatpak remote repository numeric identifier"), :required => true param :manifests, :boolean, :desc => N_("Include manifests"), :required => false def show respond :resource => @flatpak_remote_repository end api :POST, "/flatpak_remote_repositories/:id/mirror", N_("Mirror a flatpak remote repository") - param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true - param :product_id, :number, :desc => N_("Product ID to mirror the repository to"), :required => true + param :id, :number, :desc => N_("Flatpak remote repository numeric identifier"), :required => true + param :product_id, :number, :desc => N_("Product ID to mirror the remote repository to"), :required => true def mirror task = async_task(::Actions::Katello::Flatpak::MirrorRemoteRepository, @flatpak_remote_repository, @product) respond_for_async :resource => task diff --git a/app/controllers/katello/api/v2/flatpak_remotes_controller.rb b/app/controllers/katello/api/v2/flatpak_remotes_controller.rb index 9733a7fb646..ef80730a658 100644 --- a/app/controllers/katello/api/v2/flatpak_remotes_controller.rb +++ b/app/controllers/katello/api/v2/flatpak_remotes_controller.rb @@ -19,7 +19,6 @@ class Api::V2::FlatpakRemotesController < Katello::Api::V2::ApiController api :GET, "/flatpak_remotes", N_("List flatpak remotes") param :organization_id, :number, :desc => N_("organization identifier"), :required => false param :name, String, :desc => N_("Name of the flatpak remote"), :required => false - param :label, String, :desc => N_("Label of the flatpak remote"), :required => false param_group :search, Api::V2::ApiController add_scoped_search_description_for(FlatpakRemote) def index @@ -35,12 +34,14 @@ def index_relation end api :GET, "/flatpak_remotes/:id", N_("Show a flatpak remote") + api :GET, "/organizations/:organization_id/flatpak_remotes/:id", N_("Show a flatpak remote") param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true + param :organization_id, :number, :desc => N_("organization identifier") def show respond :resource => @flatpak_remote end - api :POST, "/flatpak_remote", N_("Create a flatpak remote") + api :POST, "/flatpak_remotes", N_("Create a flatpak remote") param :name, String, :desc => N_("name"), :required => true param :url, String, :desc => N_("url"), :required => true param :organization_id, :number, :desc => N_("organization identifier"), :required => true @@ -67,7 +68,7 @@ def destroy @flatpak_remote.destroy end - api :POST, "/flatpak_remote/:id/scan", N_("Scan a flatpak remote") + api :POST, "/flatpak_remotes/:id/scan", N_("Scan a flatpak remote") param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true def scan task = async_task(::Actions::Katello::Flatpak::ScanRemote, @flatpak_remote) @@ -79,7 +80,7 @@ def default_sort end def flatpak_remote_params - params.require(:flatpak_remote).permit(:name, :url, :organization_id, :description, :username, :token) + params.require(:flatpak_remote).permit(:name, :url, :description, :organization_id, :username, :token) end end end diff --git a/app/models/katello/flatpak_remote.rb b/app/models/katello/flatpak_remote.rb index bebc004ae0e..27229fb409d 100644 --- a/app/models/katello/flatpak_remote.rb +++ b/app/models/katello/flatpak_remote.rb @@ -10,6 +10,7 @@ class FlatpakRemote < Katello::Model validates :name, presence: true validates :url, presence: true validates :organization_id, presence: true + validates :name, :uniqueness => {:scope => :organization_id} scope :seeded, -> { where(:seeded => true) } diff --git a/config/routes/api/v2.rb b/config/routes/api/v2.rb index 8864ca06564..c6c894a76fe 100644 --- a/config/routes/api/v2.rb +++ b/config/routes/api/v2.rb @@ -278,6 +278,8 @@ class ActionDispatch::Routing::Mapper get :manifest_history end end + api_resources :flatpak_remotes, :only => [:index, :show] + api_resources :flatpak_remote_repositories, :only => [:index, :show] end match "/packages/thindex" => "packages#thindex", :via => :get