Merge branch 'master' into 90-pull

Conflicts:
	db/schema.rb
This commit is contained in:
Alexander Machehin 2012-08-01 13:06:41 +06:00
commit b299a51610
40 changed files with 499 additions and 46 deletions

View File

@ -81,7 +81,7 @@ end
group :test do group :test do
gem 'rspec-rails', '~> 2.11.0', :group => 'development' gem 'rspec-rails', '~> 2.11.0', :group => 'development'
gem 'factory_girl_rails', '~> 3.5.0' gem 'factory_girl_rails', '~> 3.6.0'
gem 'rr', '~> 1.0.4' gem 'rr', '~> 1.0.4'
gem 'shoulda' gem 'shoulda'
end end

View File

@ -8,7 +8,7 @@ GIT
GIT GIT
remote: git://github.com/github/gollum.git remote: git://github.com/github/gollum.git
revision: c9bc2a89f655760c0a21da6d3ab37c5f6267e96c revision: 8422b712048656c8ea391c2d7ef27fb29f66746b
specs: specs:
gollum (2.1.0) gollum (2.1.0)
github-markdown github-markdown
@ -125,10 +125,10 @@ GEM
execjs (1.4.0) execjs (1.4.0)
multi_json (~> 1.0) multi_json (~> 1.0)
expression_parser (0.9.0) expression_parser (0.9.0)
factory_girl (3.5.0) factory_girl (3.6.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (3.5.0) factory_girl_rails (3.6.0)
factory_girl (~> 3.5.0) factory_girl (~> 3.6.0)
railties (>= 3.0.0) railties (>= 3.0.0)
ffi (1.0.11) ffi (1.0.11)
fssm (0.2.9) fssm (0.2.9)
@ -376,7 +376,7 @@ DEPENDENCIES
creole creole
devise (~> 2.1.2) devise (~> 2.1.2)
diff-display (~> 0.0.1) diff-display (~> 0.0.1)
factory_girl_rails (~> 3.5.0) factory_girl_rails (~> 3.6.0)
github-linguist (~> 2.1.2) github-linguist (~> 2.1.2)
gollum! gollum!
grack! grack!

View File

@ -0,0 +1,29 @@
class Platforms::KeyPairsController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :platform, :only => [:index]
load_and_authorize_resource :only => [:create, :destroy]
def create
@key_pair.user_id = current_user.id
if @key_pair.save
flash[:notice] = t('flash.key_pairs.saved')
else
flash[:error] = t('flash.key_pairs.save_error')
flash[:warning] = @key_pair.errors.full_messages.join('. ') unless @key_pair.errors.blank?
end
redirect_to platform_key_pairs_path(@key_pair.repository.platform)
end
def destroy
if @key_pair.destroy
flash[:notice] = t('flash.key_pairs.destroyed')
else
flash[:error] = t('flash.key_pairs.destroy_error')
end
redirect_to platform_key_pairs_path(@key_pair.repository.platform)
end
end

View File

@ -54,7 +54,9 @@ module GitHelper
current = url_for(p).split('?', 2).first current = url_for(p).split('?', 2).first
res = [] res = []
res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]] unless project.repo.branches_and_tags.map(&:name).include?(params[:treeish] || project.default_branch) if params[:treeish].present? && !project.repo.branches_and_tags.map(&:name).include?(params[:treeish])
res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]]
end
linking = Proc.new {|t| [t.name.truncate(20), url_for(p.merge :treeish => t.name).split('?', 2).first]} linking = Proc.new {|t| [t.name.truncate(20), url_for(p.merge :treeish => t.name).split('?', 2).first]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&linking)] res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&linking)]
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)] res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)]

View File

@ -18,7 +18,7 @@ class Ability
can :read, Issue, :project => {:visibility => 'open'} can :read, Issue, :project => {:visibility => 'open'}
can :read, PullRequest, :project => {:visibility => 'open'} can :read, PullRequest, :project => {:visibility => 'open'}
can :search, BuildList can :search, BuildList
can :read, BuildList, :project => {:visibility => 'open'} can [:read, :everything], BuildList, :project => {:visibility => 'open'}
can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
can :read, Advisory can :read, Advisory
can(:advisories, Platform) {APP_CONFIG['anonymous_access']} can(:advisories, Platform) {APP_CONFIG['anonymous_access']}
@ -64,10 +64,10 @@ class Ability
can :remove_user, Project can :remove_user, Project
can [:autocomplete_base_project_name, :autocomplete_head_project_name], Project can [:autocomplete_base_project_name, :autocomplete_head_project_name], Project
can [:read, :owned], BuildList, :user_id => user.id can [:read, :owned, :everything], BuildList, :user_id => user.id
can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} can [:read, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
can [:read, :related], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} can [:read, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can(:read, BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project} can([:read, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can([:create, :update], BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project)} can([:create, :update], BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project)}
can(:publish, BuildList) do |build_list| can(:publish, BuildList) do |build_list|
@ -99,6 +99,8 @@ class Ability
can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?} can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?}
can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform}
can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)}
can :read, Product, :platform => {:visibility => 'open'} can :read, Product, :platform => {:visibility => 'open'}
can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'} can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'}
can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids, :platform_type => 'main'} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids, :platform_type => 'main'}

View File

@ -106,14 +106,16 @@ class BuildList < ActiveRecord::Base
# WTF? around_transition -> infinite loop # WTF? around_transition -> infinite loop
before_transition do |build_list, transition| before_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) status = BuildList::HUMAN_STATUSES[build_list.status]
MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status)
MassBuild.decrement_counter "#{status.to_s}_count", build_list.mass_build_id
end end
end end
after_transition do |build_list, transition| after_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) status = BuildList::HUMAN_STATUSES[build_list.status]
MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status)
MassBuild.increment_counter "#{status.to_s}_count", build_list.mass_build_id
end end
end end

View File

@ -52,8 +52,10 @@ class BuildList::Filter
:mass_build_id => nil :mass_build_id => nil
})) }))
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned') @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned')
@options[:status] = @options[:status].try(:to_i) @options[:status] = @options[:status].present? ? @options[:status].to_i : nil
@options[:created_at_start] = build_date_from_params(:created_at_start, @options)
@options[:created_at_end] = build_date_from_params(:created_at_end, @options)
@options[:updated_at_start] = build_date_from_params(:updated_at_start, @options) @options[:updated_at_start] = build_date_from_params(:updated_at_start, @options)
@options[:updated_at_end] = build_date_from_params(:updated_at_end, @options) @options[:updated_at_end] = build_date_from_params(:updated_at_end, @options)
@options[:project_version] = @options[:project_version].presence @options[:project_version] = @options[:project_version].presence

35
app/models/key_pair.rb Normal file
View File

@ -0,0 +1,35 @@
class KeyPair < ActiveRecord::Base
belongs_to :repository
belongs_to :user
attr_accessor :secret
attr_accessible :public, :secret, :repository_id
validates :repository_id, :public, :user_id, :presence => true
validates :secret, :presence => true, :on => :create
validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pair.repo_key_exists")}
before_create :key_create_call
before_destroy :rm_key_call
protected
def key_create_call
result, self.key_id = BuildServer.import_gpg_key_pair(public, secret)
raise "Failed to create key_pairs for repository #{repository_id} with code #{result}." if result == 4
if result != 0 || self.key_id.nil?
errors.add(:public, I18n.t("activerecord.errors.key_pair.rpc_error_#{result}"))
return false
end
result = BuildServer.set_repository_key(repository.platform.name, repository.name, self.key_id)
raise "Failed to sign repository #{repository.name} in platform #{repository.platform.name}
using key_id #{self.key_id} with code #{result}." unless result.zero?
end
def rm_key_call
result = BuildServer.rm_repository_key(repository.platform.name, repository.name)
raise "Failed to desroy repository key #{repository.name} in platform
#{repository.platform.name} with code #{result}." unless result.zero?
end
end

View File

@ -4,6 +4,7 @@ class Repository < ActiveRecord::Base
has_many :project_to_repositories, :dependent => :destroy, :validate => true has_many :project_to_repositories, :dependent => :destroy, :validate => true
has_many :projects, :through => :project_to_repositories has_many :projects, :through => :project_to_repositories
has_one :key_pair, :dependent => :destroy
validates :description, :presence => true validates :description, :presence => true
validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/}

View File

@ -35,6 +35,8 @@ class User < ActiveRecord::Base
has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
has_many :key_pairs
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true
validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? } validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? }
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true validates :role, :inclusion => {:in => ROLES}, :allow_blank => true

View File

@ -25,6 +25,9 @@
- if can? :members, @platform - if can? :members, @platform
%li{:class => (act == :members && contr == :platforms) ? 'active' : nil} %li{:class => (act == :members && contr == :platforms) ? 'active' : nil}
= link_to t("layout.platforms.members"), members_platform_path(@platform) = link_to t("layout.platforms.members"), members_platform_path(@platform)
- if can? :edit, @platform
%li{:class => (act == :index && contr == :key_pairs) ? 'active' : ''}
= link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform)
-#- if current_user.owner_of? @platform or current_user.admin? -#- if current_user.owner_of? @platform or current_user.admin?
%li{:class => (act == :index && contr == :private_users) ? 'active' : ''} %li{:class => (act == :index && contr == :private_users) ? 'active' : ''}
= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform) = link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)

View File

@ -0,0 +1,18 @@
%table#myTable.tablesorter.platform-repos{:cellspacing => "0", :cellpadding => "0"}
%thead
%tr
%th.th1= t("activerecord.attributes.key_pair.repository_id")
%th.th2= t("activerecord.attributes.key_pair.key_id")
%th.th3= t("activerecord.attributes.key_pair.user_id")
%th= t("layout.delete")
%tbody
- @platform.repositories.each do |repository|
- if repository.key_pair
%tr{:class => cycle("odd", "even")}
%td= repository.name
%td= repository.key_pair.key_id
%td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user)
%td.buttons
- if can? :destroy, repository.key_pair
= link_to platform_key_pair_path(@platform, repository.key_pair), :method => :delete, :confirm => t("layout.key_pairs.confirm_delete") do
%span.delete &nbsp;

View File

@ -0,0 +1,17 @@
= render 'platforms/base/sidebar'
%h3= t("layout.key_pairs.header")
= form_for :key_pair, :url => platform_key_pairs_path(@platform), :method => :post, :html => { :class => :form } do |f|
.leftlist= f.label :public, t("activerecord.attributes.key_pair.public"), :class => :label
.rightlist= f.text_area :public, :class => 'text_field resizable', :cols => 80
.both
.leftlist= f.label :secret, t("activerecord.attributes.key_pair.secret"), :class => :label
.rightlist= f.text_area :secret, :class => 'text_field resizable', :cols => 80
.both
.leftlist= f.label :repository_id, t("activerecord.attributes.key_pair.repository_id"), :class => :label
.rightlist= f.select :repository_id, options_from_collection_for_select(@platform.repositories, 'id', 'name')
.both
.button_block
= submit_tag t("layout.save")

View File

@ -0,0 +1,2 @@
= render 'new' if can? :edit, @platform
= render 'list'

View File

@ -37,13 +37,13 @@
- @mass_builds.each do |mass_build| - @mass_builds.each do |mass_build|
%tr %tr
%td= mass_build.id %td= mass_build.id
%td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'everything'})
%td.min_width_120 %td.min_width_120
- MassBuild::COUNT_STATUSES.each do |status| - MassBuild::COUNT_STATUSES.each do |status|
= link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'index'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {})) = link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'everything'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {}))
= mass_build.read_attribute "#{status}_count" = mass_build.read_attribute "#{status}_count"
.both .both
%td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platform_mass_build_path(@platform, mass_build.id), :target => "_blank" if can?(:failed_builds_list, mass_build) %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platform_mass_build_path(@platform, mass_build.id, :format => :txt), :target => "_blank" if can?(:failed_builds_list, mass_build)
%td= link_to image_tag('x.png'), cancel_platform_mass_build_path(@platform, mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:cancel, mass_build) %td= link_to image_tag('x.png'), cancel_platform_mass_build_path(@platform, mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:cancel, mass_build)
%td %td
%a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") %a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data")

View File

@ -31,8 +31,8 @@
.lefter= t("layout.build_lists.ownership.related") .lefter= t("layout.build_lists.ownership.related")
.both .both
.table .table
.lefter= f.radio_button :ownership, 'index', :class => 'niceRadio', :id => 'myradio3' .lefter= f.radio_button :ownership, 'everything', :class => 'niceRadio', :id => 'myradio3'
.lefter= t("layout.build_lists.ownership.index") .lefter= t("layout.build_lists.ownership.everything")
.both .both
%br %br
= f.submit t("layout.search.header") = f.submit t("layout.search.header")

View File

@ -4,5 +4,5 @@
%td.blob %td.blob
:plain :plain
<br/> <br/>
<pre>#{link_to @blob.basename, raw_path(@project, @treeish, @path)}</pre> <pre>#{link_to_unless @blob.huge?, @blob.basename, raw_path(@project, @treeish, @path)}</pre>
<br/> <br/>

View File

@ -12,8 +12,9 @@
- if @blob.render_as == :text && params[:action] != 'show' - if @blob.render_as == :text && params[:action] != 'show'
= link_to "Normal", blob_path(@project, @treeish, @path) = link_to "Normal", blob_path(@project, @treeish, @path)
\| \|
= link_to "Raw", raw_path(@project, @treeish, @path) - unless @blob.huge?
\| = link_to "Raw", raw_path(@project, @treeish, @path)
\|
- if @blob.render_as == :text && params[:action] != 'blame' - if @blob.render_as == :text && params[:action] != 'blame'
= link_to "Blame", blame_path(@project, @treeish, @path) = link_to "Blame", blame_path(@project, @treeish, @path)
\| \|

View File

@ -48,7 +48,7 @@ module Rosa
config.encoding = "utf-8" config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file. # Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password] config.filter_parameters += [:password, :secret]
# Enable the asset pipeline # Enable the asset pipeline
config.assets.enabled = true config.assets.enabled = true

View File

@ -62,7 +62,7 @@ Rosa::Application.configure do
config.assets.digest = true config.assets.digest = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js) config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js)
end end
# require 'stub_xml_rpc' # require 'stub_xml_rpc'

View File

@ -80,7 +80,7 @@ en:
header: Build list ownership header: Build list ownership
owned: My owned: My
related: Related related: Related
index: All everything: All
build_server_status: build_server_status:
header: Build server status header: Build server status

View File

@ -79,7 +79,7 @@ ru:
header: Принадлежность заданий header: Принадлежность заданий
owned: Мне owned: Мне
related: Связанные со мной related: Связанные со мной
index: Все everything: Все
build_server_status: build_server_status:
header: Статус сборочного сервера header: Статус сборочного сервера

View File

@ -0,0 +1,35 @@
en:
layout:
key_pairs:
repository_id: Repository
user_id: User
public: Public key
secret: Secret key
confirm_delete: Are you sure you want to delete this signature?
header: Signatures
flash:
key_pairs:
saved: Repository successfully signed
save_error: Signature save error
destroyed: Signature succefully destroyed
destroy_error: Signature destroy error
activerecord:
errors:
key_pair:
repo_key_exists: Repository has been signed already! Please remove old signature and try again
rpc_error_0: an unexpected error
rpc_error_1: could not import public key
rpc_error_2: could not import secret key
rpc_error_3: keys are imported, but it is not a key pair (ids differ)
models:
key_pair: Key Pair
attributes:
key_pair:
id: Id
created_at: Created
updated_at: Updated
user_id: User
repository_id: Repository
public: Public key
secret: Secret key
key_id: Signature

View File

@ -0,0 +1,35 @@
ru:
layout:
key_pairs:
repository_id: Репозиторий
user_id: Пользователь
public: Публичный ключ
secret: Секретный ключ
confirm_delete: Вы уверены, что хотите удалить подпись?
header: Подписи
flash:
key_pairs:
saved: Репозиторий успешно подписан
save_error: Ошибка создания подписи
destroyed: Подпись успешно удалена
destroy_error: Ошибка удаления подписи
activerecord:
errors:
key_pair:
repo_key_exists: Репозиторий уже подписан! Пожалуйста, удалите старую подпись и попробуйте снова
rpc_error_0: Неизвестная ошибка
rpc_error_1: Проблемы с импортром публичного ключа
rpc_error_2: Проблемы с импортром секретного ключа
rpc_error_3: Ключи импортированы, но не являются парой (идентификаторы не совпадают)
models:
key_pair: Подпись
attributes:
key_pair:
id: Id
created_at: Создано
updated_at: Обновлено
user_id: Пользователь
repository_id: Репозиторий
public: Публичный ключ
secret: Секретный ключ
key_id: Подпись

View File

@ -72,6 +72,7 @@ Rosa::Application.routes.draw do
get :projects_list get :projects_list
end end
end end
resources :key_pairs, :only => [:create, :index, :destroy]
resources :products do resources :products do
resources :product_build_lists, :only => [:create, :destroy] resources :product_build_lists, :only => [:create, :destroy]
end end

View File

@ -0,0 +1,11 @@
class CreateKeyPairs < ActiveRecord::Migration
def change
create_table :key_pairs do |t|
t.integer :repository_id
t.integer :user_id
t.integer :key_id
t.string :public
t.timestamps
end
end
end

View File

@ -0,0 +1,9 @@
class SetTextTypeForKeyPairsPublic < ActiveRecord::Migration
def up
change_column :key_pairs, :public, :text
end
def down
change_column :key_pairs, :public, :string
end
end

View File

@ -0,0 +1,9 @@
class SetStringTypeForKeyPairsKeyid < ActiveRecord::Migration
def up
change_column :key_pairs, :key_id, :string
end
def down
change_column :key_pairs, :key_id, :integer
end
end

View File

@ -0,0 +1,17 @@
class DisableNullValueForKeyPairs < ActiveRecord::Migration
def up
change_column_null :key_pairs, :repository_id, false
change_column_null :key_pairs, :user_id, false
change_column_null :key_pairs, :key_id, false
change_column_null :key_pairs, :public, false
add_index :key_pairs, :repository_id, :unique => true
end
def down
change_column_null :key_pairs, :repository_id, true
change_column_null :key_pairs, :user_id, true
change_column_null :key_pairs, :key_id, true
change_column_null :key_pairs, :public, true
remove_index :key_pairs, :repository_id
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120719045806) do ActiveRecord::Schema.define(:version => 20120730214052) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -193,6 +193,17 @@ ActiveRecord::Schema.define(:version => 20120719045806) do
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
create_table "key_pairs", :force => true do |t|
t.integer "repository_id", :null => false
t.integer "user_id", :null => false
t.string "key_id", :null => false
t.text "public", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "key_pairs", ["repository_id"], :name => "index_key_pairs_on_repository_id", :unique => true
create_table "labelings", :force => true do |t| create_table "labelings", :force => true do |t|
t.integer "label_id", :null => false t.integer "label_id", :null => false
t.integer "issue_id" t.integer "issue_id"

View File

@ -87,11 +87,11 @@ class BuildServer
# raise include_repos_hash.inspect # raise include_repos_hash.inspect
self.client.call('add_build_list', project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos_hash, priority) self.client.call('add_build_list', project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos_hash, priority)
end end
def self.delete_build_list idlist def self.delete_build_list idlist
self.client.call('delete_build_list', idlist) self.client.call('delete_build_list', idlist)
end end
def self.get_status def self.get_status
self.client.call('get_status') self.client.call('get_status')
end end
@ -99,4 +99,17 @@ class BuildServer
def self.freeze platform_name def self.freeze platform_name
self.client.call('freeze_platform', platform_name) self.client.call('freeze_platform', platform_name)
end end
# Repository key pair calls
def self.import_gpg_key_pair key_pub, key_secret
self.client.call('import_gpg_key_pair', key_pub, key_secret)
end
def self.set_repository_key platform, repository, key_id
self.client.call('set_repository_key', platform, repository, key_id)
end
def self.rm_repository_key platform, repository
self.client.call('rm_repository_key', platform, repository)
end
end end

View File

@ -7,7 +7,7 @@ module Grit
MAX_DATA_SIZE = 50.megabytes MAX_DATA_SIZE = 50.megabytes
def data_with_limit def data_with_limit
size <= MAX_DATA_SIZE ? data_without_limit : nil # 'Error: blob is too big' !huge? ? data_without_limit : nil # 'Error: blob is too big'
end end
alias_method_chain :data, :limit alias_method_chain :data, :limit
@ -15,6 +15,10 @@ module Grit
size.to_i > MAX_VIEW_SIZE size.to_i > MAX_VIEW_SIZE
end end
def huge?
size.to_i > MAX_DATA_SIZE
end
def render_as def render_as
@render_as ||= case @render_as ||= case
when large?; :binary when large?; :binary

View File

@ -21,8 +21,7 @@ module Rosa
class Treeish class Treeish
def self.matches?(request) def self.matches?(request)
params = request.path_parameters if (params = request.path_parameters) && params[:treeish] # parse existing branch (tag) and path
if params[:treeish] # parse existing branch (tag) and path
branch_or_tag = begin branch_or_tag = begin
(p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) &&
p.repo.branches_and_tags.detect{|t| params[:treeish].start_with?(t.name)}.try(:name) || p.repo.branches_and_tags.detect{|t| params[:treeish].start_with?(t.name)}.try(:name) ||

View File

@ -5,7 +5,7 @@ module Modules
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
after_create :create_wiki after_save :create_wiki
after_destroy :destroy_wiki after_destroy :destroy_wiki
end end

View File

@ -0,0 +1,155 @@
require 'spec_helper'
def create_key_pair(repository, user)
@key_pair = FactoryGirl.create(:key_pair, :repository => repository, :user => user)
end
shared_examples_for 'key_pair platform owner' do
it 'should be able to perform index action' do
get :index, :platform_id => @platform
response.should render_template(:index)
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_key_pairs_path(@platform))
end
it 'should create key pair into db on create action' do
lambda { post :create, @create_params }.should change{KeyPair.count}.by(1)
end
context "on destroy" do
before(:each) do
create_key_pair @repository, @user
end
it 'should be able to perform action' do
delete :destroy, :platform_id => @platform, :id => @key_pair
response.should redirect_to(platform_key_pairs_path(@platform))
end
it 'should delete key pair into db' do
lambda { delete :destroy, :platform_id => @platform, :id => @key_pair }.should change{KeyPair.count}.by(-1)
end
end
end
shared_examples_for 'key_pair platform reader' do
it 'should be able to perform index action' do
get :index, :platform_id => @platform
response.should render_template(:index)
end
it 'should not be able to perform create action' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
it 'should not change objects count on create success' do
lambda { post :create, @create_params }.should change{ KeyPair.count }.by(0)
end
context "on destroy" do
before(:each) do
create_key_pair @repository, @user
end
it 'should not be able to perform action' do
delete :destroy, :platform_id => @platform, :id => @key_pair
response.should redirect_to(forbidden_path)
end
it 'should not change objects count on destroy success' do
lambda { delete :destroy, :platform_id => @platform, :id => @key_pair }.should change{KeyPair.count}.by(0)
end
end
end
describe Platforms::KeyPairsController do
before(:each) do
stub_symlink_methods
stub_key_pairs_calls
@platform = FactoryGirl.create(:platform)
@repository = FactoryGirl.create(:repository, :platform => @platform)
@user = FactoryGirl.create(:user)
@create_params = {
:platform_id => @platform,
:key_pair => {
:repository_id => @repository,
:public => "iampublic",
:secret => "iamsecret"
}
}
end
context 'for guest' do
[:index, :create].each do |action|
it "should not be able to perform #{ action } action" do
get action, :platform_id => @platform
response.should redirect_to(new_user_session_path)
end
end
it 'should not change objects count on create success' do
lambda { post :create, @create_params }.should change{ KeyPair.count }.by(0)
end
context 'on destroy' do
before(:each) do
create_key_pair @repository, @user
end
it 'should not change objects count on destroy success' do
lambda { delete :destroy, :platform_id => @platform, :id => @key_pair }.should change{KeyPair.count}.by(0)
end
it "should not be able to perform destroy action" do
delete :destroy, :platform_id => @platform, :id => @key_pair
response.should redirect_to(new_user_session_path)
end
end
end
context 'for global admin' do
before(:each) do
@admin = FactoryGirl.create(:admin)
@user = FactoryGirl.create(:user)
set_session_for(@admin)
end
it_should_behave_like 'key_pair platform owner'
end
context 'for owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.update_attribute(:owner, @user)
end
it_should_behave_like 'key_pair platform owner'
end
context 'for admin user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'key_pair platform owner'
end
context 'for reader user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'key_pair platform reader'
end
end

View File

@ -125,7 +125,7 @@ describe Projects::BuildListsController do
end end
it 'should show only accessible build_lists' do it 'should show only accessible build_lists' do
get :index, :filter => {:ownership => 'index'} get :index, :filter => {:ownership => 'everything'}
assigns(:build_lists).should include(@build_list1) assigns(:build_lists).should include(@build_list1)
assigns(:build_lists).should_not include(@build_list2) assigns(:build_lists).should_not include(@build_list2)
assigns(:build_lists).should include(@build_list3) assigns(:build_lists).should include(@build_list3)
@ -210,7 +210,7 @@ describe Projects::BuildListsController do
end end
it 'should show only accessible build_lists' do it 'should show only accessible build_lists' do
get :index, :filter => {:ownership => 'index'} get :index, :filter => {:ownership => 'everything'}
assigns(:build_lists).should include(@build_list1) assigns(:build_lists).should include(@build_list1)
assigns(:build_lists).should_not include(@build_list2) assigns(:build_lists).should_not include(@build_list2)
assigns(:build_lists).should include(@build_list3) assigns(:build_lists).should include(@build_list3)
@ -297,17 +297,17 @@ describe Projects::BuildListsController do
it 'should filter by project_name' do it 'should filter by project_name' do
# Project.where(:id => build_list2.project.id).update_all(:name => 'project_name') # Project.where(:id => build_list2.project.id).update_all(:name => 'project_name')
get :index, :filter => {:project_name => @build_list2.project.name, :ownership => 'index'} get :index, :filter => {:project_name => @build_list2.project.name, :ownership => 'everything'}
assigns[:build_lists].should_not include(@build_list1) assigns[:build_lists].should_not include(@build_list1)
assigns[:build_lists].should include(@build_list2) assigns[:build_lists].should include(@build_list2)
assigns[:build_lists].should_not include(@build_list3) assigns[:build_lists].should_not include(@build_list3)
end end
it 'should filter by project_name and start_date' do it 'should filter by project_name and update_date' do
get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'index', get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'everything',
:"updated_at_start(1i)" => @build_list3.updated_at.year.to_s, "updated_at_start(1i)" => @build_list3.updated_at.year.to_s,
:"updated_at_start(2i)" => @build_list3.updated_at.month.to_s, "updated_at_start(2i)" => @build_list3.updated_at.month.to_s,
:"updated_at_start(3i)" => @build_list3.updated_at.day.to_s} "updated_at_start(3i)" => @build_list3.updated_at.day.to_s}
assigns[:build_lists].should_not include(@build_list1) assigns[:build_lists].should_not include(@build_list1)
assigns[:build_lists].should_not include(@build_list2) assigns[:build_lists].should_not include(@build_list2)
assigns[:build_lists].should include(@build_list3) assigns[:build_lists].should include(@build_list3)

View File

@ -0,0 +1,10 @@
# -*- encoding : utf-8 -*-
FactoryGirl.define do
factory :key_pair do
association :repository
association :user
public FactoryGirl.generate(:string)
secret FactoryGirl.generate(:string)
end
end

View File

@ -0,0 +1,22 @@
require 'spec_helper'
describe KeyPair do
before(:all) do
stub_symlink_methods
stub_key_pairs_calls
FactoryGirl.create(:key_pair)
end
it { should belong_to(:repository) }
it { should belong_to(:user)}
it { should_not allow_mass_assignment_of(:user) }
it { should_not allow_mass_assignment_of(:key_id) }
after(:all) do
Platform.delete_all
User.delete_all
Product.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path'])
end
end

View File

@ -38,6 +38,12 @@ def stub_symlink_methods
any_instance_of(Platform, :remove_symlink_directory => true) any_instance_of(Platform, :remove_symlink_directory => true)
end end
def stub_key_pairs_calls
stub(BuildServer).import_gpg_key_pair { [0,"1a2b3c"] }
stub(BuildServer).set_repository_key { 0 }
stub(BuildServer).rm_repository_key { 0 }
end
def test_git_commit(project) def test_git_commit(project)
project.repo.index.add('test', 'TEST') project.repo.index.add('test', 'TEST')
project.repo.index.commit('Test commit') project.repo.index.commit('Test commit')

View File

@ -241,7 +241,7 @@
} }
// attempt to load the definition for this language // attempt to load the definition for this language
var script_uri = '/javascripts/gollum/editor/langs/' + markup_name + '.js'; var script_uri = '/assets/gollum/editor/langs/' + markup_name + '.js';
$.ajax({ $.ajax({
url: script_uri, url: script_uri,
dataType: 'script', dataType: 'script',