diff --git a/Gemfile b/Gemfile index a8d3c9714..6082425d7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '3.2.2' #, :git => 'git://github.com/rails/rails.git' +gem 'rails', '3.2.3' #, :git => 'git://github.com/rails/rails.git' gem 'pg', '~> 0.13.2' # gem 'silent-postgres', :git => 'git://github.com/dolzenko/silent-postgres.git' #'~> 0.1.1' @@ -13,7 +13,7 @@ gem 'omniauth-openid', '~> 1.0.1' gem 'cancan', '~> 1.6.7' gem 'ancestry', '~> 1.2.5' -gem 'paperclip', '~> 2.7.0' +gem 'paperclip', '~> 3.0.2' gem 'delayed_job_active_record', '~> 0.3.2' gem 'russian', '~> 0.6.0' gem 'highline', '~> 1.6.11' @@ -35,30 +35,30 @@ gem 'rdiscount' gem 'RedCloth' gem 'wikicloth' -gem 'unicorn', '~> 4.2.1', :platforms => [:mri, :rbx] +gem 'unicorn', '~> 4.3.0', :platforms => [:mri, :rbx] gem 'trinidad', '~> 1.0.2', :platforms => :jruby -gem 'newrelic_rpm', '~> 3.3.2', :platforms => [:mri, :rbx] +gem 'newrelic_rpm', '~> 3.3.3', :platforms => [:mri, :rbx] gem 'whenever', '~> 0.7.3', :require => false -gem 'rails3-jquery-autocomplete', '~> 1.0.6' +gem 'rails3-jquery-autocomplete', '~> 1.0.7' gem 'will_paginate', '~> 3.0.3' gem 'meta-tags', '~> 1.2.5', :require => 'meta_tags' gem "haml-rails", '~> 0.3.4' -gem 'jquery-rails', '~> 2.0.1' +gem 'jquery-rails', '~> 2.0.2' group :assets do gem 'sass-rails', '~> 3.2.5' gem 'coffee-rails', '~> 3.2.2' gem 'compass-rails', '~> 1.0.1' gem 'uglifier', '~> 1.2.4' - gem 'therubyracer', '~> 0.10.0', :platforms => [:mri, :rbx] + gem 'therubyracer', '~> 0.10.1', :platforms => [:mri, :rbx] gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby end group :production do gem "airbrake", '~> 3.0.9' gem 'bluepill', '~> 0.0.60', :require => false - gem 'daemons', '1.1.6' # for DJ + gem 'daemons', '1.1.6' # Try to upgrade 1.1.8 to avoid tons DJ bugs? end group :development do @@ -74,7 +74,7 @@ end group :test do gem 'rspec-rails', '~> 2.9.0', :group => 'development' - gem 'factory_girl_rails', '~> 3.0.0' + gem 'factory_girl_rails', '~> 3.1.0' gem 'rr', '~> 1.0.4' gem 'shoulda' end diff --git a/Gemfile.lock b/Gemfile.lock index 893a65ef5..adf710ad5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,31 +26,31 @@ GEM specs: RedCloth (4.2.9) RedCloth (4.2.9-java) - actionmailer (3.2.2) - actionpack (= 3.2.2) - mail (~> 2.4.0) - actionpack (3.2.2) - activemodel (= 3.2.2) - activesupport (= 3.2.2) + actionmailer (3.2.3) + actionpack (= 3.2.3) + mail (~> 2.4.4) + actionpack (3.2.3) + activemodel (= 3.2.3) + activesupport (= 3.2.3) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.1) rack (~> 1.4.0) - rack-cache (~> 1.1) + rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.1.2) - activemodel (3.2.2) - activesupport (= 3.2.2) + activemodel (3.2.3) + activesupport (= 3.2.3) builder (~> 3.0.0) - activerecord (3.2.2) - activemodel (= 3.2.2) - activesupport (= 3.2.2) + activerecord (3.2.3) + activemodel (= 3.2.3) + activesupport (= 3.2.3) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.2) - activemodel (= 3.2.2) - activesupport (= 3.2.2) - activesupport (3.2.2) + activeresource (3.2.3) + activemodel (= 3.2.3) + activesupport (= 3.2.3) + activesupport (3.2.3) i18n (~> 0.6) multi_json (~> 1.0) airbrake (3.0.9) @@ -72,7 +72,7 @@ GEM builder (3.0.0) cancan (1.6.7) cape (1.4.0) - capistrano (2.11.2) + capistrano (2.12.0) highline net-scp (>= 1.0.0) net-sftp (>= 2.0.0) @@ -89,7 +89,7 @@ GEM coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.2.0) + coffee-script-source (1.3.1) compass (0.12.1) chunky_png (~> 1.2) fssm (>= 0.2.7) @@ -98,7 +98,7 @@ GEM compass (~> 0.12.0) creole (0.4.2) daemons (1.1.6) - delayed_job (3.0.1) + delayed_job (3.0.2) activesupport (~> 3.0) delayed_job_active_record (0.3.2) activerecord (> 2.1.0) @@ -116,13 +116,13 @@ GEM execjs (1.3.0) multi_json (~> 1.0) expression_parser (0.9.0) - factory_girl (3.0.0) + factory_girl (3.1.1) activesupport (>= 3.0.0) - factory_girl_rails (3.0.0) - factory_girl (~> 3.0.0) + factory_girl_rails (3.1.0) + factory_girl (~> 3.1.0) railties (>= 3.0.0) - fssm (0.2.8.1) - github-markup (0.7.1) + fssm (0.2.9) + github-markup (0.7.2) gollum (1.3.1) albino (~> 1.3.2) github-markup (>= 0.4.0, < 1.0.0) @@ -147,10 +147,10 @@ GEM activesupport (>= 3.0.0) blankslate (>= 2.1.2.4) journey (1.0.3) - jquery-rails (2.0.1) + jquery-rails (2.0.2) railties (>= 3.2.0, < 5.0) thor (~> 0.14) - jruby-rack (1.1.4) + jruby-rack (1.1.5) json (1.6.6) json (1.6.6-java) kgio (2.7.4) @@ -171,7 +171,7 @@ GEM meta-tags (1.2.6) actionpack mime-types (1.18) - multi_json (1.2.0) + multi_json (1.3.2) mustache (0.99.4) net-scp (1.0.4) net-ssh (>= 1.99.1) @@ -180,7 +180,7 @@ GEM net-ssh (2.3.0) net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) - newrelic_rpm (3.3.2.1) + newrelic_rpm (3.3.3) nokogiri (1.5.2) nokogiri (1.5.2-java) omniauth (1.0.3) @@ -190,9 +190,10 @@ GEM omniauth (~> 1.0) rack-openid (~> 1.3.1) orm_adapter (0.0.7) - paperclip (2.7.0) - activerecord (>= 2.3.0) - activesupport (>= 2.3.2) + paperclip (3.0.2) + activemodel (>= 3.0.0) + activerecord (>= 3.0.0) + activesupport (>= 3.0.0) cocaine (>= 0.0.2) mime-types pg (0.13.2) @@ -210,21 +211,21 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) - rails (3.2.2) - actionmailer (= 3.2.2) - actionpack (= 3.2.2) - activerecord (= 3.2.2) - activeresource (= 3.2.2) - activesupport (= 3.2.2) + rails (3.2.3) + actionmailer (= 3.2.3) + actionpack (= 3.2.3) + activerecord (= 3.2.3) + activeresource (= 3.2.3) + activesupport (= 3.2.3) bundler (~> 1.0) - railties (= 3.2.2) + railties (= 3.2.3) rails3-generators (0.17.4) railties (>= 3.0.0) - rails3-jquery-autocomplete (1.0.6) + rails3-jquery-autocomplete (1.0.7) rails (~> 3.0) - railties (3.2.2) - actionpack (= 3.2.2) - activesupport (= 3.2.2) + railties (3.2.3) + actionpack (= 3.2.3) + activesupport (= 3.2.3) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -241,7 +242,7 @@ GEM rspec-expectations (~> 2.9.0) rspec-mocks (~> 2.9.0) rspec-core (2.9.0) - rspec-expectations (2.9.0) + rspec-expectations (2.9.1) diff-lcs (~> 1.1.3) rspec-mocks (2.9.0) rspec-rails (2.9.0) @@ -277,11 +278,11 @@ GEM hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.5) + sqlite3 (1.3.6) state_machine (1.1.2) - therubyracer (0.10.0) + therubyracer (0.10.1) libv8 (~> 3.3.10) - therubyrhino (1.73.1) + therubyrhino (1.73.2) thin (1.3.1) daemons (>= 1.0.9) eventmachine (>= 0.12.6) @@ -294,12 +295,12 @@ GEM trinidad (1.0.5) jruby-rack (>= 1.0.2) trinidad_jars (>= 0.3.0) - trinidad_jars (1.0.2) - tzinfo (0.3.32) + trinidad_jars (1.0.3) + tzinfo (0.3.33) uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) - unicorn (4.2.1) + unicorn (4.3.0) kgio (~> 2.6) rack raindrops (~> 0.7) @@ -308,7 +309,7 @@ GEM whenever (0.7.3) activesupport (>= 2.3.4) chronic (~> 0.6.3) - wikicloth (0.7.1) + wikicloth (0.8.0) builder expression_parser will_paginate (3.0.3) @@ -334,7 +335,7 @@ DEPENDENCIES delayed_job_active_record (~> 0.3.2) devise (~> 2.0.4) diff-display (~> 0.0.1) - factory_girl_rails (~> 3.0.0) + factory_girl_rails (~> 3.1.0) gollum (= 1.3.1) grack! grit! @@ -342,17 +343,17 @@ DEPENDENCIES highline (~> 1.6.11) hirb jbuilder - jquery-rails (~> 2.0.1) + jquery-rails (~> 2.0.2) mailcatcher meta-tags (~> 1.2.5) - newrelic_rpm (~> 3.3.2) + newrelic_rpm (~> 3.3.3) omniauth (~> 1.0.3) omniauth-openid (~> 1.0.1) - paperclip (~> 2.7.0) + paperclip (~> 3.0.2) pg (~> 0.13.2) - rails (= 3.2.2) + rails (= 3.2.3) rails3-generators - rails3-jquery-autocomplete (~> 1.0.6) + rails3-jquery-autocomplete (~> 1.0.7) rdiscount redcarpet (= 1.17.2) redhillonrails_core! @@ -362,11 +363,11 @@ DEPENDENCIES sass-rails (~> 3.2.5) shotgun shoulda - therubyracer (~> 0.10.0) + therubyracer (~> 0.10.1) therubyrhino (~> 1.73.1) trinidad (~> 1.0.2) uglifier (~> 1.2.4) - unicorn (~> 4.2.1) + unicorn (~> 4.3.0) whenever (~> 0.7.3) wikicloth will_paginate (~> 3.0.3) diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 4b72de3ea..0a51d2164 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -6,15 +6,16 @@ class BuildListsController < ApplicationController before_filter :authenticate_user!, :except => CALLBACK_ACTIONS before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS skip_before_filter :authenticate_user!, :only => [:show, :index, :search] if APP_CONFIG['anonymous_access'] - before_filter :find_project, :only => NESTED_ACTIONS - before_filter :find_build_list, :only => [:show, :publish, :cancel, :reject_publish] + + before_filter :find_build_list, :only => [:show, :publish, :cancel] before_filter :find_build_list_by_bs, :only => [:publish_build, :status_build, :pre_build, :post_build, :circle_build] - before_filter :find_platform, :only => [:create] load_and_authorize_resource :project, :only => NESTED_ACTIONS load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true load_and_authorize_resource :except => CALLBACK_ACTIONS.concat(NESTED_ACTIONS) + include Modules::Controllers::FindProject + def search new_params = {:filter => {}} params[:filter].each do |k,v| @@ -41,6 +42,7 @@ class BuildListsController < ApplicationController def create notices, errors = [], [] + @platform = Platform.find params[:build_list][:pl_id] params[:build_list].delete(:auto_publish) if @platform.released Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[:bpls]).each do |bpl| @@ -159,14 +161,6 @@ class BuildListsController < ApplicationController protected - def find_project - @project = Project.find_by_id params[:project_id] - end - - def find_platform - @platform = Platform.find params[:build_list][:pl_id] - end - def find_build_list @build_list = BuildList.find(params[:id]) end diff --git a/app/controllers/collaborators_controller.rb b/app/controllers/collaborators_controller.rb index ac237350a..325e0fe59 100644 --- a/app/controllers/collaborators_controller.rb +++ b/app/controllers/collaborators_controller.rb @@ -1,13 +1,13 @@ # -*- encoding : utf-8 -*- class CollaboratorsController < ApplicationController before_filter :authenticate_user! + load_resource :project + before_filter :authorize_collaborators - before_filter :find_project before_filter :find_users before_filter :find_groups - load_resource :project - before_filter :authorize_collaborators + include Modules::Controllers::FindProject def index redirect_to edit_project_collaborators_path(@project) @@ -125,21 +125,17 @@ class CollaboratorsController < ApplicationController protected - def find_project - @project = Project.find params[:project_id] - end + def find_users + @users = @project.collaborators.order('uname')#User.all + @users = @users.without(@project.owner_id) if @project.owner_type == 'User' + end - def find_users - @users = @project.collaborators.order('uname')#User.all - @users = @users.without(@project.owner_id) if @project.owner_type == 'User' - end + def find_groups + @groups = @project.groups.order('uname')#Group.all + @groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group' + end - def find_groups - @groups = @project.groups.order('uname')#Group.all - @groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group' - end - - def authorize_collaborators - authorize! :update, @project - end + def authorize_collaborators + authorize! :update, @project + end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 6d5875178..970467e54 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -7,6 +7,7 @@ class CommentsController < ApplicationController load_and_authorize_resource include CommentsHelper + include Modules::Controllers::FindProject def create if @comment.save diff --git a/app/controllers/commit_subscribes_controller.rb b/app/controllers/commit_subscribes_controller.rb index 35029b95f..394810d81 100644 --- a/app/controllers/commit_subscribes_controller.rb +++ b/app/controllers/commit_subscribes_controller.rb @@ -1,11 +1,12 @@ # -*- encoding : utf-8 -*- class CommitSubscribesController < ApplicationController before_filter :authenticate_user! - load_and_authorize_resource :project before_filter :find_commit + include Modules::Controllers::FindProject + def create if Subscribe.subscribe_to_commit(@options) flash[:notice] = I18n.t("flash.subscribe.commit.saved") diff --git a/app/controllers/git/base_controller.rb b/app/controllers/git/base_controller.rb index 08e9def92..1d18a573b 100644 --- a/app/controllers/git/base_controller.rb +++ b/app/controllers/git/base_controller.rb @@ -11,28 +11,31 @@ class Git::BaseController < ApplicationController before_filter :set_current_tag before_filter :set_current_branch + include Modules::Controllers::FindProject + protected - def find_git_repository - @git_repository = @project.git_repository - end - def find_tags - @tags = @git_repository.tags - end + def find_git_repository + @git_repository = @project.git_repository + end - def find_branches - @branches = @git_repository.branches - end + def find_tags + @tags = @git_repository.tags + end - def set_treeish - @treeish = params[:treeish].presence || @project.default_branch - end + def find_branches + @branches = @git_repository.branches + end - def set_current_tag - @current_tag = @tags.select{|t| t.name == @treeish }.first - end + def set_treeish + @treeish = params[:treeish].presence || @project.default_branch + end - def set_current_branch - @current_branch = @branches.select{|b| b.name == @treeish }.first - 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 + end end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 0ce847f58..50b827c9c 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -9,6 +9,8 @@ class IssuesController < ApplicationController layout 'application' + include Modules::Controllers::FindProject + def index(status = 200) @is_assigned_to_me = params[:filter] == 'to_me' @status = params[:status] == 'closed' ? 'closed' : 'open' @@ -77,12 +79,12 @@ class IssuesController < ApplicationController end def create_label - status = @project.labels.create(:name => params[:name], :color => params[:color]) ? 200 : 500 + status = @project.labels.create!(:name => params[:name], :color => params[:color]) ? 200 : 500 index(status) end def update_label - status = @label.update_attributes( :name => params[:name], :color => params[:color]) ? 200 : 500 + status = @label.update_attributes(:name => params[:name], :color => params[:color]) ? 200 : 500 index(status) end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8f9a949ad..ade7fde53 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -3,6 +3,8 @@ class ProjectsController < ApplicationController before_filter :authenticate_user! load_and_authorize_resource + include Modules::Controllers::FindProject + def index @projects = Project.accessible_by(current_ability, :membered) # @projects = @projects.search(params[:query]).search_order if params[:query].present? @@ -72,11 +74,11 @@ class ProjectsController < ApplicationController if request.post? if @project.update_attributes(params[:project]) flash[:notice] = t('flash.project.saved') + redirect_to sections_project_path(@project) else @project.save flash[:error] = t('flash.project.save_error') end - render :action => :sections end end diff --git a/app/controllers/subscribes_controller.rb b/app/controllers/subscribes_controller.rb index ddf208c64..ee9e15fe3 100644 --- a/app/controllers/subscribes_controller.rb +++ b/app/controllers/subscribes_controller.rb @@ -6,6 +6,8 @@ class SubscribesController < ApplicationController load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id load_and_authorize_resource :subscribe, :through => :issue, :find_by => :user_id + include Modules::Controllers::FindProject + def create @subscribe = @issue.subscribes.build(:user_id => current_user.id) if @subscribe.save diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 9a5149b5f..97a0ea45a 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -13,6 +13,8 @@ class WikiController < ApplicationController before_filter :authorize_write_actions, :only => [:edit, :update, :new, :create, :destroy, :revert, :revert_wiki, :preview] before_filter :get_wiki + include Modules::Controllers::FindProject + def index @name = 'Home' @page = @wiki.page(@name) diff --git a/app/models/ability.rb b/app/models/ability.rb index 4002c3a68..c91c07f9e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -58,7 +58,7 @@ class Ability can(:write, Project) {|project| local_writer? project} # for grack can([:update, :sections, :manage_collaborators], Project) {|project| local_admin? project} can(:fork, Project) {|project| can? :read, project} - can(:fork_to_group, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner} + can(:fork, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner} can(:destroy, Project) {|project| owner? project} can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin')} can :remove_user, Project @@ -118,13 +118,10 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} - cannot :fork, Project, :owner_id => user.id, :owner_type => user.class.to_s cannot :destroy, Issue cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' -# cannot :read, Product, :platform => {:platform_type => 'personal'} -# cannot(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.platform_type == 'personal'} cannot [:create, :update, :destroy, :clone], Product, :platform => {:platform_type => 'personal'} cannot [:clone, :build_all], Platform, :platform_type => 'personal' diff --git a/app/models/group.rb b/app/models/group.rb index 3f9b976a2..15c6260b7 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -13,7 +13,7 @@ class Group < ActiveRecord::Base has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy validates :owner, :presence => true - validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } + validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? } scope :search_order, order("CHAR_LENGTH(uname) ASC") @@ -37,6 +37,8 @@ class Group < ActiveRecord::Base (by_owner(user) | by_admin(user)) end + def to_param; uname; end + def name uname end diff --git a/app/models/issue.rb b/app/models/issue.rb index 11f6d9849..4afeff7a5 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -9,8 +9,8 @@ class Issue < ActiveRecord::Base has_many :comments, :as => :commentable, :dependent => :destroy has_many :subscribes, :as => :subscribeable, :dependent => :destroy + has_many :labelings, :dependent => :destroy has_many :labels, :through => :labelings, :uniq => true - has_many :labelings validates :title, :body, :project_id, :presence => true diff --git a/app/models/label.rb b/app/models/label.rb index e5fe686f2..fe4ad5b22 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -4,7 +4,7 @@ class Label < ActiveRecord::Base has_many :issues, :through => :labelings belongs_to :project - validates :name, :uniqueness => { :scope => :project_id} + validates :name, :uniqueness => {:scope => :project_id} validates :name, :color, :presence => true validates :color, :format => { :with => /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, :message => I18n.t('layout.issues.invalid_labels')} diff --git a/app/models/project.rb b/app/models/project.rb index 08cd7c577..ff5da4bd8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -51,6 +51,18 @@ class Project < ActiveRecord::Base include Modules::Models::Owner + 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) and + scoped = where(:owner_id => owner.id, :owner_type => owner.class) and + scoped.find_by_name(project_name) || scoped.by_name(project_name).first + 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 + end + def build_for(platform, user, arch = 'i586') # Select main and project platform repository(contrib, non-free and etc) # If main does not exist, will connect only project platform repository @@ -58,7 +70,6 @@ class Project < ActiveRecord::Base build_reps = [platform.repositories.find_by_name('main')] build_reps += platform.repositories.select {|rep| self.repository_ids.include? rep.id} build_ids = build_reps.compact.map(&:id).uniq - arch = Arch.find_by_name(arch) if arch.acts_like?(:string) build_lists.create do |bl| bl.pl = platform diff --git a/app/models/user.rb b/app/models/user.rb index a6b7d6b32..e5f813714 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,7 +37,7 @@ class User < ActiveRecord::Base include Modules::Models::PersonalRepository - validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } + validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true validate { errors.add(:uname, :taken) if Group.where('uname LIKE ?', uname).present? } validates :role, :inclusion => {:in => ROLES}, :allow_blank => true validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true @@ -58,6 +58,8 @@ class User < ActiveRecord::Base after_create lambda { self.create_notifier } before_create :ensure_authentication_token + def to_param; uname; end + def admin? role == 'admin' end diff --git a/app/views/activity_feeds/partials/_build_list_notification.haml b/app/views/activity_feeds/partials/_build_list_notification.haml index 71cc37532..c7cb4ce97 100644 --- a/app/views/activity_feeds/partials/_build_list_notification.haml +++ b/app/views/activity_feeds/partials/_build_list_notification.haml @@ -4,7 +4,7 @@ .text %span = raw t('notifications.bodies.build_task', :task_num => task_num, :task_link => build_list_path(build_list_id)) - = raw t('notifications.bodies.project', :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t('notifications.bodies.project', :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) - message, error = case status - when BuildList::BUILD_PENDING - ['pending', nil] diff --git a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml index 1b5ff12f0..07eb376d9 100644 --- a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml +++ b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml @@ -2,7 +2,7 @@ .text %span = t('notifications.bodies.delete_branch', :branch_name => branch_name) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_git_new_push_notification.haml b/app/views/activity_feeds/partials/_git_new_push_notification.haml index 6d5488015..9c6f23edc 100644 --- a/app/views/activity_feeds/partials/_git_new_push_notification.haml +++ b/app/views/activity_feeds/partials/_git_new_push_notification.haml @@ -5,12 +5,12 @@ .text %span = raw t("notifications.bodies.#{change_type}_branch", {:branch_name => branch_name, :user_link => defined?(user_name) ? link_to(user_name, user_path(user_id)) : user_email}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both %span.subject - last_commits.each do |commit| - = link_to shortest_hash_id(commit[0]), commit_path(project_id, commit[0]) + = link_to shortest_hash_id(commit[0]), commit_path(project_owner, project_name, commit[0]) = commit[1] %br diff --git a/app/views/activity_feeds/partials/_issue_assign_notification.haml b/app/views/activity_feeds/partials/_issue_assign_notification.haml index 89b44c1fb..cf9df13d1 100644 --- a/app/views/activity_feeds/partials/_issue_assign_notification.haml +++ b/app/views/activity_feeds/partials/_issue_assign_notification.haml @@ -1,8 +1,8 @@ .top .text %span - = raw t("notifications.bodies.issue_assign_notification", { :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.issue_assign_notification", { :issue_link => link_to(issue_title, project_issue_path(project_owner, project_name, issue_serial_id))}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_new_comment_commit_notification.haml b/app/views/activity_feeds/partials/_new_comment_commit_notification.haml index fc55dca15..003ffd448 100644 --- a/app/views/activity_feeds/partials/_new_comment_commit_notification.haml +++ b/app/views/activity_feeds/partials/_new_comment_commit_notification.haml @@ -4,8 +4,8 @@ .text %span = raw t("notifications.bodies.new_comment_notification.title", :user_link => link_to(user_name, user_path(user_id)) ) - = raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_id, commit_id) + "#comment##{comment_id}")}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_owner, project_name, commit_id) + "#comment##{comment_id}")}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_new_comment_notification.haml b/app/views/activity_feeds/partials/_new_comment_notification.haml index 1f85c39e2..567aae9a3 100644 --- a/app/views/activity_feeds/partials/_new_comment_notification.haml +++ b/app/views/activity_feeds/partials/_new_comment_notification.haml @@ -4,8 +4,8 @@ .text %span = raw t("notifications.bodies.new_comment_notification.title", {:user_link => link_to(user_name, user_path(user_id))}) - = raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id) + "#comment##{comment_id}")}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_owner, project_name, issue_serial_id) + "#comment##{comment_id}")}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_new_issue_notification.haml b/app/views/activity_feeds/partials/_new_issue_notification.haml index dc82e2961..1d9e1ca06 100644 --- a/app/views/activity_feeds/partials/_new_issue_notification.haml +++ b/app/views/activity_feeds/partials/_new_issue_notification.haml @@ -3,8 +3,8 @@ = image_tag(avatar_url_by_email(user_email, :small), :alt => 'avatar') .text %span - = raw t("notifications.bodies.new_issue_notification", { :user_link => link_to(user_name, user_path(user_id)), :issue_link => project_issue_path(project_id, issue_serial_id)}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.new_issue_notification", { :user_link => link_to(user_name, user_path(user_id)), :issue_link => project_issue_path(project_owner, project_name, issue_serial_id)}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml index 69b61f326..d21a3abd9 100644 --- a/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml +++ b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml @@ -3,8 +3,8 @@ = image_tag(avatar_url_by_email(user_email, :small), :alt => 'avatar') .text %span - = raw t("notifications.bodies.wiki_new_commit_notification", {:user_link => user_name, :history_link => link_to("wiki", history_project_wiki_index_path(project_id))}) - = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_id)) ) + = raw t("notifications.bodies.wiki_new_commit_notification", {:user_link => user_name, :history_link => link_to("wiki", history_project_wiki_index_path(project_owner, project_name))}) + = raw t("notifications.bodies.project", :project_link => link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) .both %span.date= activity_feed.created_at .both diff --git a/app/views/git/shared/_choose_fork.html.haml b/app/views/git/shared/_choose_fork.html.haml index e80785982..8bffb0d33 100644 --- a/app/views/git/shared/_choose_fork.html.haml +++ b/app/views/git/shared/_choose_fork.html.haml @@ -2,7 +2,7 @@ - is_group = owner.class == Group ? "(#{t 'activerecord.models.group'})" : '' %p.center =t 'layout.projects.already_exists' - =link_to "#{owner.uname}/#{@project.name} #{is_group}", project_path(owner.projects.by_name(@project.name).first.id) + =link_to "#{owner.uname}/#{@project.name} #{is_group}", project_path(owner.projects.by_name(@project.name).first) - else = form_for @project, :url => fork_project_path(@project), :html => { :class => :form, :multipart => true, :method => :post } do |f| = hidden_field_tag :group, owner.id if owner.class == Group diff --git a/app/views/issues/_issue.html.haml b/app/views/issues/_issue.html.haml index 36cfa22c1..5f0c13ec4 100644 --- a/app/views/issues/_issue.html.haml +++ b/app/views/issues/_issue.html.haml @@ -3,7 +3,7 @@ %span{:style => "display: none;"}=issue.serial_id %td.td1=issue.serial_id %td - %a{:href => project_issue_path(@project.id, issue.serial_id)} + %a{:href => project_issue_path(@project, issue)} %div.issue_title=issue.title .smalltext =issue.created_at.to_s(:long) diff --git a/app/views/projects/_repo_block.html.haml b/app/views/projects/_repo_block.html.haml index 2a7cca771..3cf414a5b 100644 --- a/app/views/projects/_repo_block.html.haml +++ b/app/views/projects/_repo_block.html.haml @@ -5,8 +5,8 @@ =image_tag 'zip.png', :alt => 'ZIP' %b.caret %ul.dropdown-menu - %li=link_to "tar.gz", archive_path(project.id, 'tar', @treeish) - %li=link_to "zip", archive_path(project.id, 'zip', @treeish) + %li=link_to "tar.gz", archive_path(project, 'tar', @treeish) + %li=link_to "zip", archive_path(project, 'zip', @treeish) = text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true .git_help ? diff --git a/bin/autostart.sh b/bin/autostart.sh index c65917012..02a018aef 100755 --- a/bin/autostart.sh +++ b/bin/autostart.sh @@ -1,8 +1,8 @@ #!/bin/bash -for f in `ls /srv` -do - su -l rosa -c "cd /srv/$f/current && APP_NAME=$f bundle exec bluepill --no-privileged load /srv/$f/current/config/production.pill" -done +# for f in `ls /srv` +# do +# su -l rosa -c "cd /srv/$f/current && APP_NAME=$f bundle exec bluepill --no-privileged load /srv/$f/current/config/production.pill" +# done /srv/rosa_build/current/bin/mount_downloads.sh diff --git a/config/routes.rb b/config/routes.rb index d5c34c86b..95ebfa49a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,87 +75,6 @@ Rosa::Application.routes.draw do end match '/private/:platform_name/*file_path' => 'privates#show' - resources :projects, :except => [:show] do - resources :wiki do - collection do - match '_history' => 'wiki#wiki_history', :as => :history, :via => :get - match '_access' => 'wiki#git', :as => :git, :via => :get - match '_revert/:sha1/:sha2' => 'wiki#revert_wiki', :as => :revert, :via => [:get, :post] - match '_compare' => 'wiki#compare_wiki', :as => :compare, :via => :post - #match '_compare/:versions' => 'wiki#compare_wiki', :versions => /.*/, :as => :compare_versions, :via => :get - match '_compare/:versions' => 'wiki#compare_wiki', :versions => /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, :as => :compare_versions, :via => :get - post :preview - get :search - get :pages - end - member do - get :history - get :edit - match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => [:get, :post] - match ':ref' => 'wiki#show', :as => :versioned, :via => :get - - post :compare - #match 'compare/*versions' => 'wiki#compare', :as => :compare_versions, :via => :get - match 'compare/:versions' => 'wiki#compare', :versions => /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, :as => :compare_versions, :via => :get - end - end - resources :issues, :except => :edit do - resources :comments, :only => [:edit, :create, :update, :destroy] - resources :subscribes, :only => [:create, :destroy] - collection do - post :create_label - get :search_collaborators - end - end - post "labels/:label_id" => "issues#destroy_label", :as => :issues_delete_label - post "labels/:label_id/update" => "issues#update_label", :as => :issues_update_label - resources :build_lists, :only => [:index, :new, :create] do - collection { post :search } - end - resources :collaborators, :only => [:index, :edit, :update, :add] do - collection do - get :edit - post :update - post :add - delete :remove - end - member do - post :update - end - end - member do - post :fork - get :sections - post :sections - delete :remove_user - end - end - # Tree - get '/projects/:project_id' => "git/trees#show", :as => :project - get '/projects/:project_id/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree - # Commits - get '/projects/:project_id/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :as => :commits, :format => false - get '/projects/:project_id/commit/:id(.:format)' => "git/commits#show", :as => :commit - # Commit comments - post '/projects/:project_id/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments - get '/projects/:project_id/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment - put '/projects/:project_id/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment - delete '/projects/:project_id/commit/:commit_id/comments/:id(.:format)' => "comments#destroy" - # Commit subscribes - post '/projects/:project_id/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit - delete '/projects/:project_id/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit - # Editing files - get '/projects/:project_id/blob/:treeish/*path/edit' => "git/blobs#edit", :defaults => {:treeish => :master}, :as => :edit_blob - put '/projects/:project_id/blob/:treeish/*path' => "git/blobs#update", :defaults => {:treeish => :master}, :format => false - # Blobs - get '/projects/:project_id/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false - # Blame - get '/projects/:project_id/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false - # Raw - get '/projects/:project_id/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false - - get '/projects/:project_id/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ - # Core callbacks match 'build_lists/publish_build', :to => "build_lists#publish_build" match 'build_lists/status_build', :to => "build_lists#status_build" @@ -184,6 +103,97 @@ Rosa::Application.routes.draw do get '/activity_feeds.:format' => 'activity_feeds#index', :as => 'atom_activity_feeds', :format => /atom/ + resources :projects, :only => [:index, :new, :create] + scope ':owner_name' do # Owner + # TODO User routes here + + scope ':project_name', :as => 'project' do + resources :wiki do + collection do + match '_history' => 'wiki#wiki_history', :as => :history, :via => :get + match '_access' => 'wiki#git', :as => :git, :via => :get + match '_revert/:sha1/:sha2' => 'wiki#revert_wiki', :as => :revert, :via => [:get, :post] + match '_compare' => 'wiki#compare_wiki', :as => :compare, :via => :post + #match '_compare/:versions' => 'wiki#compare_wiki', :versions => /.*/, :as => :compare_versions, :via => :get + match '_compare/:versions' => 'wiki#compare_wiki', :versions => /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, :as => :compare_versions, :via => :get + post :preview + get :search + get :pages + end + member do + get :history + get :edit + match 'revert/:sha1/:sha2' => 'wiki#revert', :as => :revert_page, :via => [:get, :post] + match ':ref' => 'wiki#show', :as => :versioned, :via => :get + + post :compare + #match 'compare/*versions' => 'wiki#compare', :as => :compare_versions, :via => :get + match 'compare/:versions' => 'wiki#compare', :versions => /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, :as => :compare_versions, :via => :get + end + end + resources :issues, :except => :edit do + resources :comments, :only => [:edit, :create, :update, :destroy] + resources :subscribes, :only => [:create, :destroy] + collection do + post :create_label + get :search_collaborators + end + end + post "/labels/:label_id" => "issues#destroy_label", :as => :issues_delete_label + post "/labels/:label_id/update" => "issues#update_label", :as => :issues_update_label + resources :build_lists, :only => [:index, :new, :create] do + collection { post :search } + end + resources :collaborators, :only => [:index, :edit, :update, :add] do + collection do + get :edit + post :update + post :add + delete :remove + end + member do + post :update + end + end + end + scope ':project_name' do + # Resource + get '/edit' => 'projects#edit', :as => :edit_project + put '/' => 'projects#update' + delete '/' => 'projects#destroy' + # Member + post '/fork' => 'projects#fork', :as => :fork_project + get '/sections' => 'projects#sections', :as => :sections_project + post '/sections' => 'projects#sections' + delete '/remove_user' => 'projects#remove_user', :as => :remove_user_project + # Tree + get '/' => "git/trees#show", :as => :project + get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree + # 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/ + end + end + if APP_CONFIG['anonymous_access'] authenticated do root :to => 'activity_feeds#index' diff --git a/db/schema.rb b/db/schema.rb index 0b20e0d3a..268f35792 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "arches", :force => true do |t| @@ -180,7 +180,7 @@ ActiveRecord::Schema.define(:version => 20120418100619) do 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 @@ -251,25 +251,27 @@ ActiveRecord::Schema.define(:version => 20120418100619) 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_rpm", :default => true 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", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end @@ -323,7 +325,6 @@ ActiveRecord::Schema.define(:version => 20120418100619) 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" @@ -331,11 +332,8 @@ ActiveRecord::Schema.define(:version => 20120418100619) do 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" @@ -347,6 +345,9 @@ ActiveRecord::Schema.define(:version => 20120418100619) 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" end diff --git a/lib/ext/render_errors_in_forms.rb b/lib/ext/rails/render_errors_in_forms.rb similarity index 100% rename from lib/ext/render_errors_in_forms.rb rename to lib/ext/rails/render_errors_in_forms.rb diff --git a/lib/ext/rails/reserved_name_validator.rb b/lib/ext/rails/reserved_name_validator.rb new file mode 100644 index 000000000..c3f668b01 --- /dev/null +++ b/lib/ext/rails/reserved_name_validator.rb @@ -0,0 +1,32 @@ +class ReservedNameValidator < ActiveModel::EachValidator + RESERVED_NAMES = %w{ + about account add admin administrator api + app apps archive archives auth + blog + config connect contact create commit commits + dashboard delete direct_messages downloads + edit email + faq favorites feed feeds follow followers following + help home + invitations invite + jobs + login log-in log_in logout log-out log_out logs + map maps + oauth oauth_clients openid + privacy + register remove replies rss root + save search sessions settings + signup sign-up sign_up signin sign-in sign_in signout sign-out sign_out + sitemap ssl subscribe + teams terms test trends tree + unfollow unsubscribe url user + widget widgets wiki + xfn xmpp + } << Rails.application.routes.routes.map{|r| r.path.spec.to_s.match(/^\/([\w-]+)/)[1] rescue nil}.uniq.compact # current routes + + def validate_each(record, attribute, value) + if RESERVED_NAMES.include?(value.downcase) + record.errors.add(attribute, :exclusion, options.merge!(:value => value)) + end + end +end diff --git a/lib/ext/rails/url_for.rb b/lib/ext/rails/url_for.rb new file mode 100644 index 000000000..09e5b98cc --- /dev/null +++ b/lib/ext/rails/url_for.rb @@ -0,0 +1,19 @@ +# -*- encoding : utf-8 -*- +module ActionDispatch + module Routing + module UrlFor + def url_for_with_defaults(options = nil) + # raise options.inspect + if options.kind_of?(Hash) + # if options[:controller] == 'projects' and options[:action] == 'show' and post = options[:_positional_args].try(:first) and post.blog + if project = options[:_positional_args].try(:first) and project.is_a?(Project) + options[:_positional_args].unshift(project.owner) + # options[:use_route] = 'blog_post' + end + end + url_for_without_defaults(options) + end + alias_method_chain :url_for, :defaults + end + end +end diff --git a/lib/modules/controllers/find_project.rb b/lib/modules/controllers/find_project.rb new file mode 100644 index 000000000..3f2c7559d --- /dev/null +++ b/lib/modules/controllers/find_project.rb @@ -0,0 +1,21 @@ +# -*- encoding : utf-8 -*- +module Modules + module Controllers + module FindProject + extend ActiveSupport::Concern + + included do + prepend_before_filter :find_project + end + + protected + + def find_project + @project = Project.find_by_owner_and_name!(params[:owner_name], params[:project_name]) if params[:owner_name] && params[:project_name] + end + + module ClassMethods + end + end + end +end diff --git a/lib/plugins/grack/base.rb b/lib/plugins/grack/base.rb index 2f0cc70bc..b464f44ee 100644 --- a/lib/plugins/grack/base.rb +++ b/lib/plugins/grack/base.rb @@ -35,11 +35,8 @@ module Grack def project @project ||= begin uname, name = @env['PATH_INFO'].split('/')[1,2] - name.gsub! /\.git$/, '' - name.gsub! /\.wiki$/, '' - owner = User.find_by_uname(uname) || Group.find_by_uname(uname) - scoped = Project.where(:owner_id => owner.id, :owner_type => owner.class) - scoped.find_by_name(name) || scoped.by_name(name).first + name.gsub!(/\.git$/, '').gsub!(/\.wiki$/, '') + Project.find_by_owner_and_name uname, name end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index cafbaee12..36772f197 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -41,7 +41,7 @@ end shared_examples_for 'no group user' do it 'should be able to perform create action' do post :create, @create_params - response.should redirect_to(group_path( Group.last.id )) + response.should redirect_to(group_path(Group.last)) end it 'should change objects count on create' do diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index eceef48a5..eb99337fb 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -9,7 +9,7 @@ describe ProjectsController do @project = FactoryGirl.create(:project) @another_user = FactoryGirl.create(:user) @create_params = {:project => {:name => 'pro'}} - @update_params = {:project => {:name => 'pro2'}} + @update_params = {:project => {:description => 'pro2'}} end context 'for guest' do @@ -19,7 +19,7 @@ describe ProjectsController do end it 'should not be able to perform update action' do - put :update, {:id => @project.id}.merge(@update_params) + put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params) response.should redirect_to(new_user_session_path) end end @@ -35,7 +35,7 @@ describe ProjectsController do it 'should be able to perform create action' do post :create, @create_params - response.should redirect_to(project_path( Project.last.id )) + response.should redirect_to(project_path( Project.last )) end it 'should change objects count on create' do @@ -55,17 +55,18 @@ describe ProjectsController do it_should_behave_like 'user with rights to view projects' it 'should be able to perform destroy action' do - delete :destroy, {:id => @project.id} + delete :destroy, {:owner_name => @project.owner.uname, :project_name => @project.name} response.should redirect_to(@project.owner) end it 'should change objects count on destroy' do - lambda { delete :destroy, :id => @project.id }.should change{ Project.count }.by(-1) + lambda { delete :destroy, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Project.count }.by(-1) end it 'should not be able to fork project' do - post :fork, :id => @project.id - response.should redirect_to(forbidden_path) + post :fork, :owner_name => @project.owner.uname, :project_name => @project.name + # @project.errors.count.should == 1 + response.should redirect_to(@project) end end @@ -97,15 +98,15 @@ describe ProjectsController do it 'should not be able to fork project to other group' do group = FactoryGirl.create(:group) - post :fork, :id => @project.id, :group => group.id + post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id response.should redirect_to(forbidden_path) end it 'should be able to fork project to group' do group = FactoryGirl.create(:group) group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin') - post :fork, :id => @project.id, :group => group.id - response.should redirect_to(project_path(group.projects.first.id)) + post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id + response.should redirect_to(project_path(group.projects.first)) end end @@ -128,8 +129,8 @@ describe ProjectsController do @user = FactoryGirl.create(:user) set_session_for(@user) @project.update_attribute(:visibility, 'hidden') - post :fork, :id => @project.id - response.should redirect_to(forbidden_path) + post :fork, :owner_name => @project.owner.uname, :project_name => @project.name + response.should redirect_to(@project) end end end diff --git a/spec/support/shared_examples/projects_controller.rb b/spec/support/shared_examples/projects_controller.rb index a31fe4727..0562f06d8 100644 --- a/spec/support/shared_examples/projects_controller.rb +++ b/spec/support/shared_examples/projects_controller.rb @@ -3,14 +3,14 @@ shared_examples_for 'projects user with reader rights' do it_should_behave_like 'user with rights to view projects' it 'should be able to fork project' do - post :fork, :id => @project.id + post :fork, :owner_name => @project.owner.uname, :project_name => @project.name response.should redirect_to(project_path(Project.last)) end end shared_examples_for 'projects user with admin rights' do it 'should be able to perform update action' do - put :update, {:id => @project.id}.merge(@update_params) + put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params) response.should redirect_to(project_path(@project)) end end