Merge pull request #738 from warpc/732-maintainer-db-api

[refs #732] add maintainers api
This commit is contained in:
Vladimir Sharshov 2012-11-30 09:33:21 -08:00
commit ec57f0ba9a
8 changed files with 72 additions and 6 deletions

View File

@ -0,0 +1,11 @@
class Api::V1::MaintainersController < Api::V1::BaseController
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
load_and_authorize_resource :platform
def index
@maintainers = BuildList::Package.includes(:project)
.actual.by_platform(@platform)
.like_name(params[:filter].try(:[], :package_name))
.paginate(paginate_params)
end
end

View File

@ -5,11 +5,9 @@ class Platforms::MaintainersController < ApplicationController
load_and_authorize_resource :platform
def index
@maintainers = BuildList::Package.actual.by_platform(@platform)
.order('lower(name) ASC, length(name) ASC')
.includes(:project)
@maintainers = @maintainers.where('name ILIKE ?', "%#{params[:q]}%") if params[:q].present?
@maintainers = @maintainers.paginate(:page => params[:page])
@maintainers = BuildList::Package.includes(:project)
.actual.by_platform(@platform)
.like_name(params[:q])
.paginate(:page => params[:page])
end
end

View File

@ -12,11 +12,14 @@ class BuildList::Package < ActiveRecord::Base
:presence => true
validates :package_type, :inclusion => PACKAGE_TYPES
default_scope order('lower(name) ASC, length(name) ASC')
# Fetches only actual (last publised) packages.
scope :actual, where(:actual => true)
scope :by_platform, lambda {|platform| where(:platform_id => platform) }
scope :by_name, lambda {|name| where(:name => name) }
scope :by_package_type, lambda {|type| where(:package_type => type) }
scope :like_name, lambda {|name| where('name ILIKE ?', "%#{name}%") if name.present?}
def assignee
project.maintainer

View File

@ -0,0 +1,2 @@
json.(maintainer, :id, :uname, :name, :email)
json.url api_v1_user_path(maintainer.id)

View File

@ -0,0 +1,3 @@
json.(package, :id, :name, :version, :release)
json.type package.package_type
json.updated_at package.updated_at.to_i

View File

@ -0,0 +1,15 @@
json.maintainers @maintainers do |json, maintainer|
json.project do |json_project|
json_project.partial! 'api/v1/projects/project', :project => maintainer.project, :json => json
end
json.package do |json_package|
json_package.partial! 'package', :package => maintainer, :json => json
end
json.maintainer do |json_maintainer|
if user = maintainer.try(:assignee)
json_maintainer.partial! 'maintainer', :maintainer => user, :json => json
end
end
end

View File

@ -33,6 +33,7 @@ Rosa::Application.routes.draw do
post :clone
put :clear
}
resources :maintainers, :only => [ :index ]
end
resources :repositories, :only => [:show, :update, :destroy] do
member {

View File

@ -0,0 +1,33 @@
require 'spec_helper'
describe Api::V1::MaintainersController do
before do
stub_symlink_methods
end
let(:package) { FactoryGirl.create(:build_list_package) }
context 'for guest' do
it "should be able to perform index action", :anonymous_access => true do
get :index, :platform_id => package.platform_id, :format => :json
should render_template(:index)
end
it 'should be able to perform get_id action', :anonymous_access => false do
get :index, :platform_id => package.platform_id, :format => :json
response.status.should == 401
end
end
context 'for simple user' do
before do
stub_symlink_methods
http_login(FactoryGirl.create(:user))
end
it "should be able to perform index action" do
get :index, :platform_id => package.platform_id, :format => :json
should render_template(:index)
end
end
end