Commit e025bc82ead969b49937e0733c7647d7bcd42ae1
1 parent
614c64ab
Exists in
master
and in
29 other branches
ActionItem8: organizing the routes and making the necessary changes to the application
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@423 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
50 additions
and
14 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -77,14 +77,26 @@ module ApplicationHelper | @@ -77,14 +77,26 @@ module ApplicationHelper | ||
77 | content_tag('div', @virtual_community.name, :id => 'virtual_community_identification') | 77 | content_tag('div', @virtual_community.name, :id => 'virtual_community_identification') |
78 | end | 78 | end |
79 | 79 | ||
80 | + # TODO: test this helper | ||
81 | + # TODO: remove the absolute path | ||
80 | def link_to_cms(text, profile = nil, options = {}) | 82 | def link_to_cms(text, profile = nil, options = {}) |
81 | profile ||= current_user.login | 83 | profile ||= current_user.login |
82 | - link_to text, "/cms/#{profile}", options | 84 | + link_to text, cms_path(:profile => profile), options |
83 | end | 85 | end |
84 | 86 | ||
85 | def link_to_profile(text, profile = nil, options = {}) | 87 | def link_to_profile(text, profile = nil, options = {}) |
86 | profile ||= current_user.login | 88 | profile ||= current_user.login |
87 | - link_to text, "/#{profile}", options | 89 | + link_to text, profile_path(:profile => profile) , options |
90 | + end | ||
91 | + | ||
92 | + def link_to_homepage(text, profile = nil, options = {}) | ||
93 | + profile ||= current_user.login | ||
94 | + link_to text, homepage_path(:profile => profile) , options | ||
95 | + end | ||
96 | + | ||
97 | + def link_to_myprofile(text, url = {}, profile = nil, options = {}) | ||
98 | + profile ||= current_user.login | ||
99 | + link_to text, { :profile => profile }.merge(url), options | ||
88 | end | 100 | end |
89 | 101 | ||
90 | # TODO: add the actual links | 102 | # TODO: add the actual links |
@@ -92,10 +104,10 @@ module ApplicationHelper | @@ -92,10 +104,10 @@ module ApplicationHelper | ||
92 | def user_links | 104 | def user_links |
93 | links = [ | 105 | links = [ |
94 | ( link_to(_('My account'), { :controller => 'account' }) ), | 106 | ( link_to(_('My account'), { :controller => 'account' }) ), |
95 | - ( link_to_profile(_('My home page')) ), | 107 | + ( link_to_homepage(_('My home page')) ), |
96 | ( link_to_cms(_('Manage content')) ), | 108 | ( link_to_cms(_('Manage content')) ), |
97 | ( link_to (_('Manage layout')), :controller => 'edit_template' ), | 109 | ( link_to (_('Manage layout')), :controller => 'edit_template' ), |
98 | - ( link_to(_('My enterprises'), { :controller => 'enterprise' }) ), | 110 | + ( link_to_myprofile(_('My enterprises'), { :controller => 'enterprise' }) ), |
99 | ].join("\n") | 111 | ].join("\n") |
100 | content_tag('span', links, :id => 'user_links') | 112 | content_tag('span', links, :id => 'user_links') |
101 | end | 113 | end |
app/models/profile.rb
config/routes.rb
@@ -23,27 +23,39 @@ ActionController::Routing::Routes.draw do |map| | @@ -23,27 +23,39 @@ ActionController::Routing::Routes.draw do |map| | ||
23 | ## Controllers that are profile-specific (for profile admins ) | 23 | ## Controllers that are profile-specific (for profile admins ) |
24 | ###################################################### | 24 | ###################################################### |
25 | # profile customization - "My profile" | 25 | # profile customization - "My profile" |
26 | - map.connect 'myprofile', :controller => 'myprofile' | ||
27 | - map.connect 'myprofile/:profile/:controller/:action/:id', :controller => /(edit_template|enterprise)/ | 26 | + map.myprofile 'myprofile', :controller => 'myprofile' |
27 | + map.myprofile 'myprofile/:profile/:controller/:action/:id', :controller => /(enterprise)/ | ||
28 | # content administration | 28 | # content administration |
29 | - map.connect 'cms/:profile/:action/:id', :controller => 'cms' | 29 | + map.cms 'cms/:profile/:action/:id', :controller => 'cms' |
30 | 30 | ||
31 | ###################################################### | 31 | ###################################################### |
32 | ## Controllers that are used by environment admin | 32 | ## Controllers that are used by environment admin |
33 | ###################################################### | 33 | ###################################################### |
34 | # administrative tasks for a virtual community | 34 | # administrative tasks for a virtual community |
35 | - map.connect 'admin', :controller => 'admin_panel' | ||
36 | - map.connect 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags)/ | 35 | + map.admin 'admin', :controller => 'admin_panel' |
36 | + map.admin 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags|edit_template)/ | ||
37 | 37 | ||
38 | ###################################################### | 38 | ###################################################### |
39 | ## Controllers that are used by system admin | 39 | ## Controllers that are used by system admin |
40 | ###################################################### | 40 | ###################################################### |
41 | # administrative tasks for a virtual community | 41 | # administrative tasks for a virtual community |
42 | - map.connect 'system', :controller => 'system' | ||
43 | - map.connect 'system/:controller/:action/:id' | 42 | + map.system 'system', :controller => 'system' |
43 | + map.system 'system/:controller/:action/:id', :controller => // | ||
44 | 44 | ||
45 | + | ||
46 | + ###################################################### | ||
47 | + ## Test controllers. | ||
48 | + ## FIXME: this should not be needed | ||
49 | + ###################################################### | ||
50 | + map.connect 'test/:action/:id', :controller => 'test' | ||
51 | + | ||
52 | + ###################################################### | ||
53 | + ## Public controllers | ||
54 | + ###################################################### | ||
55 | + | ||
56 | + map.profile 'profile/:profile/:controller', :controller => 'profile' | ||
45 | # *content viewing* | 57 | # *content viewing* |
46 | # XXX this route must come last so other tasks have priority over it. | 58 | # XXX this route must come last so other tasks have priority over it. |
47 | - map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' | 59 | + map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page' |
48 | 60 | ||
49 | end | 61 | end |
test/functional/enterprise_controller_test.rb
@@ -13,9 +13,19 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -13,9 +13,19 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
13 | @response = ActionController::TestResponse.new | 13 | @response = ActionController::TestResponse.new |
14 | end | 14 | end |
15 | 15 | ||
16 | + # FIXME: this should be generic | ||
17 | + def get(action, params = {}) | ||
18 | + super(action, {:profile => 'ze'}.merge(params)) | ||
19 | + end | ||
20 | + | ||
21 | + # FIXME: this should be generic | ||
22 | + def post(action, params = {}) | ||
23 | + super(action, {:profile => 'ze'}.merge(params)) | ||
24 | + end | ||
25 | + | ||
16 | def test_logged_with_one_enterprise_index | 26 | def test_logged_with_one_enterprise_index |
17 | login_as 'ze' | 27 | login_as 'ze' |
18 | - get :index | 28 | + get :index, :profile => 'ze' |
19 | assert_response :redirect | 29 | assert_response :redirect |
20 | assert_redirected_to :action => 'show' | 30 | assert_redirected_to :action => 'show' |
21 | 31 |
test/integration/routing_test.rb
@@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest | @@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest | ||
26 | end | 26 | end |
27 | 27 | ||
28 | def test_edit_template | 28 | def test_edit_template |
29 | - assert_routing('/myprofile/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') | 29 | + assert_routing('/admin/edit_template', :controller => 'edit_template', :action => 'index') |
30 | end | 30 | end |
31 | 31 | ||
32 | # virtual community administrative controllers (admin/*) | 32 | # virtual community administrative controllers (admin/*) |
test/unit/profile_test.rb
@@ -111,6 +111,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -111,6 +111,7 @@ class ProfileTest < Test::Unit::TestCase | ||
111 | assert_invalid_identifier 'profile' | 111 | assert_invalid_identifier 'profile' |
112 | assert_invalid_identifier 'cms' | 112 | assert_invalid_identifier 'cms' |
113 | assert_invalid_identifier 'community' | 113 | assert_invalid_identifier 'community' |
114 | + assert_invalid_identifier 'test' | ||
114 | end | 115 | end |
115 | 116 | ||
116 | private | 117 | private |