#214: merge master into branch

This commit is contained in:
Vokhmin Alexey V 2013-07-19 21:08:00 +04:00
commit 78a33727a6
55 changed files with 426 additions and 279 deletions

View File

@ -22,6 +22,7 @@ gem 'perform_later', '~> 1.3.0' # should be after resque_mailer
gem 'russian', '~> 0.6.0'
gem 'highline', '~> 1.6.11'
gem 'state_machine'
gem 'redis-rails'
gem 'grack', :git => 'git://github.com/rdblue/grack.git', :require => 'git_http'
gem "grit", :git => 'git://github.com/warpc/grit.git' #, :path => '~/Sites/code/grit'
@ -43,7 +44,7 @@ gem 'trinidad', '~> 1.0.2', :platforms => :jruby
gem 'newrelic_rpm', '~> 3.5.5.38', :platforms => [:mri, :rbx]
gem 'whenever', '~> 0.7.3', :require => false
gem 'jbuilder', '~> 0.8.2'
gem 'jbuilder', '~> 1.4.2'
gem 'rails3-jquery-autocomplete', '~> 1.0.7'
gem 'will_paginate', '~> 3.0.3'
gem 'meta-tags', '~> 1.2.5', :require => 'meta_tags'

View File

@ -70,7 +70,7 @@ GEM
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
blankslate (3.1.2)
bluepill (0.0.65)
bluepill (0.0.66)
activesupport (>= 3.0.0, < 4.0.0)
daemons (~> 1.1.4)
i18n (>= 0.5.0)
@ -163,8 +163,9 @@ GEM
hirb (0.7.1)
httpauth (0.2.0)
i18n (0.6.1)
jbuilder (0.8.3)
jbuilder (1.4.2)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
journey (1.0.4)
jquery-rails (2.0.3)
railties (>= 3.1.0, < 5.0)
@ -224,7 +225,7 @@ GEM
rack
omniauth-facebook (1.4.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-github (1.1.0)
omniauth-github (1.1.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-google-oauth2 (0.2.0)
@ -292,8 +293,24 @@ GEM
json (~> 1.4)
redcarpet (2.2.2)
redis (3.0.4)
redis-actionpack (3.2.3)
actionpack (~> 3.2.3)
redis-rack (~> 1.4.0)
redis-store (~> 1.1.0)
redis-activesupport (3.2.3)
activesupport (~> 3.2.3)
redis-store (~> 1.1.0)
redis-namespace (1.3.0)
redis (~> 3.0.0)
redis-rack (1.4.2)
rack (~> 1.4.1)
redis-store (~> 1.1.0)
redis-rails (3.2.3)
redis-actionpack (~> 3.2.3)
redis-activesupport (~> 3.2.3)
redis-store (~> 1.1.0)
redis-store (1.1.3)
redis (>= 2.2.0)
redisk (0.2.2)
redis (>= 0.1.1)
redis-namespace (>= 0.1.0)
@ -434,7 +451,7 @@ DEPENDENCIES
haml-rails (~> 0.3.4)
highline (~> 1.6.11)
hirb
jbuilder (~> 0.8.2)
jbuilder (~> 1.4.2)
jquery-rails (~> 2.0.2)
mailcatcher
meta-tags (~> 1.2.5)
@ -459,6 +476,7 @@ DEPENDENCIES
rdiscount
redcarpet (~> 2.2.2)
redhillonrails_core!
redis-rails
resque (~> 1.21.0)
resque-status (~> 0.3.3)
resque_mailer (~> 2.1.0)

View File

@ -7,7 +7,7 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController
authorize_resource :build_list, :only => [:create, :update]
def index
@advisories = @advisories.scoped(:include => :platforms).
@advisories = @advisories.scoped(:include => [:platforms, :projects]).
paginate(paginate_params)
end

View File

@ -16,13 +16,13 @@ class Api::V1::IssuesController < Api::V1::BaseController
def all_index
project_ids = get_all_project_ids Project.accessible_by(current_ability, :membered).pluck(:id)
@issues = Issue.where('issues.project_id IN (?)', project_ids)
@issues = Issue.where(:project_id => project_ids)
render_issues_list
end
def user_index
project_ids = get_all_project_ids current_user.projects.pluck(:id)
@issues = Issue.where('issues.project_id IN (?)', project_ids)
@issues = Issue.where(:project_id => project_ids)
render_issues_list
end

View File

@ -7,26 +7,7 @@ class Api::V1::PlatformsController < Api::V1::BaseController
load_and_authorize_resource :except => :allowed
def allowed
platform_name = (params[:path] || '').gsub(/^[\/]+/, '')
.match(/^(#{Platform::NAME_PATTERN}\/|#{Platform::NAME_PATTERN}$)/)
render(:nothing => true) && return unless platform_name
platform_name = platform_name[0].gsub(/\//, '')
platform = Platform.find_by_name platform_name
render(:nothing => true, :status => 403) && return unless platform
render(:nothing => true) && return unless platform.hidden?
if request.authorization.present?
token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
else
render(:nothing => true, :status => 403) && return
end
render(:nothing => true) && return if platform.tokens.by_active.where(:authentication_token => token).exists?
user = User.find_by_authentication_token token
@current_ability, @current_user = nil, user
if user && can?(:show, platform)
if Platform.allowed?(params[:path] || '', request)
render :nothing => true
else
render :nothing => true, :status => 403

View File

@ -61,9 +61,9 @@ class Ability
can :create, Project
can :read, Project, :visibility => 'open'
can [:read, :archive], Project, :owner_type => 'User', :owner_id => user.id
can [:read, :archive], Project, :owner_type => 'Group', :owner_id => user.group_ids
can([:read, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project}
can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id
can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids
can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project}
can(:write, Project) {|project| local_writer? project} # for grack
can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members], Project do |project|
local_admin? project
@ -81,6 +81,7 @@ class Ability
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can(:create, BuildList) {|build_list|
build_list.project.is_package &&
can?(:write, build_list.project) &&
@ -107,7 +108,7 @@ class Ability
can [:read, :owned, :related, :members], Platform, :owner_type => 'User', :owner_id => user.id
can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
can :related, Platform, :id => user.repositories.pluck(:platform_id)
can [:read, :related], Platform, :id => user.repositories.pluck(:platform_id)
can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) }
can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
@ -116,6 +117,7 @@ class Ability
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories')) {|repository| can? :show, repository.platform}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata], Repository) {|repository| local_admin? repository.platform}
can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
@ -192,14 +194,37 @@ class Ability
end
end
# TODO group_ids ??
def read_relations_for(table, parent = nil)
key = parent ? "#{parent.singularize}_id" : 'id'
parent ||= table
# Removes duplicates from subquery
#
# ["#{table}.#{key} IN
# (
# SELECT target_id FROM relations
# INNER JOIN #{parent} ON relations.target_type = :target_type AND relations.target_id = #{parent}.id
# WHERE relations.target_type = :target_type AND
# (
# #{parent}.owner_type = 'User' AND #{parent}.owner_id != :user OR
# #{parent}.owner_type = 'Group' AND #{parent}.owner_id NOT IN (:groups)
# ) AND (
# relations.actor_type = 'User' AND relations.actor_id = :user OR
# relations.actor_type = 'Group' AND relations.actor_id IN (:groups)
# )
# )",
# {
# :target_type => parent.classify,
# :user => @user.id,
# :groups => @user.group_ids
# }
# ]
["#{table}.#{key} IN (
SELECT target_id FROM relations WHERE relations.target_type = ? AND
(relations.actor_type = 'User' AND relations.actor_id = ? OR
relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids]
SELECT target_id FROM relations WHERE relations.target_type = ? AND
(relations.actor_type = 'User' AND relations.actor_id = ? OR
relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids]
end
def local_reader?(target)

View File

@ -177,6 +177,35 @@ class Platform < ActiveRecord::Base
EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
end
# Checks access rights to platform and caching for 1 day.
def self.allowed?(path, request)
platform_name = path.gsub(/^[\/]+/, '')
.match(/^(#{NAME_PATTERN}\/|#{NAME_PATTERN}$)/)
return true unless platform_name
platform_name = platform_name[0].gsub(/\//, '')
if request.authorization.present?
token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
end
Rails.cache.fetch([platform_name, token, :platform_allowed], :expires_in => 2.minutes) do
platform = Platform.find_by_name platform_name
next false unless platform
next true unless platform.hidden?
next false unless token
next true if platform.tokens.by_active.where(:authentication_token => token).exists?
user = User.find_by_authentication_token token
current_ability = Ability.new(user)
if user && current_ability.can?(:show, platform)
true
else
false
end
end
end
protected
def create_directory

View File

@ -1,12 +1,12 @@
json.id advisory.advisory_id
json.(advisory, :description)
json.platforms advisory.platforms do |json_platform, platform|
json_platform.(platform, :id, :released)
json_platform.url api_v1_platform_path(platform.id, :format => :json)
json.platforms advisory.platforms do |platform|
json.(platform, :id, :released)
json.url api_v1_platform_path(platform.id, :format => :json)
end
json.projects advisory.projects do |json_project, project|
json_project.(project, :id, :name)
json_project.fullname project.name_with_owner
json_project.url api_v1_project_path(project.id, :format => :json)
json.projects advisory.projects do |project|
json.(project, :id, :name)
json.fullname project.name_with_owner
json.url api_v1_project_path(project.id, :format => :json)
end
json.url api_v1_advisory_path(advisory.advisory_id, :format => :json)

View File

@ -1,4 +1,4 @@
json.advisories @advisories do |json, advisory|
json.partial! 'advisory', :advisory => advisory, :json => json
json.advisories @advisories do |advisory|
json.partial! 'advisory', :advisory => advisory
end
json.url api_v1_advisories_path(:format => :json)

View File

@ -1,26 +1,24 @@
json.advisory do |json|
json.partial! 'advisory', :advisory => @advisory, :json => json
json.advisory do
json.partial! 'advisory', :advisory => @advisory
json.created_at @advisory.created_at.to_i
json.updated_at @advisory.updated_at.to_i
json.(@advisory, :update_type)
json.references @advisory.references.split('\n')
json.build_lists @advisory.build_lists do |json_build_list, build_list|
json_build_list.(build_list, :id)
json_build_list.url api_v1_build_list_path(build_list.id, :format => :json)
json.build_lists @advisory.build_lists do |build_list|
json.(build_list, :id)
json.url api_v1_build_list_path(build_list.id, :format => :json)
end
json.affected_in @packages_info do |json_platform, package_info|
json.partial! 'api/v1/platforms/platform',
:platform => package_info[0], :json => json_platform
json.affected_in @packages_info do |package_info|
json.partial! 'api/v1/platforms/platform', :platform => package_info[0]
json_platform.projects package_info[1] do |json_project, info|
json.partial! 'api/v1/projects/project',
:project => info[0], :json => json_project
json.projects package_info[1] do |info|
json.partial! 'api/v1/projects/project', :project => info[0]
packages = info[1]
json_project.srpm packages[:srpm]
json_project.rpm packages[:rpm]
json.srpm packages[:srpm]
json.rpm packages[:rpm]
end
end

View File

@ -1,3 +1,3 @@
json.architectures @arches do |json, arch|
json.architectures @arches do |arch|
json.(arch, :id, :name)
end

View File

@ -1,9 +1,5 @@
json.partial! 'api/v1/repositories/repository',
:repository => repository,
:json => json
json.partial! 'api/v1/repositories/repository', :repository => repository
json.platform do |json_str_platform|
json.partial! 'api/v1/platforms/platform',
:platform => repository.platform,
:json => json
json.platform do
json.partial! 'api/v1/platforms/platform', :platform => repository.platform
end

View File

@ -1,4 +1,4 @@
json.build_lists @build_lists do |json, build_list|
json.build_lists @build_lists do |build_list|
json.(build_list, :id, :status)
json.url api_v1_build_list_path(build_list, :format => :json)
end

View File

@ -1,4 +1,4 @@
json.build_list do |json|
json.build_list do
json.(@build_list, :id, :container_status, :status, :duration)
json.(@build_list, :update_type, :priority, :new_core)
json.(@build_list, :advisory, :mass_build)
@ -11,82 +11,74 @@ json.build_list do |json|
json.container_path ''
end
json.arch do |json_arch|
json_arch.(@build_list.arch, :id, :name)
json.arch do
json.(@build_list.arch, :id, :name)
end
json.created_at @build_list.created_at.to_i
json.updated_at @build_list.updated_at.to_i
json.project do |json_project|
json.partial! 'api/v1/projects/project',
:project => @build_list.project, :json => json_project
json.project do
json.partial! 'api/v1/projects/project', :project => @build_list.project
end
json.save_to_repository do |json_save_to_repository|
json.save_to_repository do
json.partial! 'api/v1/repositories/repository',
:repository => @build_list.save_to_repository,
:json => json_save_to_repository
:repository => @build_list.save_to_repository
json_save_to_repository.platform do |json_str_platform|
json.platform do
json.partial! 'api/v1/platforms/platform',
:platform => @build_list.save_to_repository.platform,
:json => json_str_platform
:platform => @build_list.save_to_repository.platform
end
end
json.build_for_platform do |json_build_for_platform|
json.build_for_platform do
json.partial! 'api/v1/platforms/platform',
:platform => @build_list.build_for_platform,
:json => json_build_for_platform
:platform => @build_list.build_for_platform
end
json.user do |json_user|
json.partial! 'api/v1/shared/member', :member => @build_list.user, :tag => json_user
json.user do
json.partial! 'api/v1/shared/member', :member => @build_list.user
end
json.publisher do |json_publisher|
json.partial! 'api/v1/shared/member', :member => @build_list.publisher, :tag => json_publisher
json.publisher do
json.partial! 'api/v1/shared/member', :member => @build_list.publisher
end if @build_list.publisher
inc_repos = Repository.includes(:platform).where(:id => @build_list.include_repos)
json.include_repos inc_repos do |json_include_repos, repo|
json.partial! 'repositories',
:repository => repo,
:json => json_include_repos
json.include_repos inc_repos do |repo|
json.partial! 'repositories', :repository => repo
end
extra_repos = Repository.includes(:platform).where(:id => @build_list.extra_repositories)
json.extra_repositories extra_repos do |json_extra_repos, repo|
json.partial! 'repositories',
:repository => repo,
:json => json_extra_repos
json.extra_repositories extra_repos do |repo|
json.partial! 'repositories', :repository => repo
end
extra_build_lists = BuildList.where(:id => @build_list.extra_build_lists)
json.extra_build_lists extra_build_lists do |json_extra_build_lists, bl|
json_extra_build_lists.(bl, :id, :status)
json_extra_build_lists.container_path container_url(bl)
json_extra_build_lists.url api_v1_build_list_path(bl, :format => :json)
json.extra_build_lists extra_build_lists do |bl|
json.(bl, :id, :status)
json.container_path container_url(bl)
json.url api_v1_build_list_path(bl, :format => :json)
end
json.advisory do |json_advisory|
json_advisory.name @build_list.advisory.advisory_id
json_advisory.(@build_list.advisory, :description)
json.advisory do
json.name @build_list.advisory.advisory_id
json.(@build_list.advisory, :description)
end if @build_list.advisory
json.mass_build do |json_mass_build|
json_mass_build.(@build_list.mass_build, :id, :name)
json.mass_build do
json.(@build_list.mass_build, :id, :name)
end if @build_list.mass_build
json.logs (@build_list.results || []) do |json_logs, result|
json_logs.file_name result['file_name']
json_logs.size result['size']
json_logs.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{result['sha1']}"
json.logs (@build_list.results || []) do |result|
json.file_name result['file_name']
json.size result['size']
json.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{result['sha1']}"
end if @build_list.new_core?
json.packages @build_list.packages do |json_packages, package|
json_packages.partial! 'api/v1/maintainers/package', :package => package, :json => json_packages
json.packages @build_list.packages do |package|
json.partial! 'api/v1/maintainers/package', :package => package
end
json.url api_v1_build_list_path(@build_list, :format => :json)

View File

@ -1,4 +1,4 @@
json.groups @groups do |json, group|
json.groups @groups do |group|
json.(group, :id, :uname, :own_projects_count, :description)
json.created_at group.created_at.to_i
json.updated_at group.updated_at.to_i

View File

@ -1,4 +1,4 @@
json.group do |json|
json.group do
json.(@group, :id)
json.partial! 'api/v1/shared/members'
end

View File

@ -1,4 +1,4 @@
json.group do |json|
json.group do
json.(@group, :id, :uname, :own_projects_count, :description)
json.created_at @group.created_at.to_i
json.updated_at @group.updated_at.to_i

View File

@ -1,10 +1,10 @@
json.number issue.serial_id
json.(issue, :title, :status)
json.labels issue.labels do |json_labels, label|
json.partial! 'label', :label => label, :json => json_labels
json.labels issue.labels do |label|
json.partial! 'label', :label => label
end
json.assignee do |json_assignee|
json.partial! 'api/v1/shared/member', :member => issue.assignee, :tag => json_assignee
json.assignee do
json.partial! 'api/v1/shared/member', :member => issue.assignee
end if issue.assignee
json.url api_v1_project_issue_path(issue.project.id, issue.serial_id, :format => :json)

View File

@ -1,10 +1,10 @@
json.issues @issues do |json, issue|
json.partial! 'issue', :issue => issue, :json => json
json.issues @issues do |issue|
json.partial! 'issue', :issue => issue
json.issue issue.body
json.partial! 'api/v1/shared/owner', :owner => issue.user
json.closed_at issue.closed_at.to_i
json.closed_by do |json_user|
json.partial! 'api/v1/shared/member', :member => issue.closer, :tag => json_user
json.closed_by do
json.partial! 'api/v1/shared/member', :member => issue.closer
end if issue.closer
json.created_at issue.created_at.to_i
json.updated_at issue.updated_at.to_i

View File

@ -1,10 +1,10 @@
json.issue do |json|
json.partial! 'issue', :issue => @issue, :json => json
json.issue do
json.partial! 'issue', :issue => @issue
json.issue @issue.body
json.partial! 'api/v1/shared/owner', :owner => @issue.user
json.closed_at @issue.closed_at.to_i
json.closed_by do |json_user|
json.partial! 'api/v1/shared/member', :member => @issue.closer, :tag => json_user
json.closed_by do
json.partial! 'api/v1/shared/member', :member => @issue.closer
end if @issue.closer
json.created_at @issue.created_at.to_i
json.updated_at @issue.updated_at.to_i

View File

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

View File

@ -1,10 +1,10 @@
json.platforms @platforms do |json, platform|
json.partial! 'platform', :platform => platform, :json => json
json.platforms @platforms do |platform|
json.partial! 'platform', :platform => platform
json.(platform, :platform_type, :visibility)
json.partial! 'api/v1/shared/owner', :owner => platform.owner
json.repositories platform.repositories do |json_repos, repo|
json_repos.(repo, :id, :name)
json_repos.url api_v1_repository_path(repo.id, :format => :json)
json.repositories platform.repositories do |repo|
json.(repo, :id, :name)
json.url api_v1_repository_path(repo.id, :format => :json)
end
end

View File

@ -1,5 +1,5 @@
json.platform do |json|
json.partial! 'platform', :platform => @platform, :json => json
json.platform do
json.partial! 'platform', :platform => @platform
json.partial! 'api/v1/shared/members'
end
json.url members_api_v1_platform_path(@platform.id, :format => :json)

View File

@ -1,14 +1,14 @@
json.platform do |json|
json.partial! 'platform', :platform => @platform, :json => json
json.platform do
json.partial! 'platform', :platform => @platform
json.(@platform, :description, :parent_platform_id, :released, :visibility, :platform_type, :distrib_type)
json.created_at @platform.created_at.to_i
json.updated_at @platform.updated_at.to_i
json.partial! 'api/v1/shared/owner', :owner => @platform.owner
json.repositories @platform.repositories do |json_repos, repo|
json_repos.(repo, :id, :name)
json_repos.url api_v1_repository_path(repo.id, :format => :json)
json.repositories @platform.repositories do |repo|
json.(repo, :id, :name)
json.url api_v1_repository_path(repo.id, :format => :json)
end
json.products @platform.products do |json_products, product|
json.partial! 'api/v1/products/product', :product => product, :json => json_products
json.products @platform.products do |product|
json.partial! 'api/v1/products/product', :product => product
end
end

View File

@ -1,11 +1,11 @@
json.product do |json|
json.partial! 'product', :product => @product, :json => json
json.platform do |json_platform|
json.partial! 'api/v1/platforms/platform', :platform => @product.platform, :json => json_platform
json.product do
json.partial! 'product', :product => @product
json.platform do
json.partial! 'api/v1/platforms/platform', :platform => @product.platform
end
if @product.project.present?
json.project do |json_project|
json.partial! 'api/v1/projects/project', :project => @product.project, :json => json_project
json.project do
json.partial! 'api/v1/projects/project', :project => @product.project
end
end
json.created_at @product.created_at.to_i

View File

@ -1,5 +1,5 @@
json.project do |json|
json.partial! 'project', :project => @project, :json => json
json.project do
json.partial! 'project', :project => @project
json.(@project, :visibility)
json.partial! 'api/v1/shared/owner', :owner => @project.owner
end

View File

@ -1,5 +1,5 @@
json.projects @projects do |json, project|
json.partial! 'project', :project => project, :json => json
json.projects @projects do |project|
json.partial! 'project', :project => project
json.(project, :visibility, :description, :ancestry, :has_issues, :has_wiki, :default_branch, :is_package, :average_build_time, :publish_i686_into_x86_64)
json.created_at project.created_at.to_i
json.updated_at project.updated_at.to_i

View File

@ -1,5 +1,5 @@
json.project do |json|
json.partial! 'project', :project => @project, :json => json
json.project do
json.partial! 'project', :project => @project
json.partial! 'api/v1/shared/members'
end
json.url members_api_v1_project_path(@project.id, :format => :json)

View File

@ -1,9 +1,9 @@
json.refs_list @refs do |json_grit, grit|
json_grit.ref grit.name
json_grit.object do |json_object|
json_object.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit')
json_object.sha grit.commit.id
json_object.authored_date grit.commit.authored_date.to_i
json.refs_list @refs do |grit|
json.ref grit.name
json.object do
json.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit')
json.sha grit.commit.id
json.authored_date grit.commit.authored_date.to_i
end
end
json.url refs_list_api_v1_project_path(@project.id, :format => :json)

View File

@ -1,18 +1,18 @@
json.project do |json|
json.partial! 'project', :project => @project, :json => json
json.project do
json.partial! 'project', :project => @project
json.(@project, :visibility, :description, :ancestry, :has_issues, :has_wiki, :default_branch, :is_package, :average_build_time, :publish_i686_into_x86_64)
json.created_at @project.created_at.to_i
json.updated_at @project.updated_at.to_i
json.partial! 'api/v1/shared/owner', :owner => @project.owner
json.maintainer do |json_maintainer|
json.partial! 'api/v1/shared/member', :member => @project.maintainer, :tag => json_maintainer
json.maintainer do
json.partial! 'api/v1/shared/member', :member => @project.maintainer
end
json.repositories @project.repositories do |json_repos, repo|
json_repos.(repo, :id, :name)
json_repos.url api_v1_repository_path(repo.name, :format => :json)
json_repos.platform do |json_platform|
json_platform.(repo.platform, :id, :name)
json_platform.url api_v1_platform_path(repo.platform, :format => :json)
json.repositories @project.repositories do |repo|
json.(repo, :id, :name)
json.url api_v1_repository_path(repo.name, :format => :json)
json.platform do
json.(repo.platform, :id, :name)
json.url api_v1_platform_path(repo.platform, :format => :json)
end
end
end

View File

@ -1,22 +1,22 @@
json.number pull.serial_id
json.(pull, :title, :status)
json.to_ref do |json_ref|
json_ref.ref pull.to_ref
json_ref.sha pull.to_commit.try(:id)
json_ref.project do |json_project|
json_project.partial! 'api/v1/projects/project', :project => pull.to_project, :json => json
json.to_ref do
json.ref pull.to_ref
json.sha pull.to_commit.try(:id)
json.project do
json.partial! 'api/v1/projects/project', :project => pull.to_project
end
end
json.from_ref do |json_ref|
json_ref.ref pull.from_ref
json_ref.sha pull.from_commit.try(:id)
json_ref.project do |json_project|
json_project.partial! 'api/v1/projects/project', :project => pull.from_project, :json => json
json.from_ref do
json.ref pull.from_ref
json.sha pull.from_commit.try(:id)
json.project do
json.partial! 'api/v1/projects/project', :project => pull.from_project
end
end
json.partial! 'api/v1/shared/owner', :owner => pull.user
json.assignee do |json_assignee|
json.partial! 'api/v1/shared/member', :member => pull.issue.assignee, :tag => json_assignee
json.assignee do
json.partial! 'api/v1/shared/member', :member => pull.issue.assignee
end if pull.issue.assignee
json.mergeable pull.can_merging?
json.merged_at pull.issue.closed_at.to_i if pull.merged?

View File

@ -1,22 +1,22 @@
json.commits @commits do |json_commit, commit|
json_commit.sha commit.id
json_commit.https_url commit_path(@project, commit.id)
json.author do |json_author|
json_author.name commit.author.name
json_author.email commit.author.email
json_author.date commit.authored_date.to_i
json.commits @commits do |commit|
json.sha commit.id
json.https_url commit_path(@project, commit.id)
json.author do
json.name commit.author.name
json.email commit.author.email
json.date commit.authored_date.to_i
end
json.committer do |json_committer|
json_committer.name commit.committer.name
json_committer.email commit.committer.email
json_committer.date commit.committed_date.to_i
json.committer do
json.name commit.committer.name
json.email commit.committer.email
json.date commit.committed_date.to_i
end
json.message commit.message
json.tree do |json_tree|
json_tree.sha commit.id
json_tree.https_url commit_path(@project, commit.id)
json.tree do
json.sha commit.id
json.https_url commit_path(@project, commit.id)
end
json.parents commit.parents do |json, parent|
json.parents commit.parents do |parent|
json.sha parent.id
json.https_url commit_path(@project, parent.id)
end

View File

@ -1,8 +1,8 @@
json.files @stats do |json_stat, stat|
json.files @stats do |stat|
fstat, diff = stat
commit_id = diff.deleted_file ? @pull.to_commit.id : @pull.from_commit.id
json_stat.sha commit_id
json_stat.filename diff.b_path
json.sha commit_id
json.filename diff.b_path
status = case
when diff.new_file
'added'
@ -13,12 +13,12 @@ json.files @stats do |json_stat, stat|
else
'modified'
end
json_stat.status status
json_stat.additions fstat.additions
json_stat.deletions fstat.deletions
json_stat.changes fstat.additions + fstat.deletions
json_stat.blob_https_url blob_path(@project, commit_id, diff.b_path)
json_stat.raw_https_url raw_path(@project, commit_id, diff.b_path)
json.status status
json.additions fstat.additions
json.deletions fstat.deletions
json.changes fstat.additions + fstat.deletions
json.blob_https_url blob_path(@project, commit_id, diff.b_path)
json.raw_https_url raw_path(@project, commit_id, diff.b_path)
end
json.url files_api_v1_project_pull_request_path(:format => :json)

View File

@ -1,5 +1,5 @@
json.pull_requests @pulls do |json, pull|
json.partial! 'pull', :pull => pull, :json => json
json.pull_requests @pulls do |pull|
json.partial! 'pull', :pull => pull
end
json.url @pulls_url

View File

@ -1,12 +1,12 @@
json.pull_request do |json|
json.partial! 'pull', :pull => @pull, :json => json
json.pull_request do
json.partial! 'pull', :pull => @pull
json.body @pull.body
json.closed_at @pull.issue.closed_at.to_i if @pull.merged? || @pull.closed?
json.closed_by do |json_user|
json.partial! 'api/v1/shared/member', :member => @pull.issue.closer, :tag => json_user
json.closed_by do
json.partial! 'api/v1/shared/member', :member => @pull.issue.closer
end if @pull.issue.closer
json.merged_by do |json_user|
json.partial! 'api/v1/shared/member', :member => @pull.issue.closer, :tag => json_user
json.merged_by do
json.partial! 'api/v1/shared/member', :member => @pull.issue.closer
end if @pull.merged?
json.created_at @pull.issue.created_at.to_i
json.updated_at @pull.issue.updated_at.to_i

View File

@ -1,11 +1,11 @@
json.repository do |json|
json.partial! 'repository', :repository => @repository, :json => json
json.key_pair do |json_key_pair|
json.repository do
json.partial! 'repository', :repository => @repository
json.key_pair do
if @repository.key_pair
json_key_pair.(@repository.key_pair, :public, :secret)
json.(@repository.key_pair, :public, :secret)
else
json_key_pair.public ''
json_key_pair.secret ''
json.public ''
json.secret ''
end
end
end

View File

@ -1,8 +1,7 @@
json.repository do |json|
json.partial! 'repository', :repository => @repository, :json => json
json.projects @projects do |json_project, project|
json.partial! 'api/v1/projects/project',
:project => project, :json => json_project
json.repository do
json.partial! 'repository', :repository => @repository
json.projects @projects do |project|
json.partial! 'api/v1/projects/project', :project => project
end
end
json.url projects_api_v1_repository_path(@repository.id, :format => :json)

View File

@ -1,10 +1,10 @@
json.repository do |json|
json.partial! 'repository', :repository => @repository, :json => json
json.repository do
json.partial! 'repository', :repository => @repository
json.(@repository, :description, :publish_without_qa)
json.created_at @repository.created_at.to_i
json.updated_at @repository.updated_at.to_i
json.platform do |json_platform|
json_platform.(@repository.platform, :id, :name)
json_platform.url api_v1_platform_path(@repository.platform, :format => :json)
json.platform do
json.(@repository.platform, :id, :name)
json.url api_v1_platform_path(@repository.platform, :format => :json)
end
end

View File

@ -1,3 +1,3 @@
json.groups results do |group|
json.partial! 'member', :member => group, :json => json
json.partial! 'member', :member => group
end

View File

@ -1,3 +1,3 @@
json.platforms results do |platform|
json.partial! 'api/v1/platforms/platform', :platform => platform, :json => json
json.partial! 'api/v1/platforms/platform', :platform => platform
end

View File

@ -1,3 +1,3 @@
json.projects results do |project|
json.partial! 'api/v1/projects/project', :project => project, :json => json
json.partial! 'api/v1/projects/project', :project => project
end

View File

@ -1,3 +1,3 @@
json.users results do |user|
json.partial! 'member', :member => user, :json => json
json.partial! 'member', :member => user
end

View File

@ -1,6 +1,6 @@
json.results do |json|
json.results do
@results.each do |tag, results|
json.partial! tag.dup, :results => results, :json => json
json.partial! tag.dup, :results => results
end
end
json.url api_v1_search_index_path(:format => :json)

View File

@ -1,3 +1,3 @@
tag.(member, :id, :name, :uname)
tag.type member.class.name
tag.url member_path(member)
json.(member, :id, :name, :uname)
json.type member.class.name
json.url member_path(member)

View File

@ -1,3 +1,3 @@
json.members @members do |json_members, member|
json.partial! 'api/v1/shared/member', :member => member, :tag => json_members
json.members @members do |member|
json.partial! 'api/v1/shared/member', :member => member
end

View File

@ -1,3 +1,3 @@
json.owner do |json_owner|
json.partial! 'api/v1/shared/member', :member => owner, :tag => json_owner
json.owner do
json.partial! 'api/v1/shared/member', :member => owner
end

View File

@ -1,7 +1,7 @@
json.user do |json|
json.user do
json.(@user, :id)
json.notifiers do |json_notifiers|
json_notifiers.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build)
json.notifiers do
json.(@user.notifier, :can_notify, :new_comment, :new_comment_reply, :new_issue, :issue_assign, :new_comment_commit_owner, :new_comment_commit_repo_owner, :new_comment_commit_commentor, :new_build, :new_associated_build)
end
end

View File

@ -1,4 +1,4 @@
json.user do |json|
json.user do
json.(@user, :id, :name, :email, :uname,:language, :own_projects_count, :professional_experience, :site, :company, :location, :build_priority)
json.created_at @user.created_at.to_i
json.updated_at @user.updated_at.to_i

View File

@ -24,6 +24,8 @@ Rosa::Application.configure do
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 10.minutes }
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

View File

@ -27,6 +27,7 @@ Rosa::Application.configure do
# Use a different cache store in production
# config.cache_store = :mem_cache_store
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 10.minutes }
# Disable Rails's static asset server
# In production, Apache or nginx will already do this

View File

@ -401,6 +401,38 @@ describe Api::V1::PlatformsController do
it_should_behave_like 'api platform user without global admin rights'
end
context 'for member of repository' do
before do
http_login(@user)
repository = FactoryGirl.create(:repository, :platform => @platform)
repository.add_member(@user)
personal_repository = FactoryGirl.create(:repository, :platform => @personal_platform)
personal_repository.add_member(@user)
end
context 'perform index action with type param' do
render_views
%w(main personal).each do |type|
it "ensures that filter by type = #{type} returns true result" do
get :index, :format => :json, :type => "#{type}"
JSON.parse(response.body)['platforms'].map{ |p| p['platform_type'] }.
uniq.should == ["#{type}"]
end
end
end
it 'should not be able to perform members action for hidden platform' do
@platform.update_column(:visibility, 'hidden')
get :members, :id => @platform.id, :format => :json
response.status.should == 403
end
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user with reader rights for hidden platform'
it_should_behave_like 'api platform user without member rights'
it_should_behave_like 'api platform user without owner rights'
it_should_behave_like 'api platform user without global admin rights'
end
context 'for simple user' do
before do
http_login(@user)

View File

@ -120,6 +120,23 @@ shared_examples_for 'api repository user with writer rights' do
end
end
context 'api repository user with update signatures rights' do
before do
kp = FactoryGirl.build(:key_pair)
put :signatures, :id => @repository.id, :repository => {:public => kp.public, :secret => kp.secret}, :format => :json
end
it 'should be able to perform signatures action' do
response.should be_success
end
it 'ensures that signatures has been updated' do
@repository.key_pair.should_not be_nil
end
end
end
shared_examples_for 'api repository user with project manage rights' do
context 'api repository user with add_project rights' do
before { put :add_project, :id => @repository.id, :project_id => @project.id, :format => :json }
it 'should be able to perform add_project action' do
@ -144,19 +161,6 @@ shared_examples_for 'api repository user with writer rights' do
end
end
context 'api repository user with update signatures rights' do
before do
kp = FactoryGirl.build(:key_pair)
put :signatures, :id => @repository.id, :repository => {:public => kp.public, :secret => kp.secret}, :format => :json
end
it 'should be able to perform signatures action' do
response.should be_success
end
it 'ensures that signatures has been updated' do
@repository.key_pair.should_not be_nil
end
end
end
shared_examples_for 'api repository user without writer rights' do
@ -221,6 +225,22 @@ shared_examples_for 'api repository user without writer rights' do
end
end
context 'api repository user without update signatures rights' do
before do
kp = FactoryGirl.build(:key_pair)
put :signatures, :id => @repository.id, :repository => {:public => kp.public, :secret => kp.secret}, :format => :json
end
it 'should not be able to perform signatures action' do
response.should_not be_success
end
it 'ensures that signatures has not been updated' do
@repository.key_pair.should be_nil
end
end
end
shared_examples_for 'api repository user without project manage rights' do
context 'api repository user without add_project rights' do
before { put :add_project, :id => @repository.id, :project_id => @project.id, :format => :json }
it 'should not be able to perform add_project action' do
@ -244,20 +264,6 @@ shared_examples_for 'api repository user without writer rights' do
@repository.projects.should include(@project)
end
end
context 'api repository user without update signatures rights' do
before do
kp = FactoryGirl.build(:key_pair)
put :signatures, :id => @repository.id, :repository => {:public => kp.public, :secret => kp.secret}, :format => :json
end
it 'should not be able to perform signatures action' do
response.should_not be_success
end
it 'ensures that signatures has not been updated' do
@repository.key_pair.should be_nil
end
end
end
@ -284,6 +290,7 @@ describe Api::V1::RepositoriesController do
it_should_behave_like 'api repository user with show rights'
end
it_should_behave_like 'api repository user without writer rights'
it_should_behave_like 'api repository user without project manage rights'
it_should_behave_like 'api repository user without key_pair rights'
it 'should not be able to perform projects action', :anonymous_access => false do
@ -331,6 +338,22 @@ describe Api::V1::RepositoriesController do
it_should_behave_like 'api repository user without reader rights for hidden platform'
it_should_behave_like 'api repository user with show rights'
it_should_behave_like 'api repository user without writer rights'
it_should_behave_like 'api repository user without project manage rights'
it_should_behave_like 'api repository user without key_pair rights'
end
context 'for member of repository' do
before(:each) do
@user = FactoryGirl.create(:user)
@repository.add_member @user
http_login @user
end
it_should_behave_like 'api repository user with reader rights'
it_should_behave_like 'api repository user with reader rights for hidden platform'
it_should_behave_like 'api repository user with show rights'
it_should_behave_like 'api repository user with project manage rights'
it_should_behave_like 'api repository user without writer rights'
it_should_behave_like 'api repository user without key_pair rights'
end

View File

@ -378,6 +378,22 @@ describe Platforms::PlatformsController do
it_should_behave_like 'platform user without global admin rights'
end
context 'for member of repository' do
before do
http_login(@user)
repository = FactoryGirl.create(:repository, :platform => @platform)
repository.add_member(@user)
personal_repository = FactoryGirl.create(:repository, :platform => @personal_platform)
personal_repository.add_member(@user)
end
it_should_behave_like 'platform user with reader rights'
it_should_behave_like 'platform user with reader rights for hidden platform'
it_should_behave_like 'platform user without member rights'
it_should_behave_like 'platform user without owner rights'
it_should_behave_like 'platform user without global admin rights'
end
context 'for simple user' do
before do
http_login(@user)

View File

@ -302,7 +302,7 @@ describe Platforms::RepositoriesController do
context 'for repository member user' do
before(:each) do
[@repository, @personal_repository].each do |repo|
repo.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
repo.add_member @user
end
end
@ -311,6 +311,19 @@ describe Platforms::RepositoriesController do
let(:redirect_path) { forbidden_path }
it_should_behave_like 'registered user or guest'
it_should_behave_like 'user with change projects in repository rights'
context 'for hidden platform' do
before do
@platform.update_column(:visibility, 'hidden')
@personal_repository.platform.update_column(:visibility, 'hidden')
end
it_should_behave_like 'registered user'
let(:redirect_path) { forbidden_path }
it_should_behave_like 'registered user or guest'
it_should_behave_like 'user with change projects in repository rights'
end
end
end

View File

@ -88,7 +88,7 @@ describe CanCan do
end
[Platform, Repository].each do |model_name|
it "should not be able to read #{model_name}" do
it "should be able to read #{model_name}" do
@ability.should be_able_to(:read, model_name)
end
end
@ -228,6 +228,27 @@ describe CanCan do
end
end
context 'through group-member' do
before(:each) do
@group_member = FactoryGirl.create(:group)
@project.relations.create!(:actor_id => @group_member.id, :actor_type => 'Group', :role => 'reader')
@group_member_ability = Ability.new(@group_member.owner)
end
it 'should be able to read open project' do
@group_member_ability.should be_able_to(:read, @project)
end
it 'should be able to read closed project' do
@project.update_attribute :visibility, 'hidden'
@group_member_ability.should be_able_to(:read, @project)
end
it 'should include hidden project in list' do
@project.update_attribute :visibility, 'hidden'
Project.accessible_by(@group_member_ability, :show).where(:projects => {:id => @project.id}).count.should == 1
end
end
end
context 'platform relations' do