From 9ba87cd36179959a48e12ac2c24d24ee78affd99 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 29 Aug 2014 02:22:11 +0600 Subject: [PATCH] fix api ActionView::MissingTemplate --- .../api/v1/advisories_controller.rb | 9 +++++++-- app/controllers/api/v1/arches_controller.rb | 5 ++++- app/controllers/api/v1/base_controller.rb | 2 +- .../api/v1/build_lists_controller.rb | 10 +++++++++- app/controllers/api/v1/groups_controller.rb | 16 ++++++++++++---- app/controllers/api/v1/issues_controller.rb | 10 +++++++--- .../api/v1/maintainers_controller.rb | 3 +++ .../api/v1/platforms_controller.rb | 17 ++++++++++++++--- .../api/v1/product_build_lists_controller.rb | 6 ++++++ app/controllers/api/v1/products_controller.rb | 3 +++ app/controllers/api/v1/projects_controller.rb | 19 +++++++++++++++++-- .../api/v1/pull_requests_controller.rb | 14 +++++++++++++- .../api/v1/repositories_controller.rb | 13 +++++++++++-- app/controllers/api/v1/search_controller.rb | 3 +++ app/controllers/api/v1/users_controller.rb | 11 +++++++++-- 15 files changed, 119 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/v1/advisories_controller.rb b/app/controllers/api/v1/advisories_controller.rb index 3fb5b0dd3..ab6ddc111 100644 --- a/app/controllers/api/v1/advisories_controller.rb +++ b/app/controllers/api/v1/advisories_controller.rb @@ -6,12 +6,17 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController authorize_resource :build_list, only: [:create, :update] def index - @advisories = @advisories.includes(:platforms, :projects). - paginate(paginate_params) + @advisories = @advisories.includes(:platforms, :projects).paginate(paginate_params) + respond_to do |format| + format.json + end end def show @packages_info = @advisory.fetch_packages_info + respond_to do |format| + format.json + end end def create diff --git a/app/controllers/api/v1/arches_controller.rb b/app/controllers/api/v1/arches_controller.rb index 813b5d27b..876abf9f8 100644 --- a/app/controllers/api/v1/arches_controller.rb +++ b/app/controllers/api/v1/arches_controller.rb @@ -3,6 +3,9 @@ class Api::V1::ArchesController < Api::V1::BaseController def index @arches = Arch.order(:id).paginate(paginate_params) + respond_to do |format| + format.json + end end -end \ No newline at end of file +end diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index f06fb29ee..739803f4f 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -1,6 +1,6 @@ class Api::V1::BaseController < ApplicationController include PaginateHelper - #respond_to :json + respond_to :json helper_method :member_path diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index efcb5fff4..fc706ccf0 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -1,16 +1,24 @@ class Api::V1::BuildListsController < Api::V1::BaseController - before_filter :authenticate_user! skip_before_filter :authenticate_user!, only: [:show, :index] if APP_CONFIG['anonymous_access'] load_resource :project, only: :index, parent: false load_and_authorize_resource :build_list, only: [:show, :create, :cancel, :publish, :reject_publish, :create_container, :publish_into_testing, :rerun_tests] + def show + respond_to do |format| + format.json + end + end + def index authorize!(:show, @project) if @project filter = BuildList::Filter.new(@project, current_user, current_ability, params[:filter] || {}) @build_lists = filter.find.includes(:save_to_platform, :project, :user, :arch) @build_lists = @build_lists.recent.paginate(paginate_params) + respond_to do |format| + format.json + end end def create diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index f5c19ef0d..19073acca 100644 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -7,15 +7,23 @@ class Api::V1::GroupsController < Api::V1::BaseController def index # accessible_by(current_ability) @groups = current_user.groups.paginate(paginate_params) + respond_to do |format| + format.json + end end def show + respond_to do |format| + format.json + end end def members - @members = @group.members. - where('actor_id != ?', @group.owner_id). - order('name').paginate(paginate_params) + @members = @group.members.where('actor_id != ?', @group.owner_id) + .order('name').paginate(paginate_params) + respond_to do |format| + format.json + end end def update @@ -46,4 +54,4 @@ class Api::V1::GroupsController < Api::V1::BaseController update_member_in_subject @group, :actors end -end \ No newline at end of file +end diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 3d2e40cc6..6fb77e696 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -1,6 +1,4 @@ class Api::V1::IssuesController < Api::V1::BaseController - respond_to :json - before_filter :authenticate_user! skip_before_filter :authenticate_user!, only: [:index, :group_index, :show] if APP_CONFIG['anonymous_access'] @@ -35,6 +33,9 @@ class Api::V1::IssuesController < Api::V1::BaseController def show redirect_to api_v1_project_pull_request_path(@project.id, @issue.serial_id) if @issue.pull_request + respond_to do |format| + format.json + end end def create @@ -102,7 +103,10 @@ class Api::V1::IssuesController < Api::V1::BaseController @issues = @issues.where('issues.created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/ @issues = @issues.paginate(paginate_params) - render :index + + respond_to do |format| + format.json { render :index } + end end def get_all_project_ids default_project_ids diff --git a/app/controllers/api/v1/maintainers_controller.rb b/app/controllers/api/v1/maintainers_controller.rb index c6596ca69..ec909dc9e 100644 --- a/app/controllers/api/v1/maintainers_controller.rb +++ b/app/controllers/api/v1/maintainers_controller.rb @@ -7,5 +7,8 @@ class Api::V1::MaintainersController < Api::V1::BaseController .actual.by_platform(@platform) .like_name(params[:package_name]) .paginate(paginate_params) + respond_to do |format| + format.json + end end end diff --git a/app/controllers/api/v1/platforms_controller.rb b/app/controllers/api/v1/platforms_controller.rb index 52bc77c46..c676f00e6 100644 --- a/app/controllers/api/v1/platforms_controller.rb +++ b/app/controllers/api/v1/platforms_controller.rb @@ -16,16 +16,24 @@ class Api::V1::PlatformsController < Api::V1::BaseController end def index - @platforms = @platforms.accessible_by(current_ability, :related). - by_type(params[:type]).paginate(paginate_params) + @platforms = @platforms.accessible_by(current_ability, :related) + .by_type(params[:type]).paginate(paginate_params) + respond_to do |format| + format.json + end end def show + respond_to do |format| + format.json + end end def platforms_for_build @platforms = Platform.main.opened.paginate(paginate_params) - render :index + respond_to do |format| + format.json { render :index } + end end def create @@ -44,6 +52,9 @@ class Api::V1::PlatformsController < Api::V1::BaseController def members @members = @platform.members.order('name').paginate(paginate_params) + respond_to do |format| + format.json + end end def add_member diff --git a/app/controllers/api/v1/product_build_lists_controller.rb b/app/controllers/api/v1/product_build_lists_controller.rb index 6375d1382..b9de4c416 100644 --- a/app/controllers/api/v1/product_build_lists_controller.rb +++ b/app/controllers/api/v1/product_build_lists_controller.rb @@ -13,6 +13,9 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController end @product_build_lists = @product_build_lists.joins(:product, :project, :arch) @product_build_lists = @product_build_lists.recent.paginate(paginate_params) + respond_to do |format| + format.json + end end def create @@ -24,6 +27,9 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController end def show + respond_to do |format| + format.json + end end def update diff --git a/app/controllers/api/v1/products_controller.rb b/app/controllers/api/v1/products_controller.rb index 1ca2c2bc7..c81baf935 100644 --- a/app/controllers/api/v1/products_controller.rb +++ b/app/controllers/api/v1/products_controller.rb @@ -13,6 +13,9 @@ class Api::V1::ProductsController < Api::V1::BaseController end def show + respond_to do |format| + format.json + end end def destroy diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 94276314d..e8eb21d5e 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -6,8 +6,11 @@ class Api::V1::ProjectsController < Api::V1::BaseController load_and_authorize_resource :project def index - @projects = Project.accessible_by(current_ability, :membered). - paginate(paginate_params) + @projects = Project.accessible_by(current_ability, :membered) + .paginate(paginate_params) + respond_to do |format| + format.json + end end def get_id @@ -16,13 +19,22 @@ class Api::V1::ProjectsController < Api::V1::BaseController else raise ActiveRecord::RecordNotFound end + respond_to do |format| + format.json + end end def show + respond_to do |format| + format.json + end end def refs_list @refs = @project.repo.branches + @project.repo.tags.select{ |t| t.commit } + respond_to do |format| + format.json + end end def update @@ -48,6 +60,9 @@ class Api::V1::ProjectsController < Api::V1::BaseController def members @members = @project.collaborators.order('uname').paginate(paginate_params) + respond_to do |format| + format.json + end end def add_member diff --git a/app/controllers/api/v1/pull_requests_controller.rb b/app/controllers/api/v1/pull_requests_controller.rb index 837673b37..7fc188dd3 100644 --- a/app/controllers/api/v1/pull_requests_controller.rb +++ b/app/controllers/api/v1/pull_requests_controller.rb @@ -39,6 +39,9 @@ class Api::V1::PullRequestsController < Api::V1::BaseController def show redirect_to api_v1_project_issue_path(@project.id, @issue.serial_id) if @pull.nil? + respond_to do |format| + format.json + end end def create @@ -95,10 +98,16 @@ class Api::V1::PullRequestsController < Api::V1::BaseController def commits @commits = @pull.repo.commits_between(@pull.to_commit, @pull.from_commit).paginate(paginate_params) + respond_to do |format| + format.json + end end def files @stats = @pull.diff_stats.zip(@pull.diff).paginate(paginate_params) + respond_to do |format| + format.json + end end def merge @@ -149,7 +158,10 @@ class Api::V1::PullRequestsController < Api::V1::BaseController @pulls = @pulls.where('issues.created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/ @pulls = @pulls.paginate(paginate_params) - render :index + + respond_to do |format| + format.json { render :index } + end end def get_all_project_ids default_project_ids diff --git a/app/controllers/api/v1/repositories_controller.rb b/app/controllers/api/v1/repositories_controller.rb index 3a53c08dd..fec61d6fb 100644 --- a/app/controllers/api/v1/repositories_controller.rb +++ b/app/controllers/api/v1/repositories_controller.rb @@ -1,4 +1,5 @@ class Api::V1::RepositoriesController < Api::V1::BaseController + respond_to :csv, only: :packages before_filter :authenticate_user! skip_before_filter :authenticate_user!, only: [:show, :projects] if APP_CONFIG['anonymous_access'] @@ -6,11 +7,16 @@ class Api::V1::RepositoriesController < Api::V1::BaseController load_and_authorize_resource :repository, through: :platform, shallow: true def show + respond_to do |format| + format.json + end end def projects - @projects = @repository.projects. - recent.paginate(paginate_params) + @projects = @repository.projects.recent.paginate(paginate_params) + respond_to do |format| + format.json + end end def update @@ -30,6 +36,9 @@ class Api::V1::RepositoriesController < Api::V1::BaseController end def key_pair + respond_to do |format| + format.json + end end # Only one request per 15 minutes for each platform diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb index cc02c6d25..ccb449b77 100644 --- a/app/controllers/api/v1/search_controller.rb +++ b/app/controllers/api/v1/search_controller.rb @@ -7,5 +7,8 @@ class Api::V1::SearchController < Api::V1::BaseController (params[:type] || 'all'), paginate_params ) + respond_to do |format| + format.json + end end end \ No newline at end of file diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index fed2c8e22..0c3539e8c 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -7,10 +7,15 @@ class Api::V1::UsersController < Api::V1::BaseController def show @user = User.opened.find params[:id] # dont show system users + respond_to do |format| + format.json + end end def show_current_user - render :show + respond_to do |format| + format.json { render :show } + end end def update @@ -35,7 +40,9 @@ class Api::V1::UsersController < Api::V1::BaseController render_json_response @user, error_message(@user.notifier, 'User notification settings have not been updated'), 422 end else - render :notifiers + respond_to do |format| + format.json + end end end