From b1b5363972c354411c50bd7f946a014384f069e0 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 3 May 2012 19:48:22 +0300 Subject: [PATCH 1/2] Fix deploy. Redo main group route. Refs #263 --- Gemfile | 1 + Gemfile.lock | 3 +++ app/views/groups/profile/edit.html.haml | 4 ++-- config/deploy.rb | 14 ++++++-------- config/routes.rb | 3 ++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 7802d7937..f4bcc710b 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,7 @@ group :development do gem 'shotgun' # deploy gem 'capistrano', :require => false + gem 'rvm-capistrano', :require => false gem 'cape', :require => false gem 'capistrano_colors', :require => false end diff --git a/Gemfile.lock b/Gemfile.lock index 5a00f6b74..4b3b34f2f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,6 +255,8 @@ GEM ruby-openid (2.1.8) russian (0.6.0) i18n (>= 0.5.0) + rvm-capistrano (1.1.0) + capistrano (>= 2.0.0) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) sass (3.1.16) @@ -358,6 +360,7 @@ DEPENDENCIES rspec-rails (~> 2.9.0) ruby-haml-js (~> 0.0.3) russian (~> 0.6.0) + rvm-capistrano sass-rails (~> 3.2.5) shotgun shoulda diff --git a/app/views/groups/profile/edit.html.haml b/app/views/groups/profile/edit.html.haml index fca9df91c..e4846961f 100644 --- a/app/views/groups/profile/edit.html.haml +++ b/app/views/groups/profile/edit.html.haml @@ -1,5 +1,5 @@ -set_meta_tags :title => [title_object(@group), t('layout.groups.edit')] -= form_for @group do |f| += form_for @group, :url => profile_group_path(@group) do |f| = render "form", :f => f .hr @@ -9,7 +9,7 @@ .hr .leftside= t("layout.groups.delete_warning") .rightside - = link_to t("layout.delete"), group_path(@group), :method => :delete, :confirm => t("layout.groups.confirm_delete"), :class => 'button' if can? :destroy, @group + = link_to t("layout.delete"), profile_group_path(@group), :method => :delete, :confirm => t("layout.groups.confirm_delete"), :class => 'button' if can? :destroy, @group .both - content_for :sidebar, render('sidebar') diff --git a/config/deploy.rb b/config/deploy.rb index 74734e310..ac5e272f1 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,7 +1,6 @@ # -*- encoding : utf-8 -*- -$:.unshift File.expand_path('.') -$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) -set :rvm_type, :user +require 'cape' +require 'capistrano_colors' set :default_environment, { 'LANG' => 'en_US.UTF-8' @@ -34,10 +33,10 @@ set :scm, :git set :repository, "git@github.com:warpc/rosa-build.git" set :deploy_via, :remote_cache -require 'lib/recipes/nginx' -require 'lib/recipes/unicorn' -require 'lib/recipes/bluepill' -require 'lib/recipes/delayed_job' +require './lib/recipes/nginx' +require './lib/recipes/unicorn' +require './lib/recipes/bluepill' +require './lib/recipes/delayed_job' namespace :deploy do task :stub_xml_rpc do @@ -92,7 +91,6 @@ after "deploy:restart", "delayed_job:restart" after "deploy:restart", "deploy:cleanup" -require 'cape' namespace :rake_tasks do Cape do mirror_rake_tasks 'db:seeds' diff --git a/config/routes.rb b/config/routes.rb index 37de8ec35..f410c1519 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,6 +82,7 @@ Rosa::Application.routes.draw do scope :module => 'groups' do resources :groups, :controller => 'profile' do + get '/' => 'groups/profile#show', :as => :profile, :on => :member get :autocomplete_group_uname, :on => :collection delete :remove_user, :on => :member resources :members, :only => [:index] do @@ -120,7 +121,7 @@ Rosa::Application.routes.draw do get '/' => 'users/profile#show', :as => :user end constraints OwnerConstraint.new(Group, true) do - get '/' => 'groups/profile#show', :as => :group_profile + get '/' => 'groups/profile#show', :as => :group end scope ':project_name', :as => 'project', :module => 'projects' do resources :wiki do From 5157f3108192fe58dc659868ba46f0a51cbc4092 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 4 May 2012 00:52:56 +0300 Subject: [PATCH 2/2] Refactor routes to separate owner profile and project. Redo short groups profile URL. Improve specs. Refs #236 --- app/controllers/groups/base_controller.rb | 2 +- app/controllers/users/base_controller.rb | 2 +- config/routes.rb | 127 +++++++++--------- lib/ext/rails/owner_constraint.rb | 2 +- .../projects/git/git_trees_controller_spec.rb | 2 +- .../users/profile_controller_spec.rb | 2 +- 6 files changed, 70 insertions(+), 67 deletions(-) diff --git a/app/controllers/groups/base_controller.rb b/app/controllers/groups/base_controller.rb index f40eeece2..0db3685be 100644 --- a/app/controllers/groups/base_controller.rb +++ b/app/controllers/groups/base_controller.rb @@ -6,7 +6,7 @@ class Groups::BaseController < ApplicationController protected def find_group - if group_id = params[:owner_name] || params[:group_id] || params[:id] + if group_id = params[:uname] || params[:group_id] || params[:id] @group = Group.find_by_insensitive_uname! group_id end end diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 4f789e3fb..e0231bb20 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -6,7 +6,7 @@ class Users::BaseController < ApplicationController protected def find_user - if user_id = params[:owner_name] || params[:user_id] || params[:id] + if user_id = params[:uname] || params[:user_id] || params[:id] @user = User.find_by_insensitive_uname! user_id end end diff --git a/config/routes.rb b/config/routes.rb index f410c1519..b9b5ae195 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,20 @@ Rosa::Application.routes.draw do root :to => 'activity_feeds#index' end + namespace :admin do + resources :users do + get :list, :on => :collection + end + resources :register_requests, :only => [:index] do + put :update, :on => :collection + member do + get :approve + get :reject + end + end + resources :event_logs, :only => :index + end + scope :module => 'platforms' do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] @@ -49,20 +63,6 @@ Rosa::Application.routes.draw do resources :product_build_lists, :only => [:index] end - namespace :admin do - resources :users do - get :list, :on => :collection - end - resources :register_requests, :only => [:index] do - put :update, :on => :collection - member do - get :approve - get :reject - end - end - resources :event_logs, :only => :index - end - scope :module => 'users' do resources :settings, :only => [] do collection do @@ -81,8 +81,9 @@ Rosa::Application.routes.draw do end scope :module => 'groups' do + get '/groups/new' => 'profile#new' # need to force next route exclude :id => 'new' + get '/groups/:id' => redirect("/%{id}"), :as => :profile_group # override default group show route resources :groups, :controller => 'profile' do - get '/' => 'groups/profile#show', :as => :profile, :on => :member get :autocomplete_group_uname, :on => :collection delete :remove_user, :on => :member resources :members, :only => [:index] do @@ -115,56 +116,49 @@ Rosa::Application.routes.draw do end resources :projects, :only => [:index, :new, :create] - end - scope ':owner_name' do # Owner - constraints OwnerConstraint.new(User) do - get '/' => 'users/profile#show', :as => :user - end - constraints OwnerConstraint.new(Group, true) do - get '/' => 'groups/profile#show', :as => :group - end - scope ':project_name', :as => 'project', :module => 'projects' 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 + scope ':owner_name/:project_name' do # project + scope :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 do + get :find, :on => :collection 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 do - get :find, :on => :collection - end - end - scope ':project_name', :module => 'projects' do # Resource get '/edit' => 'projects#edit', :as => :edit_project put '/' => 'projects#update' @@ -201,4 +195,13 @@ Rosa::Application.routes.draw do get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ end end + + scope ':uname' do # project owner profile + constraints OwnerConstraint.new(User) do + get '/' => 'users/profile#show', :as => :user + end + constraints OwnerConstraint.new(Group, true) do + get '/' => 'groups/profile#show', :as => :group + end + end end diff --git a/lib/ext/rails/owner_constraint.rb b/lib/ext/rails/owner_constraint.rb index 93b32935a..10f091e3f 100644 --- a/lib/ext/rails/owner_constraint.rb +++ b/lib/ext/rails/owner_constraint.rb @@ -7,6 +7,6 @@ class OwnerConstraint end def matches?(request) - @class_name.send(@finder, request.params[:owner_name]).present? + @class_name.send(@finder, request.params[:uname]).present? end end diff --git a/spec/controllers/projects/git/git_trees_controller_spec.rb b/spec/controllers/projects/git/git_trees_controller_spec.rb index f48f8afc3..16a10a40b 100644 --- a/spec/controllers/projects/git/git_trees_controller_spec.rb +++ b/spec/controllers/projects/git/git_trees_controller_spec.rb @@ -12,7 +12,7 @@ describe Projects::Git::TreesController do @project = FactoryGirl.create(:project) @another_user = FactoryGirl.create(:user) - @params = {:project_id => @project.id, :format => 'tar'} + @params = {:owner_name => @project.owner.uname, :project_name => @project.name, :format => 'tar'} end context 'for guest' do diff --git a/spec/controllers/users/profile_controller_spec.rb b/spec/controllers/users/profile_controller_spec.rb index 3fb73e1f0..6c370e44f 100644 --- a/spec/controllers/users/profile_controller_spec.rb +++ b/spec/controllers/users/profile_controller_spec.rb @@ -27,7 +27,7 @@ describe Users::ProfileController do end it 'should be able to view profile' do - get :show, :owner_name => @other_user.uname + get :show, :uname => @other_user.uname response.code.should eq('200') end