Merge branch 'master' into 579-code_line_comments

Conflicts:
	app/views/projects/pull_requests/_pull_diff.html.haml
	app/views/projects/wiki/_diff_data.html.haml
This commit is contained in:
Alexander Machehin 2012-10-16 00:19:22 +06:00
commit 938a8a0ad1
38 changed files with 845 additions and 132 deletions

View File

@ -3,7 +3,7 @@ class Api::V1::ArchesController < Api::V1::BaseController
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
def index
@arches = Arch.order(:id).all
@arches = Arch.order(:id).paginate(paginate_params)
end
end

View File

@ -1,7 +1,5 @@
# -*- encoding : utf-8 -*-
class Api::V1::BaseController < ApplicationController
before_filter :restrict_paginate, :only => :index
#respond_to :json
rescue_from CanCan::AccessDenied do |exception|
@ -12,9 +10,71 @@ class Api::V1::BaseController < ApplicationController
protected
def restrict_paginate
params[:per_page] = 30 if params[:per_page].to_i < 1
params[:per_page] = 100 if params[:per_page].to_i >100
def add_member_to_subject(subject)
class_name = subject.class.name.downcase
if member.present? && subject.add_member(member)
render_json_response subject, "#{member.class.to_s} '#{member.id}' has been added to #{class_name} successfully"
else
render_validation_error subject, "Member has not been added to #{class_name}"
end
end
def remove_member_from_subject(subject)
class_name = subject.class.name.downcase
if member.present? && subject.remove_member(member)
render_json_response subject, "#{member.class.to_s} '#{member.id}' has been removed from #{class_name} successfully"
else
render_validation_error subject, "Member has not been removed from #{class_name}"
end
end
def destroy_subject(subject)
subject.destroy # later with resque
render_json_response subject, "#{subject.class.name} has been destroyed successfully"
end
def update_subject(subject)
class_name = subject.class.name
if subject.update_attributes(params[class_name.downcase.to_sym] || {})
render_json_response subject, "#{class_name} has been updated successfully"
else
render_validation_error subject, "#{class_name} has not been updated"
end
end
def paginate_params
per_page = params[:per_page].to_i
per_page = 20 if per_page < 1
per_page = 100 if per_page >100
{:page => params[:page], :per_page => per_page}
end
def render_json_response(subject, message, status = 200)
id = status != 200 ? nil : subject.id
render :json => {
subject.class.name.downcase.to_sym => {
:id => id,
:message => message
}
}.to_json, :status => status
end
def render_validation_error(subject, message)
errors = subject.errors.full_messages.join('. ')
if errors.present?
message << '. ' << errors
end
render_json_response(subject, message, 422)
end
private
def member
if @member.blank? && %w(User Group).include?(params[:type])
@member = params[:type].constantize.where(:id => params[:member_id]).first
end
@member
end
end

View File

@ -10,17 +10,19 @@ class Api::V1::BuildListsController < Api::V1::BaseController
def index
filter = BuildList::Filter.new(nil, current_user, params[:filter] || {})
@build_lists = filter.find.scoped(:include => [:save_to_platform, :project, :user, :arch])
@build_lists = @build_lists.recent.paginate :page => params[:page], :per_page => params[:per_page]
@build_lists = @build_lists.recent.paginate(paginate_params)
end
def create
project = Project.find(params[:build_list][:project_id])
save_to_repository = Repository.find params[:build_list][:save_to_repository_id] #FIXME
params[:build_list][:save_to_platform_id] = save_to_repository.platform_id
params[:build_list][:auto_publish] = false unless save_to_repository.publish_without_qa?
bl_params = params[:build_list] || {}
project = Project.where(:id => bl_params[:project_id]).first
save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first
@build_list = project.build_lists.build(params[:build_list])
@build_list.project_version = @build_list.commit_hash
if project && save_to_repository
bl_params[:save_to_platform_id] = save_to_repository.platform_id
bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa?
@build_list = project.build_lists.build(bl_params)
@build_list.user = current_user
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
@ -30,6 +32,9 @@ class Api::V1::BuildListsController < Api::V1::BaseController
else
render :json => {:message => "Validation Failed", :errors => @build_list.errors.messages}.to_json, :status => 422
end
else
render :json => {:message => "Bad Request"}.to_json, :status => 400
end
end
def cancel

View File

@ -1,17 +1,71 @@
# -*- encoding : utf-8 -*-
class Api::V1::PlatformsController < Api::V1::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show] if APP_CONFIG['anonymous_access']
skip_before_filter :authenticate_user!, :only => [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
load_and_authorize_resource
def index
@platforms = @platforms.accessible_by(current_ability, :related).
by_type(params[:type]).paginate(:page => params[:page], :per_page => 20)
by_type(params[:type]).paginate(paginate_params)
end
def show
end
def platforms_for_build
@platforms = Platform.main.opened.paginate(paginate_params)
render :index
end
def create
platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first
@platform.owner = owner || get_owner
if @platform.save
render_json_response @platform, 'Platform has been created successfully'
else
render_validation_error @platform, 'Platform has not been created'
end
end
def update
platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first
platform_params[:owner] = owner if owner
update_subject @platform
end
def members
@members = @platform.members.order('name').paginate(paginate_params)
end
def add_member
add_member_to_subject @platform
end
def remove_member
remove_member_from_subject @platform
end
def clone
platform_params = params[:platform] || {}
platform_params[:owner] = current_user
@cloned = @platform.full_clone(platform_params)
if @cloned.persisted?
render_json_response @platform, 'Platform has been cloned successfully'
else
render_validation_error @platform, 'Platform has not been cloned'
end
end
def clear
@platform.clear
render_json_response @platform, 'Platform has been cleared successfully'
end
def destroy
destroy_subject @platform
end
end

View File

@ -2,7 +2,7 @@
class Api::V1::ProjectsController < Api::V1::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:get_id, :show] if APP_CONFIG['anonymous_access']
skip_before_filter :authenticate_user!, :only => [:get_id, :show, :refs] if APP_CONFIG['anonymous_access']
load_and_authorize_resource
@ -15,6 +15,9 @@ class Api::V1::ProjectsController < Api::V1::BaseController
end
def show
end
def refs_list
end
end

View File

@ -7,7 +7,57 @@ class Api::V1::RepositoriesController < Api::V1::BaseController
load_and_authorize_resource :repository, :through => :platform, :shallow => true
def show
end
def update
update_subject @repository
end
def add_member
add_member_to_subject @repository
end
def remove_member
remove_member_from_subject @repository
end
def destroy
destroy_subject @repository
end
def add_project
project = Project.where(:id => params[:project_id]).first
if project
begin
@repository.projects << project
render_json_response @repository, "Project '#{project.id}' has been added to repository successfully"
rescue ActiveRecord::RecordInvalid
render_validation_error @repository, t('flash.repository.project_not_added')
end
else
render_validation_error @repository, "Project has not been added to repository"
end
end
def remove_project
project_id = params[:project_id]
ProjectToRepository.where(:project_id => project_id, :repository_id => @repository.id).destroy_all
render_json_response @repository, "Project '#{project_id}' has been removed from repository successfully"
end
def signatures
key_pair = @repository.key_pair
key_pair.destroy if key_pair
key_pair = @repository.build_key_pair(params[:repository])
key_pair.user_id = current_user.id
if key_pair.save
render_json_response @repository, 'Signatures have been updated for repository successfully'
else
message = 'Signatures have not been updated for repository'
errors = key_pair.errors.full_messages.join('. ')
(message << '. ' << errors) if errors.present?
render_json_response @repository, message, 422
end
end
end

View File

@ -131,8 +131,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
end
def remove_project
@project = Project.find(params[:project_id])
ProjectToRepository.where(:project_id => @project.id, :repository_id => @repository.id).destroy_all
ProjectToRepository.where(:project_id => params[:project_id], :repository_id => @repository.id).destroy_all
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
end

View File

@ -57,8 +57,6 @@ class Projects::BuildListsController < Projects::BaseController
Arch.where(:id => params[:arches]).each do |arch|
Platform.main.where(:id => build_for_platforms).each do |build_for_platform|
@build_list = @project.build_lists.build(params[:build_list])
@build_list.commit_hash = @project.repo.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last ||
@build_list.project_version).first.id if @build_list.project_version
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority

View File

@ -146,7 +146,7 @@ class Projects::PullRequestsController < Projects::BaseController
args = params[:to_project].try(:split, '/') || []
project = (args.length == 2) ? Project.find_by_owner_and_name(*args) : nil
raise ActiveRecord::RecordNotFound if bang && !project
project.try(:parent) || @project
project || @project
end
def set_attrs

View File

@ -28,6 +28,7 @@ class Ability
# Platforms block
can [:show, :members, :advisories], Platform, :visibility => 'open'
can :platforms_for_build, Platform, :visibility => 'open', :platform_type => 'main'
can [:read, :projects_list], Repository, :platform => {:visibility => 'open'}
can :read, Product, :platform => {:visibility => 'open'}
@ -99,7 +100,7 @@ class Ability
can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :projects_list], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
can([:create, :edit, :update, :destroy, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform}
can([:remove_members, :remove_member, :add_member], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)}
can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?}
can([:change_visibility, :settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform}

View File

@ -32,6 +32,11 @@ class BuildList < ActiveRecord::Base
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) unless build_for_platform.repository_ids.include? ir.to_i
}
}
validate lambda {
if commit_hash.blank? || project.repo.commit(commit_hash).blank?
errors.add :commit_hash, I18n.t('flash.build_list.wrong_commit_hash', :commit_hash => commit_hash)
end
}
LIVE_TIME = 4.week # for unpublished
MAX_LIVE_TIME = 3.month # for published
@ -110,6 +115,7 @@ class BuildList < ActiveRecord::Base
after_commit :place_build
after_destroy :delete_container
before_validation :set_commit_and_version
@queue = :clone_and_build
@ -331,4 +337,13 @@ class BuildList < ActiveRecord::Base
yield p
end
end
def set_commit_and_version
if project_version.present? && commit_hash.blank?
self.commit_hash = project.repo.commits(project_version.match(/^latest_(.+)/).to_a.last ||
project_version).try(:first).try(:id)
elsif project_version.blank? && commit_hash.present?
self.project_version = commit_hash
end
end
end

View File

@ -20,9 +20,15 @@ class Platform < ActiveRecord::Base
has_many :mass_builds
validates :description, :presence => true
validates :owner, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\.]+$/ }
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
validate lambda {
if released_was && !released
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
end
}
before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
@ -167,7 +173,7 @@ class Platform < ActiveRecord::Base
def update_owner_relation
if owner_id_was != owner_id
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was)[0]
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was).first
r.update_attributes(:actor_id => owner_id, :actor_type => owner_type)
end
end

View File

@ -54,7 +54,7 @@ class Project < ActiveRecord::Base
where("(projects.owner_id in (?) AND projects.owner_type = 'Group') OR (projects.owner_id in (?) AND projects.owner_type = 'User')", group_owner_ids, user_owner_ids)
}
before_validation :truncate_name, :on => :create
before_create :set_maintainer
after_save :attach_to_personal_repository
@ -177,6 +177,10 @@ class Project < ActiveRecord::Base
protected
def truncate_name
self.name = name.strip if name
end
def attach_to_personal_repository
owner_rep = self.owner.personal_repository
if is_package

View File

@ -24,9 +24,14 @@
%td= request.more
%td= request.created_at
%td
= link_to t("layout.approve"), approve_admin_register_request_path(request) if can? :approve, request
|
= link_to t("layout.reject"), reject_admin_register_request_path(request) if can? :reject, request
- links = []
- if can? :approve, request
- links << link_to(t("layout.approve"), approve_admin_register_request_path(request))
- if can? :reject, request
- links << link_to(t("layout.reject"), reject_admin_register_request_path(request))
- if request.token
- links << link_to('Link', new_user_registration_url(:invitation_token => request.token))
= raw links.join('|')
.actions
%input#approve_registration{:type => 'button', :value => "Approve Selected"}

View File

@ -5,11 +5,9 @@ json.platforms @platforms do |json, platform|
json_owner.type platform.owner_type
json_owner.url url_for(platform.owner)
end
json.repositories do |json_rep|
platform.repositories.each do |repo|
json_rep.(repo, :id, :name)
json_rep.url api_v1_repository_path(repo.name, :format => :json)
end
json.repositories platform.repositories do |json_repos, repo|
json_repos.(repo, :id, :name)
json_repos.url api_v1_repository_path(repo.id, :format => :json)
end
json.url api_v1_platform_path(platform.name, :format => :json)
end

View File

@ -0,0 +1,8 @@
json.platform do |json|
json.(@platform, :id)
json.members @members do |json_members, member|
json_members.(member, :id)
json_members.type member.class.name
end
end
json.url members_api_v1_platform_path(@platform, :format => :json)

View File

@ -7,11 +7,9 @@ json.platform do |json|
json_owner.type @platform.owner_type
json_owner.url url_for(@platform.owner)
end
json.repositories do |json_rep|
@platform.repositories.each do |repo|
json_rep.(repo, :id, :name)
json_rep.url api_v1_repository_path(repo.name, :format => :json)
end
json.repositories @platform.repositories do |json_repos, repo|
json_repos.(repo, :id, :name)
json_repos.url api_v1_repository_path(repo.id, :format => :json)
end
end
json.url api_v1_platform_path(@platform, :format => :json)

View File

@ -0,0 +1,8 @@
json.refs_list (@project.repo.branches + @project.repo.tags) 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
end
end
json.url refs_list_api_v1_project_path(@project.id, :format => :json)

View File

@ -1,7 +1,6 @@
json.project do |json|
json.(@project, :id, :name, :visibility, :description, :ancestry, :has_issues, :has_wiki,
:srpm_file_name, :srpm_content_type, :srpm_file_size, :srpm_updated_at, :default_branch, :is_package,
:average_build_time, :build_count)
:default_branch, :is_package, :average_build_time)
json.created_at @project.created_at.to_i
json.updated_at @project.updated_at.to_i
json.owner do |json_owner|
@ -9,6 +8,14 @@ json.project do |json|
json_owner.type @project.owner_type
json_owner.url url_for(@project.owner)
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)
end
end
end
json.url api_v1_project_path(@project, :format => :json)

View File

@ -124,6 +124,9 @@
$(".div-filter-labels").live('click', function() {
oTable.dataTable().fnDraw();
});
$('#filter_projects').live('submit', function() {
return false;
});
});
=# will_paginate

View File

@ -6,4 +6,5 @@
- if pull_diff.b_path.present?
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path)
.clear
.diff_data= render_diff(pull_diff, pull_diff_counter, @comments) unless (Grit::Repo.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary?
-if pull_diff.diff.present? && !(Grit::Repo.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary?
.diff_data=render_diff(pull_diff, pull_diff_counter, @comments)

View File

@ -1,4 +1,6 @@
.blob_header
.size= h(diff.deleted_file ? diff.a_path : diff.b_path)
.file
%a{:name => "diff-#{diff_counter}"}
.top
.l= h((diff.deleted_file ? diff.a_path : diff.b_path).rtruncate 100)
.clear
.diff_data.highlight= render_diff(diff, diff_counter, [])
.diff_data.highlight= render_diff(diff, diff_counter, [])

View File

@ -38,6 +38,7 @@ Rosa::Application.configure do
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => 'abf.rosalinux.ru' }
config.delivery_method = :sendmail
# Enable threaded mode
# config.threadsafe!

View File

@ -29,6 +29,7 @@ en:
started_at: Build started at
duration: Build duration in seconds
mass_build_id: Mass build
commit_hash: Commit hash
build_list/item:
name: Name
@ -147,3 +148,4 @@ en:
can_not_published: Build can only be published with status "Build complete"
frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates
wrong_include_repos: Include repos have to belongs to build for platform
wrong_commit_hash: Unable find commit '%{commit_hash}' in project

View File

@ -28,6 +28,7 @@ ru:
preferences: Настройки
duration: Длительность билда в секундах
mass_build_id: Массовая сборка
commit_hash: Хэш коммита
build_list/item:
name: Название
@ -144,3 +145,4 @@ ru:
can_not_published: Опубликовать сборку можно только со статусом "Собран"
frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления
wrong_include_repos: Включаемые репозитории должны принадлежать платформе для сборки
wrong_commit_hash: Невозможно найти коммит '%{commit_hash}' в проекте

View File

@ -49,6 +49,7 @@ en:
flash:
platform:
released_status_can_not_be_changed: Released status can't be changed if platform has been released
saved: Platform saved
created: Platform created
save_error: Platform save error

View File

@ -49,6 +49,7 @@ ru:
flash:
platform:
released_status_can_not_be_changed: Released статус платформы не может быть изменен, если платформа уже выпущена
saved: Платформа успешно сохранена
created: Платформа успешно добавлена
save_error: Не удалось сохранить платформу

View File

@ -20,10 +20,32 @@ Rosa::Application.routes.draw do
}
end
resources :arches, :only => [:index]
resources :platforms, :only => [:index, :show]
resources :repositories, :only => [:show]
resources :platforms, :only => [:index, :show, :update, :destroy, :create] do
collection {
get :platforms_for_build
}
member {
get :members
put :add_member
delete :remove_member
post :clone
put :clear
}
end
resources :repositories, :only => [:show, :update, :destroy] do
member {
put :add_member
delete :remove_member
put :add_project
delete :remove_project
put :signatures
}
end
resources :projects, :only => [:show] do
collection { get :get_id }
member {
get :refs_list
}
end
end
end

View File

@ -0,0 +1 @@
google-site-verification: googleac324ed2f70faefc.html

View File

@ -47,6 +47,10 @@ shared_examples_for 'create build list via api' do
#@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id
@project.build_lists.last.commit_hash.should == @params[:commit_hash]
end
it 'should not create without existing commit hash in project' do
lambda{ post :create, @create_params.deep_merge(:build_list => {:commit_hash => 'wrong'})}.should change{@project.build_lists.count}.by(0)
end
end
shared_examples_for 'not create build list via api' do

View File

@ -9,6 +9,175 @@ shared_examples_for 'api platform user with reader rights' do
response.should render_template(:index)
end
it 'should be able to perform members action' do
get :members, :id => @platform.id, :format => :json
response.should render_template(:members)
end
end
shared_examples_for 'api platform user with writer rights' do
context 'api platform user with update rights' do
before do
put :update, {:platform => {:description => 'new description'}, :id => @platform.id}, :format => :json
end
it 'should be able to perform update action' do
response.should be_success
end
it 'ensures that platform has been updated' do
@platform.reload
@platform.description.should == 'new description'
end
end
context 'api platform user with add_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should be able to perform add_member action' do
response.should be_success
end
it 'ensures that new member has been added to platform' do
@platform.members.should include(member)
end
end
context 'api platform user with remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@platform.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should be able to perform remove_member action' do
response.should be_success
end
it 'ensures that member has been removed from platform' do
@platform.members.should_not include(member)
end
end
context 'api platform user with destroy rights for main platforms only' do
it 'should be able to perform destroy action for main platform' do
delete :destroy, :id => @platform.id, :format => :json
response.should be_success
end
it 'ensures that main platform has been destroyed' do
lambda { delete :destroy, :id => @platform.id, :format => :json }.should change{ Platform.count }.by(-1)
end
it 'should not be able to perform destroy action for personal platform' do
delete :destroy, :id => @personal_platform.id, :format => :json
response.should_not be_success
end
it 'ensures that personal platform has not been destroyed' do
lambda { delete :destroy, :id => @personal_platform.id, :format => :json }.should_not change{ Platform.count }
end
end
end
shared_examples_for 'api platform user without writer rights' do
context 'api platform user without update rights' do
before do
put :update, {:platform => {:description => 'new description'}, :id => @platform.id}, :format => :json
end
it 'should not be able to perform update action' do
response.should_not be_success
end
it 'ensures that platform has not been updated' do
@platform.reload
@platform.description.should_not == 'new description'
end
end
context 'api platform user without add_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should not be able to perform add_member action' do
response.should_not be_success
end
it 'ensures that new member has not been added to platform' do
@platform.members.should_not include(member)
end
end
context 'api platform user without remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@platform.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should be able to perform update action' do
response.should_not be_success
end
it 'ensures that member has not been removed from platform' do
@platform.members.should include(member)
end
end
context 'should not be able to perform clear action' do
it 'for personal platform' do
put :clear, :id => @personal_platform.id, :format => :json
response.should_not be_success
end
it 'for main platform' do
put :clear, :id => @platform.id, :format => :json
response.should_not be_success
end
end
context 'api platform user without destroy rights' do
it 'should not be able to perform destroy action for main platform' do
delete :destroy, :id => @platform.id, :format => :json
response.should_not be_success
end
it 'ensures that main platform has not been destroyed' do
lambda { delete :destroy, :id => @platform.id, :format => :json }.should_not change{ Platform.count }
end
it 'should not be able to perform destroy action for personal platform' do
delete :destroy, :id => @personal_platform.id, :format => :json
response.should_not be_success
end
it 'ensures that personal platform has not been destroyed' do
lambda { delete :destroy, :id => @personal_platform.id, :format => :json }.should_not change{ Platform.count }
end
end
it_should_behave_like 'api platform user without global admin rights'
end
shared_examples_for 'api platform user without global admin rights' do
context 'should not be able to perform clear action' do
it 'for personal platform' do
put :clear, :id => @personal_platform.id, :format => :json
response.should_not be_success
end
it 'for main platform' do
put :clear, :id => @platform.id, :format => :json
response.should_not be_success
end
end
[:create, :clone].each do |action|
context "api platform user without #{action} rights" do
before { any_instance_of(Platform, :create_directory => true) }
it "should not be able to perform #{action} action" do
post action, clone_or_create_params, :format => :json
response.should_not be_success
end
it "ensures that platform has not been #{action}d" do
lambda { post action, clone_or_create_params, :format => :json }.should_not change{ Platform.count }
end
end
end
end
shared_examples_for 'api platform user with reader rights for hidden platform' do
@ -32,20 +201,28 @@ shared_examples_for "api platform user with show rights" do
get :show, :id => @platform.id, :format => :json
response.should render_template(:show)
end
it 'should be able to perform platforms_for_build action' do
get :platforms_for_build, :format => :json
response.should render_template(:index)
end
end
shared_examples_for "api platform user without show rights" do
it 'should not be able to perform show action' do
get :show, :id => @platform.id, :format => :json
[:show, :members].each do |action|
it "should not be able to perform #{ action } action" do
get action, :id => @platform.id, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
end
end
end
describe Api::V1::PlatformsController do
let(:clone_or_create_params) { {:id => @platform.id, :platform => {:description => 'new description', :name => 'new_name', :owner_id => @user.id, :distrib_type => APP_CONFIG['distr_types'].first}} }
before do
stub_symlink_methods
@platform = FactoryGirl.create(:platform)
@platform = FactoryGirl.create(:platform, :visibility => 'open')
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
@user = FactoryGirl.create(:user)
end
@ -57,30 +234,53 @@ describe Api::V1::PlatformsController do
response.status.should == 401
end
it "should not be able to perform show action", :anonymous_access => false do
get :show, :id => @platform.id, :format => :json
[:show, :platforms_for_build].each do |action|
it "should not be able to perform #{ action } action", :anonymous_access => false do
get action, :format => :json
response.status.should == 401
end
end
it 'should be able to perform members action', :anonymous_access => true do
get :members, :id => @platform.id, :format => :json
response.should render_template(:members)
end
it_should_behave_like 'api platform user with show rights' if APP_CONFIG['anonymous_access']
it_should_behave_like 'api platform user without reader rights for hidden platform' if APP_CONFIG['anonymous_access']
it_should_behave_like 'api platform user without writer rights'
end
context 'for global admin' do
before do
@admin = FactoryGirl.create(:admin)
@user = FactoryGirl.create(:user)
http_login(@admin)
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 with writer rights'
[:clone, :create].each do |action|
context "with #{action} rights" do
before do
any_instance_of(Platform, :create_directory => true)
clone_or_create_params[:platform][:owner_id] = @admin.id
end
it "should be able to perform #{action} action" do
post action, clone_or_create_params, :format => :json
response.should be_success
end
it "ensures that platform has been #{action}d" do
lambda { post action, clone_or_create_params, :format => :json }.should change{ Platform.count }.by(1)
end
end
end
end
context 'for owner user' do
before do
@user = FactoryGirl.create(:user)
http_login(@user)
@platform.owner = @user; @platform.save
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
@ -88,11 +288,12 @@ describe Api::V1::PlatformsController do
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 with writer rights'
it_should_behave_like 'api platform user without global admin rights'
end
context 'for reader user' do
before do
@user = FactoryGirl.create(:user)
http_login(@user)
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
@personal_platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
@ -111,15 +312,16 @@ describe Api::V1::PlatformsController do
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 writer rights'
end
context 'for simple user' do
before do
@user = FactoryGirl.create(:user)
http_login(@user)
end
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user without reader rights for hidden platform'
it_should_behave_like 'api platform user without writer rights'
end
end

View File

@ -24,12 +24,17 @@ end
shared_examples_for "api projects user without show rights" do
it "should show access violation instead of project data" do
get :show, :id => @project.id, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
response.should_not be_success
end
it "should show access violation instead of project refs_list" do
get :refs_list, :id => @project.id, :format => :json
response.should_not be_success
end
it "should access violation instead of project data by get_id" do
get :get_id, :name => @project.name, :owner => @project.owner.uname, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
response.should_not be_success
end
end
@ -39,6 +44,11 @@ shared_examples_for "api projects user with show rights" do
render_template(:show)
end
it "should show refs_list of project" do
get :refs_list, :id => @project.id, :format => :json
render_template(:refs_list)
end
context 'project find by get_id' do
it "should find project by name and owner name" do
@project.reload
@ -70,19 +80,13 @@ describe Api::V1::ProjectsController do
context 'for guest' do
it 'should be able to perform get_id action', :anonymous_access => false do
get :get_id, :format => :json
response.status.should == 401
if APP_CONFIG['anonymous_access']
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user without reader rights for hidden project'
else
it_should_behave_like 'api projects user without show rights'
end
it 'should be able to perform show action', :anonymous_access => false do
get :show, :id => @project.id, :format => :json
response.status.should == 401
end
it_should_behave_like 'api projects user with reader rights' if APP_CONFIG['anonymous_access']
it_should_behave_like 'api projects user without reader rights for hidden project' if APP_CONFIG['anonymous_access']
end
context 'for simple user' do

View File

@ -35,6 +35,209 @@ shared_examples_for "api repository user without show rights" do
end
end
shared_examples_for 'api repository user with writer rights' do
context 'api repository user with update rights' do
before do
put :update, {:repository => {:description => 'new description'}, :id => @repository.id}, :format => :json
end
it 'should be able to perform update action' do
response.should be_success
end
it 'ensures that repository has been updated' do
@repository.reload
@repository.description.should == 'new description'
end
end
context 'api repository user with add_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
put :add_member, {:member_id => member.id, :type => 'User', :id => @repository.id}, :format => :json
end
it 'should be able to perform add_member action' do
response.should be_success
end
it 'ensures that new member has been added to repository' do
@repository.members.should include(member)
end
end
context 'api repository user with remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@repository.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @repository.id}, :format => :json
end
it 'should be able to perform remove_member action' do
response.should be_success
end
it 'ensures that member has been removed from repository' do
@repository.members.should_not include(member)
end
end
context 'api repository user with destroy rights' do
it 'should be able to perform destroy action for main platform' do
delete :destroy, :id => @repository.id, :format => :json
response.should be_success
end
it 'ensures that repository of main platform has been destroyed' do
lambda { delete :destroy, :id => @repository.id, :format => :json }.should change{ Repository.count }.by(-1)
end
it 'should not be able to perform destroy action for repository of personal platform' do
delete :destroy, :id => @personal_repository.id, :format => :json
response.should_not be_success
end
it 'ensures that repository of personal platform has not been destroyed' do
lambda { delete :destroy, :id => @personal_repository.id, :format => :json }.should_not change{ Repository.count }
end
end
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
response.should be_success
end
it 'ensures that project has been added to repository' do
@repository.projects.should include(@project)
end
end
context 'api repository user with remove_project rights' do
before do
@repository.projects << @project
delete :remove_project, :id => @repository.id, :project_id => @project.id, :format => :json
end
it 'should be able to perform remove_project action' do
response.should be_success
end
it 'ensures that project has been removed from repository' do
@repository.reload
@repository.projects.should_not include(@project)
end
end
context 'api repository user with update signatures rights' do
before do
stub_key_pairs_calls
put :signatures, :id => @repository.id, :repository => {:public => 'iampublic', :secret => 'iamsecret'}, :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
context 'api repository user without update rights' do
before do
put :update, {:repository => {:description => 'new description'}, :id => @repository.id}, :format => :json
end
it 'should not be able to perform update action' do
response.should_not be_success
end
it 'ensures that repository has not been updated' do
@repository.reload
@repository.description.should_not == 'new description'
end
end
context 'api repository user without add_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
put :add_member, {:member_id => member.id, :type => 'User', :id => @repository.id}, :format => :json
end
it 'should not be able to perform add_member action' do
response.should_not be_success
end
it 'ensures that new member has not been added to repository' do
@repository.members.should_not include(member)
end
end
context 'api repository user without remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@repository.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @repository.id}, :format => :json
end
it 'should be able to perform update action' do
response.should_not be_success
end
it 'ensures that member has not been removed from repository' do
@repository.members.should include(member)
end
end
context 'api repository user without destroy rights' do
it 'should not be able to perform destroy action for repository of main platform' do
delete :destroy, :id => @repository.id, :format => :json
response.should_not be_success
end
it 'ensures that repository of main platform has not been destroyed' do
lambda { delete :destroy, :id => @repository.id, :format => :json }.should_not change{ Repository.count }
end
it 'should not be able to perform destroy action for repository of personal platform' do
delete :destroy, :id => @personal_repository.id, :format => :json
response.should_not be_success
end
it 'ensures that repository of personal platform has not been destroyed' do
lambda { delete :destroy, :id => @personal_repository.id, :format => :json }.should_not change{ Repository.count }
end
end
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
response.should_not be_success
end
it 'ensures that project has not been added to repository' do
@repository.projects.should_not include(@project)
end
end
context 'api repository user without remove_project rights' do
before do
@repository.projects << @project
delete :remove_project, :id => @repository.id, :project_id => @project.id, :format => :json
end
it 'should not be able to perform remove_project action' do
response.should_not be_success
end
it 'ensures that project has not been removed from repository' do
@repository.reload
@repository.projects.should include(@project)
end
end
context 'api repository user without update signatures rights' do
before do
stub_key_pairs_calls
put :signatures, :id => @repository.id, :repository => {:public => 'iampublic', :secret => 'iamsecret'}, :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
describe Api::V1::RepositoriesController do
before(:each) do
stub_symlink_methods
@ -52,8 +255,11 @@ describe Api::V1::RepositoriesController do
response.status.should == 401
end
it_should_behave_like 'api repository user without reader rights for hidden platform' if APP_CONFIG['anonymous_access']
it_should_behave_like 'api repository user with show rights' if APP_CONFIG['anonymous_access']
if APP_CONFIG['anonymous_access']
it_should_behave_like 'api repository user without reader rights for hidden platform'
it_should_behave_like 'api repository user with show rights'
end
it_should_behave_like 'api repository user without writer rights'
end
context 'for admin' do
@ -64,6 +270,7 @@ describe Api::V1::RepositoriesController do
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 writer rights'
end
context 'for platform owner user' do
@ -77,6 +284,7 @@ describe Api::V1::RepositoriesController do
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 writer rights'
end
context 'for user' do
@ -88,5 +296,6 @@ describe Api::V1::RepositoriesController do
it_should_behave_like 'api repository user with reader rights'
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'
end
end

View File

@ -30,7 +30,6 @@ describe Projects::BuildListsController do
shared_examples_for 'create build list' do
before {
@project.update_attribute(:repositories, @platform.repositories)
test_git_commit(@project)
}
it 'should be able to perform new action' do
@ -53,12 +52,19 @@ describe Projects::BuildListsController do
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"})
@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id
end
it 'should not be able to create with wrong project version' do
lambda{ post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_wrong", :commit_hash => nil})}.should change{@project.build_lists.count}.by(0)
end
it 'should not be able to create with wrong git hash' do
lambda{ post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:commit_hash => 'wrong'})}.should change{@project.build_lists.count}.by(0)
end
end
shared_examples_for 'not create build list' do
before {
@project.update_attribute(:repositories, @platform.repositories)
test_git_commit(@project)
}
it 'should not be able to perform new action' do

View File

@ -74,6 +74,23 @@ shared_examples_for 'pull request user with project reader rights' do
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'already', :body => 'creating'}, :to_ref => 'master', :from_ref => 'master'}, :to_project_id => @project.id})
PullRequest.joins(:issue).where(:issues => {:title => 'already', :body => 'creating'}).count.should == 0
end
it "should create pull request to the same project" do
@parent = FactoryGirl.create(:project)
@project.update_attributes({:parent_id => @parent}, :without_protection => true)
lambda{ post :create, @create_params }.should change{ PullRequest.joins(:issue).
where(:issues => {:user_id => @user}, :to_project_id => @project, :from_project_id => @project).count }.by(1)
end
it "should create pull request to the parent project" do
@parent = FactoryGirl.create(:project)
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@parent.path})
@project.update_attributes({:parent_id => @parent}, :without_protection => true)
lambda{ post :create, @create_params.merge({:to_project => @parent.name_with_owner}) }.should change{ PullRequest.joins(:issue).
where(:issues => {:user_id => @user}, :to_project_id => @parent, :from_project_id => @project).count }.by(1)
end
end
shared_examples_for 'user with pull request update rights' do

View File

@ -8,11 +8,11 @@ FactoryGirl.define do
association :arch
build_for_platform {|bl| bl.save_to_platform}
save_to_repository {|bl| bl.save_to_platform.repositories.first}
project_version "1.0"
build_requires true
update_type 'security'
include_repos {|bl| bl.save_to_platform.repositories.map(&:id)}
commit_hash '1234567890abcdef1234567890abcdef12345678'
project_version 'latest_master'
after(:build) {|bl| test_git_commit bl.project }
end
factory :build_list_core, :parent => :build_list do

View File

@ -9,17 +9,35 @@ describe Project do
@child_child_project = @child_project.fork(FactoryGirl.create(:user))
end
context 'for destroy root' do
before do
@root_project.destroy
end
context 'for destroy' do
let!(:root_project) { FactoryGirl.create(:project) }
let!(:child_project) { root_project.fork(FactoryGirl.create(:user)) }
let!(:child_child_project) { child_project.fork(FactoryGirl.create(:user)) }
context 'root project' do
before { root_project.destroy }
it "should not be delete child" do
Project.where(:id => @child_project).count.should == 1
Project.where(:id => child_project).count.should == 1
end
it "should not be delete child of the child" do
Project.where(:id => @child_child_project).count.should == 1
Project.where(:id => child_child_project).count.should == 1
end
end
pending 'when will be available :orphan_strategy => :adopt' do
context 'middle node' do
before{ child_project.destroy }
it "should set root project as a parent for orphan child" do
Project.find(child_child_project).ancestry == root_project
end
it "should not be delete child of the child" do
Project.where(:id => child_child_project).count.should == 1
end
end
end
end
@ -48,19 +66,17 @@ describe Project do
end
end
# uncommit when will be available :orphan_strategy => :adopt
context 'truncates project name before validation' do
let!(:project) { FactoryGirl.build(:project, :name => ' test_name ') }
#context 'for destroy middle node' do
# before(:each) do
# @child_project.destroy
# end
it 'ensures that validation passed' do
project.valid?.should be_true
end
# it "should set root project as a parent for orphan child" do
# Project.find(@child_child_project).ancestry == @root_project
# end
it 'ensures that name has been truncated' do
project.valid?
project.name.should == 'test_name'
end
end
# it "should not be delete child of the child" do
# Project.where(:id => @child_child_project).count.should == 1
# end
#end
end