From d622af2963e0b69c933c066614cd5b231851ae02 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:39:44 +0100 Subject: [PATCH 01/22] Fix(routes): Use member helper for vm actions --- config/routes.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 9335430e..3db785b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,20 +26,24 @@ patch '/vms/configs/:id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - post '/vms/vm/:id/change_power_state' => 'vms#change_power_state', constraints: { id: /.*/ } - post '/vms/vm/:id/suspend_vm' => 'vms#suspend_vm', constraints: { id: /.*/ } - post '/vms/vm/:id/shutdown_guest_os' => 'vms#shutdown_guest_os', constraints: { id: /.*/ } - post '/vms/vm/:id/reboot_guest_os' => 'vms#reboot_guest_os', constraints: { id: /.*/ } - post '/vms/vm/:id/reset_vm' => 'vms#reset_vm', constraints: { id: /.*/ } - post '/vms/vm/:id/request_vm_archivation' => 'vms#request_vm_archivation', constraints: { id: /.*/ } - post '/vms/vm/:id/archive_vm' => 'vms#archive_vm', constraints: { id: /.*/ } - post '/vms/vm/:id/request_vm_revive' => 'vms#request_vm_revive', constraints: { id: /.*/ } - post '/vms/vm/:id/revive_vm' => 'vms#revive_vm', constraints: { id: /.*/ } - post '/vms/vm/:id/stop_archiving' => 'vms#stop_archiving', constraints: { id: /.*/ } - resources :vms, except: %i[new create], path: 'vms/vm' get 'slack/new' => 'slack#new', as: :new_slack get 'slack/auth' => 'slack#update', as: :update_slack + resources :vms, except: [:new, :create], path: 'vms/vm' do + # https://guides.rubyonrails.org/routing.html#adding-member-routes + member do + post 'change_power_state' + post 'suspend_vm' + post 'shutdown_guest_os' + post 'reboot_guest_os' + post 'reset_vm' + post 'request_vm_archivation' + post 'archive_vm' + post 'request_vm_revive' + post 'revive_vm' + post 'stop_archiving' + end + end devise_for :users, path: 'users', From 46f04df97826150738c1b3c31ed5949d0742e1c4 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:40:57 +0100 Subject: [PATCH 02/22] Fix(routes): Readd constraint for vm resources --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 3db785b5..f7949b5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,7 @@ get 'slack/new' => 'slack#new', as: :new_slack get 'slack/auth' => 'slack#update', as: :update_slack - resources :vms, except: [:new, :create], path: 'vms/vm' do + resources :vms, except: [:new, :create], path: 'vms/vm', constraints: { id: /.*/ } do # https://guides.rubyonrails.org/routing.html#adding-member-routes member do post 'change_power_state' From a85a4793e58d6176eecf54cfbba404ea1a6070f9 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:42:28 +0100 Subject: [PATCH 03/22] Fix(routes): Add scope for Slack routes --- config/routes.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index f7949b5e..cf78484c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,9 +26,6 @@ patch '/vms/configs/:id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - - get 'slack/new' => 'slack#new', as: :new_slack - get 'slack/auth' => 'slack#update', as: :update_slack resources :vms, except: [:new, :create], path: 'vms/vm', constraints: { id: /.*/ } do # https://guides.rubyonrails.org/routing.html#adding-member-routes member do @@ -45,6 +42,10 @@ end end + scope 'slack' do + get 'new' => 'slack#new', as: :new_slack + get 'auth' => 'slack#update', as: :update_slack + end devise_for :users, path: 'users', controllers: { From 2a5ab79936f997b799b13a4807256c11f819a79b Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:43:23 +0100 Subject: [PATCH 04/22] Fix(routes): Add comment for devise routes config --- config/routes.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index cf78484c..3751c068 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,12 +46,14 @@ get 'new' => 'slack#new', as: :new_slack get 'auth' => 'slack#update', as: :update_slack end + + # https://github.com/plataformatec/devise#configuring-routes devise_for :users, - path: 'users', - controllers: { - registrations: 'users/registrations', - omniauth_callbacks: 'users/omniauth_callbacks' - } + path: 'users', + controllers: { + registrations: 'users/registrations', + omniauth_callbacks: 'users/omniauth_callbacks' + } resources :hosts, :servers resources :users do From 875223484c955f3a90f7905e2ccc6a50d6a40f77 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:44:09 +0100 Subject: [PATCH 05/22] Fix(routes): Collapse member block for user resources --- config/routes.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 3751c068..262ea6c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,9 +57,7 @@ resources :hosts, :servers resources :users do - member do - patch :update_role - end + patch :update_role, on: :member end resources :projects, only: %i[index show new edit create update] From 2bf645b24c5459cf1705c5e7ac1d4635e8c6038b Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:48:01 +0100 Subject: [PATCH 06/22] Fix(routes): Remove duplicated root routing, add comment --- config/routes.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 262ea6c3..70acd1a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,10 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html Rails.application.routes.draw do + # You can specify what Rails should route '/' to with the root method + # https://guides.rubyonrails.org/routing.html#using-root + root 'landing#index' + resources :app_settings, only: %i[update edit] resources :operating_systems, path: '/vms/requests/operating_systems', except: :show @@ -18,7 +22,6 @@ end get '/dashboard' => 'dashboard#index', as: :dashboard - root to: 'landing#index' get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } @@ -61,6 +64,4 @@ end resources :projects, only: %i[index show new edit create update] - - root 'landing#index' end From 61e641e929e2ec08de4f30aef49e00586cd10140 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 15:52:13 +0100 Subject: [PATCH 07/22] Fix(routes): Use member block for notification resources --- config/routes.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 70acd1a3..8dd93811 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,9 +16,11 @@ end resources :notifications, only: %i[index new create destroy] do - get :mark_as_read, on: :member + member do + get :mark_as_read + delete :destroy_and_redirect + end get :has_any, on: :collection, to: 'notifications#any?' - delete :destroy_and_redirect, on: :member end get '/dashboard' => 'dashboard#index', as: :dashboard From 57b2c1c2d595e603c84fb234719b918d5aabdd49 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:04:06 +0100 Subject: [PATCH 08/22] Fix(routes): Move reject PATCH into requests resources block --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 8dd93811..eca9b85e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,9 +10,9 @@ resources :operating_systems, path: '/vms/requests/operating_systems', except: :show resources :request_templates, path: '/vms/request_templates', except: :show - patch '/vms/requests/reject', to: 'requests#reject', as: 'reject' resources :requests, path: '/vms/requests' do post :push_to_git, on: :member + patch 'reject', on: :collection end resources :notifications, only: %i[index new create destroy] do From f32fb071d91fed0930fd18ca6adce86c2f97c231 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:04:43 +0100 Subject: [PATCH 09/22] Fix(routes): Move projects resources near other non-customized resources --- config/routes.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index eca9b85e..27a053bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,9 +61,8 @@ } resources :hosts, :servers + resources :projects, only: %i[index show new edit create update] resources :users do patch :update_role, on: :member end - - resources :projects, only: %i[index show new edit create update] end From 9cc204993292e1f06b93a2dd50a7d2ae74ad18eb Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:17:03 +0100 Subject: [PATCH 10/22] Fix(routes): Move unconfigured resources to top of file --- config/routes.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 27a053bf..07379d71 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,9 +6,14 @@ # https://guides.rubyonrails.org/routing.html#using-root root 'landing#index' + resources :hosts, :servers + resources :projects, only: %i[index show new edit create update] resources :app_settings, only: %i[update edit] - resources :operating_systems, path: '/vms/requests/operating_systems', except: :show + resources :users do + patch :update_role, on: :member + end + resources :operating_systems, path: '/vms/requests/operating_systems', except: :show resources :request_templates, path: '/vms/request_templates', except: :show resources :requests, path: '/vms/requests' do post :push_to_git, on: :member @@ -59,10 +64,4 @@ registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' } - - resources :hosts, :servers - resources :projects, only: %i[index show new edit create update] - resources :users do - patch :update_role, on: :member - end end From 980c01ae31917023f9fc9317af88943d6d114c90 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:26:47 +0100 Subject: [PATCH 11/22] Fix(routes): Add OS and request templates resources to 'vms' scope. Move user resource. --- config/routes.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 07379d71..6ac9430f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,12 +9,13 @@ resources :hosts, :servers resources :projects, only: %i[index show new edit create update] resources :app_settings, only: %i[update edit] - resources :users do - patch :update_role, on: :member + + # https://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers + scope 'vms' do + resources :operating_systems, path: 'requests/operating_systems', except: :show + resources :request_templates, path: 'request_templates', except: :show end - resources :operating_systems, path: '/vms/requests/operating_systems', except: :show - resources :request_templates, path: '/vms/request_templates', except: :show resources :requests, path: '/vms/requests' do post :push_to_git, on: :member patch 'reject', on: :collection @@ -64,4 +65,7 @@ registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' } + resources :users do + patch :update_role, on: :member + end end From a1c69811e94ba268424be825b848cc5f4b066e00 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:33:17 +0100 Subject: [PATCH 12/22] Fix(routes): Move requests resoures into 'vms' scope --- config/routes.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6ac9430f..9e956752 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,13 +12,12 @@ # https://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers scope 'vms' do - resources :operating_systems, path: 'requests/operating_systems', except: :show resources :request_templates, path: 'request_templates', except: :show - end - - resources :requests, path: '/vms/requests' do - post :push_to_git, on: :member - patch 'reject', on: :collection + resources :operating_systems, path: 'requests/operating_systems', except: :show + resources :requests, path: 'requests' do + post :push_to_git, on: :member + patch :reject, on: :collection + end end resources :notifications, only: %i[index new create destroy] do From 807d2162ff8134fd58800e8d28fcf7b0c380bbb5 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:50:04 +0100 Subject: [PATCH 13/22] Fix(routes): Move 'edit_config' and 'update_config' into 'vms' scope --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 9e956752..00faaab6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,8 @@ post :push_to_git, on: :member patch :reject, on: :collection end + get 'configs/:id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config + patch 'configs/:id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config end resources :notifications, only: %i[index new create destroy] do @@ -32,8 +34,6 @@ get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } - get '/vms/configs/:id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config - patch '/vms/configs/:id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! resources :vms, except: [:new, :create], path: 'vms/vm', constraints: { id: /.*/ } do From b55f605bc2ba3a46ba75f262651c1555a4c79f79 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:55:33 +0100 Subject: [PATCH 14/22] Fix(routes): Add '/vms/configs' and '/vms/requests' scopes --- config/routes.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 00faaab6..86702a42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,15 +11,22 @@ resources :app_settings, only: %i[update edit] # https://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers + # '/vms/' scope 'vms' do resources :request_templates, path: 'request_templates', except: :show - resources :operating_systems, path: 'requests/operating_systems', except: :show - resources :requests, path: 'requests' do - post :push_to_git, on: :member - patch :reject, on: :collection + # '/vms/requests' + scope 'requests' do + resources :operating_systems, path: 'operating_systems', except: :show + resources :requests do + post :push_to_git, on: :member + patch :reject, on: :collection + end + end + # '/vms/configs' + scope 'configs' do + get ':id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config + patch ':id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config end - get 'configs/:id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config - patch 'configs/:id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config end resources :notifications, only: %i[index new create destroy] do From 7acf15c562ef370058f960fc41f1f1cde05cdb84 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 16:57:24 +0100 Subject: [PATCH 15/22] Fix(routes): Remove redundant params from OS and req. template routes --- config/routes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 86702a42..190920db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,12 +11,12 @@ resources :app_settings, only: %i[update edit] # https://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers - # '/vms/' + # '/vms' scope 'vms' do - resources :request_templates, path: 'request_templates', except: :show + resources :request_templates, except: :show # '/vms/requests' scope 'requests' do - resources :operating_systems, path: 'operating_systems', except: :show + resources :operating_systems, except: :show resources :requests do post :push_to_git, on: :member patch :reject, on: :collection From e7f674bc941e9993677b3cd09a3060c0e39b59d2 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 17:11:40 +0100 Subject: [PATCH 16/22] Refactor(routes): Restructure routes.rb and add explanatory comments --- config/routes.rb | 91 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 190920db..edc6ba4e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,65 +5,68 @@ # You can specify what Rails should route '/' to with the root method # https://guides.rubyonrails.org/routing.html#using-root root 'landing#index' - - resources :hosts, :servers + + # '/dashboard' + get '/dashboard' => 'dashboard#index', as: :dashboard + # '/projects/...' resources :projects, only: %i[index show new edit create update] + # '/app_settings/...' resources :app_settings, only: %i[update edit] + # '/hosts/...', '/servers/...' + resources :hosts, :servers + get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } + + # '/notifications/...' + resources :notifications, only: %i[index new create destroy] do + member do + get :mark_as_read + delete :destroy_and_redirect + end + get :has_any, on: :collection, to: 'notifications#any?' + end + + # '/slack/...' + scope 'slack' do + get 'new' => 'slack#new', as: :new_slack + get 'auth' => 'slack#update', as: :update_slack + end # https://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers - # '/vms' + # '/vms/...' scope 'vms' do + # '/vms/request_templates/...' resources :request_templates, except: :show - # '/vms/requests' - scope 'requests' do + # '/vms/requests/...' + resources :requests do + post :push_to_git, on: :member + patch :reject, on: :collection + # '/vms/requests/operating_systems/...' resources :operating_systems, except: :show - resources :requests do - post :push_to_git, on: :member - patch :reject, on: :collection - end end - # '/vms/configs' + # '/vms/configs/:id' scope 'configs' do get ':id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config patch ':id' => 'vms#update_config', constraints: { id: /.*/ }, as: :update_config end - end - - resources :notifications, only: %i[index new create destroy] do - member do - get :mark_as_read - delete :destroy_and_redirect - end - get :has_any, on: :collection, to: 'notifications#any?' - end - - get '/dashboard' => 'dashboard#index', as: :dashboard - - get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } - - - # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - resources :vms, except: [:new, :create], path: 'vms/vm', constraints: { id: /.*/ } do - # https://guides.rubyonrails.org/routing.html#adding-member-routes - member do - post 'change_power_state' - post 'suspend_vm' - post 'shutdown_guest_os' - post 'reboot_guest_os' - post 'reset_vm' - post 'request_vm_archivation' - post 'archive_vm' - post 'request_vm_revive' - post 'revive_vm' - post 'stop_archiving' + # '/vms/vm' + # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! + resources :vms, except: [:new, :create], path: 'vm', constraints: { id: /.*/ } do + # https://guides.rubyonrails.org/routing.html#adding-member-routes + member do + post 'change_power_state' + post 'suspend_vm' + post 'shutdown_guest_os' + post 'reboot_guest_os' + post 'reset_vm' + post 'request_vm_archivation' + post 'archive_vm' + post 'request_vm_revive' + post 'revive_vm' + post 'stop_archiving' + end end end - scope 'slack' do - get 'new' => 'slack#new', as: :new_slack - get 'auth' => 'slack#update', as: :update_slack - end - # https://github.com/plataformatec/devise#configuring-routes devise_for :users, path: 'users', From 47a665eab349e00ac8e85b8c414a48ece2f30b96 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 17:30:11 +0100 Subject: [PATCH 17/22] Fix(routes.rb): Move operating_systems out of requests resources scope --- config/routes.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index edc6ba4e..bc974ec6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,9 +40,9 @@ resources :requests do post :push_to_git, on: :member patch :reject, on: :collection - # '/vms/requests/operating_systems/...' - resources :operating_systems, except: :show end + # '/vms/requests/operating_systems/...' + resources :operating_systems, path: 'requests/operating_systems', except: :show # '/vms/configs/:id' scope 'configs' do get ':id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config @@ -67,6 +67,7 @@ end end + # '/users/...' # https://github.com/plataformatec/devise#configuring-routes devise_for :users, path: 'users', From ffdbb76a8e612616cd5610c3ac2d415deae01a11 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 18:02:07 +0100 Subject: [PATCH 18/22] Fix(routes): Reorder OS routes. Add comment on order mattering here. --- config/routes.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index bc974ec6..664d4b1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ # You can specify what Rails should route '/' to with the root method # https://guides.rubyonrails.org/routing.html#using-root root 'landing#index' - + # '/dashboard' get '/dashboard' => 'dashboard#index', as: :dashboard # '/projects/...' @@ -15,7 +15,7 @@ # '/hosts/...', '/servers/...' resources :hosts, :servers get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } - + # '/notifications/...' resources :notifications, only: %i[index new create destroy] do member do @@ -24,7 +24,7 @@ end get :has_any, on: :collection, to: 'notifications#any?' end - + # '/slack/...' scope 'slack' do get 'new' => 'slack#new', as: :new_slack @@ -36,13 +36,15 @@ scope 'vms' do # '/vms/request_templates/...' resources :request_templates, except: :show + # '/vms/requests/operating_systems/...' + # Order matters here, as routes are matched from top to bottom + # If 'resources :requests' is first, it will attempt to match that + resources :operating_systems, path: 'requests/operating_systems', except: :show # '/vms/requests/...' resources :requests do post :push_to_git, on: :member patch :reject, on: :collection end - # '/vms/requests/operating_systems/...' - resources :operating_systems, path: 'requests/operating_systems', except: :show # '/vms/configs/:id' scope 'configs' do get ':id' => 'vms#edit_config', constraints: { id: /.*/ }, as: :edit_config @@ -69,12 +71,11 @@ # '/users/...' # https://github.com/plataformatec/devise#configuring-routes - devise_for :users, - path: 'users', + devise_for :users, path: 'users', controllers: { registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' - } + } resources :users do patch :update_role, on: :member end From 86d94c8e25d66286138677c14a6bbbacbd5ac69f Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Mon, 11 Mar 2019 17:07:31 +0000 Subject: [PATCH 19/22] [CodeFactor] Apply fixes --- config/routes.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 664d4b1f..4a8577ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,7 +52,7 @@ end # '/vms/vm' # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - resources :vms, except: [:new, :create], path: 'vm', constraints: { id: /.*/ } do + resources :vms, except: %i[new create], path: 'vm', constraints: { id: /.*/ } do # https://guides.rubyonrails.org/routing.html#adding-member-routes member do post 'change_power_state' @@ -72,10 +72,10 @@ # '/users/...' # https://github.com/plataformatec/devise#configuring-routes devise_for :users, path: 'users', - controllers: { - registrations: 'users/registrations', - omniauth_callbacks: 'users/omniauth_callbacks' - } + controllers: { + registrations: 'users/registrations', + omniauth_callbacks: 'users/omniauth_callbacks' + } resources :users do patch :update_role, on: :member end From e6caf0e96ef572016e8c87ffa4b2bf5836eb5db7 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 18:11:01 +0100 Subject: [PATCH 20/22] Revert "[CodeFactor] Apply fixes" This reverts commit 86d94c8e25d66286138677c14a6bbbacbd5ac69f. --- config/routes.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 4a8577ed..664d4b1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,7 +52,7 @@ end # '/vms/vm' # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - resources :vms, except: %i[new create], path: 'vm', constraints: { id: /.*/ } do + resources :vms, except: [:new, :create], path: 'vm', constraints: { id: /.*/ } do # https://guides.rubyonrails.org/routing.html#adding-member-routes member do post 'change_power_state' @@ -72,10 +72,10 @@ # '/users/...' # https://github.com/plataformatec/devise#configuring-routes devise_for :users, path: 'users', - controllers: { - registrations: 'users/registrations', - omniauth_callbacks: 'users/omniauth_callbacks' - } + controllers: { + registrations: 'users/registrations', + omniauth_callbacks: 'users/omniauth_callbacks' + } resources :users do patch :update_role, on: :member end From cd9a50ac0df3f2dc40e63fab04f29da9fd5e6734 Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Mon, 11 Mar 2019 18:20:51 +0100 Subject: [PATCH 21/22] Refactor(routes): Use %i syntax --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 664d4b1f..69dc983e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,7 +52,7 @@ end # '/vms/vm' # move all vm actions under /vms/vm because a VM named requests might otherwise lead to issues! - resources :vms, except: [:new, :create], path: 'vm', constraints: { id: /.*/ } do + resources :vms, except: %i[new create], path: 'vm', constraints: { id: /.*/ } do # https://guides.rubyonrails.org/routing.html#adding-member-routes member do post 'change_power_state' From 36c19ec20c1e19df42b1d8b197f32092d292632a Mon Sep 17 00:00:00 2001 From: Christoph Matthies Date: Fri, 15 Mar 2019 16:28:10 +0100 Subject: [PATCH 22/22] Fix(routes): rework hosts definition --- config/routes.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 69dc983e..d4ecc7ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,13 +8,14 @@ # '/dashboard' get '/dashboard' => 'dashboard#index', as: :dashboard - # '/projects/...' - resources :projects, only: %i[index show new edit create update] # '/app_settings/...' resources :app_settings, only: %i[update edit] - # '/hosts/...', '/servers/...' - resources :hosts, :servers - get '/hosts/:id' => 'hosts#show', constraints: { id: /.*/ } + # '/projects/...' + resources :projects, except: :destroy + # '/servers/...' + resources :servers + # '/hosts/...' + resources :hosts, only: %i[index show], constraints: { id: /.*/ } # '/notifications/...' resources :notifications, only: %i[index new create destroy] do