Commit fb090c196185743a6f8b1dc9fdd0a6c02c07060b
Exists in
master
and in
29 other branches
Merge branch 'master' into rails3
Showing
27 changed files
with
293 additions
and
214 deletions
Show diff stats
AUTHORS
@@ -6,6 +6,7 @@ noosfero, that's not a problem). | @@ -6,6 +6,7 @@ noosfero, that's not a problem). | ||
6 | Developers | 6 | Developers |
7 | ========== | 7 | ========== |
8 | 8 | ||
9 | +Ábner Silva de Oliveira <abner.oliveira@serpro.gov.br> | ||
9 | Alan Freihof Tygel <alantygel@gmail.com> | 10 | Alan Freihof Tygel <alantygel@gmail.com> |
10 | alcampelo <alcampelo@alcampelo.(none)> | 11 | alcampelo <alcampelo@alcampelo.(none)> |
11 | Alessandro Palmeira <alessandro.palmeira@gmail.com> | 12 | Alessandro Palmeira <alessandro.palmeira@gmail.com> |
@@ -43,6 +44,7 @@ Ana Losnak <analosnak@gmail.com> | @@ -43,6 +44,7 @@ Ana Losnak <analosnak@gmail.com> | ||
43 | Antonio Terceiro + Carlos Morais <terceiro@colivre.coop.br> | 44 | Antonio Terceiro + Carlos Morais <terceiro@colivre.coop.br> |
44 | Antonio Terceiro + Paulo Meirelles <terceiro@colivre.coop.br> | 45 | Antonio Terceiro + Paulo Meirelles <terceiro@colivre.coop.br> |
45 | Antonio Terceiro <terceiro@colivre.coop.br> | 46 | Antonio Terceiro <terceiro@colivre.coop.br> |
47 | +Arthur Del Esposte <arthurmde@gmail.com> | ||
46 | Arthur Del Esposte <arthurmde@yahoo.com.br> | 48 | Arthur Del Esposte <arthurmde@yahoo.com.br> |
47 | Aurelio A. Heckert <aurelio@colivre.coop.br> | 49 | Aurelio A. Heckert <aurelio@colivre.coop.br> |
48 | Braulio Bhavamitra <brauliobo@gmail.com> | 50 | Braulio Bhavamitra <brauliobo@gmail.com> |
@@ -71,12 +73,14 @@ Caio Salgado + Renan Teruo <caio.salgado@gmail.com> | @@ -71,12 +73,14 @@ Caio Salgado + Renan Teruo <caio.salgado@gmail.com> | ||
71 | Caio Salgado + Renan Teruo + Jefferson Fernandes <jeffs.fernandes@gmail.com> | 73 | Caio Salgado + Renan Teruo + Jefferson Fernandes <jeffs.fernandes@gmail.com> |
72 | Caio Salgado + Renan Teruo <renanteruoc@gmail.com> | 74 | Caio Salgado + Renan Teruo <renanteruoc@gmail.com> |
73 | Caio SBA <caio@colivre.coop.br> | 75 | Caio SBA <caio@colivre.coop.br> |
76 | +Caio Tiago Oliveira <caiotiago@colivre.coop.br> | ||
74 | Carlos Andre de Souza <carlos.andre.souza@msn.com> | 77 | Carlos Andre de Souza <carlos.andre.souza@msn.com> |
75 | Carlos Morais <carlos88morais@gmail.com> | 78 | Carlos Morais <carlos88morais@gmail.com> |
76 | Carlos Morais + Diego Araújo <diegoamc90@gmail.com> | 79 | Carlos Morais + Diego Araújo <diegoamc90@gmail.com> |
77 | Carlos Morais + Eduardo Morais <carlos88morais@gmail.com> | 80 | Carlos Morais + Eduardo Morais <carlos88morais@gmail.com> |
78 | Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com> | 81 | Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com> |
79 | Carlos Morais + Pedro Leal <carlos88morais@gmail.com> | 82 | Carlos Morais + Pedro Leal <carlos88morais@gmail.com> |
83 | +Daniela Feitosa <dani@dohko.(none)> | ||
80 | Daniel Alves + Diego Araújo <danpaulalves@gmail.com> | 84 | Daniel Alves + Diego Araújo <danpaulalves@gmail.com> |
81 | Daniel Alves + Diego Araújo <diegoamc90@gmail.com> | 85 | Daniel Alves + Diego Araújo <diegoamc90@gmail.com> |
82 | Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com> | 86 | Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com> |
@@ -117,6 +121,8 @@ Diego Martinez <diegoamc90@gmail.com> | @@ -117,6 +121,8 @@ Diego Martinez <diegoamc90@gmail.com> | ||
117 | Diego Martinez <diego@diego-K55A.(none)> | 121 | Diego Martinez <diego@diego-K55A.(none)> |
118 | Diego + Renan <renanteruoc@gmail.com> | 122 | Diego + Renan <renanteruoc@gmail.com> |
119 | Eduardo Tourinho Edington <eduardo.edington@serpro.gov.br> | 123 | Eduardo Tourinho Edington <eduardo.edington@serpro.gov.br> |
124 | +Evandro Jr <evandrojr@gmail.com> | ||
125 | +Evandro Junior <evandrojr@gmail.com> | ||
120 | Fabio Teixeira <fabio1079@gmail.com> | 126 | Fabio Teixeira <fabio1079@gmail.com> |
121 | Fernanda Lopes <nanda.listas+psl@gmail.com> | 127 | Fernanda Lopes <nanda.listas+psl@gmail.com> |
122 | Francisco Marcelo A. Lima Júnior <francisco.lima-junior@serpro.gov.br> | 128 | Francisco Marcelo A. Lima Júnior <francisco.lima-junior@serpro.gov.br> |
@@ -132,6 +138,7 @@ Italo Valcy <italo@dcc.ufba.br> | @@ -132,6 +138,7 @@ Italo Valcy <italo@dcc.ufba.br> | ||
132 | Jefferson Fernandes + Diego Araujo + Rafael Manzo <jeffs.fernandes@gmail.com> | 138 | Jefferson Fernandes + Diego Araujo + Rafael Manzo <jeffs.fernandes@gmail.com> |
133 | Jefferson Fernandes + Joao M. M. da Silva <jeffs.fernandes@gmail.com> | 139 | Jefferson Fernandes + Joao M. M. da Silva <jeffs.fernandes@gmail.com> |
134 | Jefferson Fernandes + Joao M. M. Silva <jeffs.fernandes@gmail.com> | 140 | Jefferson Fernandes + Joao M. M. Silva <jeffs.fernandes@gmail.com> |
141 | +João da Silva + Eduardo Morais + Rafael Manzo <rr.manzo@gmail.com> | ||
135 | João da Silva <jaodsilv@linux.ime.usp.br> | 142 | João da Silva <jaodsilv@linux.ime.usp.br> |
136 | João Marco Maciel da Silva + Rafael Manzo + Renan Teruo <jaodsilv@linux.ime.usp.br> | 143 | João Marco Maciel da Silva + Rafael Manzo + Renan Teruo <jaodsilv@linux.ime.usp.br> |
137 | João M. M. da Silva + Alessandro Palmeira + Diego Araújo + Caio Salgado <jaodsilv@linux.ime.usp.br> | 144 | João M. M. da Silva + Alessandro Palmeira + Diego Araújo + Caio Salgado <jaodsilv@linux.ime.usp.br> |
@@ -166,6 +173,7 @@ Junior Silva <junior@bajor.localhost.localdomain> | @@ -166,6 +173,7 @@ Junior Silva <junior@bajor.localhost.localdomain> | ||
166 | Junior Silva <juniorsilva1001@gmail.com> | 173 | Junior Silva <juniorsilva1001@gmail.com> |
167 | Junior Silva <juniorsilva7@juniorsilva-Aspire-5750Z.(none)> | 174 | Junior Silva <juniorsilva7@juniorsilva-Aspire-5750Z.(none)> |
168 | Junior Silva <juniorsilva@colivre.coop.br> | 175 | Junior Silva <juniorsilva@colivre.coop.br> |
176 | +juniorsilva <juniorsilva@QonoS.localhost.localdomain> | ||
169 | Keilla Menezes <keilla@colivre.coop.br> | 177 | Keilla Menezes <keilla@colivre.coop.br> |
170 | Larissa Reis <larissa@colivre.coop.br> | 178 | Larissa Reis <larissa@colivre.coop.br> |
171 | Larissa Reis <reiss.larissa@gmail.com> | 179 | Larissa Reis <reiss.larissa@gmail.com> |
@@ -176,7 +184,9 @@ Leandro Nunes dos Santos <leandro.santos@serpro.gov.br> | @@ -176,7 +184,9 @@ Leandro Nunes dos Santos <leandro.santos@serpro.gov.br> | ||
176 | LinguÁgil 2010 <linguagil.bahia@gmail.com> | 184 | LinguÁgil 2010 <linguagil.bahia@gmail.com> |
177 | Lucas Melo <lucas@colivre.coop.br> | 185 | Lucas Melo <lucas@colivre.coop.br> |
178 | Lucas Melo <lucaspradomelo@gmail.com> | 186 | Lucas Melo <lucaspradomelo@gmail.com> |
187 | +Luciano <lucianopcbr@gmail.com> | ||
179 | Luis David Aguilar Carlos <ludwig9003@gmail.com> | 188 | Luis David Aguilar Carlos <ludwig9003@gmail.com> |
189 | +Luiz Fernando de Freitas Matos <luiz@luizff.matos@gmail.com> | ||
180 | Marcos Ramos <ms.ramos@outlook.com> | 190 | Marcos Ramos <ms.ramos@outlook.com> |
181 | Martín Olivera <molivera@solar.org.ar> | 191 | Martín Olivera <molivera@solar.org.ar> |
182 | Moises Machado <moises@colivre.coop.br> | 192 | Moises Machado <moises@colivre.coop.br> |
app/controllers/public/content_viewer_controller.rb
@@ -8,49 +8,31 @@ class ContentViewerController < ApplicationController | @@ -8,49 +8,31 @@ class ContentViewerController < ApplicationController | ||
8 | helper TagsHelper | 8 | helper TagsHelper |
9 | 9 | ||
10 | def view_page | 10 | def view_page |
11 | - path = params[:page] | ||
12 | - path = path.join('/') if path.kind_of?(Array) | ||
13 | - path = "#{path}.#{params[:format]}" if params[:format] | 11 | + path = get_path(params[:page], params[:format]) |
12 | + | ||
14 | @version = params[:version].to_i | 13 | @version = params[:version].to_i |
15 | 14 | ||
16 | if path.blank? | 15 | if path.blank? |
17 | - @page = profile.home_page | ||
18 | - if @page.nil? | ||
19 | - redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier | ||
20 | - return | ||
21 | - end | 16 | + @page = profile.home_page |
17 | + return if redirected_to_profile_index | ||
22 | else | 18 | else |
23 | @page = profile.articles.find_by_path(path) | 19 | @page = profile.articles.find_by_path(path) |
24 | - unless @page | ||
25 | - page_from_old_path = profile.articles.find_by_old_path(path) | ||
26 | - if page_from_old_path | ||
27 | - redirect_to profile.url.merge(:page => page_from_old_path.explode_path) | ||
28 | - return | ||
29 | - end | ||
30 | - end | 20 | + return if redirected_page_from_old_path(path) |
31 | end | 21 | end |
32 | 22 | ||
33 | return unless allow_access_to_page(path) | 23 | return unless allow_access_to_page(path) |
34 | 24 | ||
35 | if @version > 0 | 25 | if @version > 0 |
36 | return render_access_denied unless @page.display_versions? | 26 | return render_access_denied unless @page.display_versions? |
37 | - @versioned_article = @page.versions.find_by_version(@version) | ||
38 | - if @versioned_article && @page.versions.latest.version != @versioned_article.version | ||
39 | - render :template => 'content_viewer/versioned_article.html.erb' | ||
40 | - return | ||
41 | - end | 27 | + return if rendered_versioned_article |
42 | end | 28 | end |
43 | 29 | ||
44 | redirect_to_translation and return if @page.profile.redirect_l10n | 30 | redirect_to_translation and return if @page.profile.redirect_l10n |
45 | 31 | ||
46 | - if request.post? | ||
47 | - if @page.forum? && @page.has_terms_of_use && params[:terms_accepted] == "true" | ||
48 | - @page.add_agreed_user(user) | ||
49 | - end | ||
50 | - elsif !@page.parent.nil? && @page.parent.forum? | ||
51 | - unless @page.parent.agrees_with_terms?(user) | ||
52 | - redirect_to @page.parent.url | ||
53 | - end | 32 | + if request.post? && @page.forum? |
33 | + process_forum_terms_of_use(user, params[:terms_accepted]) | ||
34 | + elsif is_a_forum_topic?(@page) | ||
35 | + redirect_to @page.parent.url unless @page.parent.agrees_with_terms?(user) | ||
54 | end | 36 | end |
55 | 37 | ||
56 | # At this point the page will be showed | 38 | # At this point the page will be showed |
@@ -58,64 +40,22 @@ class ContentViewerController < ApplicationController | @@ -58,64 +40,22 @@ class ContentViewerController < ApplicationController | ||
58 | 40 | ||
59 | @page = FilePresenter.for @page | 41 | @page = FilePresenter.for @page |
60 | 42 | ||
61 | - if @page.download? params[:view] | ||
62 | - headers['Content-Type'] = @page.mime_type | ||
63 | - headers.merge! @page.download_headers | ||
64 | - data = @page.data | ||
65 | - | ||
66 | - # TODO test the condition | ||
67 | - if data.nil? | ||
68 | - raise "No data for file" | ||
69 | - end | ||
70 | - | ||
71 | - render :text => data, :layout => false | ||
72 | - return | ||
73 | - end | 43 | + return if rendered_file_download(params[:view]) |
74 | 44 | ||
75 | @form_div = params[:form] | 45 | @form_div = params[:form] |
76 | 46 | ||
77 | #FIXME see a better way to do this. It's not need to pass this variable anymore | 47 | #FIXME see a better way to do this. It's not need to pass this variable anymore |
78 | @comment = Comment.new | 48 | @comment = Comment.new |
79 | 49 | ||
80 | - if @page.has_posts? | ||
81 | - posts = if params[:year] and params[:month] | ||
82 | - filter_date = DateTime.parse("#{params[:year]}-#{params[:month]}-01") | ||
83 | - @page.posts.by_range(filter_date..filter_date.at_end_of_month) | ||
84 | - else | ||
85 | - @page.posts | ||
86 | - end | ||
87 | - | ||
88 | - #FIXME Need to run this before the pagination because this version of | ||
89 | - # will_paginate returns a will_paginate collection instead of a | ||
90 | - # relation. | ||
91 | - blog_with_translation = @page.blog? && @page.display_posts_in_current_language? | ||
92 | - posts = posts.native_translations if blog_with_translation | ||
93 | - | ||
94 | - @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a | ||
95 | - | ||
96 | - if blog_with_translation | ||
97 | - @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | ||
98 | - end | ||
99 | - end | 50 | + process_page_posts(params) |
100 | 51 | ||
101 | if @page.folder? && @page.gallery? | 52 | if @page.folder? && @page.gallery? |
102 | - @images = @page.images.select{ |a| a.display_to? user } | ||
103 | - @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] | 53 | + @images = get_images(@page, params[:npage], params[:slideshow]) |
104 | end | 54 | end |
105 | 55 | ||
106 | - @unfollow_form = params[:unfollow] && params[:unfollow] == 'true' | ||
107 | - if params[:unfollow] && params[:unfollow] == 'commit' && request.post? | ||
108 | - @page.followers -= [params[:email]] | ||
109 | - if @page.save | ||
110 | - session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] | ||
111 | - end | ||
112 | - end | 56 | + process_page_followers(params) |
113 | 57 | ||
114 | - @comments = @page.comments.without_spam | ||
115 | - @comments = @plugins.filter(:unavailable_comments, @comments) | ||
116 | - @comments_count = @comments.count | ||
117 | - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
118 | - @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | 58 | + process_comments(params) |
119 | 59 | ||
120 | if request.xhr? and params[:comment_order] | 60 | if request.xhr? and params[:comment_order] |
121 | if @comment_order == 'newest' | 61 | if @comment_order == 'newest' |
@@ -203,4 +143,127 @@ class ContentViewerController < ApplicationController | @@ -203,4 +143,127 @@ class ContentViewerController < ApplicationController | ||
203 | user_agent.match(/crawler/) || | 143 | user_agent.match(/crawler/) || |
204 | user_agent.match(/\(.*https?:\/\/.*\)/) | 144 | user_agent.match(/\(.*https?:\/\/.*\)/) |
205 | end | 145 | end |
146 | + | ||
147 | + def get_path(page, format = nil) | ||
148 | + path = page | ||
149 | + path = path.join('/') if path.kind_of?(Array) | ||
150 | + path = "#{path}.#{format}" if format | ||
151 | + | ||
152 | + return path | ||
153 | + end | ||
154 | + | ||
155 | + def redirected_to_profile_index | ||
156 | + if @page.nil? | ||
157 | + redirect_to :controller => 'profile', :action => 'index', :profile => profile.identifier | ||
158 | + return true | ||
159 | + end | ||
160 | + | ||
161 | + return false | ||
162 | + end | ||
163 | + | ||
164 | + def redirected_page_from_old_path(path) | ||
165 | + unless @page | ||
166 | + page_from_old_path = profile.articles.find_by_old_path(path) | ||
167 | + if page_from_old_path | ||
168 | + redirect_to profile.url.merge(:page => page_from_old_path.explode_path) | ||
169 | + return true | ||
170 | + end | ||
171 | + end | ||
172 | + | ||
173 | + return false | ||
174 | + end | ||
175 | + | ||
176 | + def process_forum_terms_of_use(user, terms_accepted = nil) | ||
177 | + if @page.forum? && @page.has_terms_of_use && terms_accepted == "true" | ||
178 | + @page.add_agreed_user(user) | ||
179 | + end | ||
180 | + end | ||
181 | + | ||
182 | + def is_a_forum_topic? (page) | ||
183 | + return (!@page.parent.nil? && @page.parent.forum?) | ||
184 | + end | ||
185 | + | ||
186 | + def rendered_versioned_article | ||
187 | + @versioned_article = @page.versions.find_by_version(@version) | ||
188 | + if @versioned_article && @page.versions.latest.version != @versioned_article.version | ||
189 | + render :template => 'content_viewer/versioned_article.html.erb' | ||
190 | + return true | ||
191 | + end | ||
192 | + | ||
193 | + return false | ||
194 | + end | ||
195 | + | ||
196 | + def rendered_file_download(view = nil) | ||
197 | + if @page.download? view | ||
198 | + headers['Content-Type'] = @page.mime_type | ||
199 | + headers.merge! @page.download_headers | ||
200 | + data = @page.data | ||
201 | + | ||
202 | + # TODO test the condition | ||
203 | + if data.nil? | ||
204 | + raise "No data for file" | ||
205 | + end | ||
206 | + | ||
207 | + render :text => data, :layout => false | ||
208 | + return true | ||
209 | + end | ||
210 | + | ||
211 | + return false | ||
212 | + end | ||
213 | + | ||
214 | + def process_page_posts(params) | ||
215 | + if @page.has_posts? | ||
216 | + posts = get_posts(params[:year], params[:month]) | ||
217 | + | ||
218 | + #FIXME Need to run this before the pagination because this version of | ||
219 | + # will_paginate returns a will_paginate collection instead of a | ||
220 | + # relation. | ||
221 | + posts = posts.native_translations if blog_with_translation?(@page) | ||
222 | + | ||
223 | + @posts = posts.paginate({ :page => params[:npage], :per_page => @page.posts_per_page }.merge(Article.display_filter(user, profile))).to_a | ||
224 | + | ||
225 | + if blog_with_translation?(@page) | ||
226 | + @posts.replace @posts.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | ||
227 | + end | ||
228 | + end | ||
229 | + end | ||
230 | + | ||
231 | + def get_posts(year = nil, month = nil) | ||
232 | + if year && month | ||
233 | + filter_date = DateTime.parse("#{year}-#{month}-01") | ||
234 | + return @page.posts.by_range(filter_date..filter_date.at_end_of_month) | ||
235 | + else | ||
236 | + return @page.posts | ||
237 | + end | ||
238 | + end | ||
239 | + | ||
240 | + def blog_with_translation?(page) | ||
241 | + return (page.blog? && page.display_posts_in_current_language?) | ||
242 | + end | ||
243 | + | ||
244 | + def get_images(page, npage, slideshow) | ||
245 | + images = page.images.select{ |a| a.display_to? user } | ||
246 | + images = images.paginate(:per_page => per_page, :page => npage) unless slideshow | ||
247 | + | ||
248 | + return images | ||
249 | + end | ||
250 | + | ||
251 | + def process_page_followers(params) | ||
252 | + @unfollow_form = params[:unfollow] == 'true' | ||
253 | + if params[:unfollow] == 'commit' && request.post? | ||
254 | + @page.followers -= [params[:email]] | ||
255 | + if @page.save | ||
256 | + session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] | ||
257 | + end | ||
258 | + end | ||
259 | + end | ||
260 | + | ||
261 | + def process_comments(params) | ||
262 | + @comments = @page.comments.without_spam | ||
263 | + @comments = @plugins.filter(:unavailable_comments, @comments) | ||
264 | + @comments_count = @comments.count | ||
265 | + @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
266 | + @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | ||
267 | + end | ||
268 | + | ||
206 | end | 269 | end |
app/helpers/application_helper.rb
@@ -1002,17 +1002,26 @@ module ApplicationHelper | @@ -1002,17 +1002,26 @@ module ApplicationHelper | ||
1002 | def display_category_menu(block, categories, root = true) | 1002 | def display_category_menu(block, categories, root = true) |
1003 | categories = categories.sort{|x,y| x.name <=> y.name} | 1003 | categories = categories.sort{|x,y| x.name <=> y.name} |
1004 | return "" if categories.blank? | 1004 | return "" if categories.blank? |
1005 | - content_tag(:ul, | 1005 | + content_tag(:ul) do |
1006 | categories.map do |category| | 1006 | categories.map do |category| |
1007 | category_path = category.kind_of?(ProductCategory) ? {:controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id} : { :controller => 'search', :action => 'category_index', :category_path => category.explode_path } | 1007 | category_path = category.kind_of?(ProductCategory) ? {:controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id} : { :controller => 'search', :action => 'category_index', :category_path => category.explode_path } |
1008 | - category.display_in_menu? ? | ||
1009 | - content_tag(:li, | ||
1010 | - ( !category.is_leaf_displayable_in_menu? ? content_tag(:a, collapsed_item_icon, :href => "#", :id => "block_#{block.id}_category_#{category.id}", :class => 'category-link-expand ' + (root ? 'category-root' : 'category-no-root'), :onclick => "expandCategory(#{block.id}, #{category.id}); return false", :style => 'display: none') : leaf_item_icon) + | ||
1011 | - link_to(content_tag(:span, category.name, :class => 'category-name'), category_path, :class => ("category-leaf" if category.is_leaf_displayable_in_menu?)) + | ||
1012 | - content_tag(:div, display_category_menu(block, category.children, false), :id => "block_#{block.id}_category_content_#{category.id}", :class => 'child-category') | ||
1013 | - ) : '' | ||
1014 | - end | ||
1015 | - ) + | 1008 | + if category.display_in_menu? |
1009 | + content_tag(:li) do | ||
1010 | + if !category.is_leaf_displayable_in_menu? | ||
1011 | + content_tag(:a, collapsed_item_icon, :href => "#", :id => "block_#{block.id}_category_#{category.id}", :class => "category-link-expand " + (root ? "category-root" : "category-no-root"), :onclick => "expandCategory(#{block.id}, #{category.id}); return false", :style => "display: none") | ||
1012 | + else | ||
1013 | + leaf_item_icon | ||
1014 | + end + | ||
1015 | + link_to(content_tag(:span, category.name, :class => "category-name"), category_path, :class => ("category-leaf" if category.is_leaf_displayable_in_menu?)) + | ||
1016 | + content_tag(:div, :id => "block_#{block.id}_category_content_#{category.id}", :class => 'child-category') do | ||
1017 | + display_category_menu(block, category.children, false) | ||
1018 | + end | ||
1019 | + end | ||
1020 | + else | ||
1021 | + "" | ||
1022 | + end | ||
1023 | + end.join.html_safe | ||
1024 | + end + | ||
1016 | content_tag(:p) + | 1025 | content_tag(:p) + |
1017 | (root ? javascript_tag(" | 1026 | (root ? javascript_tag(" |
1018 | jQuery('.child-category').hide(); | 1027 | jQuery('.child-category').hide(); |
@@ -1104,14 +1113,18 @@ module ApplicationHelper | @@ -1104,14 +1113,18 @@ module ApplicationHelper | ||
1104 | end | 1113 | end |
1105 | 1114 | ||
1106 | def manage_enterprises | 1115 | def manage_enterprises |
1107 | - return unless user && user.environment.enabled?(:display_my_enterprises_on_user_menu) | ||
1108 | - manage_link(user.enterprises, :enterprises) | 1116 | + return '' unless user && user.environment.enabled?(:display_my_enterprises_on_user_menu) |
1117 | + manage_link(user.enterprises, :enterprises).to_s | ||
1109 | end | 1118 | end |
1110 | 1119 | ||
1111 | def manage_communities | 1120 | def manage_communities |
1112 | - return unless user && user.environment.enabled?(:display_my_communities_on_user_menu) | 1121 | + return '' unless user && user.environment.enabled?(:display_my_communities_on_user_menu) |
1113 | administered_communities = user.communities.more_popular.select {|c| c.admins.include? user} | 1122 | administered_communities = user.communities.more_popular.select {|c| c.admins.include? user} |
1114 | - manage_link(administered_communities, :communities) | 1123 | + manage_link(administered_communities, :communities).to_s |
1124 | + end | ||
1125 | + | ||
1126 | + def admin_link | ||
1127 | + user.is_admin?(environment) ? link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') : '' | ||
1115 | end | 1128 | end |
1116 | 1129 | ||
1117 | def usermenu_logged_in | 1130 | def usermenu_logged_in |
@@ -1123,9 +1136,9 @@ module ApplicationHelper | @@ -1123,9 +1136,9 @@ module ApplicationHelper | ||
1123 | 1136 | ||
1124 | (_("<span class='welcome'>Welcome,</span> %s") % link_to("<i style='background-image:url(#{user.profile_custom_icon(gravatar_default)})'></i><strong>#{user.identifier}</strong>", user.public_profile_url, :id => "homepage-link", :title => _('Go to your homepage'))) + | 1137 | (_("<span class='welcome'>Welcome,</span> %s") % link_to("<i style='background-image:url(#{user.profile_custom_icon(gravatar_default)})'></i><strong>#{user.identifier}</strong>", user.public_profile_url, :id => "homepage-link", :title => _('Go to your homepage'))) + |
1125 | render_environment_features(:usermenu) + | 1138 | render_environment_features(:usermenu) + |
1126 | - link_to('<i class="icon-menu-admin"></i><strong>' + _('Administration') + '</strong>', @environment.admin_url, :title => _("Configure the environment"), :class => 'admin-link') + | ||
1127 | - manage_enterprises.to_s + | ||
1128 | - manage_communities.to_s + | 1139 | + admin_link + |
1140 | + manage_enterprises + | ||
1141 | + manage_communities + | ||
1129 | link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + | 1142 | link_to('<i class="icon-menu-ctrl-panel"></i><strong>' + _('Control panel') + '</strong>', user.admin_url, :class => 'ctrl-panel', :title => _("Configure your personal account and content")) + |
1130 | pending_tasks_count + | 1143 | pending_tasks_count + |
1131 | link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) | 1144 | link_to('<i class="icon-menu-logout"></i><strong>' + _('Logout') + '</strong>', { :controller => 'account', :action => 'logout'} , :id => "logout", :title => _("Leave the system")) |
app/mailers/user_mailer.rb
@@ -15,10 +15,12 @@ class UserMailer < ActionMailer::Base | @@ -15,10 +15,12 @@ class UserMailer < ActionMailer::Base | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def activation_code(user) | 17 | def activation_code(user) |
18 | - @recipient = user.name, | 18 | + @recipient = user.name |
19 | @activation_code = user.activation_code | 19 | @activation_code = user.activation_code |
20 | @environment = user.environment.name | 20 | @environment = user.environment.name |
21 | @url = user.environment.top_url | 21 | @url = user.environment.top_url |
22 | + @redirection = (true if user.return_to) | ||
23 | + @join = (user.community_to_join if user.community_to_join) | ||
22 | 24 | ||
23 | mail( | 25 | mail( |
24 | from: "#{user.environment.name} <#{user.environment.contact_email}>", | 26 | from: "#{user.environment.name} <#{user.environment.contact_email}>", |
app/models/image.rb
app/models/user.rb
@@ -66,45 +66,6 @@ class User < ActiveRecord::Base | @@ -66,45 +66,6 @@ class User < ActiveRecord::Base | ||
66 | # virtual attribute used to stash which community to join on signup or login | 66 | # virtual attribute used to stash which community to join on signup or login |
67 | attr_accessor :community_to_join | 67 | attr_accessor :community_to_join |
68 | 68 | ||
69 | - class Mailer < ActionMailer::Base | ||
70 | - def activation_email_notify(user) | ||
71 | - user_email = "#{user.login}@#{user.email_domain}" | ||
72 | - recipients user_email | ||
73 | - from "#{user.environment.name} <#{user.environment.noreply_email}>" | ||
74 | - subject _("[%{environment}] Welcome to %{environment} mail!") % { :environment => user.environment.name } | ||
75 | - body :name => user.name, | ||
76 | - :email => user_email, | ||
77 | - :webmail => MailConf.webmail_url(user.login, user.email_domain), | ||
78 | - :environment => user.environment.name, | ||
79 | - :url => url_for(:host => user.environment.default_hostname, :controller => 'home') | ||
80 | - end | ||
81 | - | ||
82 | - def activation_code(user) | ||
83 | - recipients user.email | ||
84 | - | ||
85 | - from "#{user.environment.name} <#{user.environment.noreply_email}>" | ||
86 | - subject _("[%s] Activate your account") % [user.environment.name] | ||
87 | - body :recipient => user.name, | ||
88 | - :activation_code => user.activation_code, | ||
89 | - :environment => user.environment.name, | ||
90 | - :url => user.environment.top_url, | ||
91 | - :redirection => (true if user.return_to), | ||
92 | - :join => (user.community_to_join if user.community_to_join) | ||
93 | - end | ||
94 | - | ||
95 | - def signup_welcome_email(user) | ||
96 | - email_body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) | ||
97 | - email_subject = user.environment.signup_welcome_text_subject | ||
98 | - | ||
99 | - content_type 'text/html' | ||
100 | - recipients user.email | ||
101 | - | ||
102 | - from "#{user.environment.name} <#{user.environment.noreply_email}>" | ||
103 | - subject email_subject.blank? ? _("Welcome to environment %s") % [user.environment.name] : email_subject | ||
104 | - body email_body | ||
105 | - end | ||
106 | - end | ||
107 | - | ||
108 | def signup! | 69 | def signup! |
109 | User.transaction do | 70 | User.transaction do |
110 | self.save! | 71 | self.save! |
app/views/user/mailer/activation_email_notify.html.erb
@@ -1,12 +0,0 @@ | @@ -1,12 +0,0 @@ | ||
1 | -<%= _('Hello %s,') % @name %> | ||
2 | - | ||
3 | -<%= _('Your email %s was just activated.') % [@email] %> | ||
4 | - | ||
5 | -<%= _('You can access your e-mail from anywhere, using the following address:') %> | ||
6 | -<%= @webmail %> | ||
7 | - | ||
8 | -<%= _('Greetings,') %> | ||
9 | - | ||
10 | --- | ||
11 | -<%= _('%s team.') % @environment %> | ||
12 | -<%= @url %> |
app/views/user/mailer/signup_welcome_email.html.erb
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> | ||
2 | + | ||
3 | +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %> | ||
4 | + | ||
5 | +<%= _("Greetings,") %> | ||
6 | + | ||
7 | +-- | ||
8 | +<%= _('%s team.') % @environment %> | ||
9 | +<%= url_for @url %> |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<%= _('Hello %s,') % @name %> | ||
2 | + | ||
3 | +<%= _('Your email %s was just activated.') % [@email] %> | ||
4 | + | ||
5 | +<%= _('You can access your e-mail from anywhere, using the following address:') %> | ||
6 | +<%= @webmail %> | ||
7 | + | ||
8 | +<%= _('Greetings,') %> | ||
9 | + | ||
10 | +-- | ||
11 | +<%= _('%s team.') % @environment %> | ||
12 | +<%= @url %> |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(:version => 20140415125414) do | 14 | +ActiveRecord::Schema.define(:version => 20140605222753) do |
15 | 15 | ||
16 | create_table "abuse_reports", :force => true do |t| | 16 | create_table "abuse_reports", :force => true do |t| |
17 | t.integer "reporter_id" | 17 | t.integer "reporter_id" |
debian/changelog
1 | +noosfero (0.99.0~rc20140618202455) wheezy-test; urgency=low | ||
2 | + | ||
3 | + * Another rc with rails3 | ||
4 | + | ||
5 | + -- Rodrigo Souto <rodrigo@colivre.coop.br> Wed, 18 Jun 2014 20:25:01 +0000 | ||
6 | + | ||
1 | noosfero (0.47.1) unstable; urgency=low | 7 | noosfero (0.47.1) unstable; urgency=low |
2 | 8 | ||
3 | * Bugfix release | 9 | * Bugfix release |
features/clickable_images.feature
@@ -14,6 +14,7 @@ Feature: clickable images | @@ -14,6 +14,7 @@ Feature: clickable images | ||
14 | | owner | name | image | dimensions | | 14 | | owner | name | image | dimensions | |
15 | | booking | small | rails.png | 20x20 | | 15 | | booking | small | rails.png | 20x20 | |
16 | When I go to /booking/small | 16 | When I go to /booking/small |
17 | + And display ".zoomify-image" | ||
17 | Then I should see "Zoom in" | 18 | Then I should see "Zoom in" |
18 | 19 | ||
19 | @selenium | 20 | @selenium |
@@ -22,6 +23,7 @@ Feature: clickable images | @@ -22,6 +23,7 @@ Feature: clickable images | ||
22 | | owner | name | image | dimensions | | 23 | | owner | name | image | dimensions | |
23 | | booking | real | rails.png | 50x64 | | 24 | | booking | real | rails.png | 50x64 | |
24 | When I go to /booking/real | 25 | When I go to /booking/real |
26 | + And display ".zoomify-image" | ||
25 | Then "Zoom in" should not be visible within "a#zoomify-image" | 27 | Then "Zoom in" should not be visible within "a#zoomify-image" |
26 | 28 | ||
27 | @selenium | 29 | @selenium |
@@ -30,6 +32,7 @@ Feature: clickable images | @@ -30,6 +32,7 @@ Feature: clickable images | ||
30 | | owner | name | image | | 32 | | owner | name | image | |
31 | | booking | not set | rails.png | | 33 | | booking | not set | rails.png | |
32 | When I go to /booking/not-set | 34 | When I go to /booking/not-set |
35 | + And display ".zoomify-image" | ||
33 | Then "Zoom in" should not be visible within "a#zoomify-image" | 36 | Then "Zoom in" should not be visible within "a#zoomify-image" |
34 | 37 | ||
35 | @selenium-fixme | 38 | @selenium-fixme |
lib/noosfero.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | require 'fast_gettext' | 3 | require 'fast_gettext' |
4 | module Noosfero | 4 | module Noosfero |
5 | PROJECT = 'noosfero' | 5 | PROJECT = 'noosfero' |
6 | - VERSION = '0.47.1' | 6 | + VERSION = '0.99.0~rc20140618202455' |
7 | 7 | ||
8 | def self.pattern_for_controllers_in_directory(dir) | 8 | def self.pattern_for_controllers_in_directory(dir) |
9 | disjunction = controllers_in_directory(dir).join('|') | 9 | disjunction = controllers_in_directory(dir).join('|') |
lib/noosfero/plugin.rb
@@ -395,7 +395,7 @@ class Noosfero::Plugin | @@ -395,7 +395,7 @@ class Noosfero::Plugin | ||
395 | end | 395 | end |
396 | 396 | ||
397 | # -> Adds fields to the signup form | 397 | # -> Adds fields to the signup form |
398 | - # returns = lambda block that creates html code | 398 | + # returns = proc that creates html code |
399 | def signup_extra_contents | 399 | def signup_extra_contents |
400 | nil | 400 | nil |
401 | end | 401 | end |
@@ -470,7 +470,7 @@ class Noosfero::Plugin | @@ -470,7 +470,7 @@ class Noosfero::Plugin | ||
470 | end | 470 | end |
471 | 471 | ||
472 | # -> Adds fields to the login form | 472 | # -> Adds fields to the login form |
473 | - # returns = lambda block that creates html code | 473 | + # returns = proc that creates html code |
474 | def login_extra_contents | 474 | def login_extra_contents |
475 | nil | 475 | nil |
476 | end | 476 | end |
plugins/stoa/install.rb
1 | require 'fileutils' | 1 | require 'fileutils' |
2 | 2 | ||
3 | -config_path = File.join('plugins', 'stoa', 'config.yml') | ||
4 | -config_template = File.join('plugins', 'stoa', 'config.yml.dist') | 3 | +config_path = File.join(File.dirname(__FILE__), 'config.yml') |
4 | +config_template = File.join(File.dirname(__FILE__), 'config.yml.dist') | ||
5 | FileUtils.cp(config_template, config_path) if !File.exist?(config_path) | 5 | FileUtils.cp(config_template, config_path) if !File.exist?(config_path) |
plugins/stoa/lib/ext/person.rb
1 | require_dependency 'person' | 1 | require_dependency 'person' |
2 | 2 | ||
3 | class Person | 3 | class Person |
4 | + attr_accessible :usp_id, :invitation_code | ||
5 | + | ||
4 | validates_uniqueness_of :usp_id, :allow_nil => true | 6 | validates_uniqueness_of :usp_id, :allow_nil => true |
5 | settings_items :invitation_code | 7 | settings_items :invitation_code |
6 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} | 8 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} |
plugins/stoa/lib/stoa_plugin.rb
@@ -2,8 +2,6 @@ require_dependency 'person' | @@ -2,8 +2,6 @@ require_dependency 'person' | ||
2 | 2 | ||
3 | class StoaPlugin < Noosfero::Plugin | 3 | class StoaPlugin < Noosfero::Plugin |
4 | 4 | ||
5 | - Person.human_names[:usp_id] = _('USP number') | ||
6 | - | ||
7 | def self.plugin_name | 5 | def self.plugin_name |
8 | "Stoa" | 6 | "Stoa" |
9 | end | 7 | end |
@@ -17,7 +15,7 @@ class StoaPlugin < Noosfero::Plugin | @@ -17,7 +15,7 @@ class StoaPlugin < Noosfero::Plugin | ||
17 | end | 15 | end |
18 | 16 | ||
19 | def signup_extra_contents | 17 | def signup_extra_contents |
20 | - lambda { | 18 | + proc { |
21 | content_tag(:div, labelled_form_field(_('USP number'), text_field(:profile_data, :usp_id, :id => 'usp_id_field')) + | 19 | content_tag(:div, labelled_form_field(_('USP number'), text_field(:profile_data, :usp_id, :id => 'usp_id_field')) + |
22 | content_tag(:small, _('The usp id grants you special powers in the network. Don\'t forget to fill it with a valid number if you have one.'), :id => 'usp-id-balloon') + | 20 | content_tag(:small, _('The usp id grants you special powers in the network. Don\'t forget to fill it with a valid number if you have one.'), :id => 'usp-id-balloon') + |
23 | content_tag('p', _("Either this usp number is being used by another user or is not valid"), :id => 'usp-id-invalid') + | 21 | content_tag('p', _("Either this usp number is being used by another user or is not valid"), :id => 'usp-id-invalid') + |
@@ -45,7 +43,7 @@ class StoaPlugin < Noosfero::Plugin | @@ -45,7 +43,7 @@ class StoaPlugin < Noosfero::Plugin | ||
45 | end | 43 | end |
46 | 44 | ||
47 | def login_extra_contents | 45 | def login_extra_contents |
48 | - lambda { | 46 | + proc { |
49 | content_tag('div', labelled_form_field(_('USP number / Username'), text_field_tag('usp_id_login', '', :id => 'stoa_field_login')) + | 47 | content_tag('div', labelled_form_field(_('USP number / Username'), text_field_tag('usp_id_login', '', :id => 'stoa_field_login')) + |
50 | labelled_form_field(_('Password'), password_field_tag('password', '', :id => 'stoa_field_password')), :id => 'stoa-login-fields') | 48 | labelled_form_field(_('Password'), password_field_tag('password', '', :id => 'stoa_field_password')), :id => 'stoa-login-fields') |
51 | } | 49 | } |
@@ -62,14 +60,13 @@ class StoaPlugin < Noosfero::Plugin | @@ -62,14 +60,13 @@ class StoaPlugin < Noosfero::Plugin | ||
62 | end | 60 | end |
63 | 61 | ||
64 | def account_controller_filters | 62 | def account_controller_filters |
65 | - environment = context.environment | ||
66 | - block = lambda do | 63 | + block = lambda do |context| |
67 | params[:profile_data] ||= {} | 64 | params[:profile_data] ||= {} |
68 | params[:profile_data][:invitation_code] = params[:invitation_code] | 65 | params[:profile_data][:invitation_code] = params[:invitation_code] |
69 | invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]}) | 66 | invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]}) |
70 | if request.post? | 67 | if request.post? |
71 | if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) | 68 | if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) |
72 | - @person = Person.new(:environment => environment) | 69 | + @person = Person.new(:environment => context.environment) |
73 | @person.errors.add(:usp_id, _(' validation failed')) | 70 | @person.errors.add(:usp_id, _(' validation failed')) |
74 | render :action => :signup | 71 | render :action => :signup |
75 | end | 72 | end |
@@ -83,7 +80,7 @@ class StoaPlugin < Noosfero::Plugin | @@ -83,7 +80,7 @@ class StoaPlugin < Noosfero::Plugin | ||
83 | end | 80 | end |
84 | 81 | ||
85 | def profile_editor_controller_filters | 82 | def profile_editor_controller_filters |
86 | - block = lambda do | 83 | + block = proc do |
87 | if request.post? | 84 | if request.post? |
88 | if !params[:profile_data][:usp_id].blank? && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) | 85 | if !params[:profile_data][:usp_id].blank? && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) |
89 | @profile_data = profile | 86 | @profile_data = profile |
@@ -106,7 +103,7 @@ class StoaPlugin < Noosfero::Plugin | @@ -106,7 +103,7 @@ class StoaPlugin < Noosfero::Plugin | ||
106 | def invite_controller_filters | 103 | def invite_controller_filters |
107 | [{ :type => 'before_filter', | 104 | [{ :type => 'before_filter', |
108 | :method_name => 'check_usp_id_existence', | 105 | :method_name => 'check_usp_id_existence', |
109 | - :block => lambda {render_access_denied if !user || user.usp_id.blank?} }] | 106 | + :block => proc {render_access_denied if !user || user.usp_id.blank?} }] |
110 | end | 107 | end |
111 | 108 | ||
112 | def control_panel_buttons | 109 | def control_panel_buttons |
plugins/stoa/lib/stoa_plugin/person_api.rb
@@ -28,7 +28,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator | @@ -28,7 +28,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator | ||
28 | end | 28 | end |
29 | 29 | ||
30 | def tags | 30 | def tags |
31 | - articles.published.tag_counts({:order => 'tags.count desc', :limit => 10}).inject({}) do |memo,tag| | 31 | + articles.published.tag_counts({:order => 'count desc', :limit => 10}).inject({}) do |memo,tag| |
32 | memo[tag.name] = tag.count | 32 | memo[tag.name] = tag.count |
33 | memo | 33 | memo |
34 | end | 34 | end |
plugins/stoa/lib/stoa_plugin/usp_user.rb
@@ -3,7 +3,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | @@ -3,7 +3,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | ||
3 | establish_connection(:stoa) | 3 | establish_connection(:stoa) |
4 | set_table_name('pessoa') | 4 | set_table_name('pessoa') |
5 | 5 | ||
6 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | 6 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] |
7 | 7 | ||
8 | alias_attribute :cpf, :numcpf | 8 | alias_attribute :cpf, :numcpf |
9 | alias_attribute :birth_date, :dtanas | 9 | alias_attribute :birth_date, :dtanas |
plugins/stoa/test/functional/account_controller_test.rb
@@ -6,32 +6,29 @@ class AccountController; def rescue_action(e) raise e end; end | @@ -6,32 +6,29 @@ class AccountController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class AccountControllerTest < ActionController::TestCase | 7 | class AccountControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | 9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] |
10 | + | ||
11 | + @db = Tempfile.new('stoa-test') | ||
12 | + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | ||
13 | + ActiveRecord::Base.establish_connection(:stoa) | ||
14 | + ActiveRecord::Schema.verbose = false | ||
15 | + ActiveRecord::Schema.create_table "pessoa" do |t| | ||
16 | + t.integer "codpes" | ||
17 | + t.text "numcpf" | ||
18 | + t.date "dtanas" | ||
19 | + end | ||
20 | + ActiveRecord::Base.establish_connection(:test) | ||
10 | 21 | ||
11 | def setup | 22 | def setup |
12 | @controller = AccountController.new | 23 | @controller = AccountController.new |
13 | @request = ActionController::TestRequest.new | 24 | @request = ActionController::TestRequest.new |
14 | @response = ActionController::TestResponse.new | 25 | @response = ActionController::TestResponse.new |
15 | - @db = Tempfile.new('stoa-test') | ||
16 | - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | ||
17 | - ActiveRecord::Base.establish_connection(:stoa) | ||
18 | - ActiveRecord::Schema.verbose = false | ||
19 | - ActiveRecord::Schema.create_table "pessoa" do |t| | ||
20 | - t.integer "codpes" | ||
21 | - t.text "numcpf" | ||
22 | - t.date "dtanas" | ||
23 | - end | ||
24 | - ActiveRecord::Base.establish_connection(:test) | ||
25 | - StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') | 26 | + StoaPlugin::UspUser.create!({:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) |
26 | Environment.default.enable_plugin(StoaPlugin.name) | 27 | Environment.default.enable_plugin(StoaPlugin.name) |
27 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') | 28 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') |
28 | @user.activate | 29 | @user.activate |
29 | end | 30 | end |
30 | 31 | ||
31 | - def teardown | ||
32 | - @db.unlink | ||
33 | - end | ||
34 | - | ||
35 | should 'fail if confirmation value doesn\'t match' do | 32 | should 'fail if confirmation value doesn\'t match' do |
36 | #StoaPlugin::UspUser.stubs(:matches?).returns(false) | 33 | #StoaPlugin::UspUser.stubs(:matches?).returns(false) |
37 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '00000000' | 34 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '00000000' |
@@ -41,10 +38,10 @@ class AccountControllerTest < ActionController::TestCase | @@ -41,10 +38,10 @@ class AccountControllerTest < ActionController::TestCase | ||
41 | should 'pass if confirmation value matches' do | 38 | should 'pass if confirmation value matches' do |
42 | #StoaPlugin::UspUser.stubs(:matches?).returns(true) | 39 | #StoaPlugin::UspUser.stubs(:matches?).returns(true) |
43 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '12345678' | 40 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '12345678' |
44 | - assert_nil assigns(:person).errors[:usp_id] | 41 | + assert !assigns(:person).errors.include?(:usp_id) |
45 | end | 42 | end |
46 | 43 | ||
47 | - should 'inlude invitation_code param in the persons attributes' do | 44 | + should 'include invitation_code param in the persons attributes' do |
48 | get :signup, :invitation_code => 12345678 | 45 | get :signup, :invitation_code => 12345678 |
49 | assert assigns(:person).invitation_code == '12345678' | 46 | assert assigns(:person).invitation_code == '12345678' |
50 | end | 47 | end |
plugins/stoa/test/functional/profile_editor_controller_test.rb
@@ -6,7 +6,7 @@ class ProfileEditorController; def rescue_action(e) raise e end; end | @@ -6,7 +6,7 @@ class ProfileEditorController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class StoaPluginProfileEditorControllerTest < ActionController::TestCase | 7 | class StoaPluginProfileEditorControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | 9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] |
10 | 10 | ||
11 | def setup | 11 | def setup |
12 | @controller = ProfileEditorController.new | 12 | @controller = ProfileEditorController.new |
@@ -45,7 +45,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase | @@ -45,7 +45,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase | ||
45 | should 'display error if usp_id does not match with supplied confirmation' do | 45 | should 'display error if usp_id does not match with supplied confirmation' do |
46 | StoaPlugin::UspUser.stubs(:matches?).returns(false) | 46 | StoaPlugin::UspUser.stubs(:matches?).returns(false) |
47 | post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999 | 47 | post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999 |
48 | - assert assigns(:profile_data).errors.invalid?(:usp_id) | 48 | + assert assigns(:profile_data).errors.include?(:usp_id) |
49 | end | 49 | end |
50 | 50 | ||
51 | should 'save usp_id if everyhtings is ok' do | 51 | should 'save usp_id if everyhtings is ok' do |
plugins/stoa/test/functional/stoa_plugin_controller_test.rb
@@ -6,7 +6,7 @@ class StoaPluginController; def rescue_action(e) raise e end; end | @@ -6,7 +6,7 @@ class StoaPluginController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class StoaPluginControllerTest < ActionController::TestCase | 7 | class StoaPluginControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | 9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] |
10 | 10 | ||
11 | def setup | 11 | def setup |
12 | @controller = StoaPluginController.new | 12 | @controller = StoaPluginController.new |
@@ -18,6 +18,7 @@ class StoaPluginControllerTest < ActionController::TestCase | @@ -18,6 +18,7 @@ class StoaPluginControllerTest < ActionController::TestCase | ||
18 | env.enable('skip_new_user_email_confirmation') | 18 | env.enable('skip_new_user_email_confirmation') |
19 | env.save! | 19 | env.save! |
20 | @user = create_user_full('real_user', {:password => '123456', :password_confirmation => '123456'}, {:usp_id => 9999999}) | 20 | @user = create_user_full('real_user', {:password => '123456', :password_confirmation => '123456'}, {:usp_id => 9999999}) |
21 | + @user.activate | ||
21 | end | 22 | end |
22 | 23 | ||
23 | attr_accessor :user | 24 | attr_accessor :user |
plugins/stoa/test/unit/person_test.rb
@@ -15,7 +15,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | @@ -15,7 +15,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | ||
15 | another_person = Person.new(:usp_id => usp_id) | 15 | another_person = Person.new(:usp_id => usp_id) |
16 | another_person.valid? | 16 | another_person.valid? |
17 | 17 | ||
18 | - assert another_person.errors.invalid?(:usp_id) | 18 | + assert another_person.errors.include?(:usp_id) |
19 | end | 19 | end |
20 | 20 | ||
21 | should 'not allow usp_id as an empty string' do | 21 | should 'not allow usp_id as an empty string' do |
@@ -28,17 +28,17 @@ class StoaPlugin::Person < ActiveSupport::TestCase | @@ -28,17 +28,17 @@ class StoaPlugin::Person < ActiveSupport::TestCase | ||
28 | should 'allow nil usp_id only if person has an invitation_code or is a template' do | 28 | should 'allow nil usp_id only if person has an invitation_code or is a template' do |
29 | person = Person.new(:environment => environment) | 29 | person = Person.new(:environment => environment) |
30 | person.valid? | 30 | person.valid? |
31 | - assert person.errors.invalid?(:usp_id) | 31 | + assert person.errors.include?(:usp_id) |
32 | 32 | ||
33 | Task.create!(:code => 12345678) | 33 | Task.create!(:code => 12345678) |
34 | person.invitation_code = 12345678 | 34 | person.invitation_code = 12345678 |
35 | person.valid? | 35 | person.valid? |
36 | - assert !person.errors.invalid?(:usp_id) | 36 | + assert !person.errors.include?(:usp_id) |
37 | 37 | ||
38 | person.invitation_code = nil | 38 | person.invitation_code = nil |
39 | person.is_template = true | 39 | person.is_template = true |
40 | person.valid? | 40 | person.valid? |
41 | - assert !person.errors.invalid?(:usp_id) | 41 | + assert !person.errors.include?(:usp_id) |
42 | end | 42 | end |
43 | 43 | ||
44 | should 'allow multiple nil usp_id' do | 44 | should 'allow multiple nil usp_id' do |
@@ -47,7 +47,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | @@ -47,7 +47,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | ||
47 | person = Person.new(:invitation_code => 87654321) | 47 | person = Person.new(:invitation_code => 87654321) |
48 | person.valid? | 48 | person.valid? |
49 | 49 | ||
50 | - assert !person.errors.invalid?(:usp_id) | 50 | + assert !person.errors.include?(:usp_id) |
51 | end | 51 | end |
52 | 52 | ||
53 | should 'not allow person to be saved with a finished invitation that is not his own' do | 53 | should 'not allow person to be saved with a finished invitation that is not his own' do |
@@ -56,7 +56,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | @@ -56,7 +56,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | ||
56 | person = Person.new(:environment => environment, :invitation_code => 87654321) | 56 | person = Person.new(:environment => environment, :invitation_code => 87654321) |
57 | person.valid? | 57 | person.valid? |
58 | 58 | ||
59 | - assert person.errors.invalid?(:usp_id) | 59 | + assert person.errors.include?(:usp_id) |
60 | end | 60 | end |
61 | 61 | ||
62 | should 'allow person to be saved with a finished invitation if it is his own' do | 62 | should 'allow person to be saved with a finished invitation if it is his own' do |
@@ -68,7 +68,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | @@ -68,7 +68,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase | ||
68 | t.finish | 68 | t.finish |
69 | 69 | ||
70 | person.valid? | 70 | person.valid? |
71 | - assert !person.errors.invalid?(:usp_id) | 71 | + assert !person.errors.include?(:usp_id) |
72 | end | 72 | end |
73 | 73 | ||
74 | 74 |
plugins/stoa/test/unit/usp_user_test.rb
@@ -2,24 +2,21 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | @@ -2,24 +2,21 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | 2 | ||
3 | class StoaPlugin::UspUserTest < ActiveSupport::TestCase | 3 | class StoaPlugin::UspUserTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | ||
6 | - | ||
7 | - def setup | ||
8 | - @db = Tempfile.new('stoa-test') | ||
9 | - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | ||
10 | - ActiveRecord::Base.establish_connection(:stoa) | ||
11 | - ActiveRecord::Schema.verbose = false | ||
12 | - ActiveRecord::Schema.create_table "pessoa" do |t| | ||
13 | - t.integer "codpes" | ||
14 | - t.text "numcpf" | ||
15 | - t.date "dtanas" | ||
16 | - end | ||
17 | - ActiveRecord::Base.establish_connection(:test) | ||
18 | - StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') | 5 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] |
6 | + | ||
7 | + @db = Tempfile.new('stoa-test') | ||
8 | + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | ||
9 | + ActiveRecord::Base.establish_connection(:stoa) | ||
10 | + ActiveRecord::Schema.verbose = false | ||
11 | + ActiveRecord::Schema.create_table "pessoa" do |t| | ||
12 | + t.integer "codpes" | ||
13 | + t.text "numcpf" | ||
14 | + t.date "dtanas" | ||
19 | end | 15 | end |
16 | + ActiveRecord::Base.establish_connection(:test) | ||
20 | 17 | ||
21 | - def teardown | ||
22 | - @db.unlink | 18 | + def setup |
19 | + StoaPlugin::UspUser.create({:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) | ||
23 | end | 20 | end |
24 | 21 | ||
25 | should 'check existence of usp_id' do | 22 | should 'check existence of usp_id' do |
@@ -48,4 +45,3 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | @@ -48,4 +45,3 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | ||
48 | assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678') | 45 | assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678') |
49 | end | 46 | end |
50 | end | 47 | end |
51 | - |
test/unit/application_helper_test.rb
@@ -606,6 +606,22 @@ class ApplicationHelperTest < ActionView::TestCase | @@ -606,6 +606,22 @@ class ApplicationHelperTest < ActionView::TestCase | ||
606 | assert_equal 'Open chat', render_environment_features(:usermenu) | 606 | assert_equal 'Open chat', render_environment_features(:usermenu) |
607 | end | 607 | end |
608 | 608 | ||
609 | + should 'not inlude administration link if user is not an environment administrator' do | ||
610 | + user = mock() | ||
611 | + stubs(:environment).returns(Environment.default) | ||
612 | + user.stubs(:is_admin?).with(environment).returns(false) | ||
613 | + stubs(:user).returns(user) | ||
614 | + assert admin_link.blank? | ||
615 | + end | ||
616 | + | ||
617 | + should 'inlude administration link if user is an environment administrator' do | ||
618 | + user = mock() | ||
619 | + stubs(:environment).returns(Environment.default) | ||
620 | + user.stubs(:is_admin?).with(environment).returns(true) | ||
621 | + stubs(:user).returns(user) | ||
622 | + assert admin_link.present? | ||
623 | + end | ||
624 | + | ||
609 | should 'not return mime type of profile icon if not requested' do | 625 | should 'not return mime type of profile icon if not requested' do |
610 | stubs(:profile).returns(Person.new) | 626 | stubs(:profile).returns(Person.new) |
611 | stubs(:current_theme).returns('default') | 627 | stubs(:current_theme).returns('default') |