Commit 742fdfb6c4cdf67a878c40cfbe0b3d4fb530cdef
1 parent
fbe0ef2a
Exists in
master
and in
79 other branches
Added patch to fix url with '~'
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com>
Showing
2 changed files
with
200 additions
and
1 deletions
Show diff stats
patches/noosfero/0001-Use-as-placeholder-for-current-user-in-URLs.patch
0 → 100644
... | ... | @@ -0,0 +1,196 @@ |
1 | +From 38e1a32782d0a2f5d66a936b707f307ceb13288f Mon Sep 17 00:00:00 2001 | |
2 | +From: David Carlos <ddavidcarlos1392@gmail.com> | |
3 | +Date: Thu, 12 Mar 2015 14:59:38 -0300 | |
4 | +Subject: [PATCH] Use ~ as placeholder for current user in URLs | |
5 | + | |
6 | +When the :profile parameter is '~', replace it with the identifier of | |
7 | +the currently logged-in user and redirect. This is useful for example | |
8 | +for adding direct links to the control panel of the current user in | |
9 | +documentation. | |
10 | + | |
11 | +Signed-off-by: Antonio Terceiro <terceiro@colivre.coop.br> | |
12 | +Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> | |
13 | +Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> | |
14 | +Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> | |
15 | +--- | |
16 | + app/controllers/application_controller.rb | 12 ++++++++ | |
17 | + config/routes.rb | 40 +++++++++++++------------- | |
18 | + lib/noosfero.rb | 6 ++++ | |
19 | + test/functional/application_controller_test.rb | 18 ++++++++++++ | |
20 | + test/integration/routing_test.rb | 4 +++ | |
21 | + 5 files changed, 60 insertions(+), 20 deletions(-) | |
22 | + | |
23 | +diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb | |
24 | +index 2bb0835..75fb3fd 100644 | |
25 | +--- a/app/controllers/application_controller.rb | |
26 | ++++ b/app/controllers/application_controller.rb | |
27 | +@@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base | |
28 | + before_filter :allow_cross_domain_access | |
29 | + before_filter :login_required, :if => :private_environment? | |
30 | + before_filter :verify_members_whitelist, :if => [:private_environment?, :user] | |
31 | ++ before_filter :redirect_to_current_user | |
32 | + | |
33 | + def verify_members_whitelist | |
34 | + render_access_denied unless user.is_admin? || environment.in_whitelist?(user) | |
35 | +@@ -191,4 +192,15 @@ class ApplicationController < ActionController::Base | |
36 | + def private_environment? | |
37 | + @environment.enabled?(:restrict_to_members) | |
38 | + end | |
39 | ++ | |
40 | ++ def redirect_to_current_user | |
41 | ++ if params[:profile] == '~' | |
42 | ++ if logged_in? | |
43 | ++ redirect_to params.merge(:profile => user.identifier) | |
44 | ++ else | |
45 | ++ render_not_found | |
46 | ++ end | |
47 | ++ end | |
48 | ++ end | |
49 | ++ | |
50 | + end | |
51 | +diff --git a/config/routes.rb b/config/routes.rb | |
52 | +index f370954..a54ea19 100644 | |
53 | +--- a/config/routes.rb | |
54 | ++++ b/config/routes.rb | |
55 | +@@ -57,37 +57,37 @@ Noosfero::Application.routes.draw do | |
56 | + match 'search(/:action(/*category_path))', :controller => 'search' | |
57 | + | |
58 | + # events | |
59 | +- match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format}/ | |
60 | +- match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format}/ | |
61 | +- match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format}/ | |
62 | +- match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format}/ | |
63 | +- match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format}/ | |
64 | ++ match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format_in_url}/ | |
65 | ++ match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format_in_url}/ | |
66 | ++ match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/ | |
67 | ++ match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/ | |
68 | ++ match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format_in_url}/ | |
69 | + | |
70 | + # catalog | |
71 | +- match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format}/, :as => :catalog | |
72 | ++ match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/, :as => :catalog | |
73 | + | |
74 | + # invite | |
75 | +- match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format}/ | |
76 | +- match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format}/ | |
77 | ++ match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format_in_url}/ | |
78 | ++ match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format_in_url}/ | |
79 | + | |
80 | + # feeds per tag | |
81 | +- match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format}/, :as => :tag_feed | |
82 | ++ match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :tag_feed | |
83 | + | |
84 | + # profile tags | |
85 | +- match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format}/ | |
86 | +- match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format}/ | |
87 | ++ match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/ | |
88 | ++ match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format_in_url}/ | |
89 | + | |
90 | + # profile search | |
91 | +- match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format}/ | |
92 | ++ match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/ | |
93 | + | |
94 | + # comments | |
95 | +- match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format}/ | |
96 | ++ match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format_in_url}/ | |
97 | + | |
98 | + # public profile information | |
99 | +- match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format}/, :as => :profile | |
100 | ++ match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :profile | |
101 | + | |
102 | + # contact | |
103 | +- match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format}/ | |
104 | ++ match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format_in_url}/ | |
105 | + | |
106 | + # map balloon | |
107 | + match 'map_balloon/:action/:id', :controller => 'map_balloon', :id => /.*/ | |
108 | +@@ -99,8 +99,8 @@ Noosfero::Application.routes.draw do | |
109 | + ## Controllers that are profile-specific (for profile admins ) | |
110 | + ###################################################### | |
111 | + # profile customization - "My profile" | |
112 | +- match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format}/ | |
113 | +- match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format}/, :as => :myprofile | |
114 | ++ match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/ | |
115 | ++ match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format_in_url}/, :as => :myprofile | |
116 | + | |
117 | + | |
118 | + ###################################################### | |
119 | +@@ -128,14 +128,14 @@ Noosfero::Application.routes.draw do | |
120 | + # cache stuff - hack | |
121 | + match 'public/:action/:id', :controller => 'public' | |
122 | + | |
123 | +- match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new | |
124 | ++ match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new | |
125 | + match '*page/versions', :controller => 'content_viewer', :action => 'article_versions' | |
126 | + | |
127 | +- match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new | |
128 | ++ match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new | |
129 | + match '*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff' | |
130 | + | |
131 | + # match requests for profiles that don't have a custom domain | |
132 | +- match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/, :constraints => EnvironmentDomainConstraint.new | |
133 | ++ match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new | |
134 | + | |
135 | + # match requests for content in domains hosted for profiles | |
136 | + match '/(*page)', :controller => 'content_viewer', :action => 'view_page' | |
137 | +diff --git a/lib/noosfero.rb b/lib/noosfero.rb | |
138 | +index d7ec786..b1ae492 100644 | |
139 | +--- a/lib/noosfero.rb | |
140 | ++++ b/lib/noosfero.rb | |
141 | +@@ -57,6 +57,12 @@ module Noosfero | |
142 | + '[a-z0-9][a-z0-9~.]*([_\-][a-z0-9~.]+)*' | |
143 | + end | |
144 | + | |
145 | ++ # All valid identifiers, plus ~ meaning "the current user". See | |
146 | ++ # ApplicationController#redirect_to_current_user | |
147 | ++ def self.identifier_format_in_url | |
148 | ++ "(#{identifier_format}|~)" | |
149 | ++ end | |
150 | ++ | |
151 | + def self.default_hostname | |
152 | + Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost' | |
153 | + end | |
154 | +diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb | |
155 | +index 1c4ca48..1a99752 100644 | |
156 | +--- a/test/functional/application_controller_test.rb | |
157 | ++++ b/test/functional/application_controller_test.rb | |
158 | +@@ -578,4 +578,22 @@ class ApplicationControllerTest < ActionController::TestCase | |
159 | + assert_response :success | |
160 | + end | |
161 | + | |
162 | ++ should "redirect to 404 if profile is '~' and user is not logged in" do | |
163 | ++ get :index, :profile => '~' | |
164 | ++ assert_response :missing | |
165 | ++ end | |
166 | ++ | |
167 | ++ should "redirect to action when profile is '~' " do | |
168 | ++ login_as('ze') | |
169 | ++ get :index, :profile => '~' | |
170 | ++ assert_response 302 | |
171 | ++ end | |
172 | ++ | |
173 | ++ should "substitute '~' by current user and redirect properly " do | |
174 | ++ login_as('ze') | |
175 | ++ profile = Profile.where(:identifier => 'ze').first | |
176 | ++ get :index, :profile => '~' | |
177 | ++ assert_redirected_to :controller => 'test', :action => 'index', :profile => profile.identifier | |
178 | ++ end | |
179 | ++ | |
180 | + end | |
181 | +diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb | |
182 | +index 5a77eff..1c57323 100644 | |
183 | +--- a/test/integration/routing_test.rb | |
184 | ++++ b/test/integration/routing_test.rb | |
185 | +@@ -272,4 +272,8 @@ class RoutingTest < ActionController::IntegrationTest | |
186 | + assert_routing('/embed/block/12345', :controller => 'embed', :action => 'block', :id => '12345') | |
187 | + end | |
188 | + | |
189 | ++ should 'accept ~ as placeholder for current user' do | |
190 | ++ assert_routing('/profile/~', :controller => 'profile', :profile => '~', :action => 'index') | |
191 | ++ end | |
192 | ++ | |
193 | + end | |
194 | +-- | |
195 | +2.1.4 | |
196 | + | ... | ... |
specs/noosfero/noosfero.spec
1 | 1 | %define writable_dirs javascripts/cache stylesheets/cache articles image_uploads thumbnails |
2 | 2 | |
3 | 3 | Name: noosfero |
4 | -Version: 1.1~rc2.4 | |
4 | +Version: 1.1~rc2.3 | |
5 | 5 | Release: 2%{?dist} |
6 | 6 | Summary: Social Networking Platform |
7 | 7 | Group: Applications/Publishing |
8 | 8 | License: AGPLv3 |
9 | 9 | URL: http://noosfero.org |
10 | 10 | Source0: %{name}-%{version}.tar.gz |
11 | +Patch0: 0001-Use-as-placeholder-for-current-user-in-URLs.patch | |
11 | 12 | BuildArch: noarch |
12 | 13 | BuildRequires: noosfero-deps, gettext, po4a |
13 | 14 | Requires: noosfero-deps, po4a, tango-icon-theme, memcached |
... | ... | @@ -21,6 +22,8 @@ participate and contribute to this free software project! |
21 | 22 | %prep |
22 | 23 | %setup -q |
23 | 24 | |
25 | +%patch0 -p1 | |
26 | + | |
24 | 27 | %build |
25 | 28 | |
26 | 29 | ln -sf /usr/lib/noosfero/Gemfile . | ... | ... |