-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37976 - API and rabl views for flatpak remotes
- Loading branch information
Showing
9 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
app/controllers/katello/api/v2/flatpak_remotes_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module Katello | ||
class Api::V2::FlatpakRemotesController < Katello::Api::V2::ApiController | ||
include Katello::Concerns::FilteredAutoCompleteSearch | ||
|
||
before_action :find_authorized_katello_resource, :except => [:index, :create, :copy, :auto_complete_search] | ||
before_action :find_optional_organization, :only => [:index, :auto_complete_search] | ||
|
||
resource_description do | ||
name 'Flatpak Remotes' | ||
end | ||
|
||
def_param_group :flatpak_remote do | ||
param :description, String, :desc => N_("Description of the flatpak remote"), :required => false | ||
param :username, String, :desc => N_("Username for the flatpak remote"), :required => false | ||
param :token, String, :desc => N_("Token/password for the flatpak remote"), :required => false | ||
end | ||
|
||
api :GET, "/organizations/:organization_id/flatpak_remotes", N_("List flatpak remotes") | ||
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 | ||
respond(:collection => scoped_search(index_relation, :name, :asc)) | ||
end | ||
|
||
def index_relation | ||
remotes = FlatpakRemote.readable | ||
remotes = remotes.where(organization_id: @organization.id) if @organization | ||
remotes = remotes.where(name: params[:name]) if params[:name] | ||
remotes = remotes.where(label: params[:label]) if params[:label] | ||
remotes | ||
end | ||
|
||
api :GET, "/flatpak_remotes/:id", N_("Show a content view") | ||
param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true | ||
def show | ||
respond :resource => @flatpak_remote | ||
end | ||
|
||
api :POST, "/flatpak_remote", 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 | ||
param_group :flatpak_remote | ||
def create | ||
flatpak_remote = FlatpakRemote.new(flatpak_remote_params) | ||
respond_for_create(resource: flatpak_remote) | ||
end | ||
|
||
api :PUT, "/flatpak_remotes/:id", N_("Update a flatpak remote") | ||
param_group :flatpak_remote | ||
param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true | ||
param :name, String, :desc => N_("name") | ||
param :url, String, :desc => N_("url") | ||
def update | ||
@flatpak_remote.update!(flatpak_remote_params) | ||
end | ||
|
||
api :DELETE, "/flatpak_remotes/:id", N_("Delete a flatpak remote") | ||
param :id, :number, :desc => N_("Flatpak remote numeric identifier"), :required => true | ||
def destroy | ||
@flatpak_remote.destroy | ||
end | ||
|
||
def default_sort | ||
%w(name asc) | ||
end | ||
|
||
def flatpak_remote_params | ||
params.require(:flatpak_remote).permit(:name, :url, :organization_id, :description, :username, :token) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Katello | ||
module Authorization::FlatpakRemote | ||
extend ActiveSupport::Concern | ||
|
||
include Authorizable | ||
|
||
def readable? | ||
authorized?(:view_flatpak_remotes) | ||
end | ||
|
||
def editable? | ||
authorized?(:edit_flatpak_remotes) | ||
end | ||
|
||
def deletable? | ||
authorized?(:destroy_flatpak_remotes) | ||
end | ||
|
||
module ClassMethods | ||
def readable | ||
authorized(:view_flatpak_remotes) | ||
end | ||
|
||
def editable | ||
authorized(:edit_flatpak_remotes) | ||
end | ||
|
||
def deletable | ||
authorized(:destroy_flatpak_remotes) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
module Katello | ||
class FlatpakRemote < Katello::Model | ||
include Authorization::FlatpakRemote | ||
include ForemanTasks::Concerns::ActionSubject | ||
|
||
has_many :remote_repositories, dependent: :destroy, class_name: 'Katello::FlatpakRemoteRepository' | ||
has_many :remote_repository_manifests, through: :remote_repositories, source: :remote_repository_manifests | ||
belongs_to :organization, inverse_of: :flatpak_remotes | ||
|
||
validates :name, presence: true | ||
validates :url, presence: true | ||
validates :organization_id, presence: true | ||
|
||
scope :seeded, -> { where(:seeded => true) } | ||
|
||
scoped_search :on => :name, :complete_value => true | ||
scoped_search :on => :organization_id, :complete_value => true, :only_explicit => true, :validator => ScopedSearch::Validators::INTEGER | ||
scoped_search :on => :url, :complete_value => true | ||
scoped_search :on => :seeded, :complete_value => true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extends 'katello/api/v2/common/identifier' | ||
extends 'katello/api/v2/common/org_reference' | ||
|
||
attributes :name | ||
attributes :url, :description, :username, :token, :seeded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
object false | ||
|
||
extends "katello/api/v2/common/index" | ||
extends 'katello/api/v2/flatpak_remotes/permissions' | ||
|
||
child @collection[:results] => :results do | ||
extends "katello/api/v2/flatpak_remotes/base" | ||
end |
11 changes: 11 additions & 0 deletions
11
app/views/katello/api/v2/flatpak_remotes/permissions.json.rabl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
collection @flatpak_remotes | ||
|
||
if ::Foreman::Cast.to_bool(params.fetch(:include_permissions, false)) | ||
user = User.current # current_user is not available here | ||
node do | ||
node(:can_create) { user.can?("create_flatpak_remotes") } | ||
node(:can_edit) { user.can?("edit_flatpak_remotes") } | ||
node(:can_delete) { user.can?("destroy_flatpak_remotes") } | ||
node(:can_view) { user.can?("view_flatpak_remotes") } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object @resource | ||
|
||
extends "katello/api/v2/flatpak_remotes/base" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters