From b4059c67fc938131c90c2fc10853cc46b48155ba Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 13 Jul 2012 15:18:12 +0400 Subject: [PATCH 01/56] [refs #441] Add key pairs for platform --- .../javascripts/platforms/key_pairs.js.coffee | 3 ++ .../stylesheets/platforms/key_pairs.css.scss | 3 ++ .../platforms/key_pairs_controller.rb | 31 ++++++++++++++++++ app/helpers/platforms/key_pairs_helper.rb | 2 ++ app/models/ability.rb | 2 ++ app/models/key_pair.rb | 32 +++++++++++++++++++ app/models/repository.rb | 1 + app/views/platforms/base/_sidebar.html.haml | 3 ++ app/views/platforms/key_pairs/_list.html.haml | 21 ++++++++++++ app/views/platforms/key_pairs/_new.html.haml | 17 ++++++++++ app/views/platforms/key_pairs/index.html.haml | 4 +++ config/locales/models/key_pair.en.yml | 27 ++++++++++++++++ config/locales/models/key_pair.ru.yml | 27 ++++++++++++++++ config/routes.rb | 1 + db/migrate/20120710134434_create_key_pairs.rb | 11 +++++++ db/schema.rb | 9 ++++++ lib/build_server.rb | 17 ++++++++-- .../platforms/key_pairs_controller_spec.rb | 5 +++ .../platforms/key_pairs_helper_spec.rb | 15 +++++++++ spec/models/key_pair_spec.rb | 5 +++ 20 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/platforms/key_pairs.js.coffee create mode 100644 app/assets/stylesheets/platforms/key_pairs.css.scss create mode 100644 app/controllers/platforms/key_pairs_controller.rb create mode 100644 app/helpers/platforms/key_pairs_helper.rb create mode 100644 app/models/key_pair.rb create mode 100644 app/views/platforms/key_pairs/_list.html.haml create mode 100644 app/views/platforms/key_pairs/_new.html.haml create mode 100644 app/views/platforms/key_pairs/index.html.haml create mode 100644 config/locales/models/key_pair.en.yml create mode 100644 config/locales/models/key_pair.ru.yml create mode 100644 db/migrate/20120710134434_create_key_pairs.rb create mode 100644 spec/controllers/platforms/key_pairs_controller_spec.rb create mode 100644 spec/helpers/platforms/key_pairs_helper_spec.rb create mode 100644 spec/models/key_pair_spec.rb diff --git a/app/assets/javascripts/platforms/key_pairs.js.coffee b/app/assets/javascripts/platforms/key_pairs.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/platforms/key_pairs.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/platforms/key_pairs.css.scss b/app/assets/stylesheets/platforms/key_pairs.css.scss new file mode 100644 index 000000000..d5b1aec6a --- /dev/null +++ b/app/assets/stylesheets/platforms/key_pairs.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Platforms::KeyPairs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb new file mode 100644 index 000000000..f1995e5ca --- /dev/null +++ b/app/controllers/platforms/key_pairs_controller.rb @@ -0,0 +1,31 @@ +class Platforms::KeyPairsController < ApplicationController + before_filter :authenticate_user! + + load_and_authorize_resource :platform + load_and_authorize_resource + + skip_load_and_authorize_resource :only => [:index] + skip_authorize_resource :platform, :only => [:create, :destroy] + + def create + @key_pair.user_id = current_user.id + + if @key_pair.key_create_call == true + flash[:notice] = t('flash.key_pairs.saved') + else + flash[:error] = t('flash.key_pairs.save_error') + end + + redirect_to platform_key_pairs_path(@platform) + end + + def destroy + if @key_pair.rm_key_call + flash[:notice] = t('flash.key_pairs.destroyed') + else + flash[:error] = t('flash.key_pairs.destroy_error') + end + + redirect_to platform_key_pairs_path(@platform) + end +end diff --git a/app/helpers/platforms/key_pairs_helper.rb b/app/helpers/platforms/key_pairs_helper.rb new file mode 100644 index 000000000..cef406c92 --- /dev/null +++ b/app/helpers/platforms/key_pairs_helper.rb @@ -0,0 +1,2 @@ +module Platforms::KeyPairsHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index c9e9d8ab7..fd55d4291 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -97,6 +97,8 @@ class Ability can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?} 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 => {: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'} diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb new file mode 100644 index 000000000..3f5f44e36 --- /dev/null +++ b/app/models/key_pair.rb @@ -0,0 +1,32 @@ +class KeyPair < ActiveRecord::Base + belongs_to :repository + belongs_to :user + + attr_accessor :secret + attr_accessible :public, :secret, :repository_id + + after_create :key_create_call + + def key_create_call + code, self.key_id = BuildServer.import_gpg_key_pair(public, secret) + if code.zero? + set_code = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) + if set_code.zero? + self.save + else + set_code + end + else + code + end + end + + def rm_key_call + if BuildServer.rm_repository_key(repository.platform_id, repository_id) == 0 + self.destroy + return true + end + + false + end +end diff --git a/app/models/repository.rb b/app/models/repository.rb index 57c741790..f559d7b77 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,6 +4,7 @@ class Repository < ActiveRecord::Base has_many :project_to_repositories, :dependent => :destroy, :validate => true has_many :projects, :through => :project_to_repositories + has_many :key_pairs validates :description, :presence => true validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 434e2ad43..35916f520 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -25,6 +25,9 @@ - if can? :members, @platform %li{:class => (act == :members && contr == :platforms) ? 'active' : nil} = 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? %li{:class => (act == :index && contr == :private_users) ? 'active' : ''} = link_to t("layout.platforms.private_users"), platform_private_users_path(@platform) diff --git a/app/views/platforms/key_pairs/_list.html.haml b/app/views/platforms/key_pairs/_list.html.haml new file mode 100644 index 000000000..f3068ff1c --- /dev/null +++ b/app/views/platforms/key_pairs/_list.html.haml @@ -0,0 +1,21 @@ +%table#myTable.tablesorter.platform-repos{:cellspacing => "0", :cellpadding => "0"} + %thead + %tr + %th.th1= t("activerecord.attributes.key_pair.repository") + %th.th2= t("activerecord.attributes.key_pair.public") + %th.th3= t("activerecord.attributes.key_pair.user_id") + %th= t("layout.delete") + %tbody + - @platform.repositories.each do |repository| + - repository.key_pairs.each do |key_pair| + %tr{:class => cycle("odd", "even")} + %td + = key_pair.repository.name + %td + = key_pair.public + %td + = key_pair.user.name + %td.buttons + - if can? :destroy, key_pair + = link_to platform_key_pair_path(@platform, key_pair), :method => :delete, :confirm => t("layout.key_pairs.confirm_delete") do + %span.delete   diff --git a/app/views/platforms/key_pairs/_new.html.haml b/app/views/platforms/key_pairs/_new.html.haml new file mode 100644 index 000000000..c6cc8f0bf --- /dev/null +++ b/app/views/platforms/key_pairs/_new.html.haml @@ -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_field :public, :class => 'text_field' + .both + .leftlist= f.label :secret, t("activerecord.attributes.key_pair.secret"), :class => :label + .rightlist= f.text_field :secret, :class => 'text_field' + .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") diff --git a/app/views/platforms/key_pairs/index.html.haml b/app/views/platforms/key_pairs/index.html.haml new file mode 100644 index 000000000..c219f563a --- /dev/null +++ b/app/views/platforms/key_pairs/index.html.haml @@ -0,0 +1,4 @@ += render 'new' if can? :edit, @platform += render 'list'#, :object => @key_pairs + +=# will_paginate @key_pairs diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml new file mode 100644 index 000000000..efe676334 --- /dev/null +++ b/config/locales/models/key_pair.en.yml @@ -0,0 +1,27 @@ +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 key pair? + header: Key Pairs + flash: + key_pairs: + saved: Key pair succefully created + save_error: Key pair save error + destroyed: Key pair succefully destroyed + destroy_error: Key pair destroy error + activerecord: + 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 diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml new file mode 100644 index 000000000..0c9c141bb --- /dev/null +++ b/config/locales/models/key_pair.ru.yml @@ -0,0 +1,27 @@ +en: + layout: + key_pairs: + repository_id: Репозиторий + user_id: Пользователь + public: Публичный ключ + secret: Секретный ключ + confirm_delete: Вы уверены, что хотите удалить эту ключевую пару? + header: Ключевые Пары + flash: + key_pairs: + saved: Ключевая пара сохранена успешно + save_error: Ошибка создания ключевой пары + destroyed: Ключевая пара удалена успешно + destroy_error: Ошибка удаления ключевой пары + activerecord: + models: + key_pair: Ключевая пара + attributes: + key_pair: + id: Id + created_at: Создано + updated_at: Обновлено + user_id: Пользователь + repository_id: Репозиторий + public: Публичный ключ + secret: Секретный ключ diff --git a/config/routes.rb b/config/routes.rb index 62c3029d3..f58555f18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,6 +71,7 @@ Rosa::Application.routes.draw do get :projects_list end end + resources :key_pairs, :only => [:create, :index, :destroy] resources :products do resources :product_build_lists, :only => [:create, :destroy] end diff --git a/db/migrate/20120710134434_create_key_pairs.rb b/db/migrate/20120710134434_create_key_pairs.rb new file mode 100644 index 000000000..50c41b1b0 --- /dev/null +++ b/db/migrate/20120710134434_create_key_pairs.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5200f5c01..1a41805c6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -184,6 +184,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do 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" + t.integer "user_id" + t.integer "key_id" + t.string "public" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "labelings", :force => true do |t| t.integer "label_id", :null => false t.integer "issue_id" diff --git a/lib/build_server.rb b/lib/build_server.rb index a1214af13..53dc35a63 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -87,11 +87,11 @@ class BuildServer # 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) end - + def self.delete_build_list idlist self.client.call('delete_build_list', idlist) end - + def self.get_status self.client.call('get_status') end @@ -99,4 +99,17 @@ class BuildServer def self.freeze platform_name self.client.call('freeze_platform', platform_name) 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 diff --git a/spec/controllers/platforms/key_pairs_controller_spec.rb b/spec/controllers/platforms/key_pairs_controller_spec.rb new file mode 100644 index 000000000..4336622c9 --- /dev/null +++ b/spec/controllers/platforms/key_pairs_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Platforms::KeyPairsController do + +end diff --git a/spec/helpers/platforms/key_pairs_helper_spec.rb b/spec/helpers/platforms/key_pairs_helper_spec.rb new file mode 100644 index 000000000..a2ba0ac62 --- /dev/null +++ b/spec/helpers/platforms/key_pairs_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Platforms::KeyPairsHelper. For example: +# +# describe Platforms::KeyPairsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Platforms::KeyPairsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/key_pair_spec.rb b/spec/models/key_pair_spec.rb new file mode 100644 index 000000000..348480097 --- /dev/null +++ b/spec/models/key_pair_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe KeyPair do + pending "add some examples to (or delete) #{__FILE__}" +end From 3cf3546c2e0632d2ac40e97199b8d12c53b5bde1 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 13 Jul 2012 18:16:56 +0400 Subject: [PATCH 02/56] [refs #441] Add secret to filter. Add repository key exist check --- app/controllers/platforms/key_pairs_controller.rb | 1 + app/models/key_pair.rb | 5 +++++ config/application.rb | 2 +- config/locales/models/key_pair.en.yml | 1 + config/locales/models/key_pair.ru.yml | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb index f1995e5ca..b7fecef5f 100644 --- a/app/controllers/platforms/key_pairs_controller.rb +++ b/app/controllers/platforms/key_pairs_controller.rb @@ -14,6 +14,7 @@ class Platforms::KeyPairsController < ApplicationController 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(@platform) diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 3f5f44e36..168a96dbf 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -8,6 +8,11 @@ class KeyPair < ActiveRecord::Base after_create :key_create_call def key_create_call + if KeyPair.exists? :repository_id => self.repository_id + errors.add(:repository_id, I18n.t('flash.key_pairs.key_exists')) + return false + end + code, self.key_id = BuildServer.import_gpg_key_pair(public, secret) if code.zero? set_code = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) diff --git a/config/application.rb b/config/application.rb index 0ec322cea..3cfd1ce68 100644 --- a/config/application.rb +++ b/config/application.rb @@ -48,7 +48,7 @@ module Rosa config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. - config.filter_parameters += [:password] + config.filter_parameters += [:password, :secret] # Enable the asset pipeline config.assets.enabled = true diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml index efe676334..59ad9ee0a 100644 --- a/config/locales/models/key_pair.en.yml +++ b/config/locales/models/key_pair.en.yml @@ -13,6 +13,7 @@ en: save_error: Key pair save error destroyed: Key pair succefully destroyed destroy_error: Key pair destroy error + key_exists: Key pair already exists for this repository activerecord: models: key_pair: Key Pair diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml index 0c9c141bb..a04a94fe4 100644 --- a/config/locales/models/key_pair.ru.yml +++ b/config/locales/models/key_pair.ru.yml @@ -13,6 +13,7 @@ en: save_error: Ошибка создания ключевой пары destroyed: Ключевая пара удалена успешно destroy_error: Ошибка удаления ключевой пары + key_exists: Ключ уже существует для данного репозитория! activerecord: models: key_pair: Ключевая пара From 70b2d62e5255859349fe20fd10441e456af046e8 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 16 Jul 2012 13:58:33 +0400 Subject: [PATCH 03/56] [refs #441] Some small fixes of locales and code --- app/models/key_pair.rb | 6 +----- app/models/repository.rb | 2 +- app/views/platforms/key_pairs/_list.html.haml | 17 +++++++---------- app/views/platforms/key_pairs/index.html.haml | 4 +--- config/locales/models/key_pair.en.yml | 2 +- config/locales/models/key_pair.ru.yml | 2 +- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 168a96dbf..7fc7aad05 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -16,11 +16,7 @@ class KeyPair < ActiveRecord::Base code, self.key_id = BuildServer.import_gpg_key_pair(public, secret) if code.zero? set_code = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) - if set_code.zero? - self.save - else - set_code - end + set_code.zero? ? self.save : set_code else code end diff --git a/app/models/repository.rb b/app/models/repository.rb index f559d7b77..19f4c8888 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,7 +4,7 @@ class Repository < ActiveRecord::Base has_many :project_to_repositories, :dependent => :destroy, :validate => true has_many :projects, :through => :project_to_repositories - has_many :key_pairs + has_one :key_pair validates :description, :presence => true validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} diff --git a/app/views/platforms/key_pairs/_list.html.haml b/app/views/platforms/key_pairs/_list.html.haml index f3068ff1c..863bb5531 100644 --- a/app/views/platforms/key_pairs/_list.html.haml +++ b/app/views/platforms/key_pairs/_list.html.haml @@ -1,21 +1,18 @@ %table#myTable.tablesorter.platform-repos{:cellspacing => "0", :cellpadding => "0"} %thead %tr - %th.th1= t("activerecord.attributes.key_pair.repository") + %th.th1= t("activerecord.attributes.key_pair.repository_id") %th.th2= t("activerecord.attributes.key_pair.public") %th.th3= t("activerecord.attributes.key_pair.user_id") %th= t("layout.delete") %tbody - @platform.repositories.each do |repository| - - repository.key_pairs.each do |key_pair| + - if repository.key_pair %tr{:class => cycle("odd", "even")} - %td - = key_pair.repository.name - %td - = key_pair.public - %td - = key_pair.user.name + %td= repository.name + %td= repository.key_pair.public + %td= repository.key_pair.user.name %td.buttons - - if can? :destroy, key_pair - = link_to platform_key_pair_path(@platform, key_pair), :method => :delete, :confirm => t("layout.key_pairs.confirm_delete") do + - 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   diff --git a/app/views/platforms/key_pairs/index.html.haml b/app/views/platforms/key_pairs/index.html.haml index c219f563a..b04743a34 100644 --- a/app/views/platforms/key_pairs/index.html.haml +++ b/app/views/platforms/key_pairs/index.html.haml @@ -1,4 +1,2 @@ = render 'new' if can? :edit, @platform -= render 'list'#, :object => @key_pairs - -=# will_paginate @key_pairs += render 'list' diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml index 59ad9ee0a..b7ad9532f 100644 --- a/config/locales/models/key_pair.en.yml +++ b/config/locales/models/key_pair.en.yml @@ -13,7 +13,7 @@ en: save_error: Key pair save error destroyed: Key pair succefully destroyed destroy_error: Key pair destroy error - key_exists: Key pair already exists for this repository + key_exists: has one key pair already! activerecord: models: key_pair: Key Pair diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml index a04a94fe4..32f93f356 100644 --- a/config/locales/models/key_pair.ru.yml +++ b/config/locales/models/key_pair.ru.yml @@ -13,7 +13,7 @@ en: save_error: Ошибка создания ключевой пары destroyed: Ключевая пара удалена успешно destroy_error: Ошибка удаления ключевой пары - key_exists: Ключ уже существует для данного репозитория! + key_exists: уже имеет одну ключевую пару! activerecord: models: key_pair: Ключевая пара From a5af7d72d92077c3698c2a2f0cbd53134e953053 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 16 Jul 2012 20:36:47 +0400 Subject: [PATCH 04/56] [refs #441] Add specs for key pairs --- .../platforms/key_pairs_controller_spec.rb | 138 ++++++++++++++++++ spec/factories/key_pair.rb | 10 ++ 2 files changed, 148 insertions(+) create mode 100644 spec/factories/key_pair.rb diff --git a/spec/controllers/platforms/key_pairs_controller_spec.rb b/spec/controllers/platforms/key_pairs_controller_spec.rb index 4336622c9..7beeec068 100644 --- a/spec/controllers/platforms/key_pairs_controller_spec.rb +++ b/spec/controllers/platforms/key_pairs_controller_spec.rb @@ -1,5 +1,143 @@ 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 + + @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, :destroy].each do |action| + it "should not be able to perform #{ action } action" do + get action, :platform_id => @platform, :id => @key_pair + 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 + + 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 + + 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 diff --git a/spec/factories/key_pair.rb b/spec/factories/key_pair.rb new file mode 100644 index 000000000..07adb4727 --- /dev/null +++ b/spec/factories/key_pair.rb @@ -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 + From 611b22baa57cd1cd698d9ee566a22ba46b00cd96 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 17 Jul 2012 11:02:56 +0300 Subject: [PATCH 05/56] Update gems, fix conflicts. Raise 404 error instead of redirect. Refactor git controllers. Refactor git methods, move to modules. Cleanup git helpers, refactor and remove unused variables from views, refactor git templates. Refactor project load. Refactor git routes and links, refactor constraints. Fix branches with slashes and dots. Apply github linguist and libmagic for binary file detection. Other refactor and code cleanup. Fix specs and deprecations. Refs #263 --- Gemfile | 24 +- Gemfile.lock | 138 ++++++----- app/controllers/application_controller.rb | 5 + .../projects/build_lists_controller.rb | 3 +- .../projects/comments_controller.rb | 2 +- .../projects/commit_subscribes_controller.rb | 2 +- .../projects/git/base_controller.rb | 33 +-- .../projects/git/blobs_controller.rb | 46 +--- .../projects/git/commits_controller.rb | 29 +-- .../projects/git/trees_controller.rb | 33 +-- .../projects/projects_controller.rb | 6 +- app/helpers/git_helper.rb | 43 ++-- app/models/activity_feed_observer.rb | 4 +- app/models/build_list.rb | 2 +- app/models/build_list/filter.rb | 14 +- app/models/comment.rb | 2 +- app/models/git/repository.rb | 130 ---------- app/models/project.rb | 228 +++--------------- app/views/projects/base/_repo_block.html.haml | 4 +- app/views/projects/base/_submenu.html.haml | 6 +- app/views/projects/build_lists/new.html.haml | 5 +- .../projects/git/blobs/_editor.html.haml | 2 +- .../git/blobs/_render_as_binary.html.haml | 8 + .../git/blobs/_render_as_image.html.haml | 8 + .../git/blobs/_render_as_text.html.haml | 6 + app/views/projects/git/blobs/_show.html.haml | 34 +-- app/views/projects/git/blobs/_top.html.haml | 10 +- app/views/projects/git/blobs/blame.html.haml | 3 +- .../git/commits/_commit_diff.html.haml | 2 +- .../projects/git/commits/index.html.haml | 2 +- app/views/projects/projects/_form.html.haml | 2 +- config/routes.rb | 63 ++--- db/schema.rb | 99 ++++---- doc/README_FOR_APP | 4 + lib/ext/git/grit.rb | 76 ++++-- lib/ext/rails/constraint.rb | 49 ++++ lib/ext/rails/constraints.rb | 18 -- lib/ext/rails/middleware.rb | 18 ++ lib/ext/rosa/constraints.rb | 42 ++++ lib/modules/models/git.rb | 187 ++++++++++++++ lib/modules/models/owner.rb | 11 +- lib/modules/models/wiki.rb | 39 +++ lib/tasks/add_branch.rake | 2 +- .../platforms/mass_builds_controller_spec.rb | 8 +- .../platforms/repositories_controller_spec.rb | 4 +- .../projects/build_lists_controller_spec.rb | 20 +- .../comments_controller_for_commit_spec.rb | 4 +- .../projects/git/git_trees_controller_spec.rb | 10 +- .../users/profile_controller_spec.rb | 2 +- spec/factories/platforms.rb | 2 +- spec/models/comment_for_commit_spec.rb | 4 +- spec/routing/projects_routing_spec.rb.rb | 1 + spec/spec_helper.rb | 4 +- 53 files changed, 746 insertions(+), 757 deletions(-) delete mode 100644 app/models/git/repository.rb create mode 100644 app/views/projects/git/blobs/_render_as_binary.html.haml create mode 100644 app/views/projects/git/blobs/_render_as_image.html.haml create mode 100644 app/views/projects/git/blobs/_render_as_text.html.haml create mode 100644 lib/ext/rails/constraint.rb delete mode 100644 lib/ext/rails/constraints.rb create mode 100644 lib/ext/rails/middleware.rb create mode 100644 lib/ext/rosa/constraints.rb create mode 100644 lib/modules/models/git.rb create mode 100644 lib/modules/models/wiki.rb diff --git a/Gemfile b/Gemfile index 7ed9a93a3..01a5c745a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,19 +2,19 @@ source 'http://rubygems.org' gem 'rails', '3.2.6' #, :git => 'git://github.com/rails/rails.git' -gem 'pg', '~> 0.13.2' +gem 'pg', '~> 0.14.0' # gem 'silent-postgres', :git => 'git://github.com/dolzenko/silent-postgres.git' #'~> 0.1.1' gem 'redhillonrails_core', :git => 'git://github.com/chipiga/redhillonrails_core.git', :branch => 'rails31' # '~> 2.0.0.pre' # deprecated # gem 'schema_plus', '~> 0.2.1' # buggy shit! -gem 'devise', '~> 2.0.4' -gem 'omniauth', '~> 1.0.3' +gem 'devise', '~> 2.1.2' +gem 'omniauth', '~> 1.1.0' gem 'omniauth-openid', '~> 1.0.1' -gem 'cancan', '~> 1.6.7' +gem 'cancan', '1.6.7' # 1.6.8 fail specs with strange error gem 'ancestry', '~> 1.3.0' -gem 'paperclip', '~> 3.0.4' -gem 'resque', '~> 1.20.0' +gem 'paperclip', '~> 3.1.3' +gem 'resque', '~> 1.21.0' gem 'resque-status', '~> 0.3.3' gem 'resque_mailer', '~> 2.1.0' gem 'perform_later', '~> 1.3.0' # should be after resque_mailer @@ -26,6 +26,8 @@ gem 'state_machine' 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' gem 'charlock_holmes', '~> 0.6.8' #, :git => 'git://github.com/brianmario/charlock_holmes.git', :branch => 'bundle-icu' +# gem 'ruby-filemagic', '~> 0.4.2', :require => 'filemagic/ext' +gem 'github-linguist', '~> 2.0.1', :require => 'linguist' gem 'diff-display', '~> 0.0.1' # Wiki @@ -39,7 +41,7 @@ gem 'wikicloth' gem 'unicorn', '~> 4.3.1', :platforms => [:mri, :rbx] gem 'trinidad', '~> 1.0.2', :platforms => :jruby -gem 'newrelic_rpm', '~> 3.3.5', :platforms => [:mri, :rbx] +gem 'newrelic_rpm', '~> 3.4.0.1', :platforms => [:mri, :rbx] gem 'whenever', '~> 0.7.3', :require => false gem 'jbuilder', '~> 0.4.0' @@ -54,14 +56,14 @@ gem 'rails-backbone', '~> 0.7.2' group :assets do gem 'sass-rails', '~> 3.2.5' gem 'coffee-rails', '~> 3.2.2' - gem 'compass-rails', '~> 1.0.2' + gem 'compass-rails', '~> 1.0.3' gem 'uglifier', '~> 1.2.4' gem 'therubyracer', '~> 0.10.1', :platforms => [:mri, :rbx] gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby end group :production do - gem "airbrake", '~> 3.1.1' + gem "airbrake", '~> 3.1.2' gem 'bluepill', '~> 0.0.60', :require => false end @@ -78,8 +80,8 @@ group :development do end group :test do - gem 'rspec-rails', '~> 2.10.1', :group => 'development' - gem 'factory_girl_rails', '~> 3.4.0' + gem 'rspec-rails', '~> 2.11.0', :group => 'development' + gem 'factory_girl_rails', '~> 3.5.0' gem 'rr', '~> 1.0.4' gem 'shoulda' end diff --git a/Gemfile.lock b/Gemfile.lock index 15dc97662..5d9e2545f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,7 +52,7 @@ GEM activesupport (3.2.6) i18n (~> 0.6) multi_json (~> 1.0) - airbrake (3.1.1) + airbrake (3.1.2) activesupport builder albino (1.3.3) @@ -88,33 +88,40 @@ GEM coffee-script-source execjs coffee-script-source (1.3.3) - compass (0.12.1) + compass (0.12.2) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) - compass-rails (1.0.2) - compass (>= 0.12.0, < 0.14) + compass-rails (1.0.3) + compass (>= 0.12.2, < 0.14) creole (0.4.2) daemons (1.1.6) - devise (2.0.4) + devise (2.1.2) bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.0.3) + orm_adapter (~> 0.1) railties (~> 3.1) - warden (~> 1.1.1) + warden (~> 1.2.1) diff-display (0.0.1) diff-lcs (1.1.3) ejs (1.0.0) erubis (2.7.0) + escape_utils (0.2.4) eventmachine (0.12.10) execjs (1.4.0) multi_json (~> 1.0) expression_parser (0.9.0) - factory_girl (3.4.0) + factory_girl (3.5.0) activesupport (>= 3.0.0) - factory_girl_rails (3.4.0) - factory_girl (~> 3.4.0) + factory_girl_rails (3.5.0) + factory_girl (~> 3.5.0) railties (>= 3.0.0) + ffi (1.0.11) fssm (0.2.9) + github-linguist (2.0.1) + charlock_holmes (~> 0.6.6) + escape_utils (~> 0.2.3) + mime-types (~> 1.18) + pygments.rb (~> 0.2.13) github-markup (0.7.2) gollum (1.3.1) albino (~> 1.3.2) @@ -132,14 +139,14 @@ GEM haml (~> 3.0) railties (~> 3.0) hashie (1.2.0) - highline (1.6.12) + highline (1.6.13) hike (1.2.1) - hirb (0.6.2) + hirb (0.7.0) i18n (0.6.0) jbuilder (0.4.0) activesupport (>= 3.0.0) blankslate (>= 2.1.2.4) - journey (1.0.3) + journey (1.0.4) jquery-rails (2.0.2) railties (>= 3.2.0, < 5.0) thor (~> 0.14) @@ -152,18 +159,18 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mailcatcher (0.5.6) + mailcatcher (0.5.7.2) activesupport (~> 3.0) eventmachine (~> 0.12) haml (~> 3.1) mail (~> 2.3) sinatra (~> 1.2) - skinny (~> 0.2) + skinny (~> 0.2, >= 0.2.1) sqlite3 (~> 1.3) thin (~> 1.2) meta-tags (1.2.6) actionpack - mime-types (1.18) + mime-types (1.19) multi_json (1.3.6) mustache (0.99.4) net-scp (1.0.4) @@ -173,16 +180,16 @@ GEM net-ssh (2.5.2) net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) - newrelic_rpm (3.3.5) - nokogiri (1.5.4) - omniauth (1.0.3) + newrelic_rpm (3.4.0.1) + nokogiri (1.5.5) + omniauth (1.1.0) hashie (~> 1.2) rack omniauth-openid (1.0.1) omniauth (~> 1.0) rack-openid (~> 1.3.1) - orm_adapter (0.0.7) - paperclip (3.0.4) + orm_adapter (0.4.0) + paperclip (3.1.3) activemodel (>= 3.0.0) activerecord (>= 3.0.0) activesupport (>= 3.0.0) @@ -192,9 +199,11 @@ GEM rails (~> 3.0) redis resque - pg (0.13.2) + pg (0.14.0) polyglot (0.3.3) posix-spawn (0.3.6) + pygments.rb (0.2.13) + rubypython (~> 0.5.3) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) @@ -230,21 +239,21 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - raindrops (0.9.0) + raindrops (0.10.0) rake (0.9.2.2) rdiscount (1.6.8) rdoc (3.12) json (~> 1.4) redcarpet (1.17.2) - redis (2.2.2) - redis-namespace (1.0.3) - redis (< 3.0.0) + redis (3.0.1) + redis-namespace (1.2.0) + redis (~> 3.0.0) redisk (0.2.2) redis (>= 0.1.1) redis-namespace (>= 0.1.0) - resque (1.20.0) + resque (1.21.0) multi_json (~> 1.0) - redis-namespace (~> 1.0.2) + redis-namespace (~> 1.0) sinatra (>= 0.9.2) vegas (~> 0.1.2) resque-status (0.3.3) @@ -254,46 +263,50 @@ GEM resque_mailer (2.1.0) actionmailer (~> 3.0) rr (1.0.4) - rspec (2.10.0) - rspec-core (~> 2.10.0) - rspec-expectations (~> 2.10.0) - rspec-mocks (~> 2.10.0) - rspec-core (2.10.1) - rspec-expectations (2.10.0) + rspec (2.11.0) + rspec-core (~> 2.11.0) + rspec-expectations (~> 2.11.0) + rspec-mocks (~> 2.11.0) + rspec-core (2.11.0) + rspec-expectations (2.11.1) diff-lcs (~> 1.1.3) - rspec-mocks (2.10.1) - rspec-rails (2.10.1) + rspec-mocks (2.11.1) + rspec-rails (2.11.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec (~> 2.10.0) + rspec (~> 2.11.0) ruby-haml-js (0.0.3) execjs sprockets (>= 2.0.0) - ruby-openid (2.1.8) + ruby-openid (2.2.0) + rubypython (0.5.3) + blankslate (>= 2.1.2.3) + ffi (~> 1.0.7) russian (0.6.0) i18n (>= 0.5.0) - rvm-capistrano (1.2.2) + rvm-capistrano (1.2.3) capistrano (>= 2.0.0) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.1.19) + sass (3.1.20) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) shotgun (0.9) rack (>= 1.0) - shoulda (3.0.1) - shoulda-context (~> 1.0.0) - shoulda-matchers (~> 1.0.0) + shoulda (3.1.0) + shoulda-context (~> 1.0) + shoulda-matchers (~> 1.2) shoulda-context (1.0.0) - shoulda-matchers (1.0.0) + shoulda-matchers (1.2.0) + activesupport (>= 3.0.0) sinatra (1.3.2) rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) - skinny (0.2.0) + skinny (0.2.1) eventmachine (~> 0.12) thin (~> 1.2) sprockets (2.1.3) @@ -302,22 +315,22 @@ GEM tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6) state_machine (1.1.2) - systemu (2.5.1) + systemu (2.5.2) therubyracer (0.10.1) libv8 (~> 3.3.10) - thin (1.3.1) + thin (1.4.1) daemons (>= 1.0.9) eventmachine (>= 0.12.6) rack (>= 1.0.0) - thor (0.15.2) + thor (0.15.4) tilt (1.3.3) treetop (1.4.10) polyglot polyglot (>= 0.3.1) tzinfo (0.3.33) - uglifier (1.2.4) + uglifier (1.2.6) execjs (>= 0.3.0) - multi_json (>= 1.0.2) + multi_json (~> 1.3) unicorn (4.3.1) kgio (~> 2.6) rack @@ -326,7 +339,7 @@ GEM macaddr (~> 1.0) vegas (0.1.11) rack (>= 1.0.0) - warden (1.1.1) + warden (1.2.1) rack (>= 1.0) whenever (0.7.3) activesupport (>= 2.3.4) @@ -341,20 +354,21 @@ PLATFORMS DEPENDENCIES RedCloth - airbrake (~> 3.1.1) + airbrake (~> 3.1.2) ancestry (~> 1.3.0) bluepill (~> 0.0.60) - cancan (~> 1.6.7) + cancan (= 1.6.7) cape capistrano capistrano_colors charlock_holmes (~> 0.6.8) coffee-rails (~> 3.2.2) - compass-rails (~> 1.0.2) + compass-rails (~> 1.0.3) creole - devise (~> 2.0.4) + devise (~> 2.1.2) diff-display (~> 0.0.1) - factory_girl_rails (~> 3.4.0) + factory_girl_rails (~> 3.5.0) + github-linguist (~> 2.0.1) gollum (= 1.3.1) grack! grit! @@ -365,12 +379,12 @@ DEPENDENCIES jquery-rails (~> 2.0.2) mailcatcher meta-tags (~> 1.2.5) - newrelic_rpm (~> 3.3.5) - omniauth (~> 1.0.3) + newrelic_rpm (~> 3.4.0.1) + omniauth (~> 1.1.0) omniauth-openid (~> 1.0.1) - paperclip (~> 3.0.4) + paperclip (~> 3.1.3) perform_later (~> 1.3.0) - pg (~> 0.13.2) + pg (~> 0.14.0) rails (= 3.2.6) rails-backbone (~> 0.7.2) rails3-generators @@ -378,11 +392,11 @@ DEPENDENCIES rdiscount redcarpet (= 1.17.2) redhillonrails_core! - resque (~> 1.20.0) + resque (~> 1.21.0) resque-status (~> 0.3.3) resque_mailer (~> 2.1.0) rr (~> 1.0.4) - rspec-rails (~> 2.10.1) + rspec-rails (~> 2.11.0) ruby-haml-js (~> 0.0.3) russian (~> 0.6.0) rvm-capistrano diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 642ee629b..b191227aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,6 +17,7 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to forbidden_url, :alert => t("flash.exception_message") end + rescue_from Grit::NoSuchPathError, :with => :not_found protected @@ -53,4 +54,8 @@ class ApplicationController < ActionController::Base "application" end end + + def not_found + raise ActionController::RoutingError.new('Not Found') + end end diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index cb5115741..eea85eb9c 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -46,7 +46,7 @@ class Projects::BuildListsController < Projects::BaseController Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform| @build_list = @project.build_lists.build(params[:build_list]) - @build_list.commit_hash = @project.git_repository.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last || @build_list.project_version).first.id if @build_list.project_version + @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 @@ -98,7 +98,6 @@ class Projects::BuildListsController < Projects::BaseController else @build_list.fail_publish end - render :nothing => true, :status => 200 end diff --git a/app/controllers/projects/comments_controller.rb b/app/controllers/projects/comments_controller.rb index 371365eb9..3b36c3456 100644 --- a/app/controllers/projects/comments_controller.rb +++ b/app/controllers/projects/comments_controller.rb @@ -41,7 +41,7 @@ class Projects::CommentsController < Projects::BaseController def find_commentable @commentable = params[:issue_id].present? && @project.issues.find_by_serial_id(params[:issue_id]) || - params[:commit_id].present? && @project.git_repository.commit(params[:commit_id]) + params[:commit_id].present? && @project.repo.commit(params[:commit_id]) end def find_or_build_comment diff --git a/app/controllers/projects/commit_subscribes_controller.rb b/app/controllers/projects/commit_subscribes_controller.rb index de5b2ac6e..b7dbc31c7 100644 --- a/app/controllers/projects/commit_subscribes_controller.rb +++ b/app/controllers/projects/commit_subscribes_controller.rb @@ -25,7 +25,7 @@ class Projects::CommitSubscribesController < Projects::BaseController protected def find_commit - @commit = @project.git_repository.commit(params[:commit_id]) + @commit = @project.repo.commit(params[:commit_id]) @options = {:project_id => @project.id, :subscribeable_id => @commit.id.hex, :subscribeable_type => @commit.class.name, :user_id => current_user.id} end end diff --git a/app/controllers/projects/git/base_controller.rb b/app/controllers/projects/git/base_controller.rb index 37168d764..a77c39ffd 100644 --- a/app/controllers/projects/git/base_controller.rb +++ b/app/controllers/projects/git/base_controller.rb @@ -4,36 +4,19 @@ class Projects::Git::BaseController < Projects::BaseController skip_before_filter :authenticate_user!, :only => [:show, :index, :blame, :raw, :archive] if APP_CONFIG['anonymous_access'] load_and_authorize_resource :project - before_filter :find_git_repository - before_filter :find_tags - before_filter :find_branches - before_filter :set_treeish - before_filter :set_current_tag - before_filter :set_current_branch + before_filter :set_treeish_and_path + before_filter :set_branch_and_tree protected - def find_git_repository - @git_repository = @project.git_repository - end - - def find_tags - @tags = @git_repository.tags - end - - def find_branches - @branches = @git_repository.branches - end - - def set_treeish + def set_treeish_and_path @treeish = params[:treeish].presence || @project.default_branch + @path = params[:path] end - def set_current_tag - @current_tag = @tags.select{|t| t.name == @treeish }.first - end - - def set_current_branch - @current_branch = @branches.select{|b| b.name == @treeish }.first + def set_branch_and_tree + @branch = @project.repo.branches.detect{|b| b.name == @treeish} + @tree = @project.repo.tree(@treeish) + # raise Grit::NoSuchPathError if @tree.blobs.blank? end end diff --git a/app/controllers/projects/git/blobs_controller.rb b/app/controllers/projects/git/blobs_controller.rb index b8abb0799..96dc586dc 100644 --- a/app/controllers/projects/git/blobs_controller.rb +++ b/app/controllers/projects/git/blobs_controller.rb @@ -1,34 +1,17 @@ # -*- encoding : utf-8 -*- class Projects::Git::BlobsController < Projects::Git::BaseController - before_filter :find_tree - before_filter :find_branch - before_filter :set_path_blob + before_filter :set_blob + before_filter lambda {authorize! :write, @project}, :only => [:edit, :update] def show - redirect_to project_path(@project) and return unless @blob.present? - if params[:raw] - response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}" - response.headers['Content-Type'] = @blob.mime_type - response.headers['Content-Disposition'] = 'inline' - render(:text => @blob.data) and return - end end def edit - redirect_to project_path(@project) and return unless @blob.present? - authorize! :write, @project end def update - redirect_to project_path(@project) and return unless @blob.present? - authorize! :write, @project - # Here might be callbacks for notification purposes: - # @git_repository.after_update_file do |repo, sha| - # end - - res = @git_repository.update_file(params[:path], params[:content].gsub("\r", ''), - :message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish) - if res + if @project.update_file(params[:path], params[:content].gsub("\r", ''), + :message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish) flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path]) else flash[:notice] = t("flash.blob.updating_error", :name => params[:path]) @@ -37,28 +20,17 @@ class Projects::Git::BlobsController < Projects::Git::BaseController end def blame - @blame = Grit::Blob.blame(@git_repository.repo, @commit.id, @path) + @blame = Grit::Blob.blame(@project.repo, @commit.id, @path) end def raw - redirect_to project_path(@project) and return unless @blob.present? - headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] - render :text => @blob.data, :content_type => @blob.mime_type + send_data @blob.data, :type => @blob.content_type, :disposition => @blob.disposition end protected - def find_branch - @branch = @project.branch(@treeish) - end - - def set_path_blob - @path = params[:path] - @blob = @tree / @path - @commit = @git_repository.log(@treeish, @path, :max_count => 1).first - end - - def find_tree - @tree = @git_repository.tree(@treeish) + def set_blob + @blob = @tree / @path or raise Grit::NoSuchPathError + @commit = @project.repo.log(@treeish, @path, :max_count => 1).first end end diff --git a/app/controllers/projects/git/commits_controller.rb b/app/controllers/projects/git/commits_controller.rb index cf9a20021..31816996c 100644 --- a/app/controllers/projects/git/commits_controller.rb +++ b/app/controllers/projects/git/commits_controller.rb @@ -1,42 +1,19 @@ # -*- encoding : utf-8 -*- class Projects::Git::CommitsController < Projects::Git::BaseController - helper_method :split_commits_by_date - def index - @branch_name = params[:treeish] || @project.default_branch - @branch = @project.branch(@branch_name) - @path = params[:path] - if @path.present? - @commits = @git_repository.repo.log(@branch_name, @path) - @render_paginate = false + @commits = @project.repo.log(@treeish, @path) else - @commits, @page, @last_page = @git_repository.paginate_commits(@branch_name, :page => params[:page]) - @render_paginate = true + @commits, @page, @last_page = @project.paginate_commits(@treeish, :page => params[:page]) end end def show - @commit = @git_repository.commit(params[:id]) # @git_repository.commits(params[:id]).first - + @commit = @project.repo.commit(params[:id]) respond_to do |format| format.html format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" } format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" } end end - - protected - - def split_commits_by_date(commits) - res = commits.sort{|x, y| y.authored_date <=> x.authored_date}.inject({}) do |h, commit| - dt = commit.authored_date - h[dt.year] ||= {} - h[dt.year][dt.month] ||= {} - h[dt.year][dt.month][dt.day] ||= [] - h[dt.year][dt.month][dt.day] << commit - h - end - return res - end end diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index 9655ffd4b..45dae2aa1 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -1,32 +1,21 @@ # -*- encoding : utf-8 -*- class Projects::Git::TreesController < Projects::Git::BaseController + before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => 'show' + def show - redirect_to project_path(@project) and return if params[:treeish] == @project.default_branch and params[:path].blank? - - @path = params[:path] - @tree = @git_repository.tree(@treeish) - @branch = @project.branch(@treeish) - -# @commit = @git_repository.commits(@treeish, 1).first -# Raises Grit::Git::GitTimeout - @commit = @branch.present? ? @branch.commit() : @git_repository.log(@treeish, @path, :max_count => 1).first - render "empty" and return unless @commit - - @tree = @tree / @path if @path + @tree = @tree / @path if @path.present? + @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first + render 'empty' unless @commit end def archive - treeish = params[:treeish].presence || @project.default_branch - format = params[:format] || 'tar' - commit = @project.git_repository.log(treeish, nil, :max_count => 1).first - if !commit or !['tar', 'zip'].include?(format) - raise ActiveRecord::RecordNotFound#("Couldn't send Project archive with id=#{@project.id}, treeish=#{treeish} and format=#{format}") - end - name = "#{@project.owner.uname}-#{@project.name}#{@project.tags.include?(treeish) ? "-#{treeish}" : ''}-#{commit.id[0..19]}" - fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}" + @commit = @project.repo.log(@treeish, nil, :max_count => 1).first + raise Grit::NoSuchPathError unless @commit + name = "#{@project.owner.uname}-#{@project.name}#{@project.repo.tags.include?(@treeish) ? "-#{@treeish}" : ''}-#{@commit.id[0..19]}" + fullname = "#{name}.#{params[:format] == 'tar' ? 'tar.gz' : 'zip'}" file = Tempfile.new fullname, 'tmp' - system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}") + system("cd #{@project.path}; git archive --format=#{params[:format]} --prefix=#{name}/ #{@treeish} #{params[:format] == 'tar' ? ' | gzip -9' : ''} > #{file.path}") file.close - send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname + send_file file.path, :disposition => 'attachment', :type => "application/#{params[:format] == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname end end diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index b948f5d7c..845d89ccb 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -1,11 +1,7 @@ # -*- encoding : utf-8 -*- class Projects::ProjectsController < Projects::BaseController before_filter :authenticate_user! - load_and_authorize_resource - # TODO WTF ? fork, update, sections not authorize - before_filter do |controller| - authorize! params[:action].to_sym, @project if params[:action] != 'index' - end + load_and_authorize_resource :id_param => :project_name # to force member actions load def index @projects = Project.accessible_by(current_ability, :membered) diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index 78af65bda..f3ea0bdc6 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -4,7 +4,7 @@ module GitHelper def render_path # TODO: Looks ugly, rewrite with clear mind. if @path.present? - if @treeish == "master" + if @treeish == @project.default_branch res = "#{link_to @project.name, tree_path(@project)} / " else res = "#{link_to @project.name, tree_path(@project, @treeish)} / " @@ -36,22 +36,6 @@ module GitHelper res.html_safe end - def render_blob(blob) - blob.data.split("\n").collect do |line| - content_tag :div, line.present? ? h(line) : tag(:br) - end.join.html_safe - end - - def choose_render_way(blob) - case - when blob.mime_type.match(/image/); :image - when blob.binary?; :binary - else - @text = @blob.data.split("\n") - :text - end - end - def iterate_path(path, &block) path.split(File::SEPARATOR).inject('') do |a, e| if e != '.' and e != '..' @@ -71,10 +55,29 @@ module GitHelper current = url_for(p).split('?', 2).first res = [] - res << [I18n.t('layout.git.repositories.commits'), [truncate(params[:treeish], :length => 20)]] unless (project.branches + project.tags).map(&:name).include?(params[:treeish] || project.default_branch) - res << [I18n.t('layout.git.repositories.branches'), project.branches.map{|b| [truncate(b.name, :length => 20), url_for(p.merge :treeish => b.name).split('?', 2).first]}] - res << [I18n.t('layout.git.repositories.tags'), project.tags.map{|t| [truncate(t.name, :length => 20), url_for(p.merge :treeish => t.name).split('?', 2).first]}] + res << [I18n.t('layout.git.repositories.commits'), [truncate(params[:treeish], :length => 20)]] unless (project.repo.branches + project.repo.tags).map(&:name).include?(params[:treeish] || project.default_branch) + res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map{|b| [truncate(b.name, :length => 20), url_for(p.merge :treeish => b.name).split('?', 2).first]}] + res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map{|t| [truncate(t.name, :length => 20), url_for(p.merge :treeish => t.name).split('?', 2).first]}] grouped_options_for_select(res, current) end + + def versions_for_group_select(project) + [ + ['Branches', project.repo.branches.map{|b| "latest_#{b.name}"}], + ['Tags', project.repo.tags.map(&:name)] + ] + end + + def split_commits_by_date(commits) + commits.sort{|x, y| y.authored_date <=> x.authored_date}.inject({}) do |h, commit| + dt = commit.authored_date + h[dt.year] ||= {} + h[dt.year][dt.month] ||= {} + h[dt.year][dt.month][dt.day] ||= [] + h[dt.year][dt.month][dt.day] << commit + h + end + end end + diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 94a12fbc2..a62366f1f 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -74,7 +74,7 @@ class ActivityFeedObserver < ActiveRecord::Observer change_type = record.change_type branch_name = record.refname.split('/').last - last_commits = record.project.git_repository.repo.log(branch_name, nil).first(3) + last_commits = record.project.repo.log(branch_name, nil).first(3) first_commiter = User.find_by_email(last_commits[0].author.email) unless last_commits.blank? last_commits = last_commits.collect do |commit| #:author => 'author' [commit.sha, commit.message] @@ -87,7 +87,7 @@ class ActivityFeedObserver < ActiveRecord::Observer else kind = 'git_new_push_notification' options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits, :branch_name => branch_name, - :change_type => change_type, :user_email => record.project.git_repository.repo.log(branch_name, nil).first.author.email, + :change_type => change_type, :user_email => record.project.repo.repo.log(branch_name, nil).first.author.email, :project_owner => record.project.owner.uname} options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index a3f0b416b..3df87673d 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -189,7 +189,7 @@ class BuildList < ActiveRecord::Base # TODO: remove 'return' after deployment ABF kernel 2.0 return if pkg.nil? # For old client that does not sends data about packages self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" - system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + system("cd #{self.project.repo.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit save end diff --git a/app/models/build_list/filter.rb b/app/models/build_list/filter.rb index b6095fc71..7de174460 100644 --- a/app/models/build_list/filter.rb +++ b/app/models/build_list/filter.rb @@ -20,15 +20,7 @@ class BuildList::Filter build_lists = build_lists.scoped_to_is_circle(@options[:is_circle]) if @options[:is_circle].present? build_lists = build_lists.scoped_to_project_name(@options[:project_name]) if @options[:project_name] build_lists = build_lists.by_mass_build(@options[:mass_build_id]) if @options[:mass_build_id] - -# TODO [BuildList#created_at filters] Uncomment here and in build_lists/_filter.html.haml to return filters -# -# if @options[:created_at_start] || @options[:created_at_end] -# build_lists = build_lists.for_creation_date_period(@options[:created_at_start], @options[:created_at_end]) -# end - if @options[:updated_at_start] || @options[:updated_at_end] - build_lists = build_lists.for_notified_date_period(@options[:updated_at_start], @options[:updated_at_end]) - end + build_lists = build_lists.for_notified_date_period(@options[:updated_at_start], @options[:updated_at_end]) if @options[:updated_at_start] || @options[:updated_at_end] end build_lists @@ -49,8 +41,6 @@ class BuildList::Filter @options = HashWithIndifferentAccess.new(options.reverse_merge({ :ownership => nil, :status => nil, - :created_at_start => nil, - :created_at_end => nil, :updated_at_start => nil, :updated_at_end => nil, :arch_id => nil, @@ -64,8 +54,6 @@ class BuildList::Filter @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned') @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_end] = build_date_from_params(:updated_at_end, @options) @options[:project_version] = @options[:project_version].presence diff --git a/app/models/comment.rb b/app/models/comment.rb index e5c22c36f..f73fa7d67 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -15,7 +15,7 @@ class Comment < ActiveRecord::Base attr_accessible :body def commentable - commit_comment? ? project.git_repository.commit(commentable_id.to_s(16)) : super + commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super end def commentable=(c) diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb deleted file mode 100644 index 057ba4968..000000000 --- a/app/models/git/repository.rb +++ /dev/null @@ -1,130 +0,0 @@ -# -*- encoding : utf-8 -*- -class Git::Repository - delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :branches, :to => :repo - - attr_accessor :path, :name, :repo, :last_actor - - def initialize(path) - @path = path - @update_callbacks = [] - end - - def master - commits('master', 1).first - end - - def to_s - name - end - - def repo - @repo ||= Grit::Repo.new(path) rescue Grit::Repo.new(GAP_REPO_PATH) - end - - # Adds a callback to be fired after update file. - # - # block - A block that expects this Git::Repository instance and the created - # commit's SHA1 as the arguments. - # - # For example: - # - # after_update_file do |repo, sha| - # # callback body - # end - # - # Returns nothing. - def after_update_file(&block) - @update_callbacks << block - end - - # Writes file to repo and runs 'after_update_file' callbacks - # - # path - path to file in repository - # data - new content of file - # options - an optional Hash of options - # :head - branch name to write this commit to - # (Default: 'master') - # :actor - author of this commit. (See Git::Repository#get_actor) - # (Default: nil) - # :message - commit message - # (Default: "Updated file ") - # - # Returns commits sha if committing was successful and false otherwise - def update_file(path, data, options = {}) - head = options[:head].to_s || 'master' - actor = get_actor(options[:actor]) - filename = File.split(path).last - message = options[:message] - message = "Updated file #{filename}" if message.nil? or message.empty? - - # can not write to unexisted branch - return false if branches.select{|b| b.name == head}.size != 1 - - parent = commits(head).first - - index = repo.index - index.read_tree(parent.tree.id) - - # can not create new file - return false if (index.current_tree / path).nil? - - index.add(path, data) - sha = index.commit(message, :parents => [parent], :actor => actor, - :last_tree => parent.tree.id, :head => head) - # call all defined callbacks - @update_callbacks.each do |cb| - cb.call(self, sha) - end - sha - end - - def self.create(path) - repo = Grit::Repo.init_bare(path) - repo.enable_daemon_serve - end - - def paginate_commits(treeish, options = {}) - options[:page] = 1 unless options[:page].present? - options[:page] = options[:page].to_i - - options[:per_page] = 20 unless options[:per_page].present? - options[:per_page] = options[:per_page].to_i - - skip = options[:per_page] * (options[:page] - 1) - last_page = (skip + options[:per_page]) >= commit_count(treeish) - - [commits(treeish, options[:per_page], skip), options[:page], last_page] - end - - # Pretty object inspection - def inspect - %Q{#} - end - - protected - - # Creates new Grit::Actor instance - # - # Might be: - # * A Hash containing :name and :email - # * An instance of Grit::Actor - # * A String like "John Doe - # * Any object that responds to `name` and `email` methods - def get_actor(actor = nil) - @last_actor = case actor.class.to_s - when 'Grit::Actor' then options[:actor] - when 'Hash' then Grit::Actor.new(actor[:name], actor[:email]) - when 'String' then Grit::Actor.from_stirng(actor) - else begin - if actor.respond_to?(:name) and actor.respond_to?(:email) - Grit::Actor.new(actor.name, actor.email) - else - config = Grit::Config.new(repo) - Grit::Actor.new(config['user.name'], config['user.email']) - end - end - end - @last_actor - end - -end diff --git a/app/models/project.rb b/app/models/project.rb index 927e7da61..458fba2bc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -25,9 +25,6 @@ class Project < ActiveRecord::Base validates :owner, :presence => true validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } - validates_attachment_size :srpm, :less_than => 500.megabytes - validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type') - attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki attr_readonly :name @@ -40,34 +37,50 @@ class Project < ActiveRecord::Base scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") } after_create :attach_to_personal_repository - after_create :create_git_repo - after_save :create_wiki - after_commit(:on => :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque - - after_destroy :destroy_git_repo - after_destroy :destroy_wiki - after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?}# later with resque # should be after create_git_repo - # after_rollback lambda { destroy_git_repo rescue true if new_record? } has_ancestry - has_attached_file :srpm - include Modules::Models::Owner + include Modules::Models::Git + include Modules::Models::Wiki + + class << self + def find_by_owner_and_name(owner_name, project_name) + owner = User.find_by_uname(owner_name) || Group.find_by_uname(owner_name) || User.by_uname(owner_name).first || Group.by_uname(owner_name).first and + scoped = where(:owner_id => owner.id, :owner_type => owner.class) and + scoped.find_by_name(project_name) || scoped.by_name(project_name).first + # owner.projects.find_by_name(project_name) || owner.projects.by_name(project_name).first # TODO force this work? + end + + def find_by_owner_and_name!(owner_name, project_name) + find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound + end + end def to_param name end - def self.find_by_owner_and_name(owner_name, project_name) - owner = User.find_by_uname(owner_name) || Group.find_by_uname(owner_name) || User.by_uname(owner_name).first || Group.by_uname(owner_name).first and - scoped = where(:owner_id => owner.id, :owner_type => owner.class) and - scoped.find_by_name(project_name) || scoped.by_name(project_name).first - # owner.projects.find_by_name(project_name) || owner.projects.by_name(project_name).first # TODO force this work? + def members + collaborators + groups.map(&:members).flatten end - def self.find_by_owner_and_name!(owner_name, project_name) - find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound + def platforms + @platforms ||= repositories.map(&:platform).uniq + end + + def owner_and_admin_ids + recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } + recipients = recipients | [self.owner_id] if self.owner_type == 'User' + recipients + end + + def public? + visibility == 'open' + end + + def owner?(user) + owner == user end def build_for(platform, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0) @@ -93,85 +106,6 @@ class Project < ActiveRecord::Base end end - def tags - self.git_repository.tags #.sort_by{|t| t.name.gsub(/[a-zA-Z.]+/, '').to_i} - end - - def branches - self.git_repository.branches - end - - def last_active_branch - @last_active_branch ||= branches.inject do |r, c| - r_last = r.commit.committed_date || r.commit.authored_date unless r.nil? - c_last = c.commit.committed_date || c.commit.authored_date - if r.nil? or r_last < c_last - r = c - end - r - end - @last_active_branch - end - - def branch(name = nil) - name = default_branch if name.blank? - branches.select{|b| b.name == name}.first - end - - def tree_info(tree, treeish = nil, path = nil) - treeish = tree.id unless treeish.present? - # initialize result as hash of => nil - res = (tree.trees.sort + tree.blobs.sort).inject({}){|h, e| h.merge!({e => nil})} - # fills result vith commits that describes this file - res = res.inject(res) do |h, (entry, commit)| - # only if commit == nil ... - if commit.nil? and entry.respond_to? :name - # ... find last commit corresponds to this file ... - c = git_repository.log(treeish, File.join([path, entry.name].compact), :max_count => 1).first - # ... and add it to result. - h[entry] = c - # find another files, that linked to this commit and set them their commit - # c.diffs.map{|diff| diff.b_path.split(File::SEPARATOR, 2).first}.each do |name| - # h.each_pair do |k, v| - # h[k] = c if k.name == name and v.nil? - # end - # end - end - h - end - end - - def versions - tags.map(&:name) + branches.map{|b| "latest_#{b.name}"} - end - - def versions_for_group_select - [ - ['Branches', branches.map{|b| "latest_#{b.name}"}], - ['Tags', tags.map(&:name)] - ] - end - - def members - collaborators + groups.map(&:members).flatten - end - - def git_repository - @git_repository ||= Git::Repository.new(path) - end - - def git_repo_name - File.join owner.uname, name - end - - def wiki_repo_name - File.join owner.uname, "#{name}.wiki" - end - - def public? - visibility == 'open' - end - def fork(new_owner) dup.tap do |c| c.parent_id = id @@ -181,12 +115,8 @@ class Project < ActiveRecord::Base end end - def path - build_path(git_repo_name) - end - - def wiki_path - build_wiki_path(git_repo_name) + def human_average_build_time + I18n.t("layout.projects.human_average_build_time", {:hours => (average_build_time/3600).to_i, :minutes => (average_build_time%3600/60).to_i}) end def xml_rpc_create(repository) @@ -207,97 +137,9 @@ class Project < ActiveRecord::Base end end - def platforms - @platforms ||= repositories.map(&:platform).uniq - end - - def import_srpm(srpm_path = srpm.path, branch_name = 'import') - system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} >> /dev/null 2>&1") - end - - def owner?(user) - owner == user - end - - def owner_and_admin_ids - recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) } - recipients = recipients | [self.owner_id] if self.owner_type == 'User' - recipients - end - - def human_average_build_time - time = average_build_time - I18n.t("layout.projects.human_average_build_time", {:hours => (time/3600).to_i, :minutes => (time%3600/60).to_i}) - end - protected - def build_path(dir) - File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git") - end - - def build_wiki_path(dir) - File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.wiki.git") - end - def attach_to_personal_repository repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository) end - - def create_git_repo - if is_root? - Grit::Repo.init_bare(path) - write_hook - end - end - - def fork_git_repo - dummy = Grit::Repo.new(path) rescue parent.git_repository.repo.fork_bare(path) - write_hook - end - later :fork_git_repo, :queue => :fork_import - - def destroy_git_repo - FileUtils.rm_rf path - end - - def import_attached_srpm - if srpm? - import_srpm # srpm.path - self.srpm = nil; save # clear srpm - end - end - later :import_attached_srpm, :queue => :fork_import - - def create_wiki - if has_wiki && !FileTest.exist?(wiki_path) - Grit::Repo.init_bare(wiki_path) - wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(owner, self)}) - wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"), - {:name => owner.name, :email => owner.email, :message => 'Initial commit'}) - end - end - - def destroy_wiki - FileUtils.rm_rf wiki_path - end - - def write_hook - is_production = Rails.env == "production" - hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") - FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) - File.open(hook, 'a') do |f| - s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\"" - s << " > /dev/null 2>&1" if is_production - s << "\ndone\n" - f.write(s) - f.chmod(0755) - end - - hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(hook, hook_file) - FileUtils.rm_rf(hook) - - rescue Exception # FIXME - end end diff --git a/app/views/projects/base/_repo_block.html.haml b/app/views/projects/base/_repo_block.html.haml index 0870762d5..f301d63b3 100644 --- a/app/views/projects/base/_repo_block.html.haml +++ b/app/views/projects/base/_repo_block.html.haml @@ -6,8 +6,8 @@ =image_tag 'zip.png', :alt => 'ZIP' %b.caret %ul.dropdown-menu - %li=link_to "tar.gz", archive_path(project, 'tar', @treeish) - %li=link_to "zip", archive_path(project, 'zip', @treeish) + %li=link_to "tar.gz", archive_path(project, @treeish, 'tar') + %li=link_to "zip", archive_path(project, @treeish, 'zip') = text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true .git_help ? diff --git a/app/views/projects/base/_submenu.html.haml b/app/views/projects/base/_submenu.html.haml index c4bb613fd..8cb83b928 100644 --- a/app/views/projects/base/_submenu.html.haml +++ b/app/views/projects/base/_submenu.html.haml @@ -1,12 +1,12 @@ - content_for :submenu do - - act = action_name.to_sym; contr = controller_name.to_sym + - act = action_name.to_sym; contr = controller_name.to_sym; treeish = params[:treeish].presence || @project.default_branch .left .table-sort-left=image_tag visibility_icon(@project.visibility) .table-sort-right=@project.name %nav %ul - %li= link_to t("project_menu.project"), project_path(@project), :class => (act.in?([:show, :edit]) && contr.in?([:trees, :blobs]) ? 'active' : nil) - %li= link_to t("project_menu.commits"), commits_path(@project), :class => (act.in?([:index, :show]) && contr == :commits ? 'active' : nil) + %li= link_to t("project_menu.project"), tree_path(@project, treeish), :class => (act.in?([:show, :edit]) && contr.in?([:trees, :blobs]) ? 'active' : nil) + %li= link_to t("project_menu.commits"), commits_path(@project, treeish), :class => (act.in?([:index, :show]) && contr == :commits ? 'active' : nil) - if @project.is_package and can?(:read, @project => BuildList) %li= link_to t("project_menu.builds"), project_build_lists_path(@project), :class => (contr == :build_lists ? 'active' : nil) - if @project.has_issues diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index 10024025a..ccda36113 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -13,10 +13,7 @@ %h3= t("activerecord.attributes.build_list.save_to_platform") .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.platform.id]} %h3= t("activerecord.attributes.build_list.project_version") - - if controller.action_name == 'new' - .lineForm= f.select :project_version, @project.versions_for_group_select, :selected => "latest_" + @project.default_branch - - else - .lineForm= f.select :project_version, @project.versions_for_group_select + .lineForm= f.select :project_version, versions_for_group_select(@project), :selected => params[:build_list].try(:fetch, :project_version) || "latest_" + @project.default_branch %h3= t("activerecord.attributes.build_list.arch") - Arch.recent.each do |arch| .both diff --git a/app/views/projects/git/blobs/_editor.html.haml b/app/views/projects/git/blobs/_editor.html.haml index 874945aee..1298ff0c0 100644 --- a/app/views/projects/git/blobs/_editor.html.haml +++ b/app/views/projects/git/blobs/_editor.html.haml @@ -4,7 +4,7 @@ = render 'fork' .both -= form_tag blob_path(@project, @treeish, @path), :name => 'blob-editor', :method => :put do += form_tag edit_blob_path(@project, @treeish, @path), :name => 'blob-editor', :method => :put do .file= text_area_tag :content, @blob.data, :id => 'code' .both diff --git a/app/views/projects/git/blobs/_render_as_binary.html.haml b/app/views/projects/git/blobs/_render_as_binary.html.haml new file mode 100644 index 000000000..bd7379a10 --- /dev/null +++ b/app/views/projects/git/blobs/_render_as_binary.html.haml @@ -0,0 +1,8 @@ +%table.table.blob + %tr + %td.lines + %td.blob + :plain +
+
#{link_to @blob.basename, raw_path(@project, @treeish, @path)}
+
\ No newline at end of file diff --git a/app/views/projects/git/blobs/_render_as_image.html.haml b/app/views/projects/git/blobs/_render_as_image.html.haml new file mode 100644 index 000000000..ae1ef4884 --- /dev/null +++ b/app/views/projects/git/blobs/_render_as_image.html.haml @@ -0,0 +1,8 @@ +%table.table.blob + %tr + %td.lines + %td.blob + :plain +
+
+
\ No newline at end of file diff --git a/app/views/projects/git/blobs/_render_as_text.html.haml b/app/views/projects/git/blobs/_render_as_text.html.haml new file mode 100644 index 000000000..3105d704e --- /dev/null +++ b/app/views/projects/git/blobs/_render_as_text.html.haml @@ -0,0 +1,6 @@ +.gutter= render_line_numbers(@blob.loc) +#output.formatted.cm-s-default + %pre#code + :preserve + #{h(@blob.data).html_safe} +.both diff --git a/app/views/projects/git/blobs/_show.html.haml b/app/views/projects/git/blobs/_show.html.haml index f867189fd..3f686249c 100644 --- a/app/views/projects/git/blobs/_show.html.haml +++ b/app/views/projects/git/blobs/_show.html.haml @@ -1,40 +1,14 @@ +/ - raise @blob.file_mime_type.inspect %h3= t("layout.projects.files_in_project") .files .l= render 'whereami' = render 'fork' .both -- render_way = choose_render_way(@blob) .file - .top= render 'top', :render_way => render_way - .data - - case render_way - - when :image - %table.table.blob - %tr - %td.lines - %td.blob - :plain -
-
-
- - when :text - .gutter= render_line_numbers(@text.length) - #output.formatted.cm-s-default - %pre#code - =#{render_blob(@blob)} - :preserve - #{h(@blob.data).html_safe} - .both - - when :binary - %table.table.blob - %tr - %td.lines - %td.blob - :plain -
-
#{ link_to @blob.basename, raw_path(@project, @treeish, @path) }
-
+ .top= render 'top' + .data= render "render_as_#{@blob.render_as}" + :javascript $(document).ready(function() { var text = $('#code').text().replace(/&/gi, '&'); diff --git a/app/views/projects/git/blobs/_top.html.haml b/app/views/projects/git/blobs/_top.html.haml index 8073aa9db..a3631075d 100644 --- a/app/views/projects/git/blobs/_top.html.haml +++ b/app/views/projects/git/blobs/_top.html.haml @@ -1,20 +1,20 @@ .l = @blob.mode \| - - if render_way == :text - #{@text.length} lines (#{@text.select{|s| s.strip.length > 0}.length} sloc) + - if @blob.render_as == :text + #{@blob.loc} lines (#{@blob.sloc} sloc) \| = number_to_human_size @blob.size .r - - if render_way == :text and can? :write, @project and @treeish.in? @project.branches.map(&:name) + - if @blob.render_as == :text and can? :write, @project and @branch.present? = link_to "Edit", edit_blob_path(@project, @treeish, @path) \| - - if render_way == :text and params[:action] != 'show' + - if @blob.render_as == :text and params[:action] != 'show' = link_to "Normal", blob_path(@project, @treeish, @path) \| = link_to "Raw", raw_path(@project, @treeish, @path) \| - - if render_way == :text and params[:action] != 'blame' + - if @blob.render_as == :text and params[:action] != 'blame' = link_to "Blame", blame_path(@project, @treeish, @path) \| = link_to "History", commits_path(@project, @treeish, @path) diff --git a/app/views/projects/git/blobs/blame.html.haml b/app/views/projects/git/blobs/blame.html.haml index 81fef4b00..9f19328e8 100644 --- a/app/views/projects/git/blobs/blame.html.haml +++ b/app/views/projects/git/blobs/blame.html.haml @@ -20,7 +20,6 @@ .l= render 'whereami' .both - - render_way = choose_render_way(@blob) .file - .top= render 'top', :render_way => render_way + .top= render 'top' .blame_data= render 'blame_table' if @blame.first.first.present? diff --git a/app/views/projects/git/commits/_commit_diff.html.haml b/app/views/projects/git/commits/_commit_diff.html.haml index c15055706..46f639af9 100644 --- a/app/views/projects/git/commits/_commit_diff.html.haml +++ b/app/views/projects/git/commits/_commit_diff.html.haml @@ -7,4 +7,4 @@ .r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path) .clear - .diff_data= render_diff(commit_diff) unless (@git_repository.tree(commit_id) / commit_diff.b_path).binary? \ No newline at end of file + .diff_data= render_diff(commit_diff) unless (@project.repo.tree(commit_id) / commit_diff.b_path).binary? \ No newline at end of file diff --git a/app/views/projects/git/commits/index.html.haml b/app/views/projects/git/commits/index.html.haml index f3f9cca11..e8221fb1e 100644 --- a/app/views/projects/git/commits/index.html.haml +++ b/app/views/projects/git/commits/index.html.haml @@ -3,4 +3,4 @@ = render 'repo_block', :project => @project = render :partial => 'commits', :object => @commits -= render 'paginate' if @render_paginate += render 'paginate' if @path.blank? diff --git a/app/views/projects/projects/_form.html.haml b/app/views/projects/projects/_form.html.haml index ffede9552..9a7b90ba2 100644 --- a/app/views/projects/projects/_form.html.haml +++ b/app/views/projects/projects/_form.html.haml @@ -35,7 +35,7 @@ .both - if [:edit, :update].include? act .leftlist= t("activerecord.attributes.project.default_branch") - .rightlist= f.select :default_branch, options_from_collection_for_select(@project.branches, :name, :name, @project.default_branch), :class => 'sel80', :id => 'branch_selector' + .rightlist= f.select :default_branch, options_from_collection_for_select(@project.repo.branches, :name, :name, @project.default_branch), :class => 'sel80', :id => 'branch_selector' .both - if [:edit, :update].include? act .leftlist diff --git a/config/routes.rb b/config/routes.rb index 62c3029d3..7b86054f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,7 @@ Rosa::Application.routes.draw do end end resources :event_logs, :only => :index - constraints AdminAccess do + constraints Rosa::Constraints::AdminAccess do mount Resque::Server => 'resque' end end @@ -132,7 +132,6 @@ Rosa::Application.routes.draw do end resources :projects, :only => [:index, :new, :create] - scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project scope :as => 'project' do resources :wiki do @@ -176,7 +175,7 @@ Rosa::Application.routes.draw do end end # Resource - get '/edit' => 'projects#edit', :as => :edit_project + get '/modify' => 'projects#edit', :as => :edit_project put '/' => 'projects#update' delete '/' => 'projects#destroy' # Member @@ -184,41 +183,43 @@ Rosa::Application.routes.draw do get '/sections' => 'projects#sections', :as => :sections_project post '/sections' => 'projects#sections' delete '/remove_user' => 'projects#remove_user', :as => :remove_user_project - constraints :treeish => /[^\/]+/ do - # Tree - get '/' => "git/trees#show", :as => :project - get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree, :format => false - # Commits - get '/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :as => :commits, :format => false - get '/commit/:id(.:format)' => "git/commits#show", :as => :commit - # Commit comments - post '/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments - get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment - put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment - delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy" - # Commit subscribes - post '/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit - delete '/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit - # Editing files - get '/blob/:treeish/*path/edit' => "git/blobs#edit", :defaults => {:treeish => :master}, :as => :edit_blob - put '/blob/:treeish/*path' => "git/blobs#update", :defaults => {:treeish => :master}, :format => false - # Blobs - get '/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false - # Blame - get '/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false - # Raw - get '/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false - # Archive - get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ + constraints :treeish => /.+/ do + constraints Rosa::Constraints::Treeish do + # Tree + get '/' => "git/trees#show", :as => :project + get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false + # Commits + get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false + get '/commit/:id(.:format)' => "git/commits#show", :as => :commit + # Commit comments + post '/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments + get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment + put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment + delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy" + # Commit subscribes + post '/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit + delete '/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit + # Editing files + get '/edit/:treeish/*path' => "git/blobs#edit", :as => :edit_blob, :format => false + put '/edit/:treeish/*path' => "git/blobs#update", :format => false + # Blobs + get '/blob/:treeish/*path' => "git/blobs#show", :as => :blob, :format => false + # Blame + get '/blame/:treeish/*path' => "git/blobs#blame", :as => :blame, :format => false + # Raw + get '/raw/:treeish/*path' => "git/blobs#raw", :as => :raw, :format => false + # Archive + get '/archive/:treeish.:format' => "git/trees#archive", :as => :archive, :format => /zip|tar/ + end end end end scope ':uname' do # project owner profile - constraints OwnerConstraint.new(User) do + constraints Rosa::Constraints::Owner.new(User) do get '/' => 'users/profile#show', :as => :user end - constraints OwnerConstraint.new(Group, true) do + constraints Rosa::Constraints::Owner.new(Group, true) do get '/' => 'groups/profile#show', :as => :group end end diff --git a/db/schema.rb b/db/schema.rb index 5200f5c01..481588bde 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "version" end @@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "project_id" t.integer "arch_id" t.datetime "notified_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -137,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -155,14 +155,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -175,8 +175,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -225,14 +225,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -241,8 +241,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" end @@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "build_script" t.text "counter" t.text "ks" @@ -278,8 +278,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "platform_id" end @@ -288,25 +288,25 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true - t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" + t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false @@ -321,8 +321,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end @@ -335,16 +335,16 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "name", :null => false end @@ -355,8 +355,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -365,8 +365,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -376,21 +376,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" - t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.text "ssh_key" + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false t.datetime "reset_password_sent_at" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -399,11 +393,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" - t.integer "build_priority", :default => 50 + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP index 8458ee4f1..cca71ab75 100644 --- a/doc/README_FOR_APP +++ b/doc/README_FOR_APP @@ -21,4 +21,8 @@ Add to /etc/rc.d/rc.sysinit sudo urpmi lib64icu-devel # mandriva gem install charlock_holmes -- --with-icu-dir=/opt/local # macports +sudo urpmi lib64magic-devel # mandriva +brew install libmagic; brew link libmagic # brew +gem install ruby-filemagic + git config --global core.quotepath false diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 1fbc50109..43195530c 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -1,11 +1,49 @@ # -*- encoding : utf-8 -*- module Grit class Blob + include Linguist::BlobHelper + + MAX_VIEW_SIZE = 2.megabytes + MAX_DATA_SIZE = 50.megabytes + + def data_with_limit + size <= MAX_DATA_SIZE ? data_without_limit : nil # 'Error: blob is too big' + end + alias_method_chain :data, :limit + + def large? + size.to_i > MAX_VIEW_SIZE + end + + def render_as + @render_as ||= case + when large?; :binary + when image?; :image + when text?; :text + else + :binary + end + end + + # def file_mime_type + # @file_mime_type ||= data.file_type(:mime_type) + # end + # + # def text? + # file_mime_type =~ /^text\// # not binary? + # end + # + # def binary? + # not text? # file_mime_type !~ /^text\// + # # s = data.split(//); ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 # works only for latin chars + # end + # + # def image? + # mime_type.match(/image/) + # end DEFAULT_RAW_MIME_TYPE = MIME::Types[DEFAULT_MIME_TYPE].first - delegate :binary?, :ascii?, :encoding, :to => :raw_mime_type - def mime_type_with_class_store set_associated_mimes @associated_mimes.first.simplified @@ -24,30 +62,30 @@ module Grit end protected + + # store all associated MIME::Types inside class + def set_associated_mimes + @associated_mimes ||= [] + if @associated_mimes.empty? + guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE] + guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty? - # store all associated MIME::Types inside class - def set_associated_mimes - @associated_mimes ||= [] - if @associated_mimes.empty? - guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE] - guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty? - - @associated_mimes = guesses.sort{|a,b| mime_sort(a, b)} - end - @associated_mimes - end - - # TODO make more clever function - def mime_sort(a,b) - return 0 if a.media_type == b.media_type and a.registered? == b.registered? - return -1 if a.media_type == 'text' and !a.registered? - return 1 + @associated_mimes = guesses.sort{|a,b| mime_sort(a, b)} end + @associated_mimes + end + # TODO make more clever function + def mime_sort(a,b) + return 0 if a.media_type == b.media_type and a.registered? == b.registered? + return -1 if a.media_type == 'text' and !a.registered? + return 1 + end end end Grit::Git.git_timeout = 60 +# Grit::Git.git_max_size = 5.megabytes # Grit.debug = true GAP_REPO_PATH = '/tmp/gap_repo.git' unless File.directory? GAP_REPO_PATH diff --git a/lib/ext/rails/constraint.rb b/lib/ext/rails/constraint.rb new file mode 100644 index 000000000..9a4b707f2 --- /dev/null +++ b/lib/ext/rails/constraint.rb @@ -0,0 +1,49 @@ +# -*- encoding : utf-8 -*- +class OwnerConstraint + def initialize(class_name, bang = false) + @class_name = class_name + @finder = 'find_by_insensitive_uname' + @finder << '!' if bang + end + + def matches?(request) + @class_name.send(@finder, request.params[:uname]).present? + end +end + +class AdminAccess + def self.matches?(request) + !!request.env['warden'].user.try(:admin?) + end +end + +class TreeishConstraint + def self.matches?(request) + # raise request.params.inspect + # params = request.env['action_dispatch.request.path_parameters'] || request.params + params = request.path_parameters + if params[:treeish] # parse existing branch (tag) and path + branch_or_tag = begin + (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && + (p.repo.branches + p.repo.tags).detect{|t| params[:treeish].start_with?(t.name)}.try(:name) || + params[:treeish].split('/').first + end + if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present? + params[:path] = File.join([path, params[:path]].compact) + end + params[:treeish] = branch_or_tag + end + true + end + + # def set_treeish_and_path + # if params[:treeish] and params[:path] and # try to correct branch with slashes + # treeish_with_path = File.join(params[:treeish], params[:path]) and + # branch_name = @project.repo.branches.detect{|t| treeish_with_path.start_with?(t.name)}.try(:name) + # params[:treeish] = branch_name + # params[:path] = treeish_with_path.sub(branch_name, '')[1..-1] + # end + # @treeish = params[:treeish].presence || @project.default_branch + # @path = params[:path] + # end +end diff --git a/lib/ext/rails/constraints.rb b/lib/ext/rails/constraints.rb deleted file mode 100644 index 2ec8ef342..000000000 --- a/lib/ext/rails/constraints.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class OwnerConstraint - def initialize(class_name, bang = false) - @class_name = class_name - @finder = 'find_by_insensitive_uname' - @finder << '!' if bang - end - - def matches?(request) - @class_name.send(@finder, request.params[:uname]).present? - end -end - -class AdminAccess - def self.matches?(request) - !!request.env['warden'].user.try(:admin?) - end -end diff --git a/lib/ext/rails/middleware.rb b/lib/ext/rails/middleware.rb new file mode 100644 index 000000000..be6da8940 --- /dev/null +++ b/lib/ext/rails/middleware.rb @@ -0,0 +1,18 @@ +# class ParamsParser +# DEFAULT_PARSERS = { +# Mime::XML => :xml_simple, +# Mime::JSON => :json +# } +# +# def initialize(app, parsers = {}) +# @app, @parsers = app, DEFAULT_PARSERS.merge(parsers) +# end +# +# def call(env) +# if params = parse_formatted_parameters(env) +# env["action_dispatch.request.request_parameters"] = params +# end +# +# @app.call(env) +# end +# end diff --git a/lib/ext/rosa/constraints.rb b/lib/ext/rosa/constraints.rb new file mode 100644 index 000000000..8cbf1b26c --- /dev/null +++ b/lib/ext/rosa/constraints.rb @@ -0,0 +1,42 @@ +# -*- encoding : utf-8 -*- +module Rosa + module Constraints + class Owner + def initialize(class_name, bang = false) + @class_name = class_name + @finder = 'find_by_insensitive_uname' + @finder << '!' if bang + end + + def matches?(request) + @class_name.send(@finder, request.params[:uname]).present? + end + end + + class AdminAccess + def self.matches?(request) + !!request.env['warden'].user.try(:admin?) + end + end + + class Treeish + def self.matches?(request) + # raise request.params.inspect + # params = request.env['action_dispatch.request.path_parameters'] || request.params + params = request.path_parameters + if params[:treeish] # parse existing branch (tag) and path + branch_or_tag = begin + (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && + (p.repo.branches + p.repo.tags).detect{|t| params[:treeish].start_with?(t.name)}.try(:name) || + params[:treeish].split('/').first + end + if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present? + params[:path] = File.join([path, params[:path]].compact) + end + params[:treeish] = branch_or_tag + end + true + end + end + end +end diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb new file mode 100644 index 000000000..e58ac3b25 --- /dev/null +++ b/lib/modules/models/git.rb @@ -0,0 +1,187 @@ +# -*- encoding : utf-8 -*- +module Modules + module Models + module Git + extend ActiveSupport::Concern + + included do + validates_attachment_size :srpm, :less_than => 500.megabytes + validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type') + + has_attached_file :srpm + # attr_accessible :srpm + + after_create :create_git_repo + after_commit(:on => :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque + after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo + after_destroy :destroy_git_repo + # after_rollback lambda { destroy_git_repo rescue true if new_record? } + + later :import_attached_srpm, :queue => :fork_import + later :fork_git_repo, :queue => :fork_import + end + + def repo + @repo ||= Grit::Repo.new(path) rescue Grit::Repo.new(GAP_REPO_PATH) + end + + def path + build_path(git_repo_name) + end + + def git_repo_name + File.join owner.uname, name + end + + def versions + repo.tags.map(&:name) + repo.branches.map{|b| "latest_#{b.name}"} + end + + def update_file(path, data, options = {}) + head = options[:head].to_s || default_branch + actor = get_actor(options[:actor]) + filename = File.split(path).last + message = options[:message] + message = "Updated file #{filename}" if message.nil? or message.empty? + + # can not write to unexisted branch + return false if repo.branches.select{|b| b.name == head}.size != 1 + + parent = repo.commits(head).first + + index = repo.index + index.read_tree(parent.tree.id) + + # can not create new file + return false if (index.current_tree / path).nil? + + index.add(path, data) + index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => head) + end + + def paginate_commits(treeish, options = {}) + options[:page] = 1 unless options[:page].present? + options[:page] = options[:page].to_i + + options[:per_page] = 20 unless options[:per_page].present? + options[:per_page] = options[:per_page].to_i + + skip = options[:per_page] * (options[:page] - 1) + last_page = (skip + options[:per_page]) >= repo.commit_count(treeish) + + [repo.commits(treeish, options[:per_page], skip), options[:page], last_page] + end + + def last_active_branch + @last_active_branch ||= repo.branches.inject do |r, c| + r_last = r.commit.committed_date || r.commit.authored_date unless r.nil? + c_last = c.commit.committed_date || c.commit.authored_date + if r.nil? or r_last < c_last + r = c + end + r + end + @last_active_branch + end + + def tree_info(tree, treeish = nil, path = nil) + treeish = tree.id unless treeish.present? + # initialize result as hash of => nil + res = (tree.trees.sort + tree.blobs.sort).inject({}){|h, e| h.merge!({e => nil})} + # fills result vith commits that describes this file + res = res.inject(res) do |h, (entry, commit)| + # only if commit == nil ... + if commit.nil? and entry.respond_to? :name + # ... find last commit corresponds to this file ... + c = repo.log(treeish, File.join([path, entry.name].compact), :max_count => 1).first + # ... and add it to result. + h[entry] = c + # find another files, that linked to this commit and set them their commit + # c.diffs.map{|diff| diff.b_path.split(File::SEPARATOR, 2).first}.each do |name| + # h.each_pair do |k, v| + # h[k] = c if k.name == name and v.nil? + # end + # end + end + h + end + end + + def import_srpm(srpm_path = srpm.path, branch_name = 'import') + system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} >> /dev/null 2>&1") + end + + protected + + def build_path(dir) + File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git") + end + + def import_attached_srpm + if srpm? + import_srpm # srpm.path + self.srpm = nil; save # clear srpm + end + end + + def create_git_repo + if is_root? + Grit::Repo.init_bare(path) + write_hook + end + end + + def fork_git_repo + dummy = Grit::Repo.new(path) rescue parent.repo.fork_bare(path) + write_hook + end + + def destroy_git_repo + FileUtils.rm_rf path + end + + def write_hook + is_production = Rails.env == "production" + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + f.chmod(0755) + end + + hook_file = File.join(path, 'hooks', 'post-receive') + FileUtils.cp(hook, hook_file) + FileUtils.rm_rf(hook) + + rescue Exception # FIXME + end + + def get_actor(actor = nil) + @last_actor = case actor.class.to_s + when 'Grit::Actor' then options[:actor] + when 'Hash' then Grit::Actor.new(actor[:name], actor[:email]) + when 'String' then Grit::Actor.from_stirng(actor) + else begin + if actor.respond_to?(:name) and actor.respond_to?(:email) + Grit::Actor.new(actor.name, actor.email) + else + config = Grit::Config.new(repo) + Grit::Actor.new(config['user.name'], config['user.email']) + end + end + end + @last_actor + end + + module ClassMethods + def process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type) + rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type) + ActivityFeedObserver.instance.after_create rec + end + end + end + end +end diff --git a/lib/modules/models/owner.rb b/lib/modules/models/owner.rb index 182682e18..e88ac3f5f 100644 --- a/lib/modules/models/owner.rb +++ b/lib/modules/models/owner.rb @@ -8,15 +8,8 @@ module Modules after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' } end - module ClassMethods - end - - module InstanceMethods - - def name_with_owner - "#{owner.respond_to?(:uname) ? owner.uname : owner.name}/#{self.name}" - end - + def name_with_owner + "#{owner.respond_to?(:uname) ? owner.uname : owner.name}/#{self.name}" end end end diff --git a/lib/modules/models/wiki.rb b/lib/modules/models/wiki.rb new file mode 100644 index 000000000..1f13446b9 --- /dev/null +++ b/lib/modules/models/wiki.rb @@ -0,0 +1,39 @@ +# -*- encoding : utf-8 -*- +module Modules + module Models + module Wiki + extend ActiveSupport::Concern + + included do + after_create :create_wiki + after_destroy :destroy_wiki + end + + def wiki_path + build_path(wiki_repo_name) + end + + def wiki_repo_name + File.join owner.uname, "#{name}.wiki" + end + + protected + + def create_wiki + if has_wiki && !FileTest.exist?(wiki_path) + Grit::Repo.init_bare(wiki_path) + wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(owner, self)}) + wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"), + {:name => owner.name, :email => owner.email, :message => 'Initial commit'}) + end + end + + def destroy_wiki + FileUtils.rm_rf wiki_path + end + + module ClassMethods + end + end + end +end diff --git a/lib/tasks/add_branch.rake b/lib/tasks/add_branch.rake index c8d7cf48d..1857cb7c9 100644 --- a/lib/tasks/add_branch.rake +++ b/lib/tasks/add_branch.rake @@ -9,7 +9,7 @@ task :add_branch => :environment do Platform.find_by_name(dst_branch).repositories.each do |r| say "=== Process #{r.name} repo" r.projects.find_each do |p| - next if p.branches.map(&:name).include?(dst_branch) + next if p.repo.branches.map(&:name).include?(dst_branch) say "===== Process #{p.name} project" tmp_path = Rails.root.join('tmp', p.name) system("git clone #{p.path} #{tmp_path}") diff --git a/spec/controllers/platforms/mass_builds_controller_spec.rb b/spec/controllers/platforms/mass_builds_controller_spec.rb index 6a85981f9..357d66d94 100644 --- a/spec/controllers/platforms/mass_builds_controller_spec.rb +++ b/spec/controllers/platforms/mass_builds_controller_spec.rb @@ -76,6 +76,7 @@ describe Platforms::MassBuildsController do before(:each) do stub_symlink_methods + FactoryGirl.create(:arch) @platform = FactoryGirl.create(:platform) @repository = FactoryGirl.create(:repository, :platform => @platform) @personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal') @@ -91,13 +92,18 @@ describe Platforms::MassBuildsController do end context 'for guest' do - [:index, :create, :cancel, :failed_builds_list].each do |action| + [: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 be able to perform failed_builds_list action" do + get :failed_builds_list, :platform_id => @platform, :id => @mass_build + response.should redirect_to(new_user_session_path) + end + it 'should not change objects count on create success' do lambda { post :create, @create_params }.should change{ MassBuild.count }.by(0) end diff --git a/spec/controllers/platforms/repositories_controller_spec.rb b/spec/controllers/platforms/repositories_controller_spec.rb index 35120683d..82c4a5712 100644 --- a/spec/controllers/platforms/repositories_controller_spec.rb +++ b/spec/controllers/platforms/repositories_controller_spec.rb @@ -32,7 +32,7 @@ end shared_examples_for 'registered user' do it 'should be able to perform index action' do - get :index + get :index, :platform_id => @platform.id response.should render_template(:index) end @@ -80,7 +80,7 @@ describe Platforms::RepositoriesController do context 'for guest' do [:index, :create].each do |action| it "should not be able to perform #{ action } action" do - get action + get action, :platform_id => @platform response.should redirect_to(new_user_session_path) end end diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 1431004eb..ef95a4cf7 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -42,13 +42,13 @@ describe Projects::BuildListsController do it 'should save correct commit_hash for branch based build' do post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_master"}) - @project.build_lists.last.commit_hash.should == @project.git_repository.commits('master').last.id + @project.build_lists.last.commit_hash.should == @project.repo.commits('master').last.id end it 'should save correct commit_hash for tag based build' do - system("cd #{@project.git_repository.path} && git tag 4.7.5.3") # TODO REDO through grit + system("cd #{@project.repo.path} && git tag 4.7.5.3") # TODO REDO through grit 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.git_repository.commits('4.7.5.3').last.id + @project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id end end @@ -283,7 +283,7 @@ describe Projects::BuildListsController do @build_list1 = FactoryGirl.create(:build_list_core) @build_list2 = FactoryGirl.create(:build_list_core) @build_list3 = FactoryGirl.create(:build_list_core) - @build_list4 = FactoryGirl.create(:build_list_core, :created_at => (Time.now - 1.day), + @build_list4 = FactoryGirl.create(:build_list_core, :updated_at => (Time.now - 1.day), :project => @build_list3.project, :save_to_platform => @build_list3.save_to_platform, :arch => @build_list3.arch) end @@ -305,9 +305,9 @@ describe Projects::BuildListsController do it 'should filter by project_name and start_date' do get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'index', - "created_at_start(1i)" => @build_list3.created_at.year.to_s, - "created_at_start(2i)" => @build_list3.created_at.month.to_s, - "created_at_start(3i)" => @build_list3.created_at.day.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(3i)" => @build_list3.updated_at.day.to_s} assigns[:build_lists].should_not include(@build_list1) assigns[:build_lists].should_not include(@build_list2) assigns[:build_lists].should include(@build_list3) @@ -326,7 +326,7 @@ describe Projects::BuildListsController do describe 'publish_build' do before { test_git_commit(build_list.project) - build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id + build_list.update_attribute :commit_hash, build_list.project.repo.commits('master').last.id build_list.update_attribute(:status, BuildList::BUILD_PUBLISH) build_list_package } @@ -343,8 +343,8 @@ describe Projects::BuildListsController do } it 'should create correct git tag for correct commit' do do_get(BuildServer::SUCCESS) - build_list.project.git_repository.tags.last.name.should == build_list.package_version - build_list.project.git_repository.commits(build_list.package_version).last.id.should == build_list.commit_hash + build_list.project.repo.tags.last.name.should == build_list.package_version + build_list.project.repo.commits(build_list.package_version).last.id.should == build_list.commit_hash end it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to("#{ build_list_package.platform.name }-4.7.5.3-1") } diff --git a/spec/controllers/projects/comments_controller_for_commit_spec.rb b/spec/controllers/projects/comments_controller_for_commit_spec.rb index 3ddce850e..7555d5a79 100644 --- a/spec/controllers/projects/comments_controller_for_commit_spec.rb +++ b/spec/controllers/projects/comments_controller_for_commit_spec.rb @@ -78,8 +78,8 @@ describe Projects::CommentsController do before(:each) do stub_symlink_methods @project = FactoryGirl.create(:project) - %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ? - @commit = @project.git_repository.commits.first + %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ? + @commit = @project.repo.commits.first @create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id} @update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id} diff --git a/spec/controllers/projects/git/git_trees_controller_spec.rb b/spec/controllers/projects/git/git_trees_controller_spec.rb index ce9884232..f2baf5020 100644 --- a/spec/controllers/projects/git/git_trees_controller_spec.rb +++ b/spec/controllers/projects/git/git_trees_controller_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe Projects::Git::TreesController do def fill_project - %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ? + %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ? end before(:each) do @@ -12,7 +12,7 @@ describe Projects::Git::TreesController do @project = FactoryGirl.create(:project) @another_user = FactoryGirl.create(:user) - @params = {:owner_name => @project.owner.uname, :project_name => @project.name} + @params = {:owner_name => @project.owner.uname, :project_name => @project.name, :treeish => 'master'} end context 'for guest' do @@ -35,21 +35,21 @@ describe Projects::Git::TreesController do it 'should not be able to archive empty project' do @user = FactoryGirl.create(:user) set_session_for(@user) - expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActiveRecord::RecordNotFound) + expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActionController::RoutingError) end it 'should not be able to injection code with format' do @user = FactoryGirl.create(:user) set_session_for(@user) fill_project - expect { get :archive, @params.merge(:format => "tar master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActiveRecord::RecordNotFound) + expect { get :archive, @params.merge(:format => "tar master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError) end it 'should not be able to injection code with treeish' do @user = FactoryGirl.create(:user) set_session_for(@user) fill_project - expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActiveRecord::RecordNotFound) + expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError) end it 'should be able to perform archive action' do diff --git a/spec/controllers/users/profile_controller_spec.rb b/spec/controllers/users/profile_controller_spec.rb index 0451de6a8..76617cf8d 100644 --- a/spec/controllers/users/profile_controller_spec.rb +++ b/spec/controllers/users/profile_controller_spec.rb @@ -16,7 +16,7 @@ describe Users::ProfileController do context 'for guest' do it 'should not be able to view profile' do - get :show, :owner_name => @simple_user.uname + get :show, :uname => @simple_user.uname response.should redirect_to(new_user_session_path) end end diff --git a/spec/factories/platforms.rb b/spec/factories/platforms.rb index e8d6aad69..6877fb58c 100644 --- a/spec/factories/platforms.rb +++ b/spec/factories/platforms.rb @@ -8,7 +8,7 @@ FactoryGirl.define do association :owner, :factory => :user factory :platform_with_repos do - after_create {|p| FactoryGirl.create_list(:repository, 1, platform: p)} + after(:create) {|p| FactoryGirl.create_list(:repository, 1, platform: p)} end factory :personal_platform do diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index e4ad33f74..6e51eb1fa 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -10,8 +10,8 @@ def set_comments_data_for_commit @ability = Ability.new(@user) @project = FactoryGirl.create(:project, :owner => @user) - %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ? - @commit = @project.git_repository.commits.first + %x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ? + @commit = @project.repo.commits.first @comment = create_comment(@user) @stranger_comment = create_comment(@stranger) diff --git a/spec/routing/projects_routing_spec.rb.rb b/spec/routing/projects_routing_spec.rb.rb index 5bcc65d06..6f964e50c 100644 --- a/spec/routing/projects_routing_spec.rb.rb +++ b/spec/routing/projects_routing_spec.rb.rb @@ -39,6 +39,7 @@ describe Projects::Git::TreesController do get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'lib2safe-0.03') get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch-with.dot', :path => 'folder_with.dot/path-with.dot') # get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'ветка-с.точкой', :path => 'папка_с.точкой/путь-с.точкой') + get("/import/glib2.0-mib/tree/tag13.52-5").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'tag13.52-5') end # TODO write more specs also with slash in branch name! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 843efa51f..72f943b66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,8 +39,8 @@ def stub_symlink_methods end def test_git_commit(project) - project.git_repository.repo.index.add('test', 'TEST') - project.git_repository.repo.index.commit('Test commit') + project.repo.index.add('test', 'TEST') + project.repo.index.commit('Test commit') end Resque.inline = true From 3a183e0dc3cb825e4295c14eb9a7c0cfcf292133 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 17 Jul 2012 13:31:32 +0400 Subject: [PATCH 06/56] [refs #441] Remove unused files. Add mass assigment specs --- .../javascripts/platforms/key_pairs.js.coffee | 3 --- .../stylesheets/platforms/key_pairs.css.scss | 3 --- app/helpers/platforms/key_pairs_helper.rb | 2 -- app/models/key_pair.rb | 6 +----- app/models/user.rb | 2 ++ .../helpers/platforms/key_pairs_helper_spec.rb | 15 --------------- spec/models/key_pair_spec.rb | 18 +++++++++++++++++- 7 files changed, 20 insertions(+), 29 deletions(-) delete mode 100644 app/assets/javascripts/platforms/key_pairs.js.coffee delete mode 100644 app/assets/stylesheets/platforms/key_pairs.css.scss delete mode 100644 app/helpers/platforms/key_pairs_helper.rb delete mode 100644 spec/helpers/platforms/key_pairs_helper_spec.rb diff --git a/app/assets/javascripts/platforms/key_pairs.js.coffee b/app/assets/javascripts/platforms/key_pairs.js.coffee deleted file mode 100644 index 761567942..000000000 --- a/app/assets/javascripts/platforms/key_pairs.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/platforms/key_pairs.css.scss b/app/assets/stylesheets/platforms/key_pairs.css.scss deleted file mode 100644 index d5b1aec6a..000000000 --- a/app/assets/stylesheets/platforms/key_pairs.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Platforms::KeyPairs controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/helpers/platforms/key_pairs_helper.rb b/app/helpers/platforms/key_pairs_helper.rb deleted file mode 100644 index cef406c92..000000000 --- a/app/helpers/platforms/key_pairs_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Platforms::KeyPairsHelper -end diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 7fc7aad05..ec85e53fc 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -23,11 +23,7 @@ class KeyPair < ActiveRecord::Base end def rm_key_call - if BuildServer.rm_repository_key(repository.platform_id, repository_id) == 0 - self.destroy - return true - end - + return self.destroy if BuildServer.rm_repository_key(repository.platform_id, repository_id) == 0 false end end diff --git a/app/models/user.rb b/app/models/user.rb index ede3710e6..c807cfbac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,6 +35,8 @@ class User < ActiveRecord::Base 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 :key_pairs + 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? } validates :role, :inclusion => {:in => ROLES}, :allow_blank => true diff --git a/spec/helpers/platforms/key_pairs_helper_spec.rb b/spec/helpers/platforms/key_pairs_helper_spec.rb deleted file mode 100644 index a2ba0ac62..000000000 --- a/spec/helpers/platforms/key_pairs_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Platforms::KeyPairsHelper. For example: -# -# describe Platforms::KeyPairsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Platforms::KeyPairsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/key_pair_spec.rb b/spec/models/key_pair_spec.rb index 348480097..bda634ebe 100644 --- a/spec/models/key_pair_spec.rb +++ b/spec/models/key_pair_spec.rb @@ -1,5 +1,21 @@ require 'spec_helper' describe KeyPair do - pending "add some examples to (or delete) #{__FILE__}" + before(:all) do + stub_symlink_methods + 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 From 778b76e5ff3d428316af5f049d4875a39e910a13 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 18 Jul 2012 14:31:49 +0400 Subject: [PATCH 07/56] [refs #570] Fix mass builds counters update. Fix mass build and failed_build_list links --- app/models/build_list.rb | 4 ++-- app/views/platforms/mass_builds/index.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index a3f0b416b..5c7a151d7 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -106,13 +106,13 @@ class BuildList < ActiveRecord::Base # WTF? around_transition -> infinite loop before_transition do |build_list, transition| - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end after_transition do |build_list, transition| - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index 15ba91f7a..fd5332ec1 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -37,13 +37,13 @@ - @mass_builds.each do |mass_build| %tr %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 => 'index'}) %td.min_width_120 - 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)} : {})) = mass_build.read_attribute "#{status}_count" .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 %a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") From 6430678c00d465a530c57d7cd41a0565c9f718c1 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 18 Jul 2012 16:00:40 +0400 Subject: [PATCH 08/56] [refs #570] Add :all option for build lists visibility --- app/models/ability.rb | 10 +++++----- app/models/build_list/filter.rb | 2 +- app/views/platforms/mass_builds/index.html.haml | 4 ++-- app/views/projects/build_lists/_filter.html.haml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index c9e9d8ab7..b1ca521e6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,7 +17,7 @@ class Ability can :archive, Project, :visibility => 'open' can :read, Issue, :project => {:visibility => 'open'} can :search, BuildList - can :read, BuildList, :project => {:visibility => 'open'} + can [:read, :all], BuildList, :project => {:visibility => 'open'} can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work can :read, Advisory can(:advisories, Platform) {APP_CONFIG['anonymous_access']} @@ -62,10 +62,10 @@ class Ability can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')} can :remove_user, Project - can [:read, :owned], BuildList, :user_id => user.id - can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} - can [:read, :related], 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, :owned, :all], BuildList, :user_id => user.id + can [:read, :related, :all], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} + can [:read, :related, :all], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} + can([:read, :all], 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(:publish, BuildList) do |build_list| diff --git a/app/models/build_list/filter.rb b/app/models/build_list/filter.rb index b6095fc71..6384fb8bc 100644 --- a/app/models/build_list/filter.rb +++ b/app/models/build_list/filter.rb @@ -62,7 +62,7 @@ class BuildList::Filter :mass_build_id => nil })) - @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned') + @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'all' : 'owned') @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) diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index fd5332ec1..3f90ab6ee 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -37,10 +37,10 @@ - @mass_builds.each do |mass_build| %tr %td= mass_build.id - %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'index'}) + %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'all'}) %td.min_width_120 - 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 => 'all'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {})) = mass_build.read_attribute "#{status}_count" .both %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) diff --git a/app/views/projects/build_lists/_filter.html.haml b/app/views/projects/build_lists/_filter.html.haml index 0d7d38eaa..883828c8f 100644 --- a/app/views/projects/build_lists/_filter.html.haml +++ b/app/views/projects/build_lists/_filter.html.haml @@ -31,7 +31,7 @@ .lefter= t("layout.build_lists.ownership.related") .both .table - .lefter= f.radio_button :ownership, 'index', :class => 'niceRadio', :id => 'myradio3' + .lefter= f.radio_button :ownership, 'all', :class => 'niceRadio', :id => 'myradio3' .lefter= t("layout.build_lists.ownership.index") .both %br From 70616961007a9c1e6d7b3f8d0454da33397cd87a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 18 Jul 2012 17:49:21 +0400 Subject: [PATCH 09/56] [refs #570] Replace :all to :everything for builds filter --- app/models/ability.rb | 10 +++++----- app/models/build_list/filter.rb | 2 +- app/views/platforms/mass_builds/index.html.haml | 4 ++-- app/views/projects/build_lists/_filter.html.haml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index b1ca521e6..062eb05f6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,7 +17,7 @@ class Ability can :archive, Project, :visibility => 'open' can :read, Issue, :project => {:visibility => 'open'} can :search, BuildList - can [:read, :all], 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, Advisory can(:advisories, Platform) {APP_CONFIG['anonymous_access']} @@ -62,10 +62,10 @@ class Ability can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')} can :remove_user, Project - can [:read, :owned, :all], BuildList, :user_id => user.id - can [:read, :related, :all], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} - can [:read, :related, :all], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} - can([:read, :all], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project} + can [:read, :owned, :everything], BuildList, :user_id => user.id + can [:read, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} + can [:read, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} + 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(:publish, BuildList) do |build_list| diff --git a/app/models/build_list/filter.rb b/app/models/build_list/filter.rb index 6384fb8bc..05408cb85 100644 --- a/app/models/build_list/filter.rb +++ b/app/models/build_list/filter.rb @@ -62,7 +62,7 @@ class BuildList::Filter :mass_build_id => nil })) - @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'all' : 'owned') + @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned') @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) diff --git a/app/views/platforms/mass_builds/index.html.haml b/app/views/platforms/mass_builds/index.html.haml index 3f90ab6ee..e1115e0fa 100644 --- a/app/views/platforms/mass_builds/index.html.haml +++ b/app/views/platforms/mass_builds/index.html.haml @@ -37,10 +37,10 @@ - @mass_builds.each do |mass_build| %tr %td= mass_build.id - %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'all'}) + %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'everything'}) %td.min_width_120 - 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 => 'all'}.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" .both %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) diff --git a/app/views/projects/build_lists/_filter.html.haml b/app/views/projects/build_lists/_filter.html.haml index 883828c8f..5c8071a8e 100644 --- a/app/views/projects/build_lists/_filter.html.haml +++ b/app/views/projects/build_lists/_filter.html.haml @@ -31,7 +31,7 @@ .lefter= t("layout.build_lists.ownership.related") .both .table - .lefter= f.radio_button :ownership, 'all', :class => 'niceRadio', :id => 'myradio3' + .lefter= f.radio_button :ownership, 'everything', :class => 'niceRadio', :id => 'myradio3' .lefter= t("layout.build_lists.ownership.index") .both %br From 94456e6319c895bcb66b9a59e6399ea56d6a0931 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 18 Jul 2012 18:13:37 +0400 Subject: [PATCH 10/56] [refs #570] Replace :index to :everything into specs --- spec/controllers/projects/build_lists_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 1431004eb..e52beb320 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -125,7 +125,7 @@ describe Projects::BuildListsController do end 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_not include(@build_list2) assigns(:build_lists).should include(@build_list3) @@ -210,7 +210,7 @@ describe Projects::BuildListsController do end 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_not include(@build_list2) assigns(:build_lists).should include(@build_list3) @@ -297,14 +297,14 @@ describe Projects::BuildListsController do it 'should filter by project_name' do # 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 include(@build_list2) assigns[:build_lists].should_not include(@build_list3) end it 'should filter by project_name and start_date' do - get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'index', + get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'everything', "created_at_start(1i)" => @build_list3.created_at.year.to_s, "created_at_start(2i)" => @build_list3.created_at.month.to_s, "created_at_start(3i)" => @build_list3.created_at.day.to_s} From 71fc19edc8ebc8b638c2d1d413c0eb638ccd7e9c Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 18 Jul 2012 23:04:26 +0400 Subject: [PATCH 11/56] [refs #570] Change localization for fields --- config/locales/models/build_list.en.yml | 2 +- config/locales/models/build_list.ru.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index cdcf7530e..20d1177fa 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -80,7 +80,7 @@ en: header: Build list ownership owned: My related: Related - index: All + everything: All build_server_status: header: Build server status diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 5c5820a9d..09dd8ef46 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -79,7 +79,7 @@ ru: header: Принадлежность заданий owned: Мне related: Связанные со мной - index: Все + everything: Все build_server_status: header: Статус сборочного сервера From 1f0887ac97e8eb979993443521ab87300bc0d172 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 18 Jul 2012 23:26:13 +0400 Subject: [PATCH 12/56] [refs #570] Change localization for fields(part 2) --- app/views/projects/build_lists/_filter.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/build_lists/_filter.html.haml b/app/views/projects/build_lists/_filter.html.haml index 5c8071a8e..a9ca14988 100644 --- a/app/views/projects/build_lists/_filter.html.haml +++ b/app/views/projects/build_lists/_filter.html.haml @@ -32,7 +32,7 @@ .both .table .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 %br = f.submit t("layout.search.header") From 15a86c2ecd94474a5995d5b99f032651d9da3c66 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 23 Jul 2012 18:25:37 +0400 Subject: [PATCH 13/56] [refs #576] Add flash notifies --- .../javascripts/extra/flash_notifies.js | 19 +++ app/assets/stylesheets/design/custom.scss | 60 ++++++++ app/controllers/flash_notifies_controller.rb | 46 ++++++ app/models/flash_notify.rb | 24 ++++ app/views/flash_notifies/_form.html.haml | 21 +++ app/views/flash_notifies/edit.html.haml | 4 + app/views/flash_notifies/index.html.haml | 21 +++ app/views/flash_notifies/new.html.haml | 4 + app/views/layouts/_notifies.html.haml | 12 ++ app/views/layouts/application.html.haml | 1 + config/locales/models/flash_notify.en.yml | 28 ++++ config/locales/models/flash_notify.ru.yml | 28 ++++ config/routes.rb | 2 + .../20120719045806_create_flash_notifies.rb | 11 ++ db/schema.rb | 9 ++ .../flash_notifies_controller_spec.rb | 132 ++++++++++++++++++ spec/factories/flash_notify.rb | 10 ++ spec/models/flash_notify_spec.rb | 5 + vendor/assets/javascripts/bootstrap-alert.js | 90 ++++++++++++ vendor/assets/javascripts/vendor.js | 1 + 20 files changed, 528 insertions(+) create mode 100644 app/assets/javascripts/extra/flash_notifies.js create mode 100644 app/controllers/flash_notifies_controller.rb create mode 100644 app/models/flash_notify.rb create mode 100644 app/views/flash_notifies/_form.html.haml create mode 100644 app/views/flash_notifies/edit.html.haml create mode 100644 app/views/flash_notifies/index.html.haml create mode 100644 app/views/flash_notifies/new.html.haml create mode 100644 app/views/layouts/_notifies.html.haml create mode 100644 config/locales/models/flash_notify.en.yml create mode 100644 config/locales/models/flash_notify.ru.yml create mode 100644 db/migrate/20120719045806_create_flash_notifies.rb create mode 100644 spec/controllers/flash_notifies_controller_spec.rb create mode 100644 spec/factories/flash_notify.rb create mode 100644 spec/models/flash_notify_spec.rb create mode 100644 vendor/assets/javascripts/bootstrap-alert.js diff --git a/app/assets/javascripts/extra/flash_notifies.js b/app/assets/javascripts/extra/flash_notifies.js new file mode 100644 index 000000000..4002c4873 --- /dev/null +++ b/app/assets/javascripts/extra/flash_notifies.js @@ -0,0 +1,19 @@ +function setCookie (name, value, expires, path, domain, secure) { + document.cookie = name + "=" + escape(value) + + ((expires) ? "; expires=" + expires : "") + + ((path) ? "; path=" + path : "") + + ((domain) ? "; domain=" + domain : "") + + ((secure) ? "; secure" : ""); +} + +$(document).ready(function() { + if ($(".alert").size()) { + $(".alert").alert() + } + + $('#close-alert').click(function () { + setCookie("flash_notify_id", FLASH_NOTIFY_ID, FLASH_EXPIRES_AT); + setCookie("flash_notify_hash", FLASH_HASH_ID, FLASH_EXPIRES_AT); + }); +}); + diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index ccf97e3d0..193800920 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1172,3 +1172,63 @@ table.tablesorter tr td.no_results { text-align: center; } /* end */ + +/* Flash Notifies */ + +.flash_notify { + .alert-success { + color: #468847; + background-color: #DFF0D8; + border-color: #D6E9C6; + } + + .alert { + padding: 8px 35px 8px 14px; + margin-bottom: 18px; + color: #C09853; + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); + background-color: #FCF8E3; + border: 1px solid #FBEED5; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + } + + .alert-danger, .alert-error { + color: #B94A48; + background-color: #F2DEDE; + border-color: #EED3D7; + } + + .alert-info { + color: #3A87AD; + background-color: #D9EDF7; + border-color: #BCE8F1; + } + + .alert .close { + position: relative; + top: -2px; + right: -21px; + line-height: 18px; + } + + button.close { + padding: 0; + cursor: pointer; + background: transparent; + border: 0; + -webkit-appearance: none; + } + + .close { + float: right; + font-size: 20px; + font-weight: bold; + line-height: 18px; + color: black; + text-shadow: 0 1px 0 white; + opacity: 0.2; + filter: alpha(opacity=20); + } +} diff --git a/app/controllers/flash_notifies_controller.rb b/app/controllers/flash_notifies_controller.rb new file mode 100644 index 000000000..c7d3915ef --- /dev/null +++ b/app/controllers/flash_notifies_controller.rb @@ -0,0 +1,46 @@ +class FlashNotifiesController < ApplicationController + before_filter :authenticate_user! + + load_and_authorize_resource + + def index + @flash_notifies = FlashNotify.paginate(:page => params[:page], :per_page => 20) + end + + def new + @flash_notify = FlashNotify.new(:published => true) + end + + def create + @flash_notify = FlashNotify.new(params[:flash_notify]) + if @flash_notify.save + flash[:notice] = t("flash.flash_notify.saved") + redirect_to flash_notifies_path + else + flash[:error] = t("flash.flash_notify.save_error") + flash[:warning] = @flash_notify.errors.full_messages.join('. ') + render :new + end + end + + def update + if @flash_notify.update_attributes(params[:flash_notify]) + flash[:notice] = t("flash.flash_notify.saved") + redirect_to flash_notifies_path + else + flash[:error] = t("flash.flash_notify.save_error") + flash[:warning] = @flash_notify.errors.full_messages.join('. ') + render :edit + end + end + + def destroy + if @flash_notify.destroy + flash[:notice] = t("flash.flash_notify.destroyed") + redirect_to flash_notifies_path + else + flash[:error] = t("flash.flash_notify.destroy_error") + redirect_to flash_notifies_path + end + end +end diff --git a/app/models/flash_notify.rb b/app/models/flash_notify.rb new file mode 100644 index 000000000..884e13096 --- /dev/null +++ b/app/models/flash_notify.rb @@ -0,0 +1,24 @@ +require 'digest/md5' + +class FlashNotify < ActiveRecord::Base + # attr_accessible :title, :body + + STATUSES = %w[error success info] + + validates :status, :inclusion => {:in => STATUSES} + validates :body_ru, :body_en, :status, :presence => true + + scope :published, where(:published => true) + + def hash_id + @digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}") + end + + def body(language) + read_attribute("body_#{language}") + end + + def should_show?(cookie_id, cookie_hash_id) + cookie_id.to_i == id && cookie_hash_id == hash_id ? false : true + end +end diff --git a/app/views/flash_notifies/_form.html.haml b/app/views/flash_notifies/_form.html.haml new file mode 100644 index 000000000..73f0ec876 --- /dev/null +++ b/app/views/flash_notifies/_form.html.haml @@ -0,0 +1,21 @@ +.leftlist= f.label :body_ru, t("activerecord.attributes.flash_notify.body_ru"), :class => :label +.rightlist= f.text_area :body_ru, :class => 'text_field' +.both + +.leftlist= f.label :body_en, t("activerecord.attributes.flash_notify.body_en"), :class => :label +.rightlist= f.text_area :body_en, :class => 'text_field' +.both + +.leftlist= f.label :status, t("activerecord.attributes.flash_notify.status"), :class => :label +.rightlist= f.select :status, FlashNotify::STATUSES +.both + +.leftlist= f.label :published, t("activerecord.attributes.flash_notify.published"), :class => :label +.rightlist= f.check_box :published +.both + +.button_block + = submit_tag t("layout.save") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), flash_notifies_path, :class => "button" + diff --git a/app/views/flash_notifies/edit.html.haml b/app/views/flash_notifies/edit.html.haml new file mode 100644 index 000000000..2dc979eaa --- /dev/null +++ b/app/views/flash_notifies/edit.html.haml @@ -0,0 +1,4 @@ +%h3= t("layout.flash_notifies.edit_header") + += form_for @flash_notify, :url => flash_notifies_path(@flash_notify), :html => { :class => :form } do |f| + = render "form", :f => f diff --git a/app/views/flash_notifies/index.html.haml b/app/views/flash_notifies/index.html.haml new file mode 100644 index 000000000..4b42da4a5 --- /dev/null +++ b/app/views/flash_notifies/index.html.haml @@ -0,0 +1,21 @@ += link_to t("layout.flash_notifies.new"), new_flash_notify_path, :class => 'button' if can? :create, FlashNotify + +%table#myTable.tablesorter.flash_notifys{:cellspacing => "0", :cellpadding => "0"} + %thead + %tr + %th.th1= t("activerecord.attributes.flash_notify.body_en") + %th.th2= t("activerecord.attributes.flash_notify.body_ru") + %th.th3= t("activerecord.attributes.flash_notify.published") + %th.th3= t("layout.flash_notifies.actions") + %tbody + - @flash_notifies.each do |flash_notify| + %tr{:class => cycle("odd", "even")} + %td= flash_notify.body_en.slice(0..15) + "..." + %td= flash_notify.body_ru.slice(0..15) + "..." + %td= flash_notify.published + %td + = link_to t("layout.flash_notifies.edit"), edit_flash_notify_path(flash_notify) + = link_to t("layout.flash_notifies.delete"), flash_notify_path(flash_notify), :method => :delete, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify) + += will_paginate @flash_notifies + diff --git a/app/views/flash_notifies/new.html.haml b/app/views/flash_notifies/new.html.haml new file mode 100644 index 000000000..4b4bba0bf --- /dev/null +++ b/app/views/flash_notifies/new.html.haml @@ -0,0 +1,4 @@ +%h3= t("layout.flash_notifies.new_header") + += form_for @flash_notify, :url => flash_notifies_path, :html => { :class => :form } do |f| + = render "form", :f => f diff --git a/app/views/layouts/_notifies.html.haml b/app/views/layouts/_notifies.html.haml new file mode 100644 index 000000000..766485dcd --- /dev/null +++ b/app/views/layouts/_notifies.html.haml @@ -0,0 +1,12 @@ +- if current_user || APP_CONFIG['anonymous_access'] + .flash_notify + - flash_notify = FlashNotify.published.first + - if flash_notify && flash_notify.should_show?(cookies[:flash_notify_id], cookies[:flash_notify_hash]) + .alert{:class => "alert-#{flash_notify.status}"} + = flash_notify.body current_user.language + %a{:class=>"close", :'data-dismiss'=>"alert", :href=>"#", :id => 'close-alert'} × + +:javascript + var FLASH_NOTIFY_ID = "#{flash_notify.id}"; + var FLASH_HASH_ID = "#{flash_notify.hash_id}"; + var FLASH_EXPIRES_AT = "#{Date.today + 1.year}"; diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 642d9b82e..ce5659724 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -47,6 +47,7 @@ = yield :feed_tabs .both = render "layouts/flashes" + = render "layouts/notifies" %article - if content_for?(:sidebar) %aside= yield :sidebar diff --git a/config/locales/models/flash_notify.en.yml b/config/locales/models/flash_notify.en.yml new file mode 100644 index 000000000..50f5ac06c --- /dev/null +++ b/config/locales/models/flash_notify.en.yml @@ -0,0 +1,28 @@ +en: + layout: + flash_notifies: + list_header: Notifies + new: New notify + new_header: New notify + actions: Actions + edit: Edit + edit_header: Edit notify + delete: Delete + + flash: + flash_notify: + saved: Notify added + save_error: Unable to add notify + destroyed: Notify deleted + + activerecord: + models: + flash_notify: Notify + attributes: + flash_notify: + body_ru: Body Ru + body_en: Body En + published: Published + status: Status + created_at: Created + updated_at: Updated diff --git a/config/locales/models/flash_notify.ru.yml b/config/locales/models/flash_notify.ru.yml new file mode 100644 index 000000000..b2be708c1 --- /dev/null +++ b/config/locales/models/flash_notify.ru.yml @@ -0,0 +1,28 @@ +ru: + layout: + flash_notifies: + list_header: Оповещения + new: Новое оповещение + new_header: Новое оповещение + actions: Действия + edit: Редактирование + edit_header: Редактировать оповещение + delete: Удалить + + flash: + flash_notify: + saved: Оповещение сохранено + save_error: Не получилось сохранить оповещение + destroyed: Оповещение удалено + + activerecord: + models: + flash_notify: Оповещение + attributes: + flash_notify: + body_ru: Текст Ru + body_en: Текст En + published: Опубликовано + status: Статус + created_at: Создано + updated_at: Обновлено diff --git a/config/routes.rb b/config/routes.rb index 62c3029d3..6e7299f2d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,8 @@ Rosa::Application.routes.draw do root :to => 'activity_feeds#index' end + resources :flash_notifies + namespace :admin do resources :users do get :list, :on => :collection diff --git a/db/migrate/20120719045806_create_flash_notifies.rb b/db/migrate/20120719045806_create_flash_notifies.rb new file mode 100644 index 000000000..2a9f16a29 --- /dev/null +++ b/db/migrate/20120719045806_create_flash_notifies.rb @@ -0,0 +1,11 @@ +class CreateFlashNotifies < ActiveRecord::Migration + def change + create_table :flash_notifies do |t| + t.text :body_ru, :null => false + t.text :body_en, :null => false + t.string :status, :null => false + t.boolean :published, :null => false, :default => true + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5200f5c01..a23a418d6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -159,6 +159,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.datetime "updated_at", :null => false end + create_table "flash_notifies", :force => true do |t| + t.text "body_ru", :null => false + t.text "body_en", :null => false + t.string "status", :null => false + t.boolean "published", :default => true, :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "groups", :force => true do |t| t.integer "owner_id" t.datetime "created_at", :null => false diff --git a/spec/controllers/flash_notifies_controller_spec.rb b/spec/controllers/flash_notifies_controller_spec.rb new file mode 100644 index 000000000..b00301fbd --- /dev/null +++ b/spec/controllers/flash_notifies_controller_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +describe FlashNotifiesController do + before(:each) do + stub_symlink_methods + + @user = FactoryGirl.create(:user) + @create_params = { + :flash_notify => { + :body_ru => "Hello! I`m ru body", + :body_en => "Hello! I`m en body", + :status => "error", + :published => true + } + } + + @flash_notify = FactoryGirl.create(:flash_notify) + @flash_notify2 = FactoryGirl.create(:flash_notify) + + @update_params = { + :id => @flash_notify, + :flash_notify => { + :body_ru => "updated!" + } + } + end + + context 'for guest' do + [:index, :create, :update, :edit, :new, :destroy].each do |action| + it "should not be able to perform #{ action } action" do + get action, :id => @flash_notify + response.should redirect_to(new_user_session_path) + end + end + + it 'should not change objects count on create' do + lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(0) + end + + it 'should not change objects count on destroy' do + lambda { delete :destroy, :id => @flash_notify }.should change{ FlashNotify.count }.by(0) + end + + it 'should not change flash notify body on update' do + put :update, @update_params + @flash_notify.reload.body_ru.should_not == "updated!" + 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 be able to perform index action' do + get :index + response.should render_template(:index) + end + + it 'should load 2 flash notifies objects on index' do + get :index + assigns[:flash_notifies].count.should == 2 + end + + it 'should be able to perform new action' do + get :new + response.should render_template(:new) + end + + it 'should be able to perform edit action' do + get :edit + response.should render_template(:edit) + end + + it 'should be able to perform create action' do + post :create, @create_params + response.should redirect_to(flash_notifies_path) + end + + it 'should change objects count on create' do + lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(1) + end + + it 'should be able to perform destroy action' do + delete :destroy, :id => @flash_notify + response.should redirect_to(flash_notifies_path) + end + + it 'should change objects count on destroy' do + lambda { delete :destroy, :id => @flash_notify }.should change{ FlashNotify.count }.by(-1) + end + + it 'should be able to perform update action' do + put :update, @update_params + response.should redirect_to(flash_notifies_path) + end + + it 'should change flash notify body on update' do + put :update, @update_params + @flash_notify.reload.body_ru.should == "updated!" + end + end + + context 'for simple user' do + before(:each) do + @user = FactoryGirl.create(:user) + set_session_for(@user) + end + + [:index, :create, :update, :edit, :new, :destroy].each do |action| + it "should not be able to perform #{ action } action" do + get action, :id => @flash_notify + response.should redirect_to(forbidden_path) + end + end + + it 'should not change objects count on create' do + lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(0) + end + + it 'should not change objects count on destroy' do + lambda { delete :destroy, :id => @flash_notify }.should change{ FlashNotify.count }.by(0) + end + + it 'should not change flash notify body on update' do + put :update, @update_params + @flash_notify.reload.body_ru.should_not == "updated!" + end + end +end diff --git a/spec/factories/flash_notify.rb b/spec/factories/flash_notify.rb new file mode 100644 index 000000000..b3f239540 --- /dev/null +++ b/spec/factories/flash_notify.rb @@ -0,0 +1,10 @@ +# -*- encoding : utf-8 -*- +FactoryGirl.define do + factory :flash_notify do + body_ru { FactoryGirl.generate(:string) } + body_en { FactoryGirl.generate(:string) } + status "error" + published true + end +end + diff --git a/spec/models/flash_notify_spec.rb b/spec/models/flash_notify_spec.rb new file mode 100644 index 000000000..8501d64a4 --- /dev/null +++ b/spec/models/flash_notify_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe FlashNotify do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/vendor/assets/javascripts/bootstrap-alert.js b/vendor/assets/javascripts/bootstrap-alert.js new file mode 100644 index 000000000..57890a9a2 --- /dev/null +++ b/vendor/assets/javascripts/bootstrap-alert.js @@ -0,0 +1,90 @@ +/* ========================================================== + * bootstrap-alert.js v2.0.4 + * http://twitter.github.com/bootstrap/javascript.html#alerts + * ========================================================== + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + + +!function ($) { + + "use strict"; // jshint ;_; + + + /* ALERT CLASS DEFINITION + * ====================== */ + + var dismiss = '[data-dismiss="alert"]' + , Alert = function (el) { + $(el).on('click', dismiss, this.close) + } + + Alert.prototype.close = function (e) { + var $this = $(this) + , selector = $this.attr('data-target') + , $parent + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } + + $parent = $(selector) + + e && e.preventDefault() + + $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) + + $parent.trigger(e = $.Event('close')) + + if (e.isDefaultPrevented()) return + + $parent.removeClass('in') + + function removeElement() { + $parent + .trigger('closed') + .remove() + } + + $.support.transition && $parent.hasClass('fade') ? + $parent.on($.support.transition.end, removeElement) : + removeElement() + } + + + /* ALERT PLUGIN DEFINITION + * ======================= */ + + $.fn.alert = function (option) { + return this.each(function () { + var $this = $(this) + , data = $this.data('alert') + if (!data) $this.data('alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } + + $.fn.alert.Constructor = Alert + + + /* ALERT DATA-API + * ============== */ + + $(function () { + $('body').on('click.alert.data-api', dismiss, Alert.prototype.close) + }) + +}(window.jQuery); \ No newline at end of file diff --git a/vendor/assets/javascripts/vendor.js b/vendor/assets/javascripts/vendor.js index 9d833de06..a4d1ebcfb 100644 --- a/vendor/assets/javascripts/vendor.js +++ b/vendor/assets/javascripts/vendor.js @@ -12,6 +12,7 @@ //= require bootstrap-dropdown // require bootstrap-tooltip // require bootstrap-popover +//= require bootstrap-alert //= require chosen.jquery // require html5shiv // require_tree . From 3d19a4f23eea92a19c8bba3c1340f66991792b0e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 24 Jul 2012 13:19:22 +0400 Subject: [PATCH 14/56] [refs #576] Optimize tests, views and model --- app/models/flash_notify.rb | 2 +- app/views/flash_notifies/edit.html.haml | 2 +- app/views/flash_notifies/index.html.haml | 4 ++-- .../flash_notifies_controller_spec.rb | 18 +++++------------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/models/flash_notify.rb b/app/models/flash_notify.rb index 884e13096..5cc407173 100644 --- a/app/models/flash_notify.rb +++ b/app/models/flash_notify.rb @@ -19,6 +19,6 @@ class FlashNotify < ActiveRecord::Base end def should_show?(cookie_id, cookie_hash_id) - cookie_id.to_i == id && cookie_hash_id == hash_id ? false : true + !(cookie_id.to_i == id && cookie_hash_id == hash_id) end end diff --git a/app/views/flash_notifies/edit.html.haml b/app/views/flash_notifies/edit.html.haml index 2dc979eaa..e545e4c6a 100644 --- a/app/views/flash_notifies/edit.html.haml +++ b/app/views/flash_notifies/edit.html.haml @@ -1,4 +1,4 @@ %h3= t("layout.flash_notifies.edit_header") -= form_for @flash_notify, :url => flash_notifies_path(@flash_notify), :html => { :class => :form } do |f| += form_for @flash_notify, :url => flash_notify_path(@flash_notify), :html => { :class => :form } do |f| = render "form", :f => f diff --git a/app/views/flash_notifies/index.html.haml b/app/views/flash_notifies/index.html.haml index 4b42da4a5..566938029 100644 --- a/app/views/flash_notifies/index.html.haml +++ b/app/views/flash_notifies/index.html.haml @@ -10,8 +10,8 @@ %tbody - @flash_notifies.each do |flash_notify| %tr{:class => cycle("odd", "even")} - %td= flash_notify.body_en.slice(0..15) + "..." - %td= flash_notify.body_ru.slice(0..15) + "..." + %td= flash_notify.body_en.truncate 18 + %td= flash_notify.body_ru.truncate 18 %td= flash_notify.published %td = link_to t("layout.flash_notifies.edit"), edit_flash_notify_path(flash_notify) diff --git a/spec/controllers/flash_notifies_controller_spec.rb b/spec/controllers/flash_notifies_controller_spec.rb index b00301fbd..169bbe8b5 100644 --- a/spec/controllers/flash_notifies_controller_spec.rb +++ b/spec/controllers/flash_notifies_controller_spec.rb @@ -54,24 +54,16 @@ describe FlashNotifiesController do set_session_for(@admin) end - it 'should be able to perform index action' do - get :index - response.should render_template(:index) - end - it 'should load 2 flash notifies objects on index' do get :index assigns[:flash_notifies].count.should == 2 end - it 'should be able to perform new action' do - get :new - response.should render_template(:new) - end - - it 'should be able to perform edit action' do - get :edit - response.should render_template(:edit) + [:index, :new, :edit].each do |action| + it "should be able to perform #{action} action" do + get action, :id => @flash_notify + response.should render_template(action) + end end it 'should be able to perform create action' do From a0a4c8b1000016bf3c64fe18189280e89089d9a5 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 24 Jul 2012 22:02:02 +0600 Subject: [PATCH 15/56] [refs #581] dont destroy child projects --- app/models/project.rb | 2 +- spec/models/project_spec.rb | 41 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 927e7da61..24ab4d1ab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -49,7 +49,7 @@ class Project < ActiveRecord::Base after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?}# later with resque # should be after create_git_repo # after_rollback lambda { destroy_git_repo rescue true if new_record? } - has_ancestry + has_ancestry :orphan_strategy => :rootify #:adopt not available yet has_attached_file :srpm diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 572af1b76..b50c1e6a4 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,6 +1,41 @@ # -*- encoding : utf-8 -*- require 'spec_helper' -#describe Project do -# pending "add some examples to (or delete) #{__FILE__}" -#end +describe Project do + before(:each) do + stub_symlink_methods + @root_project = FactoryGirl.create(:project) + @child_project = @root_project.fork(FactoryGirl.create(:user)) + @child_child_project = @child_project.fork(FactoryGirl.create(:user)) + end + + context 'for destroy root' do + before(:each) do + @root_project.destroy + end + + it "should not be delete child" do + 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 + end + end + + # uncommit when will be available :orphan_strategy => :adopt + + #context 'for destroy middle node' do + # before(:each) do + # @child_project.destroy + # end + + # 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 \ No newline at end of file From c0036a1bb5594ff5ca09ddcfc71be62c355137f4 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 25 Jul 2012 16:41:06 +0400 Subject: [PATCH 16/56] [refs #576] Fix should_show? method and template offsets --- app/assets/javascripts/extra/flash_notifies.js | 1 - app/models/flash_notify.rb | 4 ++-- app/views/layouts/_notifies.html.haml | 9 ++++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/extra/flash_notifies.js b/app/assets/javascripts/extra/flash_notifies.js index 4002c4873..52c9fbf53 100644 --- a/app/assets/javascripts/extra/flash_notifies.js +++ b/app/assets/javascripts/extra/flash_notifies.js @@ -12,7 +12,6 @@ $(document).ready(function() { } $('#close-alert').click(function () { - setCookie("flash_notify_id", FLASH_NOTIFY_ID, FLASH_EXPIRES_AT); setCookie("flash_notify_hash", FLASH_HASH_ID, FLASH_EXPIRES_AT); }); }); diff --git a/app/models/flash_notify.rb b/app/models/flash_notify.rb index 5cc407173..601b197b2 100644 --- a/app/models/flash_notify.rb +++ b/app/models/flash_notify.rb @@ -18,7 +18,7 @@ class FlashNotify < ActiveRecord::Base read_attribute("body_#{language}") end - def should_show?(cookie_id, cookie_hash_id) - !(cookie_id.to_i == id && cookie_hash_id == hash_id) + def should_show?(cookie_hash_id) + cookie_hash_id != hash_id && published end end diff --git a/app/views/layouts/_notifies.html.haml b/app/views/layouts/_notifies.html.haml index 766485dcd..46f5b8d00 100644 --- a/app/views/layouts/_notifies.html.haml +++ b/app/views/layouts/_notifies.html.haml @@ -1,12 +1,11 @@ - if current_user || APP_CONFIG['anonymous_access'] .flash_notify - flash_notify = FlashNotify.published.first - - if flash_notify && flash_notify.should_show?(cookies[:flash_notify_id], cookies[:flash_notify_hash]) + - if flash_notify && flash_notify.should_show?(cookies[:flash_notify_hash]) .alert{:class => "alert-#{flash_notify.status}"} = flash_notify.body current_user.language %a{:class=>"close", :'data-dismiss'=>"alert", :href=>"#", :id => 'close-alert'} × -:javascript - var FLASH_NOTIFY_ID = "#{flash_notify.id}"; - var FLASH_HASH_ID = "#{flash_notify.hash_id}"; - var FLASH_EXPIRES_AT = "#{Date.today + 1.year}"; + :javascript + var FLASH_HASH_ID = "#{flash_notify.hash_id}"; + var FLASH_EXPIRES_AT = "#{Date.today + 1.year}"; From e09a9467e2251021c4f545fafdc0351dc1697724 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 25 Jul 2012 21:05:25 +0300 Subject: [PATCH 17/56] Fix flash notifies display bug. Add admin section link. Move controller to admin namspace. Refactor and fix notifies controller. Refs #576 --- .../{ => admin}/flash_notifies_controller.rb | 13 +-- .../flash_notifies/_form.html.haml | 2 +- app/views/admin/flash_notifies/edit.html.haml | 4 + .../flash_notifies/index.html.haml | 6 +- app/views/admin/flash_notifies/new.html.haml | 4 + app/views/flash_notifies/edit.html.haml | 4 - app/views/flash_notifies/new.html.haml | 4 - app/views/layouts/_notifies.html.haml | 11 +- config/locales/menu.en.yml | 1 + config/locales/menu.ru.yml | 1 + config/routes.rb | 3 +- db/schema.rb | 101 +++++++++--------- .../flash_notifies_controller_spec.rb | 8 +- 13 files changed, 77 insertions(+), 85 deletions(-) rename app/controllers/{ => admin}/flash_notifies_controller.rb (78%) rename app/views/{ => admin}/flash_notifies/_form.html.haml (90%) create mode 100644 app/views/admin/flash_notifies/edit.html.haml rename app/views/{ => admin}/flash_notifies/index.html.haml (60%) create mode 100644 app/views/admin/flash_notifies/new.html.haml delete mode 100644 app/views/flash_notifies/edit.html.haml delete mode 100644 app/views/flash_notifies/new.html.haml rename spec/controllers/{ => admin}/flash_notifies_controller_spec.rb (93%) diff --git a/app/controllers/flash_notifies_controller.rb b/app/controllers/admin/flash_notifies_controller.rb similarity index 78% rename from app/controllers/flash_notifies_controller.rb rename to app/controllers/admin/flash_notifies_controller.rb index c7d3915ef..5946427bf 100644 --- a/app/controllers/flash_notifies_controller.rb +++ b/app/controllers/admin/flash_notifies_controller.rb @@ -1,8 +1,4 @@ -class FlashNotifiesController < ApplicationController - before_filter :authenticate_user! - - load_and_authorize_resource - +class Admin::FlashNotifiesController < Admin::BaseController def index @flash_notifies = FlashNotify.paginate(:page => params[:page], :per_page => 20) end @@ -15,7 +11,7 @@ class FlashNotifiesController < ApplicationController @flash_notify = FlashNotify.new(params[:flash_notify]) if @flash_notify.save flash[:notice] = t("flash.flash_notify.saved") - redirect_to flash_notifies_path + redirect_to admin_flash_notifies_path else flash[:error] = t("flash.flash_notify.save_error") flash[:warning] = @flash_notify.errors.full_messages.join('. ') @@ -26,7 +22,7 @@ class FlashNotifiesController < ApplicationController def update if @flash_notify.update_attributes(params[:flash_notify]) flash[:notice] = t("flash.flash_notify.saved") - redirect_to flash_notifies_path + redirect_to admin_flash_notifies_path else flash[:error] = t("flash.flash_notify.save_error") flash[:warning] = @flash_notify.errors.full_messages.join('. ') @@ -37,10 +33,9 @@ class FlashNotifiesController < ApplicationController def destroy if @flash_notify.destroy flash[:notice] = t("flash.flash_notify.destroyed") - redirect_to flash_notifies_path else flash[:error] = t("flash.flash_notify.destroy_error") - redirect_to flash_notifies_path end + redirect_to admin_flash_notifies_path end end diff --git a/app/views/flash_notifies/_form.html.haml b/app/views/admin/flash_notifies/_form.html.haml similarity index 90% rename from app/views/flash_notifies/_form.html.haml rename to app/views/admin/flash_notifies/_form.html.haml index 73f0ec876..c609dd20b 100644 --- a/app/views/flash_notifies/_form.html.haml +++ b/app/views/admin/flash_notifies/_form.html.haml @@ -17,5 +17,5 @@ .button_block = submit_tag t("layout.save") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), flash_notifies_path, :class => "button" + = link_to t("layout.cancel"), admin_flash_notifies_path, :class => "button" diff --git a/app/views/admin/flash_notifies/edit.html.haml b/app/views/admin/flash_notifies/edit.html.haml new file mode 100644 index 000000000..89bed7609 --- /dev/null +++ b/app/views/admin/flash_notifies/edit.html.haml @@ -0,0 +1,4 @@ +%h3= t("layout.flash_notifies.edit_header") + += form_for @flash_notify, :url => admin_flash_notify_path(@flash_notify), :html => { :class => :form } do |f| + = render "form", :f => f diff --git a/app/views/flash_notifies/index.html.haml b/app/views/admin/flash_notifies/index.html.haml similarity index 60% rename from app/views/flash_notifies/index.html.haml rename to app/views/admin/flash_notifies/index.html.haml index 566938029..41a82be53 100644 --- a/app/views/flash_notifies/index.html.haml +++ b/app/views/admin/flash_notifies/index.html.haml @@ -1,4 +1,4 @@ -= link_to t("layout.flash_notifies.new"), new_flash_notify_path, :class => 'button' if can? :create, FlashNotify += link_to t("layout.flash_notifies.new"), new_admin_flash_notify_path, :class => 'button' if can? :create, FlashNotify %table#myTable.tablesorter.flash_notifys{:cellspacing => "0", :cellpadding => "0"} %thead @@ -14,8 +14,8 @@ %td= flash_notify.body_ru.truncate 18 %td= flash_notify.published %td - = link_to t("layout.flash_notifies.edit"), edit_flash_notify_path(flash_notify) - = link_to t("layout.flash_notifies.delete"), flash_notify_path(flash_notify), :method => :delete, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify) + = link_to t("layout.flash_notifies.edit"), edit_admin_flash_notify_path(flash_notify) + = link_to t("layout.flash_notifies.delete"), admin_flash_notify_path(flash_notify), :method => :delete, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify) = will_paginate @flash_notifies diff --git a/app/views/admin/flash_notifies/new.html.haml b/app/views/admin/flash_notifies/new.html.haml new file mode 100644 index 000000000..301a12bab --- /dev/null +++ b/app/views/admin/flash_notifies/new.html.haml @@ -0,0 +1,4 @@ +%h3= t("layout.flash_notifies.new_header") + += form_for @flash_notify, :url => admin_flash_notifies_path, :html => { :class => :form } do |f| + = render "form", :f => f diff --git a/app/views/flash_notifies/edit.html.haml b/app/views/flash_notifies/edit.html.haml deleted file mode 100644 index e545e4c6a..000000000 --- a/app/views/flash_notifies/edit.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%h3= t("layout.flash_notifies.edit_header") - -= form_for @flash_notify, :url => flash_notify_path(@flash_notify), :html => { :class => :form } do |f| - = render "form", :f => f diff --git a/app/views/flash_notifies/new.html.haml b/app/views/flash_notifies/new.html.haml deleted file mode 100644 index 4b4bba0bf..000000000 --- a/app/views/flash_notifies/new.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%h3= t("layout.flash_notifies.new_header") - -= form_for @flash_notify, :url => flash_notifies_path, :html => { :class => :form } do |f| - = render "form", :f => f diff --git a/app/views/layouts/_notifies.html.haml b/app/views/layouts/_notifies.html.haml index 46f5b8d00..d2c3f8b1b 100644 --- a/app/views/layouts/_notifies.html.haml +++ b/app/views/layouts/_notifies.html.haml @@ -1,11 +1,10 @@ - if current_user || APP_CONFIG['anonymous_access'] .flash_notify - - flash_notify = FlashNotify.published.first - - if flash_notify && flash_notify.should_show?(cookies[:flash_notify_hash]) + - if (flash_notify = FlashNotify.published.first) && flash_notify.should_show?(cookies[:flash_notify_hash]) .alert{:class => "alert-#{flash_notify.status}"} = flash_notify.body current_user.language - %a{:class=>"close", :'data-dismiss'=>"alert", :href=>"#", :id => 'close-alert'} × + %a.close#close-alert{:'data-dismiss'=>"alert", :href=>"#"} × - :javascript - var FLASH_HASH_ID = "#{flash_notify.hash_id}"; - var FLASH_EXPIRES_AT = "#{Date.today + 1.year}"; + :javascript + var FLASH_HASH_ID = "#{flash_notify.hash_id}"; + var FLASH_EXPIRES_AT = "#{Date.today + 1.year}"; diff --git a/config/locales/menu.en.yml b/config/locales/menu.en.yml index b12e73c29..5b6b58ac8 100644 --- a/config/locales/menu.en.yml +++ b/config/locales/menu.en.yml @@ -37,5 +37,6 @@ en: admins_menu: users: Users register_requests: Invites + flash_notifies: Notifies event_logs: Event log resque_server: Resque diff --git a/config/locales/menu.ru.yml b/config/locales/menu.ru.yml index 6850b6b00..e4a81ad6b 100644 --- a/config/locales/menu.ru.yml +++ b/config/locales/menu.ru.yml @@ -37,5 +37,6 @@ ru: admins_menu: users: Пользователи register_requests: Инвайты + flash_notifies: Оповещения event_logs: Лог событий resque_server: Resque diff --git a/config/routes.rb b/config/routes.rb index 6e7299f2d..9bedc15ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,8 +21,6 @@ Rosa::Application.routes.draw do root :to => 'activity_feeds#index' end - resources :flash_notifies - namespace :admin do resources :users do get :list, :on => :collection @@ -34,6 +32,7 @@ Rosa::Application.routes.draw do get :reject end end + resources :flash_notifies resources :event_logs, :only => :index constraints AdminAccess do mount Resque::Server => 'resque' diff --git a/db/schema.rb b/db/schema.rb index a23a418d6..88f4b829f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120703101719) do +ActiveRecord::Schema.define(:version => 20120719045806) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "version" end @@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "project_id" t.integer "arch_id" t.datetime "notified_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -137,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -155,8 +155,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "flash_notifies", :force => true do |t| @@ -170,8 +170,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -184,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -234,14 +234,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -250,8 +250,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" end @@ -267,8 +267,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "build_script" t.text "counter" t.text "ks" @@ -287,8 +287,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "platform_id" end @@ -297,25 +297,25 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true - t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" + t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false @@ -330,8 +330,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end @@ -344,16 +344,16 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "name", :null => false end @@ -364,8 +364,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -374,8 +374,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -385,21 +385,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" - t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.text "ssh_key" + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false t.datetime "reset_password_sent_at" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -408,11 +402,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" - t.integer "build_priority", :default => 50 + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" diff --git a/spec/controllers/flash_notifies_controller_spec.rb b/spec/controllers/admin/flash_notifies_controller_spec.rb similarity index 93% rename from spec/controllers/flash_notifies_controller_spec.rb rename to spec/controllers/admin/flash_notifies_controller_spec.rb index 169bbe8b5..ad7494fda 100644 --- a/spec/controllers/flash_notifies_controller_spec.rb +++ b/spec/controllers/admin/flash_notifies_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe FlashNotifiesController do +describe Admin::FlashNotifiesController do before(:each) do stub_symlink_methods @@ -68,7 +68,7 @@ describe FlashNotifiesController do it 'should be able to perform create action' do post :create, @create_params - response.should redirect_to(flash_notifies_path) + response.should redirect_to(admin_flash_notifies_path) end it 'should change objects count on create' do @@ -77,7 +77,7 @@ describe FlashNotifiesController do it 'should be able to perform destroy action' do delete :destroy, :id => @flash_notify - response.should redirect_to(flash_notifies_path) + response.should redirect_to(admin_flash_notifies_path) end it 'should change objects count on destroy' do @@ -86,7 +86,7 @@ describe FlashNotifiesController do it 'should be able to perform update action' do put :update, @update_params - response.should redirect_to(flash_notifies_path) + response.should redirect_to(admin_flash_notifies_path) end it 'should change flash notify body on update' do From 1362ee87c58d92059505f9868079825f47d1a1ff Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 25 Jul 2012 21:14:22 +0300 Subject: [PATCH 18/56] Add submenu for notifies section. Refs #576 --- app/views/admin/flash_notifies/edit.html.haml | 2 ++ app/views/admin/flash_notifies/index.html.haml | 1 + app/views/admin/flash_notifies/new.html.haml | 2 ++ 3 files changed, 5 insertions(+) diff --git a/app/views/admin/flash_notifies/edit.html.haml b/app/views/admin/flash_notifies/edit.html.haml index 89bed7609..a1f10e1cd 100644 --- a/app/views/admin/flash_notifies/edit.html.haml +++ b/app/views/admin/flash_notifies/edit.html.haml @@ -2,3 +2,5 @@ = form_for @flash_notify, :url => admin_flash_notify_path(@flash_notify), :html => { :class => :form } do |f| = render "form", :f => f + += render 'submenu' diff --git a/app/views/admin/flash_notifies/index.html.haml b/app/views/admin/flash_notifies/index.html.haml index 41a82be53..9578d1a0e 100644 --- a/app/views/admin/flash_notifies/index.html.haml +++ b/app/views/admin/flash_notifies/index.html.haml @@ -19,3 +19,4 @@ = will_paginate @flash_notifies += render 'submenu' diff --git a/app/views/admin/flash_notifies/new.html.haml b/app/views/admin/flash_notifies/new.html.haml index 301a12bab..0177e384e 100644 --- a/app/views/admin/flash_notifies/new.html.haml +++ b/app/views/admin/flash_notifies/new.html.haml @@ -2,3 +2,5 @@ = form_for @flash_notify, :url => admin_flash_notifies_path, :html => { :class => :form } do |f| = render "form", :f => f + += render 'submenu' From e3ee41294dd74974c19e91e9c96f48ede3eb1bf9 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 25 Jul 2012 21:21:52 +0300 Subject: [PATCH 19/56] Use current locale for message body display. Refs #576 --- app/views/layouts/_notifies.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_notifies.html.haml b/app/views/layouts/_notifies.html.haml index d2c3f8b1b..82ca70300 100644 --- a/app/views/layouts/_notifies.html.haml +++ b/app/views/layouts/_notifies.html.haml @@ -2,7 +2,7 @@ .flash_notify - if (flash_notify = FlashNotify.published.first) && flash_notify.should_show?(cookies[:flash_notify_hash]) .alert{:class => "alert-#{flash_notify.status}"} - = flash_notify.body current_user.language + = flash_notify.body I18n.locale %a.close#close-alert{:'data-dismiss'=>"alert", :href=>"#"} × :javascript From 6f4f48cbce74fc338dbab90f1fc5953b9db82c6b Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 26 Jul 2012 01:49:55 +0400 Subject: [PATCH 20/56] [issue #578] Fixed error handling in PresonalRepository. --- app/controllers/admin/users_controller.rb | 2 +- lib/modules/models/personal_repository.rb | 30 ++++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 91d5076b8..9e042ab3b 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -12,7 +12,7 @@ class Admin::UsersController < Admin::BaseController def create @user.role = params[:role] @user.confirmed_at = Time.now.utc - if @user.save + if (@user.save rescue false) flash[:notice] = t('flash.user.saved') redirect_to admin_users_path else diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index b821ce750..b5ca7bdb2 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -9,19 +9,25 @@ module Modules end def create_personal_repository - pl = own_platforms.build - pl.owner = self - pl.name = "#{self.uname}_personal" - pl.description = "#{self.uname}_personal" - pl.platform_type = 'personal' - pl.distrib_type = APP_CONFIG['distr_types'].first - pl.visibility = 'open' - pl.save! + begin + pl = own_platforms.build + pl.owner = self + pl.name = "#{self.uname}_personal" + pl.description = "#{self.uname}_personal" + pl.platform_type = 'personal' + pl.distrib_type = APP_CONFIG['distr_types'].first + pl.visibility = 'open' + pl.save! - rep = pl.repositories.build - rep.name = 'main' - rep.description = 'main' - rep.save! + rep = pl.repositories.build + rep.name = 'main' + rep.description = 'main' + rep.save! + rescue Exception => e + pl.now_destroy rescue false + raise e + end + return true end def personal_platform From f1839f0ad0bca8833f760834375ad528166edf3b Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 26 Jul 2012 02:12:06 +0400 Subject: [PATCH 21/56] [issue #578] Added submit blocking to user creation --- app/views/users/base/_form.html.haml | 2 +- config/locales/en.yml | 1 + config/locales/ru.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/users/base/_form.html.haml b/app/views/users/base/_form.html.haml index d88807a92..4baa5218e 100644 --- a/app/views/users/base/_form.html.haml +++ b/app/views/users/base/_form.html.haml @@ -43,5 +43,5 @@ .both .leftlist \  -.rightlist= submit_tag t("layout.save") +.rightlist= submit_tag t("layout.save"), :data => {:"disable-with" => t("layout.saving")} .both diff --git a/config/locales/en.yml b/config/locales/en.yml index 0b8acbf02..9abd215e8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -26,6 +26,7 @@ en: delete: Erase delete_selected: Remove selected save: Save + saving: Saving clone: Clone search_by_name: Filter by name are_you_sure: "Sure?" diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c2081b9f3..4b80c0c06 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -26,6 +26,7 @@ ru: delete: Удалить delete_selected: Удалить выбранное save: Сохранить + saving: Сохранение... clone: Клонировать search_by_name: Фильтр по имени are_you_sure: "Вы уверены?" From f9b217379d16b1921fa931b678876e67d12cd7f5 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 26 Jul 2012 15:45:23 +0400 Subject: [PATCH 22/56] [refs #570] Add mass build counters logs --- app/models/build_list.rb | 5 ++ app/models/counters_log.rb | 4 ++ app/models/mass_build.rb | 1 + .../20120726110848_create_counters_logs.rb | 11 +++++ db/schema.rb | 49 +++++++++++++------ 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 app/models/counters_log.rb create mode 100644 db/migrate/20120726110848_create_counters_logs.rb diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 5c7a151d7..f1b1da794 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -9,6 +9,7 @@ class BuildList < ActiveRecord::Base belongs_to :mass_build, :counter_cache => true has_many :items, :class_name => "BuildList::Item", :dependent => :destroy has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy + has_many :counters_logs, :dependent => :destroy UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage] RELEASE_UPDATE_TYPES = %w[security bugfix] @@ -100,6 +101,8 @@ class BuildList < ActiveRecord::Base after_commit :place_build after_destroy :delete_container + after_create lambda { |build_list| build_list.counters_logs.create(:status => build_list.status, :event => "create", :mass_build_id => build_list.mass_build_id) } + @queue = :clone_and_build state_machine :status, :initial => :waiting_for_response do @@ -108,12 +111,14 @@ class BuildList < ActiveRecord::Base before_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + build_list.counters_logs.create(:status => build_list.status, :event => "decrement", :mass_build_id => build_list.mass_build_id) end end after_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + build_list.counters_logs.create(:status => build_list.status, :event => "increment", :mass_build_id => build_list.mass_build_id) end end diff --git a/app/models/counters_log.rb b/app/models/counters_log.rb new file mode 100644 index 000000000..756471ad5 --- /dev/null +++ b/app/models/counters_log.rb @@ -0,0 +1,4 @@ +class CountersLog < ActiveRecord::Base + belongs_to :build_list + belongs_to :mass_build +end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 8cdc5c0f9..a756afd1b 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -2,6 +2,7 @@ class MassBuild < ActiveRecord::Base belongs_to :platform belongs_to :user has_many :build_lists, :dependent => :destroy + has_many :counters_logs, :dependent => :destroy scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } diff --git a/db/migrate/20120726110848_create_counters_logs.rb b/db/migrate/20120726110848_create_counters_logs.rb new file mode 100644 index 000000000..fdd3f9941 --- /dev/null +++ b/db/migrate/20120726110848_create_counters_logs.rb @@ -0,0 +1,11 @@ +class CreateCountersLogs < ActiveRecord::Migration + def change + create_table :counters_logs do |t| + t.integer :mass_build_id + t.integer :build_list_id + t.string :status + t.string :event + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 88f4b829f..c21808c13 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120719045806) do +ActiveRecord::Schema.define(:version => 20120726110848) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -143,6 +143,15 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.integer "project_id" end + create_table "counters_logs", :force => true do |t| + t.integer "mass_build_id" + t.integer "build_list_id" + t.string "status" + t.string "event" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "event_logs", :force => true do |t| t.integer "user_id" t.string "user_name" @@ -160,12 +169,12 @@ ActiveRecord::Schema.define(:version => 20120719045806) do end create_table "flash_notifies", :force => true do |t| - t.text "body_ru", :null => false - t.text "body_en", :null => false - t.string "status", :null => false - t.boolean "published", :default => true, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.text "body_ru" + t.text "body_en" + t.string "status" + t.boolean "published" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "groups", :force => true do |t| @@ -193,6 +202,15 @@ ActiveRecord::Schema.define(:version => 20120719045806) do 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" + t.integer "user_id" + t.integer "key_id" + t.string "public" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "labelings", :force => true do |t| t.integer "label_id", :null => false t.integer "issue_id" @@ -311,27 +329,25 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false - create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "interest" t.text "more" end @@ -385,6 +401,7 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" t.datetime "created_at" @@ -392,8 +409,11 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.string "uname" t.string "role" t.string "language", :default => "en" - t.datetime "reset_password_sent_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.integer "own_projects_count", :default => 0, :null => false + t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -405,9 +425,6 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end From 03cc4668dcb5415e6fffc26bf1683ab02c85b2bf Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 00:25:44 +0400 Subject: [PATCH 23/56] [issue #586] Custom JSON generators changed to JBuilder --- .../platforms/repositories_controller.rb | 5 ++- app/views/admin/users/_users_ajax.js.erb | 19 ------------ .../admin/users/_users_ajax.json.jbuilder | 21 +++++++++++++ .../platforms/repositories/_proj_ajax.js.erb | 15 --------- .../repositories/_proj_ajax.json.jbuilder | 12 +++++++ .../platforms/repositories/_project.js.erb | 31 ------------------- .../repositories/_project.json.jbuilder | 23 ++++++++++++++ 7 files changed, 60 insertions(+), 66 deletions(-) delete mode 100644 app/views/admin/users/_users_ajax.js.erb create mode 100644 app/views/admin/users/_users_ajax.json.jbuilder delete mode 100644 app/views/platforms/repositories/_proj_ajax.js.erb create mode 100644 app/views/platforms/repositories/_proj_ajax.json.jbuilder delete mode 100644 app/views/platforms/repositories/_project.js.erb create mode 100644 app/views/platforms/repositories/_project.json.jbuilder diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index d37caf8c6..22cf37d29 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -76,7 +76,10 @@ class Platforms::RepositoriesController < Platforms::BaseController @projects = Project.joins(owner_subquery).addable_to_repository(@repository.id) @projects = @projects.by_visibilities('open') if @repository.platform.platform_type == 'main' end - @projects = @projects.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength]) + @projects = @projects.paginate( + :page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1, + :per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25 + ) @total_projects = @projects.count @projects = @projects.search(params[:sSearch]).search_order if params[:sSearch].present? diff --git a/app/views/admin/users/_users_ajax.js.erb b/app/views/admin/users/_users_ajax.js.erb deleted file mode 100644 index 76db767ec..000000000 --- a/app/views/admin/users/_users_ajax.js.erb +++ /dev/null @@ -1,19 +0,0 @@ -{ - "sEcho": <%=h params[:sEcho].to_i || -1 %>, - "iTotalRecords": <%= @total_users %>, - "iTotalDisplayRecords": <%= @total_user %>, - "aaData": [ - <% @users.each do |user| %> - [ - "<%= user.name %>", - "<%= user.uname %>", - "<%= user.email %>", - "'><%= user.role %>", - "<%= j raw [(link_to t('layout.show'), user if can? :read, user), - (link_to t('layout.edit'), edit_admin_user_path(user) if can? :edit, user), - (link_to t('layout.delete'), admin_user_path(user), :method => :delete, :confirm => t('layout.users.confirm_delete') if can? :destroy, user) - ].compact.join(' | ') %>" - ]<%= user == @users.last ? '' : ',' %> - <% end %> - ] -} diff --git a/app/views/admin/users/_users_ajax.json.jbuilder b/app/views/admin/users/_users_ajax.json.jbuilder new file mode 100644 index 000000000..62504692e --- /dev/null +++ b/app/views/admin/users/_users_ajax.json.jbuilder @@ -0,0 +1,21 @@ +users = @users.map do |user| + link_block = [ + (link_to t('layout.show'), user if can? :read, user), + (link_to t('layout.edit'), edit_admin_user_path(user) if can? :edit, user), + (link_to t('layout.delete'), admin_user_path(user), :method => :delete, :confirm => t('layout.users.confirm_delete') if can? :destroy, user) + ].compact.join(' | ').html_safe + + [ + user.name, + user.uname, + user.email, + content_tag(:span, user.role, :style => user.access_locked? ? 'background: #FEDEDE' : ''), + link_block + ] +end + + +json.sEcho params[:sEcho].to_i || -1 +json.iTotalRecords @total_users +json.iTotalDisplayRecords @total_user +json.aaData users diff --git a/app/views/platforms/repositories/_proj_ajax.js.erb b/app/views/platforms/repositories/_proj_ajax.js.erb deleted file mode 100644 index 3058ffbb2..000000000 --- a/app/views/platforms/repositories/_proj_ajax.js.erb +++ /dev/null @@ -1,15 +0,0 @@ -{ - "sEcho": <%=h params[:sEcho].to_i || -1 %>, - "iTotalRecords": <%= @total_projects %>, - "iTotalDisplayRecords": <%= @total_project %>, - "aaData": [ - <% @projects.each do |project| %> - [ - "<%=j link_to(project.name_with_owner, project) %>", - "<%= truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' ') %>", - "<%=j link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id) %>" - ]<%= project == @projects.last ? '' : ',' %> - <% end %> - ] -} - diff --git a/app/views/platforms/repositories/_proj_ajax.json.jbuilder b/app/views/platforms/repositories/_proj_ajax.json.jbuilder new file mode 100644 index 000000000..1676111c1 --- /dev/null +++ b/app/views/platforms/repositories/_proj_ajax.json.jbuilder @@ -0,0 +1,12 @@ +projs = @projects.map do |project| + [ + link_to(project.name_with_owner, project), + truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' '), + link_to(t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id)) + ] +end + +json.sEcho params[:sEcho] || -1 +json.iTotalRecords @total_projects +json.iTotalDisplayRecords @total_project +json.aaData projs diff --git a/app/views/platforms/repositories/_project.js.erb b/app/views/platforms/repositories/_project.js.erb deleted file mode 100644 index 2dd623397..000000000 --- a/app/views/platforms/repositories/_project.js.erb +++ /dev/null @@ -1,31 +0,0 @@ -{ - "sEcho": <%=h params[:sEcho].to_i || -1 %>, - "iTotalRecords": <%= @total_projects %>, - "iTotalDisplayRecords": <%= @total_project %>, - "aaData": [ - <% @projects.each do |project| %> - [ - "<%=( - "
" + - j(image_tag(visibility_icon(project.visibility))) + - "
" + - "
" + - j(link_to("#{project.owner.respond_to?(:uname) ? project.owner.uname : project.owner.name} / #{project.name}", project)) + - "
").html_safe - %>", - "<%= truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' ') %>", - "<%= - if can? :remove_project, @repository - j(link_to(' '.html_safe, - remove_project_platform_repository_path(@platform, @repository, :project_id => project.id), - :method => :delete, :confirm => t("layout.confirm") - ) - ) - else - '' - end - %>" - ]<%= project == @projects.last ? '' : ',' %> - <% end %> - ] -} diff --git a/app/views/platforms/repositories/_project.json.jbuilder b/app/views/platforms/repositories/_project.json.jbuilder new file mode 100644 index 000000000..dd1413886 --- /dev/null +++ b/app/views/platforms/repositories/_project.json.jbuilder @@ -0,0 +1,23 @@ + projs = @projects.map do |pr| + [ + content_tag(:div, image_tag(visibility_icon(pr.visibility)), :class => 'table-sort-left') + + content_tag(:div, link_to(pr.name_with_owner, pr), :class => 'table-sort-right'), + + truncate(pr.description || '', :length => 60).gsub(/\n|\r|\t/, ' '), + + if can? :remove_project, @repository + link_to( + remove_project_platform_repository_path(@platform, @repository, :project_id => pr.id), + :method => :delete, :confirm => t("layout.confirm")) do + content_tag(:span, " ".html_safe, :class => 'delete') + end + else + '' + end + ] + end + +json.sEcho params[:sEcho].to_i || -1 +json.iTotalRecords @total_projects +json.iTotalDisplayRecords @total_project +json.aaData projs From 35e673d44e9f5369c593e46bfc19f8ed49ba4bb6 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 27 Jul 2012 00:15:57 +0300 Subject: [PATCH 24/56] Minor gems update. Fix string length, refactor git helper and module, add branches_and_tags method, refactor build_list filter, cleanup and refactor templates. Take back test. Filter incorrect symbols during git encoding fix. Fix git http level bug. Refs #263 --- Gemfile | 4 +- Gemfile.lock | 24 ++++----- .../projects/build_lists_controller.rb | 3 +- app/helpers/git_helper.rb | 14 +++--- app/models/build_list/filter.rb | 6 +-- app/models/comment.rb | 4 +- app/views/projects/git/blobs/_show.html.haml | 1 - app/views/projects/git/blobs/_top.html.haml | 6 +-- .../projects/git/commits/_show.html.haml | 1 - app/views/projects/git/trees/_show.html.haml | 4 +- lib/ext/core/string.rb | 35 ++++++------- lib/ext/git/grit.rb | 2 +- lib/ext/rails/constraint.rb | 49 ------------------- lib/ext/rails/middleware.rb | 18 ------- lib/ext/rosa/constraints.rb | 4 +- lib/modules/models/git.rb | 24 ++------- lib/plugins/grack/base.rb | 2 +- .../platforms/mass_builds_controller_spec.rb | 5 ++ spec/routing/projects_routing_spec.rb.rb | 3 +- 19 files changed, 63 insertions(+), 146 deletions(-) delete mode 100644 lib/ext/rails/constraint.rb delete mode 100644 lib/ext/rails/middleware.rb diff --git a/Gemfile b/Gemfile index 01a5c745a..0ace218c6 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'omniauth-openid', '~> 1.0.1' gem 'cancan', '1.6.7' # 1.6.8 fail specs with strange error gem 'ancestry', '~> 1.3.0' -gem 'paperclip', '~> 3.1.3' +gem 'paperclip', '~> 3.1.4' gem 'resque', '~> 1.21.0' gem 'resque-status', '~> 0.3.3' gem 'resque_mailer', '~> 2.1.0' @@ -27,7 +27,7 @@ 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' gem 'charlock_holmes', '~> 0.6.8' #, :git => 'git://github.com/brianmario/charlock_holmes.git', :branch => 'bundle-icu' # gem 'ruby-filemagic', '~> 0.4.2', :require => 'filemagic/ext' -gem 'github-linguist', '~> 2.0.1', :require => 'linguist' +gem 'github-linguist', '~> 2.1.2', :require => 'linguist' gem 'diff-display', '~> 0.0.1' # Wiki diff --git a/Gemfile.lock b/Gemfile.lock index 5d9e2545f..1ff9bd23d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,12 +117,12 @@ GEM railties (>= 3.0.0) ffi (1.0.11) fssm (0.2.9) - github-linguist (2.0.1) + github-linguist (2.1.2) charlock_holmes (~> 0.6.6) escape_utils (~> 0.2.3) mime-types (~> 1.18) - pygments.rb (~> 0.2.13) - github-markup (0.7.2) + pygments.rb (>= 0.2.13) + github-markup (0.7.4) gollum (1.3.1) albino (~> 1.3.2) github-markup (>= 0.4.0, < 1.0.0) @@ -150,7 +150,7 @@ GEM jquery-rails (2.0.2) railties (>= 3.2.0, < 5.0) thor (~> 0.14) - json (1.7.3) + json (1.7.4) kgio (2.7.4) libv8 (3.3.10.4) macaddr (1.6.1) @@ -159,7 +159,7 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mailcatcher (0.5.7.2) + mailcatcher (0.5.8) activesupport (~> 3.0) eventmachine (~> 0.12) haml (~> 3.1) @@ -189,7 +189,7 @@ GEM omniauth (~> 1.0) rack-openid (~> 1.3.1) orm_adapter (0.4.0) - paperclip (3.1.3) + paperclip (3.1.4) activemodel (>= 3.0.0) activerecord (>= 3.0.0) activesupport (>= 3.0.0) @@ -267,8 +267,8 @@ GEM rspec-core (~> 2.11.0) rspec-expectations (~> 2.11.0) rspec-mocks (~> 2.11.0) - rspec-core (2.11.0) - rspec-expectations (2.11.1) + rspec-core (2.11.1) + rspec-expectations (2.11.2) diff-lcs (~> 1.1.3) rspec-mocks (2.11.1) rspec-rails (2.11.0) @@ -285,7 +285,7 @@ GEM ffi (~> 1.0.7) russian (0.6.0) i18n (>= 0.5.0) - rvm-capistrano (1.2.3) + rvm-capistrano (1.2.5) capistrano (>= 2.0.0) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) @@ -296,7 +296,7 @@ GEM tilt (~> 1.3) shotgun (0.9) rack (>= 1.0) - shoulda (3.1.0) + shoulda (3.1.1) shoulda-context (~> 1.0) shoulda-matchers (~> 1.2) shoulda-context (1.0.0) @@ -368,7 +368,7 @@ DEPENDENCIES devise (~> 2.1.2) diff-display (~> 0.0.1) factory_girl_rails (~> 3.5.0) - github-linguist (~> 2.0.1) + github-linguist (~> 2.1.2) gollum (= 1.3.1) grack! grit! @@ -382,7 +382,7 @@ DEPENDENCIES newrelic_rpm (~> 3.4.0.1) omniauth (~> 1.1.0) omniauth-openid (~> 1.0.1) - paperclip (~> 3.1.3) + paperclip (~> 3.1.4) perform_later (~> 1.3.0) pg (~> 0.14.0) rails (= 3.2.6) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index eea85eb9c..ce7364d52 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -46,7 +46,8 @@ class Projects::BuildListsController < Projects::BaseController Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[: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.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 diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index f3ea0bdc6..753db6e64 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -47,7 +47,6 @@ module GitHelper end end - # TODO This is very dirty hack. Maybe need to be changed. def branch_selector_options(project) p = params.dup p.delete(:path) if p[:path].present? # to root path @@ -55,18 +54,17 @@ module GitHelper current = url_for(p).split('?', 2).first res = [] - res << [I18n.t('layout.git.repositories.commits'), [truncate(params[:treeish], :length => 20)]] unless (project.repo.branches + project.repo.tags).map(&:name).include?(params[:treeish] || project.default_branch) - res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map{|b| [truncate(b.name, :length => 20), url_for(p.merge :treeish => b.name).split('?', 2).first]}] - res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map{|t| [truncate(t.name, :length => 20), url_for(p.merge :treeish => t.name).split('?', 2).first]}] + 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) + 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.tags'), project.repo.tags.map(&linking)] grouped_options_for_select(res, current) end def versions_for_group_select(project) - [ - ['Branches', project.repo.branches.map{|b| "latest_#{b.name}"}], - ['Tags', project.repo.tags.map(&:name)] - ] + [ ['Branches', project.repo.branches.map{|b| "latest_#{b.name}"}], + ['Tags', project.repo.tags.map(&:name)] ] end def split_commits_by_date(commits) diff --git a/app/models/build_list/filter.rb b/app/models/build_list/filter.rb index 7de174460..48f0b59cc 100644 --- a/app/models/build_list/filter.rb +++ b/app/models/build_list/filter.rb @@ -53,12 +53,12 @@ class BuildList::Filter })) @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned') - @options[:status] = @options[:status].present? ? @options[:status].to_i : nil + @options[:status] = @options[:status].try(:to_i) @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[:project_version] = @options[:project_version].presence - @options[:arch_id] = @options[:arch_id].present? ? @options[:arch_id].to_i : nil - @options[:platform_id] = @options[:platform_id].present? ? @options[:platform_id].to_i : nil + @options[:arch_id] = @options[:arch_id].try(:to_i) + @options[:platform_id] = @options[:platform_id].try(:to_i) @options[:is_circle] = @options[:is_circle].present? ? @options[:is_circle] == "1" : nil @options[:bs_id] = @options[:bs_id].presence @options[:project_name] = @options[:project_name].presence diff --git a/app/models/comment.rb b/app/models/comment.rb index f73fa7d67..6960860cc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -15,7 +15,9 @@ class Comment < ActiveRecord::Base attr_accessible :body def commentable - commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super + # raise commentable_id.inspect + # raise commentable_id.to_s(16).inspect + commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super # TODO leading zero problem end def commentable=(c) diff --git a/app/views/projects/git/blobs/_show.html.haml b/app/views/projects/git/blobs/_show.html.haml index 3f686249c..b808cefc1 100644 --- a/app/views/projects/git/blobs/_show.html.haml +++ b/app/views/projects/git/blobs/_show.html.haml @@ -1,4 +1,3 @@ -/ - raise @blob.file_mime_type.inspect %h3= t("layout.projects.files_in_project") .files .l= render 'whereami' diff --git a/app/views/projects/git/blobs/_top.html.haml b/app/views/projects/git/blobs/_top.html.haml index a3631075d..3fa62790b 100644 --- a/app/views/projects/git/blobs/_top.html.haml +++ b/app/views/projects/git/blobs/_top.html.haml @@ -6,15 +6,15 @@ \| = number_to_human_size @blob.size .r - - if @blob.render_as == :text and can? :write, @project and @branch.present? + - if @blob.render_as == :text && can?(:write, @project) && @branch.present? = link_to "Edit", edit_blob_path(@project, @treeish, @path) \| - - if @blob.render_as == :text and params[:action] != 'show' + - if @blob.render_as == :text && params[:action] != 'show' = link_to "Normal", blob_path(@project, @treeish, @path) \| = link_to "Raw", raw_path(@project, @treeish, @path) \| - - if @blob.render_as == :text and params[:action] != 'blame' + - if @blob.render_as == :text && params[:action] != 'blame' = link_to "Blame", blame_path(@project, @treeish, @path) \| = link_to "History", commits_path(@project, @treeish, @path) diff --git a/app/views/projects/git/commits/_show.html.haml b/app/views/projects/git/commits/_show.html.haml index 9e6e6a30c..9815b5e2d 100644 --- a/app/views/projects/git/commits/_show.html.haml +++ b/app/views/projects/git/commits/_show.html.haml @@ -13,7 +13,6 @@ -begin = render_commit_stats(stats) - = render :partial => 'commit_diff', :collection => @commit.diffs - rescue Grit::Git::GitTimeout %p= t 'layout.git.repositories.commit_diff_too_big' diff --git a/app/views/projects/git/trees/_show.html.haml b/app/views/projects/git/trees/_show.html.haml index 2bf2868aa..35bae8bea 100644 --- a/app/views/projects/git/trees/_show.html.haml +++ b/app/views/projects/git/trees/_show.html.haml @@ -31,7 +31,7 @@ .pic= image_tag 'folder.png' .name= link_to(entry.name, tree_path(@project, @treeish, entry_path), :class => 'files-see') %td - %span{:style => "display: none;"}= commit.committed_date || commit.authored_date - = l(commit.committed_date || commit.authored_date, :format => :short) + %span{:style => "display: none;"}= date = commit.committed_date || commit.authored_date + = l(date, :format => :short) %td= commit.short_message %td= (commit.committer || commit.author).name \ No newline at end of file diff --git a/lib/ext/core/string.rb b/lib/ext/core/string.rb index a8640324f..8e6e7d293 100644 --- a/lib/ext/core/string.rb +++ b/lib/ext/core/string.rb @@ -1,27 +1,24 @@ # -*- encoding : utf-8 -*- require 'charlock_holmes/string' -# require 'iconv' class String def default_encoding! - if ascii_only? - force_encoding(Encoding.default_internal || Encoding::UTF_8) - else - force_encoding((detected = detect_encoding and detected[:encoding]) || Encoding.default_internal || Encoding::UTF_8).encode! + default_encoding = Encoding.default_internal || Encoding::UTF_8 + if ascii_only? # no need to encode if ascii + force_encoding(default_encoding) + else # should encode + if (detected = detect_encoding) && detected[:encoding] + force_encoding(detected[:encoding]) + encode!(default_encoding, detected[:encoding], :invalid => :replace, :undef => :replace, :replace => '') + end + # re-encode through UTF-16 to filter incorrect symbols + encode!(Encoding::UTF_16, default_encoding, :invalid => :replace, :undef => :replace, :replace => '') + encode!(default_encoding, Encoding::UTF_16) + raise unless valid_encoding? # check result end + rescue + replace "--broken encoding: #{detect_encoding[:encoding] || 'unknown'}" + ensure + self end - - # def enforce_utf8(from = nil) - # begin - # is_utf8? ? self : ::Iconv.iconv('utf8', from, self).first - # rescue - # converter = ::Iconv.new('UTF-8//IGNORE//TRANSLIT', 'ASCII//IGNORE//TRANSLIT') - # # If Ruby 1.9, else another RubyEngine (ree, Ruby 1.8) - # begin - # converter.iconv(self).unpack('U*').select{|cp| cp < 127}.pack('U*').force_encoding('utf-8') - # rescue - # converter.iconv(self).unpack('U*').select{|cp| cp < 127}.pack('U*') - # end - # end - # end end diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 43195530c..6a0095de3 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -62,7 +62,7 @@ module Grit end protected - + # store all associated MIME::Types inside class def set_associated_mimes @associated_mimes ||= [] diff --git a/lib/ext/rails/constraint.rb b/lib/ext/rails/constraint.rb deleted file mode 100644 index 9a4b707f2..000000000 --- a/lib/ext/rails/constraint.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -*- encoding : utf-8 -*- -class OwnerConstraint - def initialize(class_name, bang = false) - @class_name = class_name - @finder = 'find_by_insensitive_uname' - @finder << '!' if bang - end - - def matches?(request) - @class_name.send(@finder, request.params[:uname]).present? - end -end - -class AdminAccess - def self.matches?(request) - !!request.env['warden'].user.try(:admin?) - end -end - -class TreeishConstraint - def self.matches?(request) - # raise request.params.inspect - # params = request.env['action_dispatch.request.path_parameters'] || request.params - params = request.path_parameters - if params[:treeish] # parse existing branch (tag) and path - branch_or_tag = begin - (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && - (p.repo.branches + p.repo.tags).detect{|t| params[:treeish].start_with?(t.name)}.try(:name) || - params[:treeish].split('/').first - end - if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present? - params[:path] = File.join([path, params[:path]].compact) - end - params[:treeish] = branch_or_tag - end - true - end - - # def set_treeish_and_path - # if params[:treeish] and params[:path] and # try to correct branch with slashes - # treeish_with_path = File.join(params[:treeish], params[:path]) and - # branch_name = @project.repo.branches.detect{|t| treeish_with_path.start_with?(t.name)}.try(:name) - # params[:treeish] = branch_name - # params[:path] = treeish_with_path.sub(branch_name, '')[1..-1] - # end - # @treeish = params[:treeish].presence || @project.default_branch - # @path = params[:path] - # end -end diff --git a/lib/ext/rails/middleware.rb b/lib/ext/rails/middleware.rb deleted file mode 100644 index be6da8940..000000000 --- a/lib/ext/rails/middleware.rb +++ /dev/null @@ -1,18 +0,0 @@ -# class ParamsParser -# DEFAULT_PARSERS = { -# Mime::XML => :xml_simple, -# Mime::JSON => :json -# } -# -# def initialize(app, parsers = {}) -# @app, @parsers = app, DEFAULT_PARSERS.merge(parsers) -# end -# -# def call(env) -# if params = parse_formatted_parameters(env) -# env["action_dispatch.request.request_parameters"] = params -# end -# -# @app.call(env) -# end -# end diff --git a/lib/ext/rosa/constraints.rb b/lib/ext/rosa/constraints.rb index 8cbf1b26c..54e9e6191 100644 --- a/lib/ext/rosa/constraints.rb +++ b/lib/ext/rosa/constraints.rb @@ -21,13 +21,11 @@ module Rosa class Treeish def self.matches?(request) - # raise request.params.inspect - # params = request.env['action_dispatch.request.path_parameters'] || request.params params = request.path_parameters if params[:treeish] # parse existing branch (tag) and path branch_or_tag = begin (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && - (p.repo.branches + p.repo.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) || params[:treeish].split('/').first end if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present? diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index e58ac3b25..4cf2baafc 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -60,11 +60,8 @@ module Modules end def paginate_commits(treeish, options = {}) - options[:page] = 1 unless options[:page].present? - options[:page] = options[:page].to_i - - options[:per_page] = 20 unless options[:per_page].present? - options[:per_page] = options[:per_page].to_i + options[:page] = options[:page].try(:to_i) || 1 + options[:per_page] = options[:per_page].try(:to_i) || 20 skip = options[:per_page] * (options[:page] - 1) last_page = (skip + options[:per_page]) >= repo.commit_count(treeish) @@ -72,26 +69,13 @@ module Modules [repo.commits(treeish, options[:per_page], skip), options[:page], last_page] end - def last_active_branch - @last_active_branch ||= repo.branches.inject do |r, c| - r_last = r.commit.committed_date || r.commit.authored_date unless r.nil? - c_last = c.commit.committed_date || c.commit.authored_date - if r.nil? or r_last < c_last - r = c - end - r - end - @last_active_branch - end - def tree_info(tree, treeish = nil, path = nil) - treeish = tree.id unless treeish.present? + treeish ||= tree.id # initialize result as hash of => nil res = (tree.trees.sort + tree.blobs.sort).inject({}){|h, e| h.merge!({e => nil})} # fills result vith commits that describes this file res = res.inject(res) do |h, (entry, commit)| - # only if commit == nil ... - if commit.nil? and entry.respond_to? :name + if commit.nil? and entry.respond_to?(:name) # only if commit == nil # ... find last commit corresponds to this file ... c = repo.log(treeish, File.join([path, entry.name].compact), :max_count => 1).first # ... and add it to result. diff --git a/lib/plugins/grack/base.rb b/lib/plugins/grack/base.rb index b464f44ee..99b2d160b 100644 --- a/lib/plugins/grack/base.rb +++ b/lib/plugins/grack/base.rb @@ -35,7 +35,7 @@ module Grack def project @project ||= begin uname, name = @env['PATH_INFO'].split('/')[1,2] - name.gsub!(/\.git$/, '').gsub!(/\.wiki$/, '') + name.gsub!(/(\.wiki)?\.git$/, '') Project.find_by_owner_and_name uname, name end end diff --git a/spec/controllers/platforms/mass_builds_controller_spec.rb b/spec/controllers/platforms/mass_builds_controller_spec.rb index 357d66d94..1cd611d72 100644 --- a/spec/controllers/platforms/mass_builds_controller_spec.rb +++ b/spec/controllers/platforms/mass_builds_controller_spec.rb @@ -104,6 +104,11 @@ describe Platforms::MassBuildsController do response.should redirect_to(new_user_session_path) end + it "should not be able to perform cancel action" do + post :cancel, :platform_id => @platform, :id => @mass_build + response.should redirect_to(new_user_session_path) + end + it 'should not change objects count on create success' do lambda { post :create, @create_params }.should change{ MassBuild.count }.by(0) end diff --git a/spec/routing/projects_routing_spec.rb.rb b/spec/routing/projects_routing_spec.rb.rb index 6f964e50c..caa2042ee 100644 --- a/spec/routing/projects_routing_spec.rb.rb +++ b/spec/routing/projects_routing_spec.rb.rb @@ -13,7 +13,7 @@ describe Projects::ProjectsController do end it "routes to #edit" do - get("/import/glib2.0-mib/edit").should route_to("projects/projects#edit", :owner_name => 'import', :project_name => 'glib2.0-mib') + get("/import/glib2.0-mib/modify").should route_to("projects/projects#edit", :owner_name => 'import', :project_name => 'glib2.0-mib') end it "routes to #create" do @@ -39,6 +39,7 @@ describe Projects::Git::TreesController do get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'lib2safe-0.03') get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch-with.dot', :path => 'folder_with.dot/path-with.dot') # get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'ветка-с.точкой', :path => 'папка_с.точкой/путь-с.точкой') + get("/import/glib2.0-mib/tree/branch-with/slash.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch-with/slash.dot', :path => 'folder_with.dot/path-with.dot') get("/import/glib2.0-mib/tree/tag13.52-5").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'tag13.52-5') end From 566cd8209b863fec0eb195b19035c79fec61c802 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 27 Jul 2012 00:24:14 +0300 Subject: [PATCH 25/56] Take back branches_and_repos method. Refs #263 --- lib/ext/git/grit.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 6a0095de3..4fa2f11f3 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -82,6 +82,12 @@ module Grit return 1 end end + + class Repo + def branches_and_tags + branches + tags # @branches_and_tags ||= # ??? + end + end end Grit::Git.git_timeout = 60 From 3e4c03dd6a6a6ef64778ca5efaf769334dccd752 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 01:44:15 +0400 Subject: [PATCH 26/56] [issue #583] Added missing check to BuildList page --- app/views/projects/build_lists/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index f061efcf3..cc977cae8 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -85,7 +85,7 @@ = link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list), :method => :put, :confirm => t("layout.confirm"), :class => 'button' - - if @build_list.can_publish? and @build_list.save_to_platform.released and @build_list.advisory.nil? + - if @build_list.can_publish? and @build_list.save_to_platform.released and @build_list.advisory.nil? and can?(:publish, @build_list) #advisory_block .leftlist= label_tag :attach_advisory, t("layout.build_lists.attached_advisory") .rightlist From bc2eb541f30a5d3dacecc61b81f59896d461c011 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 27 Jul 2012 03:17:37 +0400 Subject: [PATCH 27/56] [refs #583] Change and to && --- app/views/projects/build_lists/show.html.haml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index cc977cae8..f0f3f1d19 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -35,7 +35,7 @@ .both .leftlist= t("activerecord.attributes.build_list.update_type") .rightlist - - if @build_list.can_publish? and can?(:publish, @build_list) + - if @build_list.can_publish? && can?(:publish, @build_list) = f.select :update_type, options_for_select(build_list_classified_update_types, @build_list.update_type) - else = @build_list.update_type @@ -81,11 +81,11 @@ = "#{@build_list.human_current_duration} / #{@build_list.project.human_average_build_time}" .both - - if @build_list.can_cancel? and can?(:cancel, @build_list) + - if @build_list.can_cancel? && can?(:cancel, @build_list) = link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list), :method => :put, :confirm => t("layout.confirm"), :class => 'button' - - if @build_list.can_publish? and @build_list.save_to_platform.released and @build_list.advisory.nil? and can?(:publish, @build_list) + - if @build_list.can_publish? && @build_list.save_to_platform.released && @build_list.advisory.nil? && can?(:publish, @build_list) #advisory_block .leftlist= label_tag :attach_advisory, t("layout.build_lists.attached_advisory") .rightlist @@ -123,8 +123,8 @@ var r = new Rosa.Routers.BuildListsAdvisoriesRouter(); }); - = submit_tag t("layout.publish"), :confirm => t("layout.confirm"), :name => 'publish' if @build_list.can_publish? and can?(:publish, @build_list) - = submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish' if @build_list.can_reject_publish? and can?(:reject_publish, @build_list) + = submit_tag t("layout.publish"), :confirm => t("layout.confirm"), :name => 'publish' if @build_list.can_publish? && can?(:publish, @build_list) + = submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish' if @build_list.can_reject_publish? && can?(:reject_publish, @build_list) .hr %h3= t("layout.build_lists.items_header") From 40b0bb4b5882ad5ef0500d1e33671237b67da79f Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 08:12:09 +0400 Subject: [PATCH 28/56] [issue #551] by_object changed to by_actor. --- app/controllers/groups/profile_controller.rb | 2 +- app/controllers/projects/projects_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/groups/profile_controller.rb b/app/controllers/groups/profile_controller.rb index 30b62c795..1fd4ebab5 100644 --- a/app/controllers/groups/profile_controller.rb +++ b/app/controllers/groups/profile_controller.rb @@ -49,7 +49,7 @@ class Groups::ProfileController < Groups::BaseController end def remove_user - Relation.by_object(current_user).by_target(@group).destroy_all + Relation.by_actor(current_user).by_target(@group).destroy_all redirect_to groups_path end end diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index b948f5d7c..320f7dab2 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -85,7 +85,7 @@ class Projects::ProjectsController < Projects::BaseController end def remove_user - @project.relations.by_object(current_user).destroy_all + @project.relations.by_actor(current_user).destroy_all flash[:notice] = t("flash.project.user_removed") redirect_to projects_path end From b476f7248c6d21e983aa5273f9234a0ebb552901 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 27 Jul 2012 13:47:23 +0300 Subject: [PATCH 29/56] Minor refactor. Refs #263 --- lib/ext/core/string.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ext/core/string.rb b/lib/ext/core/string.rb index 8e6e7d293..e84bca715 100644 --- a/lib/ext/core/string.rb +++ b/lib/ext/core/string.rb @@ -7,13 +7,12 @@ class String if ascii_only? # no need to encode if ascii force_encoding(default_encoding) else # should encode + options = {:invalid => :replace, :undef => :replace, :replace => ''} if (detected = detect_encoding) && detected[:encoding] - force_encoding(detected[:encoding]) - encode!(default_encoding, detected[:encoding], :invalid => :replace, :undef => :replace, :replace => '') + force_encoding(detected[:encoding]).encode!(default_encoding, detected[:encoding], options) end # re-encode through UTF-16 to filter incorrect symbols - encode!(Encoding::UTF_16, default_encoding, :invalid => :replace, :undef => :replace, :replace => '') - encode!(default_encoding, Encoding::UTF_16) + encode!(Encoding::UTF_16, default_encoding, options).encode!(default_encoding, Encoding::UTF_16) raise unless valid_encoding? # check result end rescue From 548fb99ebe80a625d123490d6d555807e330f372 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 27 Jul 2012 16:28:08 +0400 Subject: [PATCH 30/56] [refs #570] Try to do counters change into transaction with locking --- app/models/build_list.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f1b1da794..3de142fcb 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -110,14 +110,20 @@ class BuildList < ActiveRecord::Base # WTF? around_transition -> infinite loop before_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + #MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + MassBuild.transaction do + MassBuild.lock(true).decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + end build_list.counters_logs.create(:status => build_list.status, :event => "decrement", :mass_build_id => build_list.mass_build_id) end end after_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + #MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + MassBuild.transaction do + MassBuild.lock(true).increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + end build_list.counters_logs.create(:status => build_list.status, :event => "increment", :mass_build_id => build_list.mass_build_id) end end From bbb03d3243528e5d3e9a59184153877902d58bff Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 16:40:13 +0400 Subject: [PATCH 31/56] [issue #586] Removed @total_project & @total_user. --- app/controllers/admin/users_controller.rb | 1 - app/controllers/platforms/repositories_controller.rb | 3 +-- app/views/admin/users/_users_ajax.json.jbuilder | 2 +- app/views/platforms/repositories/_proj_ajax.json.jbuilder | 2 +- app/views/platforms/repositories/_project.json.jbuilder | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 91d5076b8..e162ba918 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -60,7 +60,6 @@ class Admin::UsersController < Admin::BaseController end @filter = params[:filter] || 'all' @users = @users.send(@filter) if ['real', 'admin', 'banned'].include? @filter - @total_user = @users.count @users = @users.order(order) render :partial => 'users_ajax', :layout => false diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index 22cf37d29..7e617e7d5 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -81,9 +81,8 @@ class Platforms::RepositoriesController < Platforms::BaseController :per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25 ) - @total_projects = @projects.count + @total_projects_count = @projects.count @projects = @projects.search(params[:sSearch]).search_order if params[:sSearch].present? - @total_project = @projects.count @projects = @projects.order(order) render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false diff --git a/app/views/admin/users/_users_ajax.json.jbuilder b/app/views/admin/users/_users_ajax.json.jbuilder index 62504692e..f595d528d 100644 --- a/app/views/admin/users/_users_ajax.json.jbuilder +++ b/app/views/admin/users/_users_ajax.json.jbuilder @@ -17,5 +17,5 @@ end json.sEcho params[:sEcho].to_i || -1 json.iTotalRecords @total_users -json.iTotalDisplayRecords @total_user +json.iTotalDisplayRecords @users.count json.aaData users diff --git a/app/views/platforms/repositories/_proj_ajax.json.jbuilder b/app/views/platforms/repositories/_proj_ajax.json.jbuilder index 1676111c1..39d2b7a3a 100644 --- a/app/views/platforms/repositories/_proj_ajax.json.jbuilder +++ b/app/views/platforms/repositories/_proj_ajax.json.jbuilder @@ -8,5 +8,5 @@ end json.sEcho params[:sEcho] || -1 json.iTotalRecords @total_projects -json.iTotalDisplayRecords @total_project +json.iTotalDisplayRecords @projects.count json.aaData projs diff --git a/app/views/platforms/repositories/_project.json.jbuilder b/app/views/platforms/repositories/_project.json.jbuilder index dd1413886..f3e1a20c2 100644 --- a/app/views/platforms/repositories/_project.json.jbuilder +++ b/app/views/platforms/repositories/_project.json.jbuilder @@ -19,5 +19,5 @@ json.sEcho params[:sEcho].to_i || -1 json.iTotalRecords @total_projects -json.iTotalDisplayRecords @total_project +json.iTotalDisplayRecords @projects.count json.aaData projs From d5b0c96d1ea81a8b515304d77dcd2af746f660b5 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 17:17:37 +0400 Subject: [PATCH 32/56] [issue #551] Added spec. --- spec/controllers/groups/profile_controller_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/controllers/groups/profile_controller_spec.rb b/spec/controllers/groups/profile_controller_spec.rb index 21c62b7df..3b331ef68 100644 --- a/spec/controllers/groups/profile_controller_spec.rb +++ b/spec/controllers/groups/profile_controller_spec.rb @@ -144,6 +144,15 @@ describe Groups::ProfileController do @group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') end + it "should remove user from groups" do + get :remove_user, :id => @group + response.should redirect_to(groups_path) + end + + it "should change relations count" do + lambda { get :remove_user, :id => @group }.should change{ Relation.count }.by(-1) + end + it_should_behave_like 'no group user' it_should_behave_like 'group user without destroy rights' it_should_behave_like 'group user without update rights' From 2efb1030843600516e2fe4e19ecf4356ed9f90b2 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 17:27:24 +0400 Subject: [PATCH 33/56] [issue #551] Changed get to delete in spec. --- spec/controllers/groups/profile_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/groups/profile_controller_spec.rb b/spec/controllers/groups/profile_controller_spec.rb index 3b331ef68..a0e29c31b 100644 --- a/spec/controllers/groups/profile_controller_spec.rb +++ b/spec/controllers/groups/profile_controller_spec.rb @@ -145,12 +145,12 @@ describe Groups::ProfileController do end it "should remove user from groups" do - get :remove_user, :id => @group + delete :remove_user, :id => @group response.should redirect_to(groups_path) end it "should change relations count" do - lambda { get :remove_user, :id => @group }.should change{ Relation.count }.by(-1) + lambda { delete :remove_user, :id => @group }.should change{ Relation.count }.by(-1) end it_should_behave_like 'no group user' From 33e6cdc285a0766cd1dcfc22ef6eb12cea153fe8 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 27 Jul 2012 19:17:07 +0400 Subject: [PATCH 34/56] [refs #570] Remove mass build counters logs and transactions --- app/models/build_list.rb | 15 ++------------- app/models/counters_log.rb | 4 ---- app/models/mass_build.rb | 1 - db/migrate/20120726110848_create_counters_logs.rb | 11 ----------- db/schema.rb | 11 +---------- 5 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 app/models/counters_log.rb delete mode 100644 db/migrate/20120726110848_create_counters_logs.rb diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3de142fcb..5c7a151d7 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -9,7 +9,6 @@ class BuildList < ActiveRecord::Base belongs_to :mass_build, :counter_cache => true has_many :items, :class_name => "BuildList::Item", :dependent => :destroy has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy - has_many :counters_logs, :dependent => :destroy UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage] RELEASE_UPDATE_TYPES = %w[security bugfix] @@ -101,8 +100,6 @@ class BuildList < ActiveRecord::Base after_commit :place_build after_destroy :delete_container - after_create lambda { |build_list| build_list.counters_logs.create(:status => build_list.status, :event => "create", :mass_build_id => build_list.mass_build_id) } - @queue = :clone_and_build state_machine :status, :initial => :waiting_for_response do @@ -110,21 +107,13 @@ class BuildList < ActiveRecord::Base # WTF? around_transition -> infinite loop before_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - #MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id - MassBuild.transaction do - MassBuild.lock(true).decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id - end - build_list.counters_logs.create(:status => build_list.status, :event => "decrement", :mass_build_id => build_list.mass_build_id) + MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end after_transition do |build_list, transition| if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - #MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id - MassBuild.transaction do - MassBuild.lock(true).increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id - end - build_list.counters_logs.create(:status => build_list.status, :event => "increment", :mass_build_id => build_list.mass_build_id) + MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end diff --git a/app/models/counters_log.rb b/app/models/counters_log.rb deleted file mode 100644 index 756471ad5..000000000 --- a/app/models/counters_log.rb +++ /dev/null @@ -1,4 +0,0 @@ -class CountersLog < ActiveRecord::Base - belongs_to :build_list - belongs_to :mass_build -end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index a756afd1b..8cdc5c0f9 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -2,7 +2,6 @@ class MassBuild < ActiveRecord::Base belongs_to :platform belongs_to :user has_many :build_lists, :dependent => :destroy - has_many :counters_logs, :dependent => :destroy scope :by_platform, lambda { |platform| where(:platform_id => platform.id) } diff --git a/db/migrate/20120726110848_create_counters_logs.rb b/db/migrate/20120726110848_create_counters_logs.rb deleted file mode 100644 index fdd3f9941..000000000 --- a/db/migrate/20120726110848_create_counters_logs.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateCountersLogs < ActiveRecord::Migration - def change - create_table :counters_logs do |t| - t.integer :mass_build_id - t.integer :build_list_id - t.string :status - t.string :event - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index c21808c13..f39cf11c9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120726110848) do +ActiveRecord::Schema.define(:version => 20120719045806) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -143,15 +143,6 @@ ActiveRecord::Schema.define(:version => 20120726110848) do t.integer "project_id" end - create_table "counters_logs", :force => true do |t| - t.integer "mass_build_id" - t.integer "build_list_id" - t.string "status" - t.string "event" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "event_logs", :force => true do |t| t.integer "user_id" t.string "user_name" From cc66e2ee4ad2e7e7ec5f857d4bc00c31ed4294fe Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 20:01:26 +0400 Subject: [PATCH 35/56] [issue #590] Save repository to save to in BuildList. --- app/controllers/projects/build_lists_controller.rb | 7 ++++++- app/models/build_list.rb | 7 ++++++- app/views/projects/build_lists/new.html.haml | 2 +- app/views/projects/build_lists/show.html.haml | 2 ++ config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + db/schema.rb | 7 ++++--- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index ce7364d52..dde971380 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -41,8 +41,13 @@ class Projects::BuildListsController < Projects::BaseController def create notices, errors = [], [] - @platform = Platform.find params[:build_list][:save_to_platform_id] + save_to_platform_id, save_to_repository_id = params[:build_list][:save_to_platform_id].split('-').map{|i| i.to_i} + params[:build_list].merge!({:save_to_platform_id => save_to_platform_id, :save_to_repository_id => save_to_repository_id}) + + @platform = Platform.find save_to_platform_id + @repository = Repository.find save_to_repository_id params[:build_list][:auto_publish] = false if @platform.released + Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform| @build_list = @project.build_lists.build(params[:build_list]) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3df87673d..56bda2c86 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -3,6 +3,7 @@ class BuildList < ActiveRecord::Base belongs_to :project belongs_to :arch belongs_to :save_to_platform, :class_name => 'Platform' + belongs_to :save_to_repository, :class_name => 'Repository' belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :user belongs_to :advisory @@ -13,7 +14,8 @@ class BuildList < ActiveRecord::Base UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage] RELEASE_UPDATE_TYPES = %w[security bugfix] - validates :project_id, :project_version, :arch, :include_repos, :presence => true + validates :project_id, :project_version, :arch, :include_repos, + :build_for_platform_id, :save_to_platform_id, :save_to_repository_id, :presence => true validates_numericality_of :priority, :greater_than_or_equal_to => 0 validates :update_type, :inclusion => UPDATE_TYPES, :unless => Proc.new { |b| b.advisory.present? } @@ -22,6 +24,9 @@ class BuildList < ActiveRecord::Base validate lambda { errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id } + validate lambda { + errors.add(:save_to_platform, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id) + } LIVE_TIME = 3.week diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index ccda36113..6abe473b0 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -11,7 +11,7 @@ .offset25{:style => 'padding-left: 25px'}= render 'include_repos', :platform => pl %section.right %h3= t("activerecord.attributes.build_list.save_to_platform") - .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.platform.id]} + .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", "#{r.platform.id}-#{r.id}"]} %h3= t("activerecord.attributes.build_list.project_version") .lineForm= f.select :project_version, versions_for_group_select(@project), :selected => params[:build_list].try(:fetch, :project_version) || "latest_" + @project.default_branch %h3= t("activerecord.attributes.build_list.arch") diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index f0f3f1d19..f5db7ae86 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -29,6 +29,8 @@ .leftlist= t("activerecord.attributes.build_list.save_to_platform") .rightlist = link_to @build_list.save_to_platform.name, @build_list.save_to_platform + \/ + = link_to @build_list.save_to_repository.name, [@build_list.save_to_platform, @build_list.save_to_repository] .both .leftlist= t("activerecord.attributes.build_list.include_repos") .rightlist= (@build_list.include_repos||[]).map{|r| Repository.find(r).name}.join(', ') diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index cdcf7530e..eb127271f 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -125,5 +125,6 @@ en: no_project_version_found: Project version '%{project_version}' not found no_arch_or_platform_selected: At least one of architecture of platform must selected wrong_platform: Only the primary platform can be selected for the main repository! + wrong_repository: Repository to save package to must belongs to platform. 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 diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 5c5820a9d..8006d456c 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -124,5 +124,6 @@ ru: no_project_version_found: Выбранная версия '%{project_version}' не найдена no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа! + wrong_repository: Репозиторий для сохранения должен принадлежать платформе. can_not_published: Опубликовать сборку можно только со статусом "Собран" frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления diff --git a/db/schema.rb b/db/schema.rb index 88f4b829f..5406a0893 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120719045806) do +ActiveRecord::Schema.define(:version => 20120727141521) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -126,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.integer "duration" t.integer "advisory_id" t.integer "mass_build_id" + t.integer "save_to_repository_id" end add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id" @@ -311,11 +312,11 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false @@ -386,13 +387,13 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" - t.datetime "reset_password_sent_at" t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" From 63801e2676d8b9a0776413ff374a38c980629d52 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 27 Jul 2012 23:37:56 +0400 Subject: [PATCH 36/56] [issue #590] Platform fetches through repository. --- app/controllers/projects/build_lists_controller.rb | 7 +++---- app/views/projects/build_lists/new.html.haml | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index dde971380..49e532877 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -41,11 +41,10 @@ class Projects::BuildListsController < Projects::BaseController def create notices, errors = [], [] - save_to_platform_id, save_to_repository_id = params[:build_list][:save_to_platform_id].split('-').map{|i| i.to_i} - params[:build_list].merge!({:save_to_platform_id => save_to_platform_id, :save_to_repository_id => save_to_repository_id}) - @platform = Platform.find save_to_platform_id - @repository = Repository.find save_to_repository_id + @repository = Repository.find params[:build_list][:save_to_repository_id] + @platform = @repository.platform + params[:build_list][:save_to_platform_id] = @platform.id params[:build_list][:auto_publish] = false if @platform.released Arch.where(:id => params[:arches]).each do |arch| diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index 6abe473b0..756535df9 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -11,7 +11,7 @@ .offset25{:style => 'padding-left: 25px'}= render 'include_repos', :platform => pl %section.right %h3= t("activerecord.attributes.build_list.save_to_platform") - .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", "#{r.platform.id}-#{r.id}"]} + .lineForm= f.select :save_to_repository_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.id]} %h3= t("activerecord.attributes.build_list.project_version") .lineForm= f.select :project_version, versions_for_group_select(@project), :selected => params[:build_list].try(:fetch, :project_version) || "latest_" + @project.default_branch %h3= t("activerecord.attributes.build_list.arch") From 27030566a426bf0b1cd9c0bad47ef9c7d29da586 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 30 Jul 2012 02:32:23 +0300 Subject: [PATCH 37/56] Update rails, grit, gollum. Fix re-encoding bug. Refs #263 --- Gemfile | 6 +-- Gemfile.lock | 93 +++++++++++++++++++++++------------------- doc/README_FOR_APP | 2 + lib/ext/core/string.rb | 5 ++- 4 files changed, 59 insertions(+), 47 deletions(-) diff --git a/Gemfile b/Gemfile index 0ace218c6..65f5da383 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '3.2.6' #, :git => 'git://github.com/rails/rails.git' +gem 'rails', '3.2.7' #, :git => 'git://github.com/rails/rails.git' gem 'pg', '~> 0.14.0' # gem 'silent-postgres', :git => 'git://github.com/dolzenko/silent-postgres.git' #'~> 0.1.1' @@ -31,7 +31,7 @@ gem 'github-linguist', '~> 2.1.2', :require => 'linguist' gem 'diff-display', '~> 0.0.1' # Wiki -gem "gollum", "1.3.1" +gem "gollum", :git => 'git://github.com/github/gollum.git' gem "redcarpet", "1.17.2" gem 'creole' gem 'rdiscount' @@ -41,7 +41,7 @@ gem 'wikicloth' gem 'unicorn', '~> 4.3.1', :platforms => [:mri, :rbx] gem 'trinidad', '~> 1.0.2', :platforms => :jruby -gem 'newrelic_rpm', '~> 3.4.0.1', :platforms => [:mri, :rbx] +gem 'newrelic_rpm', '~> 3.4.1', :platforms => [:mri, :rbx] gem 'whenever', '~> 0.7.3', :require => false gem 'jbuilder', '~> 0.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1ff9bd23d..8d70a5ad0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,23 @@ GIT redhillonrails_core (2.0.0.pre) activerecord (>= 3.1.0.rc) +GIT + remote: git://github.com/github/gollum.git + revision: c9bc2a89f655760c0a21da6d3ab37c5f6267e96c + specs: + gollum (2.1.0) + github-markdown + github-markup (>= 0.7.0, < 1.0.0) + grit (~> 2.5.0) + mustache (>= 0.11.2, < 1.0.0) + nokogiri (~> 1.4) + posix-spawn (~> 0.3.0) + pygments.rb (~> 0.2.0) + sanitize (~> 2.0.0) + sinatra (~> 1.0) + stringex (~> 1.4.0) + useragent (~> 0.4.9) + GIT remote: git://github.com/rdblue/grack.git revision: 020be3fef3fb308b9d214252522aa5945bf6584a @@ -14,9 +31,9 @@ GIT GIT remote: git://github.com/warpc/grit.git - revision: 696b0967cb7e6bac044569d898e5acef431d4f97 + revision: f04f779fb052725b964ba259f8073a34e493c0c7 specs: - grit (2.4.1) + grit (2.5.0) diff-lcs (~> 1.1) mime-types (~> 1.15) posix-spawn (~> 0.3.6) @@ -25,38 +42,36 @@ GEM remote: http://rubygems.org/ specs: RedCloth (4.2.9) - actionmailer (3.2.6) - actionpack (= 3.2.6) + actionmailer (3.2.7) + actionpack (= 3.2.7) mail (~> 2.4.4) - actionpack (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + actionpack (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) erubis (~> 2.7.0) - journey (~> 1.0.1) + journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.1.3) - activemodel (3.2.6) - activesupport (= 3.2.6) + activemodel (3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) - activerecord (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + activerecord (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) - activesupport (3.2.6) + activeresource (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) + activesupport (3.2.7) i18n (~> 0.6) multi_json (~> 1.0) airbrake (3.1.2) activesupport builder - albino (1.3.3) - posix-spawn (>= 0.3.6) ancestry (1.3.0) activerecord (>= 2.3.14) arel (3.0.2) @@ -122,16 +137,8 @@ GEM escape_utils (~> 0.2.3) mime-types (~> 1.18) pygments.rb (>= 0.2.13) + github-markdown (0.5.0) github-markup (0.7.4) - gollum (1.3.1) - albino (~> 1.3.2) - github-markup (>= 0.4.0, < 1.0.0) - grit (~> 2.4.1) - mustache (>= 0.11.2, < 1.0.0) - nokogiri (~> 1.4) - redcarpet - sanitize (~> 2.0.0) - sinatra (~> 1.0) haml (3.1.6) haml-rails (0.3.4) actionpack (~> 3.0) @@ -180,7 +187,7 @@ GEM net-ssh (2.5.2) net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) - newrelic_rpm (3.4.0.1) + newrelic_rpm (3.4.1) nokogiri (1.5.5) omniauth (1.1.0) hashie (~> 1.2) @@ -216,14 +223,14 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) - rails (3.2.6) - actionmailer (= 3.2.6) - actionpack (= 3.2.6) - activerecord (= 3.2.6) - activeresource (= 3.2.6) - activesupport (= 3.2.6) + rails (3.2.7) + actionmailer (= 3.2.7) + actionpack (= 3.2.7) + activerecord (= 3.2.7) + activeresource (= 3.2.7) + activesupport (= 3.2.7) bundler (~> 1.0) - railties (= 3.2.6) + railties (= 3.2.7) rails-backbone (0.7.2) coffee-script (~> 2.2.0) ejs (~> 1.0.0) @@ -232,9 +239,9 @@ GEM railties (>= 3.0.0) rails3-jquery-autocomplete (1.0.7) rails (~> 3.0) - railties (3.2.6) - actionpack (= 3.2.6) - activesupport (= 3.2.6) + railties (3.2.7) + actionpack (= 3.2.7) + activesupport (= 3.2.7) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -315,6 +322,7 @@ GEM tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6) state_machine (1.1.2) + stringex (1.4.0) systemu (2.5.2) therubyracer (0.10.1) libv8 (~> 3.3.10) @@ -335,6 +343,7 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + useragent (0.4.10) uuid (2.3.5) macaddr (~> 1.0) vegas (0.1.11) @@ -369,7 +378,7 @@ DEPENDENCIES diff-display (~> 0.0.1) factory_girl_rails (~> 3.5.0) github-linguist (~> 2.1.2) - gollum (= 1.3.1) + gollum! grack! grit! haml-rails (~> 0.3.4) @@ -379,13 +388,13 @@ DEPENDENCIES jquery-rails (~> 2.0.2) mailcatcher meta-tags (~> 1.2.5) - newrelic_rpm (~> 3.4.0.1) + newrelic_rpm (~> 3.4.1) omniauth (~> 1.1.0) omniauth-openid (~> 1.0.1) paperclip (~> 3.1.4) perform_later (~> 1.3.0) pg (~> 0.14.0) - rails (= 3.2.6) + rails (= 3.2.7) rails-backbone (~> 0.7.2) rails3-generators rails3-jquery-autocomplete (~> 1.0.7) diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP index cca71ab75..cd837c6bc 100644 --- a/doc/README_FOR_APP +++ b/doc/README_FOR_APP @@ -25,4 +25,6 @@ sudo urpmi lib64magic-devel # mandriva brew install libmagic; brew link libmagic # brew gem install ruby-filemagic +sudo urpmi python-devel + git config --global core.quotepath false diff --git a/lib/ext/core/string.rb b/lib/ext/core/string.rb index e84bca715..9ff9bde77 100644 --- a/lib/ext/core/string.rb +++ b/lib/ext/core/string.rb @@ -15,9 +15,10 @@ class String encode!(Encoding::UTF_16, default_encoding, options).encode!(default_encoding, Encoding::UTF_16) raise unless valid_encoding? # check result end + self rescue replace "--broken encoding: #{detect_encoding[:encoding] || 'unknown'}" - ensure - self + # ensure + # return self end end From dd13b38da36b928a0d0cf3263679c6438a93e3d2 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 30 Jul 2012 18:49:40 +0400 Subject: [PATCH 38/56] [refs #570] Add status variable --- app/models/build_list.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 5c7a151d7..31985b391 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -106,14 +106,16 @@ class BuildList < ActiveRecord::Base # WTF? around_transition -> infinite loop before_transition do |build_list, transition| - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + status = BuildList::HUMAN_STATUSES[build_list.status] + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status) + MassBuild.decrement_counter "#{status.to_s}_count", build_list.mass_build_id end end after_transition do |build_list, transition| - if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(BuildList::HUMAN_STATUSES[build_list.status]) - MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + status = BuildList::HUMAN_STATUSES[build_list.status] + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status) + MassBuild.increment_counter "#{status.to_s}_count", build_list.mass_build_id end end From 844e81a73d93d8ef99e5c843e4c5fe04c0aef0af Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 30 Jul 2012 19:25:51 +0400 Subject: [PATCH 39/56] [refs #441] Change public key type --- ...0317_set_text_type_for_key_pairs_public.rb | 9 ++ db/schema.rb | 99 ++++++++++--------- 2 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 db/migrate/20120730150317_set_text_type_for_key_pairs_public.rb diff --git a/db/migrate/20120730150317_set_text_type_for_key_pairs_public.rb b/db/migrate/20120730150317_set_text_type_for_key_pairs_public.rb new file mode 100644 index 000000000..1492d5feb --- /dev/null +++ b/db/migrate/20120730150317_set_text_type_for_key_pairs_public.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1a41805c6..23a83d945 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120703101719) do +ActiveRecord::Schema.define(:version => 20120730150317) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "version" end @@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "project_id" t.integer "arch_id" t.datetime "notified_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -137,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -155,14 +155,23 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "flash_notifies", :force => true do |t| + t.text "body_ru" + t.text "body_en" + t.string "status" + t.boolean "published" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -175,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -188,7 +197,7 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "repository_id" t.integer "user_id" t.integer "key_id" - t.string "public" + t.text "public" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end @@ -234,14 +243,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -250,8 +259,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" end @@ -267,8 +276,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "build_script" t.text "counter" t.text "ks" @@ -287,8 +296,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "platform_id" end @@ -297,14 +306,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" @@ -322,8 +331,6 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.integer "build_count", :default => 0, :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false - create_table "register_requests", :force => true do |t| t.string "name" t.string "email" @@ -344,16 +351,16 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "name", :null => false end @@ -364,8 +371,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -374,8 +381,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -387,11 +394,9 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "password_salt", :default => "", :null => false t.string "reset_password_token" - t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.text "ssh_key" + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" @@ -408,11 +413,11 @@ ActiveRecord::Schema.define(:version => 20120703101719) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" t.string "authentication_token" - t.integer "build_priority", :default => 50 + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" From 89d67f9ea6a74e7da87ea546d7c1383c36f7fcc5 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Mon, 30 Jul 2012 23:07:49 +0400 Subject: [PATCH 40/56] [refs #441] Refactring, fix errors --- .../platforms/key_pairs_controller.rb | 4 +- app/models/key_pair.rb | 38 ++++++++++--------- app/views/platforms/key_pairs/_new.html.haml | 4 +- config/locales/models/key_pair.en.yml | 19 ++++++---- config/locales/models/key_pair.ru.yml | 25 +++++++----- ...119_set_string_type_for_key_pairs_keyid.rb | 9 +++++ 6 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 db/migrate/20120730185119_set_string_type_for_key_pairs_keyid.rb diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb index b7fecef5f..c45f53dcb 100644 --- a/app/controllers/platforms/key_pairs_controller.rb +++ b/app/controllers/platforms/key_pairs_controller.rb @@ -10,7 +10,7 @@ class Platforms::KeyPairsController < ApplicationController def create @key_pair.user_id = current_user.id - if @key_pair.key_create_call == true + if @key_pair.save flash[:notice] = t('flash.key_pairs.saved') else flash[:error] = t('flash.key_pairs.save_error') @@ -21,7 +21,7 @@ class Platforms::KeyPairsController < ApplicationController end def destroy - if @key_pair.rm_key_call + if @key_pair.destroy flash[:notice] = t('flash.key_pairs.destroyed') else flash[:error] = t('flash.key_pairs.destroy_error') diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index ec85e53fc..5b752c513 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -5,25 +5,29 @@ class KeyPair < ActiveRecord::Base attr_accessor :secret attr_accessible :public, :secret, :repository_id - after_create :key_create_call + validates :repository_id, :public, :user_id, :presence => true + validates :secret, :presence => true, :on => :create - def key_create_call - if KeyPair.exists? :repository_id => self.repository_id - errors.add(:repository_id, I18n.t('flash.key_pairs.key_exists')) - return false + validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pairs.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}." unless result == 4 + if result != 0 || key_id.nil? + errors.add(:public, I18n.t("activerecord.errors.key_pairs.#{result}")) + return false + end + result = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) + raise "Failed to sign repository key #{repository_id} with code #{set_code}." unless result.zero? end - code, self.key_id = BuildServer.import_gpg_key_pair(public, secret) - if code.zero? - set_code = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) - set_code.zero? ? self.save : set_code - else - code + def rm_key_call + result = BuildServer.rm_repository_key(repository.platform_id, repository_id) + raise "Failed to desroy repository key #{repository_id} with code #{result}." unless result.zero? end - end - - def rm_key_call - return self.destroy if BuildServer.rm_repository_key(repository.platform_id, repository_id) == 0 - false - end end diff --git a/app/views/platforms/key_pairs/_new.html.haml b/app/views/platforms/key_pairs/_new.html.haml index c6cc8f0bf..b740fe218 100644 --- a/app/views/platforms/key_pairs/_new.html.haml +++ b/app/views/platforms/key_pairs/_new.html.haml @@ -4,10 +4,10 @@ = 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_field :public, :class => 'text_field' + .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_field :secret, :class => 'text_field' + .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') diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml index b7ad9532f..0d55e41d9 100644 --- a/config/locales/models/key_pair.en.yml +++ b/config/locales/models/key_pair.en.yml @@ -5,16 +5,21 @@ en: user_id: User public: Public key secret: Secret key - confirm_delete: Are you sure you want to delete this key pair? - header: Key Pairs + confirm_delete: Are you sure you want to delete this signature? + header: Signatures flash: key_pairs: - saved: Key pair succefully created - save_error: Key pair save error - destroyed: Key pair succefully destroyed - destroy_error: Key pair destroy error - key_exists: has one key pair already! + 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 + 1: could not import public key + 2: could not import secret key + 3: keys are imported, but it is not a key pair (ids differ) models: key_pair: Key Pair attributes: diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml index 32f93f356..451fc8b9d 100644 --- a/config/locales/models/key_pair.ru.yml +++ b/config/locales/models/key_pair.ru.yml @@ -1,22 +1,27 @@ -en: +ru: layout: key_pairs: repository_id: Репозиторий user_id: Пользователь public: Публичный ключ secret: Секретный ключ - confirm_delete: Вы уверены, что хотите удалить эту ключевую пару? - header: Ключевые Пары + confirm_delete: Вы уверены, что хотите удалить подпись? + header: Подписи flash: key_pairs: - saved: Ключевая пара сохранена успешно - save_error: Ошибка создания ключевой пары - destroyed: Ключевая пара удалена успешно - destroy_error: Ошибка удаления ключевой пары - key_exists: уже имеет одну ключевую пару! + saved: Репозиторий успешно подписан + save_error: Ошибка создания подписи + destroyed: Подпись удалена успешно + destroy_error: Ошибка удаления подписи activerecord: + errors: + key_pair: + repo_key_exists: Репозиторий уже подписан! Пожалуйста, удалите старую подпись и попробуйте снова + 1: Проблемы с импортром публичного ключа + 2: Проблемы с импортром секретного ключа + 3: Ключи импортированы, но не являются парой (идентификаторы не совпадают) models: - key_pair: Ключевая пара + key_pair: Подпись attributes: key_pair: id: Id @@ -25,4 +30,4 @@ en: user_id: Пользователь repository_id: Репозиторий public: Публичный ключ - secret: Секретный ключ + secret: Секретный ключ \ No newline at end of file diff --git a/db/migrate/20120730185119_set_string_type_for_key_pairs_keyid.rb b/db/migrate/20120730185119_set_string_type_for_key_pairs_keyid.rb new file mode 100644 index 000000000..da6337e16 --- /dev/null +++ b/db/migrate/20120730185119_set_string_type_for_key_pairs_keyid.rb @@ -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 From d7e9cefd0be4919ac52e402d1c53baeb73a48ba3 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 30 Jul 2012 23:25:57 +0400 Subject: [PATCH 41/56] [issue #590] Added validation on repository. --- app/models/build_list.rb | 5 ++++- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 56bda2c86..f1ad3b1f0 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -25,7 +25,10 @@ class BuildList < ActiveRecord::Base errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id } validate lambda { - errors.add(:save_to_platform, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id) + errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id) + } + validate lambda { + errors.add(:save_to_repository, I18n.t('flash.build_list.cannot_write')) unless current_user.can?(:write, save_to_repository) } LIVE_TIME = 3.week diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index eb127271f..6a34964ca 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -126,5 +126,6 @@ en: no_arch_or_platform_selected: At least one of architecture of platform must selected wrong_platform: Only the primary platform can be selected for the main repository! wrong_repository: Repository to save package to must belongs to platform. + cannot_write: You can't build project to this repository. 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 diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 8006d456c..fa306e55b 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -125,5 +125,6 @@ ru: no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа! wrong_repository: Репозиторий для сохранения должен принадлежать платформе. + cannot_write: Вы не можете сохранять пакет в этот репозиторий. can_not_published: Опубликовать сборку можно только со статусом "Собран" frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления From 73a369ba493f8d44eb966c246621786893a7fc78 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 31 Jul 2012 01:24:31 +0400 Subject: [PATCH 42/56] [refs #441] Refactring: part 2. Fix integration with kernel, change view for keys list --- app/models/key_pair.rb | 16 +++++++++------- app/views/platforms/key_pairs/_list.html.haml | 6 +++--- config/locales/models/key_pair.en.yml | 1 + config/locales/models/key_pair.ru.yml | 5 +++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 5b752c513..35fe32203 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -8,7 +8,7 @@ class KeyPair < ActiveRecord::Base validates :repository_id, :public, :user_id, :presence => true validates :secret, :presence => true, :on => :create - validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pairs.repo_key_exists")} + validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pair.repo_key_exists")} before_create :key_create_call before_destroy :rm_key_call @@ -17,17 +17,19 @@ class KeyPair < ActiveRecord::Base 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}." unless result == 4 + raise "Failed to create key_pairs for repository #{repository_id} with code #{result}." if result == 4 if result != 0 || key_id.nil? - errors.add(:public, I18n.t("activerecord.errors.key_pairs.#{result}")) + errors.add(:public, I18n.t("activerecord.errors.key_pair.#{result}")) return false end - result = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id) - raise "Failed to sign repository key #{repository_id} with code #{set_code}." unless result.zero? + result = BuildServer.set_repository_key(repository.platform.name, repository.name, key_id) + raise "Failed to sign repository #{repository.name} in platform #{repository.platform.name} + using key_id #{key_id} with code #{result}." unless result.zero? end def rm_key_call - result = BuildServer.rm_repository_key(repository.platform_id, repository_id) - raise "Failed to desroy repository key #{repository_id} with code #{result}." unless result.zero? + 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 diff --git a/app/views/platforms/key_pairs/_list.html.haml b/app/views/platforms/key_pairs/_list.html.haml index 863bb5531..ca39da716 100644 --- a/app/views/platforms/key_pairs/_list.html.haml +++ b/app/views/platforms/key_pairs/_list.html.haml @@ -2,7 +2,7 @@ %thead %tr %th.th1= t("activerecord.attributes.key_pair.repository_id") - %th.th2= t("activerecord.attributes.key_pair.public") + %th.th2= t("activerecord.attributes.key_pair.key_id") %th.th3= t("activerecord.attributes.key_pair.user_id") %th= t("layout.delete") %tbody @@ -10,8 +10,8 @@ - if repository.key_pair %tr{:class => cycle("odd", "even")} %td= repository.name - %td= repository.key_pair.public - %td= repository.key_pair.user.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 diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml index 0d55e41d9..139c9da5a 100644 --- a/config/locales/models/key_pair.en.yml +++ b/config/locales/models/key_pair.en.yml @@ -31,3 +31,4 @@ en: repository_id: Repository public: Public key secret: Secret key + key_id: Signature diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml index 451fc8b9d..0b2fb496f 100644 --- a/config/locales/models/key_pair.ru.yml +++ b/config/locales/models/key_pair.ru.yml @@ -11,7 +11,7 @@ ru: key_pairs: saved: Репозиторий успешно подписан save_error: Ошибка создания подписи - destroyed: Подпись удалена успешно + destroyed: Подпись успешно удалена destroy_error: Ошибка удаления подписи activerecord: errors: @@ -30,4 +30,5 @@ ru: user_id: Пользователь repository_id: Репозиторий public: Публичный ключ - secret: Секретный ключ \ No newline at end of file + secret: Секретный ключ + key_id: Подпись \ No newline at end of file From 0305976a2764495146cc303ebc4f82827b5f433c Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 31 Jul 2012 12:56:55 +0400 Subject: [PATCH 43/56] [refs #441] Fix schema --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index f39cf11c9..eaf97e8a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -163,7 +163,7 @@ ActiveRecord::Schema.define(:version => 20120719045806) do t.text "body_ru" t.text "body_en" t.string "status" - t.boolean "published" + t.boolean "published", :default => true t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end From 931d4a7db02deebf5a630fb84faef096709cbfd8 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 31 Jul 2012 16:50:53 +0400 Subject: [PATCH 44/56] [refs #441] Key Pairs fixes and refactoring --- .../platforms/key_pairs_controller.rb | 11 ++++------ app/models/key_pair.rb | 4 ++-- app/models/repository.rb | 2 +- config/locales/models/key_pair.en.yml | 7 ++++--- config/locales/models/key_pair.ru.yml | 9 +++++---- .../platforms/key_pairs_controller_spec.rb | 20 +++++++++++++++---- spec/spec_helper.rb | 6 ++++++ 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb index c45f53dcb..4d9fb0ab0 100644 --- a/app/controllers/platforms/key_pairs_controller.rb +++ b/app/controllers/platforms/key_pairs_controller.rb @@ -1,11 +1,8 @@ class Platforms::KeyPairsController < ApplicationController before_filter :authenticate_user! - load_and_authorize_resource :platform - load_and_authorize_resource - - skip_load_and_authorize_resource :only => [:index] - skip_authorize_resource :platform, :only => [:create, :destroy] + load_and_authorize_resource :platform, :only => [:index] + load_and_authorize_resource :only => [:create, :destroy] def create @key_pair.user_id = current_user.id @@ -17,7 +14,7 @@ class Platforms::KeyPairsController < ApplicationController flash[:warning] = @key_pair.errors.full_messages.join('. ') unless @key_pair.errors.blank? end - redirect_to platform_key_pairs_path(@platform) + redirect_to platform_key_pairs_path(@key_pair.repository.platform) end def destroy @@ -27,6 +24,6 @@ class Platforms::KeyPairsController < ApplicationController flash[:error] = t('flash.key_pairs.destroy_error') end - redirect_to platform_key_pairs_path(@platform) + redirect_to platform_key_pairs_path(@key_pair.repository.platform) end end diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 35fe32203..ce6c77365 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -18,8 +18,8 @@ class KeyPair < ActiveRecord::Base 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 || key_id.nil? - errors.add(:public, I18n.t("activerecord.errors.key_pair.#{result}")) + 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, key_id) diff --git a/app/models/repository.rb b/app/models/repository.rb index 19f4c8888..491d219e8 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,7 +4,7 @@ class Repository < ActiveRecord::Base has_many :project_to_repositories, :dependent => :destroy, :validate => true has_many :projects, :through => :project_to_repositories - has_one :key_pair + has_one :key_pair, :dependent => :destroy validates :description, :presence => true validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} diff --git a/config/locales/models/key_pair.en.yml b/config/locales/models/key_pair.en.yml index 139c9da5a..9b685612a 100644 --- a/config/locales/models/key_pair.en.yml +++ b/config/locales/models/key_pair.en.yml @@ -17,9 +17,10 @@ en: errors: key_pair: repo_key_exists: Repository has been signed already! Please remove old signature and try again - 1: could not import public key - 2: could not import secret key - 3: keys are imported, but it is not a key pair (ids differ) + 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: diff --git a/config/locales/models/key_pair.ru.yml b/config/locales/models/key_pair.ru.yml index 0b2fb496f..465ab0052 100644 --- a/config/locales/models/key_pair.ru.yml +++ b/config/locales/models/key_pair.ru.yml @@ -17,9 +17,10 @@ ru: errors: key_pair: repo_key_exists: Репозиторий уже подписан! Пожалуйста, удалите старую подпись и попробуйте снова - 1: Проблемы с импортром публичного ключа - 2: Проблемы с импортром секретного ключа - 3: Ключи импортированы, но не являются парой (идентификаторы не совпадают) + rpc_error_0: Неизвестная ошибка + rpc_error_1: Проблемы с импортром публичного ключа + rpc_error_2: Проблемы с импортром секретного ключа + rpc_error_3: Ключи импортированы, но не являются парой (идентификаторы не совпадают) models: key_pair: Подпись attributes: @@ -31,4 +32,4 @@ ru: repository_id: Репозиторий public: Публичный ключ secret: Секретный ключ - key_id: Подпись \ No newline at end of file + key_id: Подпись diff --git a/spec/controllers/platforms/key_pairs_controller_spec.rb b/spec/controllers/platforms/key_pairs_controller_spec.rb index 7beeec068..5b27e41b0 100644 --- a/spec/controllers/platforms/key_pairs_controller_spec.rb +++ b/spec/controllers/platforms/key_pairs_controller_spec.rb @@ -69,6 +69,7 @@ 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) @@ -84,9 +85,9 @@ describe Platforms::KeyPairsController do end context 'for guest' do - [:index, :create, :destroy].each do |action| + [:index, :create].each do |action| it "should not be able to perform #{ action } action" do - get action, :platform_id => @platform, :id => @key_pair + get action, :platform_id => @platform response.should redirect_to(new_user_session_path) end end @@ -95,8 +96,19 @@ describe Platforms::KeyPairsController do lambda { post :create, @create_params }.should change{ KeyPair.count }.by(0) 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) + 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72f943b66..241d36fc9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,12 @@ def stub_symlink_methods any_instance_of(Platform, :remove_symlink_directory => true) end +def stub_key_pairs_calls + stub(BuildServer).import_gpg_key_pair { [0,0] } + stub(BuildServer).set_repository_key { 0 } + stub(BuildServer).rm_repository_key { 0 } +end + def test_git_commit(project) project.repo.index.add('test', 'TEST') project.repo.index.commit('Test commit') From 6c4a574f498d1a56c19b6dc40b7065e930b806f5 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 31 Jul 2012 17:05:25 +0400 Subject: [PATCH 45/56] [refs #441] self.key_id and stub result fix --- app/models/key_pair.rb | 4 ++-- spec/spec_helper.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index ce6c77365..25c5c50d5 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -22,9 +22,9 @@ class KeyPair < ActiveRecord::Base 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, key_id) + 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 #{key_id} with code #{result}." unless result.zero? + using key_id #{self.key_id} with code #{result}." unless result.zero? end def rm_key_call diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 241d36fc9..a29d72fa6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,7 +39,7 @@ def stub_symlink_methods end def stub_key_pairs_calls - stub(BuildServer).import_gpg_key_pair { [0,0] } + stub(BuildServer).import_gpg_key_pair { [0,"1a2b3c"] } stub(BuildServer).set_repository_key { 0 } stub(BuildServer).rm_repository_key { 0 } end From ebc5cd2603e415a00d44ae54c4de194b3f80e69a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 31 Jul 2012 17:35:05 +0400 Subject: [PATCH 46/56] [refs #441] Fix schema --- db/schema.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index dd125c3d3..6d4c81e73 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -159,14 +159,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do end create_table "flash_notifies", :force => true do |t| - t.text "body_ru" - t.text "body_en" - t.string "status" - t.boolean "published", :default => true + t.text "body_ru", :null => false + t.text "body_en", :null => false + t.string "status", :null => false + t.boolean "published", :default => true, :null => false t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false + create_table "groups", :force => true do |t| t.integer "owner_id" t.datetime "created_at", :null => false From 01a3572de04d63eb787a72513759ad681bb7f748 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 31 Jul 2012 17:35:18 +0300 Subject: [PATCH 47/56] Minor update. Fix helper bug. Minor refactor. Refs #263 --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- app/helpers/git_helper.rb | 4 +++- lib/ext/rosa/constraints.rb | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 65f5da383..60869b4bb 100644 --- a/Gemfile +++ b/Gemfile @@ -81,7 +81,7 @@ end group :test do 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 'shoulda' end diff --git a/Gemfile.lock b/Gemfile.lock index 8d70a5ad0..896f7a8ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: git://github.com/github/gollum.git - revision: c9bc2a89f655760c0a21da6d3ab37c5f6267e96c + revision: 8422b712048656c8ea391c2d7ef27fb29f66746b specs: gollum (2.1.0) github-markdown @@ -125,10 +125,10 @@ GEM execjs (1.4.0) multi_json (~> 1.0) expression_parser (0.9.0) - factory_girl (3.5.0) + factory_girl (3.6.0) activesupport (>= 3.0.0) - factory_girl_rails (3.5.0) - factory_girl (~> 3.5.0) + factory_girl_rails (3.6.0) + factory_girl (~> 3.6.0) railties (>= 3.0.0) ffi (1.0.11) fssm (0.2.9) @@ -376,7 +376,7 @@ DEPENDENCIES creole devise (~> 2.1.2) diff-display (~> 0.0.1) - factory_girl_rails (~> 3.5.0) + factory_girl_rails (~> 3.6.0) github-linguist (~> 2.1.2) gollum! grack! diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index 753db6e64..853c69b8a 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -54,7 +54,9 @@ module GitHelper current = url_for(p).split('?', 2).first 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]} res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&linking)] res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)] diff --git a/lib/ext/rosa/constraints.rb b/lib/ext/rosa/constraints.rb index 54e9e6191..fd7f45fbf 100644 --- a/lib/ext/rosa/constraints.rb +++ b/lib/ext/rosa/constraints.rb @@ -21,8 +21,7 @@ module Rosa class Treeish def self.matches?(request) - params = request.path_parameters - if params[:treeish] # parse existing branch (tag) and path + if (params = request.path_parameters) && params[:treeish] # parse existing branch (tag) and path branch_or_tag = begin (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) || From 8e05c0222d4e0c1d735de90a1795e59f88e6744d Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 31 Jul 2012 20:06:57 +0400 Subject: [PATCH 48/56] [refs #374] Fix key pairs tests --- spec/models/key_pair_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/models/key_pair_spec.rb b/spec/models/key_pair_spec.rb index bda634ebe..1bf3b9c2b 100644 --- a/spec/models/key_pair_spec.rb +++ b/spec/models/key_pair_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe KeyPair do before(:all) do stub_symlink_methods + stub_key_pairs_calls FactoryGirl.create(:key_pair) end From 8e91159b5b270ff9b65aedb6163adb8a1d9d40e9 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 31 Jul 2012 20:32:49 +0300 Subject: [PATCH 49/56] Improve and refacror huge blob display. Fix wiki create and display. Fix build_lists test. Refs #263 --- .../git/blobs/_render_as_binary.html.haml | 2 +- config/environments/production.rb | 2 +- db/schema.rb | 106 +++++++++--------- lib/ext/git/grit.rb | 6 +- lib/modules/models/wiki.rb | 2 +- .../projects/build_lists_controller_spec.rb | 8 +- .../gollum/editor/gollum.editor.js | 2 +- 7 files changed, 66 insertions(+), 62 deletions(-) diff --git a/app/views/projects/git/blobs/_render_as_binary.html.haml b/app/views/projects/git/blobs/_render_as_binary.html.haml index bd7379a10..a8fd16a3d 100644 --- a/app/views/projects/git/blobs/_render_as_binary.html.haml +++ b/app/views/projects/git/blobs/_render_as_binary.html.haml @@ -4,5 +4,5 @@ %td.blob :plain
-
#{link_to @blob.basename, raw_path(@project, @treeish, @path)}
+
#{link_to_unless @blob.huge?, @blob.basename, raw_path(@project, @treeish, @path)}

\ No newline at end of file diff --git a/config/environments/production.rb b/config/environments/production.rb index 37372580c..b3ca044d1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -62,7 +62,7 @@ Rosa::Application.configure do config.assets.digest = true # 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 # require 'stub_xml_rpc' diff --git a/db/schema.rb b/db/schema.rb index 6d4c81e73..f40616a68 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "version" end @@ -106,8 +106,9 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "project_version" t.integer "project_id" t.integer "arch_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "notified_at" + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -136,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -154,25 +155,23 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "flash_notifies", :force => true do |t| - t.text "body_ru", :null => false - t.text "body_en", :null => false - t.string "status", :null => false + t.text "body_ru", :null => false + t.text "body_en", :null => false + t.string "status", :null => false t.boolean "published", :default => true, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false - create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -185,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -262,16 +261,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" end create_table "product_build_lists", :force => true do |t| t.integer "product_id" t.integer "status", :default => 2, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id" @@ -279,8 +278,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "build_script" t.text "counter" t.text "ks" @@ -299,8 +298,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "platform_id" end @@ -309,39 +308,41 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true - t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" + t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true + create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end @@ -354,16 +355,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "name", :null => false end @@ -374,8 +375,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -384,8 +385,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -395,19 +396,15 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.string "role" t.string "language", :default => "en" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false t.datetime "reset_password_sent_at" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -419,6 +416,9 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 4fa2f11f3..3ec533062 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -7,7 +7,7 @@ module Grit MAX_DATA_SIZE = 50.megabytes 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 alias_method_chain :data, :limit @@ -15,6 +15,10 @@ module Grit size.to_i > MAX_VIEW_SIZE end + def huge? + size.to_i > MAX_DATA_SIZE + end + def render_as @render_as ||= case when large?; :binary diff --git a/lib/modules/models/wiki.rb b/lib/modules/models/wiki.rb index 1f13446b9..ef8884708 100644 --- a/lib/modules/models/wiki.rb +++ b/lib/modules/models/wiki.rb @@ -5,7 +5,7 @@ module Modules extend ActiveSupport::Concern included do - after_create :create_wiki + after_save :create_wiki after_destroy :destroy_wiki end diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 0cb7e4b2f..b2aa0d17d 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -303,11 +303,11 @@ describe Projects::BuildListsController do assigns[:build_lists].should_not include(@build_list3) 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 => 'everything', - "created_at_start(1i)" => @build_list3.created_at.year.to_s, - "created_at_start(2i)" => @build_list3.created_at.month.to_s, - "created_at_start(3i)" => @build_list3.created_at.day.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(3i)" => @build_list3.updated_at.day.to_s} assigns[:build_lists].should_not include(@build_list1) assigns[:build_lists].should_not include(@build_list2) assigns[:build_lists].should include(@build_list3) diff --git a/vendor/assets/javascripts/gollum/editor/gollum.editor.js b/vendor/assets/javascripts/gollum/editor/gollum.editor.js index 075887eab..f7ddc6012 100755 --- a/vendor/assets/javascripts/gollum/editor/gollum.editor.js +++ b/vendor/assets/javascripts/gollum/editor/gollum.editor.js @@ -241,7 +241,7 @@ } // 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({ url: script_uri, dataType: 'script', From 1269806aaebf356a53567e8204fd2d6c349c684f Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 31 Jul 2012 22:24:27 +0300 Subject: [PATCH 50/56] Hide another raw link for huge blobs. Refs #263 --- app/views/projects/git/blobs/_top.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/projects/git/blobs/_top.html.haml b/app/views/projects/git/blobs/_top.html.haml index 3fa62790b..f770185d2 100644 --- a/app/views/projects/git/blobs/_top.html.haml +++ b/app/views/projects/git/blobs/_top.html.haml @@ -12,8 +12,9 @@ - if @blob.render_as == :text && params[:action] != 'show' = 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' = link_to "Blame", blame_path(@project, @treeish, @path) \| From b6c5221f41d00b910de707feff1fffd1baa53ba0 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 1 Aug 2012 00:38:21 +0300 Subject: [PATCH 51/56] Rollback schema.rb. Refs #263 --- db/schema.rb | 108 +++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index f40616a68..f9df9fb18 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "version" end @@ -106,9 +106,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "project_version" t.integer "project_id" t.integer "arch_id" - t.datetime "notified_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -137,8 +136,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" end @@ -155,23 +154,25 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "flash_notifies", :force => true do |t| - t.text "body_ru", :null => false - t.text "body_en", :null => false - t.string "status", :null => false + t.text "body_ru", :null => false + t.text "body_en", :null => false + t.string "status", :null => false t.boolean "published", :default => true, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false + create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -184,8 +185,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -261,16 +262,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "user_id" end create_table "product_build_lists", :force => true do |t| t.integer "product_id" t.integer "status", :default => 2, :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id" @@ -278,8 +279,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.text "build_script" t.text "counter" t.text "ks" @@ -298,8 +299,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "platform_id" end @@ -308,41 +309,39 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true - create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "interest" t.text "more" end @@ -355,16 +354,16 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "name", :null => false end @@ -375,8 +374,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -385,8 +384,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -396,15 +395,19 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "uname" t.string "role" t.string "language", :default => "en" - t.datetime "reset_password_sent_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.integer "own_projects_count", :default => 0, :null => false + t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -416,9 +419,6 @@ ActiveRecord::Schema.define(:version => 20120730214052) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end @@ -430,4 +430,4 @@ ActiveRecord::Schema.define(:version => 20120730214052) do add_index "users", ["uname"], :name => "index_users_on_uname", :unique => true add_index "users", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true -end +end \ No newline at end of file From 7f5f147c36aafc0cfd90f6e0a287382526b40c6c Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 1 Aug 2012 09:15:56 +0400 Subject: [PATCH 52/56] [issue #590] Fixed translation --- config/locales/models/build_list.ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index fa306e55b..db0ec6781 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -125,6 +125,6 @@ ru: no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа! wrong_repository: Репозиторий для сохранения должен принадлежать платформе. - cannot_write: Вы не можете сохранять пакет в этот репозиторий. + cannot_write: Вы не можете собирать пакет в этот репозиторий. can_not_published: Опубликовать сборку можно только со статусом "Собран" frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления From 33d722b77998d9cdbcf72b1f9be2863f8b09d297 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 2 Aug 2012 17:54:34 +0300 Subject: [PATCH 53/56] Fix branch_or_tag parse constraint, minor refactor. Refs #263 --- lib/ext/rosa/constraints.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ext/rosa/constraints.rb b/lib/ext/rosa/constraints.rb index fd7f45fbf..df007e540 100644 --- a/lib/ext/rosa/constraints.rb +++ b/lib/ext/rosa/constraints.rb @@ -24,7 +24,7 @@ module Rosa if (params = request.path_parameters) && params[:treeish] # parse existing branch (tag) and path branch_or_tag = begin (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.map(&:name).sort{|a,b| b.length <=> a.length}.detect{|b| params[:treeish].start_with?(b)} || params[:treeish].split('/').first end if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present? From 80d69a924898ec0a8e634e0b5f48b9bb6c8c02c8 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 3 Aug 2012 13:31:50 +0300 Subject: [PATCH 54/56] Improve srpm import script for processing projects which already exists. Refs #112 --- lib/tasks/import.rake | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index b031980bf..cf1e326a6 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -27,7 +27,7 @@ namespace :import do say 'DONE' end - # bundle exec rake import:srpm RAILS_ENV=production BASE=/share/platforms/naulinux5x_personal/tmp/SRPMS LIST=https://dl.dropbox.com/u/984976/nauschool5x.srpms.txt OWNER=naulinux PLATFORM=naulinux REPO=main > log/srpm_naulinux.log + # bundle exec rake import:srpm RAILS_ENV=production BASE=/share/platforms/naulinux5x_personal/tmp/SRPMS LIST=https://dl.dropbox.com/u/984976/nauschool5x.srpms.txt OWNER=naulinux PLATFORM=naulinux REPO=main CLEAR=true > log/srpm_naulinux.log & desc 'Import SRPMs as projects' task :srpm => :environment do base = ENV['BASE'] || '/share/alt_repos/rsync' @@ -36,17 +36,39 @@ namespace :import do owner = User.find_by_uname(ENV['OWNER']) || Group.find_by_uname!(ENV['OWNER'] || 'altlinux') platform = Platform.find_by_name!(ENV['PLATFORM'] || 'altlinux5') repo = platform.repositories.find_by_name!(ENV['REPO'] || 'main') + clear = ENV['CLEAR'] == 'true' ? true : false + say "START import projects from '#{base}' using '#{list || mask}' for '#{owner.uname}' to repo '#{platform.name}/#{repo.name}'." - repo.project_to_repositories.clear if agree "Clear destination repo #{platform.name}/#{repo.name}?" - (list ? open(list).readlines.map{|n| File.join base, n.chomp.strip} : Dir[File.join base, mask]).each do |path| - print "Processing '#{path}'..." - if name = `rpm -q --qf '[%{Name}]' -p #{path}` and $?.success? and name.present? - p = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) - p.import_srpm(path, platform.name) - repo.projects << p - print "Ok! - #{p.name}" + repo.project_to_repositories.clear if clear + (list ? open(list).readlines.map{|n| File.join base, n.chomp.strip} : Dir[File.join base, mask]).each do |srpm_file| + print "Processing '#{srpm_file}'... " + if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? + if clear # simply add + project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) + repo.projects << project + else # check if project already added + if project = repo.projects.find_by_name(name) || repo.projects.by_name(name).first # fallback to speedup + print "Found project '#{project.owner.uname}/#{project.name}' in '#{platform.name}/#{repo.name}'." + elsif scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) and + project = scoped.find_by_name(name) || scoped.by_name(name).first + begin + repo.projects << project + rescue Exception => e + print "Add project '#{project.owner.uname}/#{project.name}' to '#{platform.name}/#{repo.name}' FAILED: #{e.message}." + else + print "Add project '#{project.owner.uname}/#{project.name}' to '#{platform.name}/#{repo.name}' OK." + end + else + description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) + project = Project.create!(:name => name, :description => description) {|p| p.owner = owner} + repo.projects << project + print "Create project #{project.owner.uname}/#{project.name} in #{platform.name}/#{repo.name} OK." + end + end + project.import_srpm(srpm_file, platform.name) + print " Code import complete!" else - print 'Fail!' + print 'RPM Error!' end puts end From 8bc229f933c1d4ac18dc4f7beeb0bb441ed92476 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 3 Aug 2012 17:15:29 +0400 Subject: [PATCH 55/56] [refs #597] Add help page for new git repo. Remove link to README in project pages, small refactoring. --- .../projects/base/_about_block.html.haml | 6 ++ app/views/projects/base/_layout.html.haml | 7 +- app/views/projects/base/_submenu.html.haml | 2 +- app/views/projects/git/blobs/blame.html.haml | 6 +- app/views/projects/git/commits/show.html.haml | 6 +- app/views/projects/git/trees/empty.html.haml | 71 ++++++++++++++----- config/locales/models/project.en.yml | 4 ++ config/locales/models/project.ru.yml | 4 ++ 8 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 app/views/projects/base/_about_block.html.haml diff --git a/app/views/projects/base/_about_block.html.haml b/app/views/projects/base/_about_block.html.haml new file mode 100644 index 000000000..29cb06554 --- /dev/null +++ b/app/views/projects/base/_about_block.html.haml @@ -0,0 +1,6 @@ +- if project.description.present? + .description + %h3= t("layout.projects.about_subheader") + %p + = project.description + -# link_to t('layout.read_more'), '#' \ No newline at end of file diff --git a/app/views/projects/base/_layout.html.haml b/app/views/projects/base/_layout.html.haml index f21b69b05..bfcce95bb 100644 --- a/app/views/projects/base/_layout.html.haml +++ b/app/views/projects/base/_layout.html.haml @@ -1,11 +1,6 @@ = render 'submenu' = render 'repo_block', :project => @project - -.description - %h3= t("layout.projects.about_subheader") - %p - = @project.description - = link_to t('layout.read_more'), '#' += render 'about_block', :project => @project %h3= t("layout.projects.last_commit") - GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter| diff --git a/app/views/projects/base/_submenu.html.haml b/app/views/projects/base/_submenu.html.haml index 8cb83b928..607ee2ef6 100644 --- a/app/views/projects/base/_submenu.html.haml +++ b/app/views/projects/base/_submenu.html.haml @@ -13,6 +13,6 @@ %li= link_to t("project_menu.tracker"), project_issues_path(@project), :class => (contr == :issues ? 'active' : nil) - if @project.has_wiki %li= link_to t("project_menu.wiki"), project_wiki_index_path(@project), :class => (contr == :wiki ? 'active' : nil) - %li= link_to t("project_menu.readme"), "#" #pending + %li=# link_to t("project_menu.readme"), "#" #pending - if can? :update, @project %li= link_to t("project_menu.settings"), edit_project_path(@project), :class => (act == :edit && contr == :projects ? 'active' : nil) diff --git a/app/views/projects/git/blobs/blame.html.haml b/app/views/projects/git/blobs/blame.html.haml index 9f19328e8..75d54a250 100644 --- a/app/views/projects/git/blobs/blame.html.haml +++ b/app/views/projects/git/blobs/blame.html.haml @@ -1,12 +1,8 @@ -set_meta_tags :title => "#{title_object @project} #{t('at') if @branch} #{@branch.try :name}" = render 'submenu' = render 'repo_block', :project => @project += render 'about_block', :project => @project -.description - %h3= t("layout.projects.about_subheader") - %p - = @project.description - = link_to t('layout.read_more'), '#' %h3= t("layout.projects.last_commit") - GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter| diff --git a/app/views/projects/git/commits/show.html.haml b/app/views/projects/git/commits/show.html.haml index 2fc7f5282..28a008ac9 100644 --- a/app/views/projects/git/commits/show.html.haml +++ b/app/views/projects/git/commits/show.html.haml @@ -1,11 +1,7 @@ -set_meta_tags :title => [title_object(@project), shortest_hash_id(@commit.id), @commit.message] = render 'submenu' += render 'about_block', :project => @project -.description - %h3= t("layout.projects.about_subheader") - %p - = @project.description - = link_to t('layout.read_more'), '#' %h3= t("layout.projects.last_commit") - GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter| diff --git a/app/views/projects/git/trees/empty.html.haml b/app/views/projects/git/trees/empty.html.haml index 2f1ff6733..19edecbf5 100644 --- a/app/views/projects/git/trees/empty.html.haml +++ b/app/views/projects/git/trees/empty.html.haml @@ -1,29 +1,64 @@ -set_meta_tags :title => title_object(@project) = render 'submenu' = render 'repo_block', :project => @project += render 'about_block', :project => @project -.description - %h3= t("layout.projects.about_subheader") - %p - = @project.description - = link_to t('layout.read_more'), '#' -.both -#repo-wrapper +- if @project.parent_id.present? || @project.srpm.exists? + + .both + #repo-wrapper %h3= t("layout.projects.files_in_project") .files .l= render 'whereami' .both + %table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"} + %thead + %tr + %th.th1= t("layout.projects.filename") + %th.th2= t("layout.projects.age") + %th.th3= t("layout.projects.message") + %th.th4= t("layout.projects.author") + %tbody + %tr + %td.centered{:colspan => 4} + %h3= I18n.t("layout.git.repositories.empty") + +- else + - if current_user + %h3= t("layout.projects.git_global_setup") + %p + %code + = "git config --global user.name #{current_user.fullname}" + %br/ + = "git config --global user.email #{current_user.email}" + %br/ + git config --global http.postBuffer 524288000 + + %h3= t("layout.projects.create_repository") + %p + %code + = "git clone #{git_repo_url(@project.git_repo_name)}" + %br/ + = "cd #{@project.name}" + %br/ + %br/ + %p= t("layout.projects.move_files_to_folder") + %br/ + %code + git add . + %br/ + git commit -m 'description message' + %br/ + git push -u origin master + + %h3= t("layout.projects.existing_git_repo") + %p + %code + cd existing_git_repo + %br/ + = "git remote add origin #{git_repo_url(@project.git_repo_name)}" + %br/ + git push -u origin master - %table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"} - %thead - %tr - %th.th1= t("layout.projects.filename") - %th.th2= t("layout.projects.age") - %th.th3= t("layout.projects.message") - %th.th4= t("layout.projects.author") - %tbody - %tr - %td.centered{:colspan => 4} - %h3= I18n.t("layout.git.repositories.empty") diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index ae36f87f0..cbece0222 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -34,6 +34,10 @@ en: has_issue_description: Tracker adds a lightweight issue management system tightly integrated with your repository. has_wiki_description: Wikis are the simplest way to allow other users to contribute content. Any user can create and edit pages for documentation, examples, support or anything you wish. human_average_build_time: Expected time is %{hours} h. %{minutes} min. + git_global_setup: Git global setup + create_repository: Create Repository + move_files_to_folder: Move files you need to the project or create them. + existing_git_repo: Git repo already exist? git_help: cloning: Cloning the repository diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index acaea82e0..db37e98b4 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -34,6 +34,10 @@ ru: has_issue_description: Трэкер предоставляет лекговесный менеджер для задач по разработке Вашего проекта. has_wiki_description: Wiki - это самый простой способ предоставить другим вносить свой вклад в развитие Вашего проекта. Каждый пользователь нашего сервиса может использовать Wiki для документирования, примеров, поддержки или всего другого, в чем у Вас появится необходимость. human_average_build_time: 'Ожидаемое время: %{hours} ч. %{minutes} мин.' + git_global_setup: Общие настройки Git + create_repository: Создание репозитория + move_files_to_folder: Переместите нужные файлы в проект или создайте их. + existing_git_repo: Git репозиторий уже существует? diff_show_header: "%{files} с %{additions} и %{deletions}." about_subheader: "О проекте" From 877007eb8d7bf4022025ec4f817ec1d357c75526 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 3 Aug 2012 23:16:56 +0400 Subject: [PATCH 56/56] [issue #590] Added missed migration --- ...1_add_save_to_repository_to_build_lists.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db/migrate/20120727141521_add_save_to_repository_to_build_lists.rb diff --git a/db/migrate/20120727141521_add_save_to_repository_to_build_lists.rb b/db/migrate/20120727141521_add_save_to_repository_to_build_lists.rb new file mode 100644 index 000000000..f71eb1d01 --- /dev/null +++ b/db/migrate/20120727141521_add_save_to_repository_to_build_lists.rb @@ -0,0 +1,24 @@ +class AddSaveToRepositoryToBuildLists < ActiveRecord::Migration + def self.up + add_column :build_lists, :save_to_repository_id, :integer + + BuildList.scoped.find_in_batches do |batch| + batch.each do |bl| + begin + project = bl.project + platform = bl.save_to_platform + + rep = (project.repositories.map(&:id) & platform.repositories.map(&:id)).first + bl.save_to_repository_id = rep + bl.save + rescue + false + end + end + end + end + + def self.down + remove_column :build_lists, :save_to_repository_id + end +end