Commit fb090c196185743a6f8b1dc9fdd0a6c02c07060b
Exists in
master
and in
27 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 | Developers |
| 7 | 7 | ========== |
| 8 | 8 | |
| 9 | +Ábner Silva de Oliveira <abner.oliveira@serpro.gov.br> | |
| 9 | 10 | Alan Freihof Tygel <alantygel@gmail.com> |
| 10 | 11 | alcampelo <alcampelo@alcampelo.(none)> |
| 11 | 12 | Alessandro Palmeira <alessandro.palmeira@gmail.com> |
| ... | ... | @@ -43,6 +44,7 @@ Ana Losnak <analosnak@gmail.com> |
| 43 | 44 | Antonio Terceiro + Carlos Morais <terceiro@colivre.coop.br> |
| 44 | 45 | Antonio Terceiro + Paulo Meirelles <terceiro@colivre.coop.br> |
| 45 | 46 | Antonio Terceiro <terceiro@colivre.coop.br> |
| 47 | +Arthur Del Esposte <arthurmde@gmail.com> | |
| 46 | 48 | Arthur Del Esposte <arthurmde@yahoo.com.br> |
| 47 | 49 | Aurelio A. Heckert <aurelio@colivre.coop.br> |
| 48 | 50 | Braulio Bhavamitra <brauliobo@gmail.com> |
| ... | ... | @@ -71,12 +73,14 @@ Caio Salgado + Renan Teruo <caio.salgado@gmail.com> |
| 71 | 73 | Caio Salgado + Renan Teruo + Jefferson Fernandes <jeffs.fernandes@gmail.com> |
| 72 | 74 | Caio Salgado + Renan Teruo <renanteruoc@gmail.com> |
| 73 | 75 | Caio SBA <caio@colivre.coop.br> |
| 76 | +Caio Tiago Oliveira <caiotiago@colivre.coop.br> | |
| 74 | 77 | Carlos Andre de Souza <carlos.andre.souza@msn.com> |
| 75 | 78 | Carlos Morais <carlos88morais@gmail.com> |
| 76 | 79 | Carlos Morais + Diego Araújo <diegoamc90@gmail.com> |
| 77 | 80 | Carlos Morais + Eduardo Morais <carlos88morais@gmail.com> |
| 78 | 81 | Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com> |
| 79 | 82 | Carlos Morais + Pedro Leal <carlos88morais@gmail.com> |
| 83 | +Daniela Feitosa <dani@dohko.(none)> | |
| 80 | 84 | Daniel Alves + Diego Araújo <danpaulalves@gmail.com> |
| 81 | 85 | Daniel Alves + Diego Araújo <diegoamc90@gmail.com> |
| 82 | 86 | Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com> |
| ... | ... | @@ -117,6 +121,8 @@ Diego Martinez <diegoamc90@gmail.com> |
| 117 | 121 | Diego Martinez <diego@diego-K55A.(none)> |
| 118 | 122 | Diego + Renan <renanteruoc@gmail.com> |
| 119 | 123 | Eduardo Tourinho Edington <eduardo.edington@serpro.gov.br> |
| 124 | +Evandro Jr <evandrojr@gmail.com> | |
| 125 | +Evandro Junior <evandrojr@gmail.com> | |
| 120 | 126 | Fabio Teixeira <fabio1079@gmail.com> |
| 121 | 127 | Fernanda Lopes <nanda.listas+psl@gmail.com> |
| 122 | 128 | Francisco Marcelo A. Lima Júnior <francisco.lima-junior@serpro.gov.br> |
| ... | ... | @@ -132,6 +138,7 @@ Italo Valcy <italo@dcc.ufba.br> |
| 132 | 138 | Jefferson Fernandes + Diego Araujo + Rafael Manzo <jeffs.fernandes@gmail.com> |
| 133 | 139 | Jefferson Fernandes + Joao M. M. da Silva <jeffs.fernandes@gmail.com> |
| 134 | 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 | 142 | João da Silva <jaodsilv@linux.ime.usp.br> |
| 136 | 143 | João Marco Maciel da Silva + Rafael Manzo + Renan Teruo <jaodsilv@linux.ime.usp.br> |
| 137 | 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 | 173 | Junior Silva <juniorsilva1001@gmail.com> |
| 167 | 174 | Junior Silva <juniorsilva7@juniorsilva-Aspire-5750Z.(none)> |
| 168 | 175 | Junior Silva <juniorsilva@colivre.coop.br> |
| 176 | +juniorsilva <juniorsilva@QonoS.localhost.localdomain> | |
| 169 | 177 | Keilla Menezes <keilla@colivre.coop.br> |
| 170 | 178 | Larissa Reis <larissa@colivre.coop.br> |
| 171 | 179 | Larissa Reis <reiss.larissa@gmail.com> |
| ... | ... | @@ -176,7 +184,9 @@ Leandro Nunes dos Santos <leandro.santos@serpro.gov.br> |
| 176 | 184 | LinguÁgil 2010 <linguagil.bahia@gmail.com> |
| 177 | 185 | Lucas Melo <lucas@colivre.coop.br> |
| 178 | 186 | Lucas Melo <lucaspradomelo@gmail.com> |
| 187 | +Luciano <lucianopcbr@gmail.com> | |
| 179 | 188 | Luis David Aguilar Carlos <ludwig9003@gmail.com> |
| 189 | +Luiz Fernando de Freitas Matos <luiz@luizff.matos@gmail.com> | |
| 180 | 190 | Marcos Ramos <ms.ramos@outlook.com> |
| 181 | 191 | Martín Olivera <molivera@solar.org.ar> |
| 182 | 192 | Moises Machado <moises@colivre.coop.br> | ... | ... |
app/controllers/public/content_viewer_controller.rb
| ... | ... | @@ -8,49 +8,31 @@ class ContentViewerController < ApplicationController |
| 8 | 8 | helper TagsHelper |
| 9 | 9 | |
| 10 | 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 | 13 | @version = params[:version].to_i |
| 15 | 14 | |
| 16 | 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 | 18 | else |
| 23 | 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 | 21 | end |
| 32 | 22 | |
| 33 | 23 | return unless allow_access_to_page(path) |
| 34 | 24 | |
| 35 | 25 | if @version > 0 |
| 36 | 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 | 28 | end |
| 43 | 29 | |
| 44 | 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 | 36 | end |
| 55 | 37 | |
| 56 | 38 | # At this point the page will be showed |
| ... | ... | @@ -58,64 +40,22 @@ class ContentViewerController < ApplicationController |
| 58 | 40 | |
| 59 | 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 | 45 | @form_div = params[:form] |
| 76 | 46 | |
| 77 | 47 | #FIXME see a better way to do this. It's not need to pass this variable anymore |
| 78 | 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 | 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 | 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 | 60 | if request.xhr? and params[:comment_order] |
| 121 | 61 | if @comment_order == 'newest' |
| ... | ... | @@ -203,4 +143,127 @@ class ContentViewerController < ApplicationController |
| 203 | 143 | user_agent.match(/crawler/) || |
| 204 | 144 | user_agent.match(/\(.*https?:\/\/.*\)/) |
| 205 | 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 | 269 | end | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -1002,17 +1002,26 @@ module ApplicationHelper |
| 1002 | 1002 | def display_category_menu(block, categories, root = true) |
| 1003 | 1003 | categories = categories.sort{|x,y| x.name <=> y.name} |
| 1004 | 1004 | return "" if categories.blank? |
| 1005 | - content_tag(:ul, | |
| 1005 | + content_tag(:ul) do | |
| 1006 | 1006 | categories.map do |category| |
| 1007 | 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 | 1025 | content_tag(:p) + |
| 1017 | 1026 | (root ? javascript_tag(" |
| 1018 | 1027 | jQuery('.child-category').hide(); |
| ... | ... | @@ -1104,14 +1113,18 @@ module ApplicationHelper |
| 1104 | 1113 | end |
| 1105 | 1114 | |
| 1106 | 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 | 1118 | end |
| 1110 | 1119 | |
| 1111 | 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 | 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 | 1128 | end |
| 1116 | 1129 | |
| 1117 | 1130 | def usermenu_logged_in |
| ... | ... | @@ -1123,9 +1136,9 @@ module ApplicationHelper |
| 1123 | 1136 | |
| 1124 | 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 | 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 | 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 | 1143 | pending_tasks_count + |
| 1131 | 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 | 15 | end |
| 16 | 16 | |
| 17 | 17 | def activation_code(user) |
| 18 | - @recipient = user.name, | |
| 18 | + @recipient = user.name | |
| 19 | 19 | @activation_code = user.activation_code |
| 20 | 20 | @environment = user.environment.name |
| 21 | 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 | 25 | mail( |
| 24 | 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 | 66 | # virtual attribute used to stash which community to join on signup or login |
| 67 | 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 | 69 | def signup! |
| 109 | 70 | User.transaction do |
| 110 | 71 | self.save! | ... | ... |
app/views/user/mailer/activation_email_notify.html.erb
| ... | ... | @@ -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 @@ |
| 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 @@ |
| 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 | 11 | # |
| 12 | 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 | 16 | create_table "abuse_reports", :force => true do |t| |
| 17 | 17 | t.integer "reporter_id" | ... | ... |
debian/changelog
features/clickable_images.feature
| ... | ... | @@ -14,6 +14,7 @@ Feature: clickable images |
| 14 | 14 | | owner | name | image | dimensions | |
| 15 | 15 | | booking | small | rails.png | 20x20 | |
| 16 | 16 | When I go to /booking/small |
| 17 | + And display ".zoomify-image" | |
| 17 | 18 | Then I should see "Zoom in" |
| 18 | 19 | |
| 19 | 20 | @selenium |
| ... | ... | @@ -22,6 +23,7 @@ Feature: clickable images |
| 22 | 23 | | owner | name | image | dimensions | |
| 23 | 24 | | booking | real | rails.png | 50x64 | |
| 24 | 25 | When I go to /booking/real |
| 26 | + And display ".zoomify-image" | |
| 25 | 27 | Then "Zoom in" should not be visible within "a#zoomify-image" |
| 26 | 28 | |
| 27 | 29 | @selenium |
| ... | ... | @@ -30,6 +32,7 @@ Feature: clickable images |
| 30 | 32 | | owner | name | image | |
| 31 | 33 | | booking | not set | rails.png | |
| 32 | 34 | When I go to /booking/not-set |
| 35 | + And display ".zoomify-image" | |
| 33 | 36 | Then "Zoom in" should not be visible within "a#zoomify-image" |
| 34 | 37 | |
| 35 | 38 | @selenium-fixme | ... | ... |
lib/noosfero.rb
lib/noosfero/plugin.rb
| ... | ... | @@ -395,7 +395,7 @@ class Noosfero::Plugin |
| 395 | 395 | end |
| 396 | 396 | |
| 397 | 397 | # -> Adds fields to the signup form |
| 398 | - # returns = lambda block that creates html code | |
| 398 | + # returns = proc that creates html code | |
| 399 | 399 | def signup_extra_contents |
| 400 | 400 | nil |
| 401 | 401 | end |
| ... | ... | @@ -470,7 +470,7 @@ class Noosfero::Plugin |
| 470 | 470 | end |
| 471 | 471 | |
| 472 | 472 | # -> Adds fields to the login form |
| 473 | - # returns = lambda block that creates html code | |
| 473 | + # returns = proc that creates html code | |
| 474 | 474 | def login_extra_contents |
| 475 | 475 | nil |
| 476 | 476 | end | ... | ... |
plugins/stoa/install.rb
| 1 | 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 | 5 | FileUtils.cp(config_template, config_path) if !File.exist?(config_path) | ... | ... |
plugins/stoa/lib/ext/person.rb
| 1 | 1 | require_dependency 'person' |
| 2 | 2 | |
| 3 | 3 | class Person |
| 4 | + attr_accessible :usp_id, :invitation_code | |
| 5 | + | |
| 4 | 6 | validates_uniqueness_of :usp_id, :allow_nil => true |
| 5 | 7 | settings_items :invitation_code |
| 6 | 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 | 2 | |
| 3 | 3 | class StoaPlugin < Noosfero::Plugin |
| 4 | 4 | |
| 5 | - Person.human_names[:usp_id] = _('USP number') | |
| 6 | - | |
| 7 | 5 | def self.plugin_name |
| 8 | 6 | "Stoa" |
| 9 | 7 | end |
| ... | ... | @@ -17,7 +15,7 @@ class StoaPlugin < Noosfero::Plugin |
| 17 | 15 | end |
| 18 | 16 | |
| 19 | 17 | def signup_extra_contents |
| 20 | - lambda { | |
| 18 | + proc { | |
| 21 | 19 | content_tag(:div, labelled_form_field(_('USP number'), text_field(:profile_data, :usp_id, :id => 'usp_id_field')) + |
| 22 | 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 | 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 | 43 | end |
| 46 | 44 | |
| 47 | 45 | def login_extra_contents |
| 48 | - lambda { | |
| 46 | + proc { | |
| 49 | 47 | content_tag('div', labelled_form_field(_('USP number / Username'), text_field_tag('usp_id_login', '', :id => 'stoa_field_login')) + |
| 50 | 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 | 60 | end |
| 63 | 61 | |
| 64 | 62 | def account_controller_filters |
| 65 | - environment = context.environment | |
| 66 | - block = lambda do | |
| 63 | + block = lambda do |context| | |
| 67 | 64 | params[:profile_data] ||= {} |
| 68 | 65 | params[:profile_data][:invitation_code] = params[:invitation_code] |
| 69 | 66 | invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]}) |
| 70 | 67 | if request.post? |
| 71 | 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 | 70 | @person.errors.add(:usp_id, _(' validation failed')) |
| 74 | 71 | render :action => :signup |
| 75 | 72 | end |
| ... | ... | @@ -83,7 +80,7 @@ class StoaPlugin < Noosfero::Plugin |
| 83 | 80 | end |
| 84 | 81 | |
| 85 | 82 | def profile_editor_controller_filters |
| 86 | - block = lambda do | |
| 83 | + block = proc do | |
| 87 | 84 | if request.post? |
| 88 | 85 | if !params[:profile_data][:usp_id].blank? && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) |
| 89 | 86 | @profile_data = profile |
| ... | ... | @@ -106,7 +103,7 @@ class StoaPlugin < Noosfero::Plugin |
| 106 | 103 | def invite_controller_filters |
| 107 | 104 | [{ :type => 'before_filter', |
| 108 | 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 | 107 | end |
| 111 | 108 | |
| 112 | 109 | def control_panel_buttons | ... | ... |
plugins/stoa/lib/stoa_plugin/person_api.rb
| ... | ... | @@ -28,7 +28,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 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 | 32 | memo[tag.name] = tag.count |
| 33 | 33 | memo |
| 34 | 34 | end | ... | ... |
plugins/stoa/lib/stoa_plugin/usp_user.rb
| ... | ... | @@ -3,7 +3,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base |
| 3 | 3 | establish_connection(:stoa) |
| 4 | 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 | 8 | alias_attribute :cpf, :numcpf |
| 9 | 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 | 6 | |
| 7 | 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 | 22 | def setup |
| 12 | 23 | @controller = AccountController.new |
| 13 | 24 | @request = ActionController::TestRequest.new |
| 14 | 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 | 27 | Environment.default.enable_plugin(StoaPlugin.name) |
| 27 | 28 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') |
| 28 | 29 | @user.activate |
| 29 | 30 | end |
| 30 | 31 | |
| 31 | - def teardown | |
| 32 | - @db.unlink | |
| 33 | - end | |
| 34 | - | |
| 35 | 32 | should 'fail if confirmation value doesn\'t match' do |
| 36 | 33 | #StoaPlugin::UspUser.stubs(:matches?).returns(false) |
| 37 | 34 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '00000000' |
| ... | ... | @@ -41,10 +38,10 @@ class AccountControllerTest < ActionController::TestCase |
| 41 | 38 | should 'pass if confirmation value matches' do |
| 42 | 39 | #StoaPlugin::UspUser.stubs(:matches?).returns(true) |
| 43 | 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 | 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 | 45 | get :signup, :invitation_code => 12345678 |
| 49 | 46 | assert assigns(:person).invitation_code == '12345678' |
| 50 | 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 | 6 | |
| 7 | 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 | 11 | def setup |
| 12 | 12 | @controller = ProfileEditorController.new |
| ... | ... | @@ -45,7 +45,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase |
| 45 | 45 | should 'display error if usp_id does not match with supplied confirmation' do |
| 46 | 46 | StoaPlugin::UspUser.stubs(:matches?).returns(false) |
| 47 | 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 | 49 | end |
| 50 | 50 | |
| 51 | 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 | 6 | |
| 7 | 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 | 11 | def setup |
| 12 | 12 | @controller = StoaPluginController.new |
| ... | ... | @@ -18,6 +18,7 @@ class StoaPluginControllerTest < ActionController::TestCase |
| 18 | 18 | env.enable('skip_new_user_email_confirmation') |
| 19 | 19 | env.save! |
| 20 | 20 | @user = create_user_full('real_user', {:password => '123456', :password_confirmation => '123456'}, {:usp_id => 9999999}) |
| 21 | + @user.activate | |
| 21 | 22 | end |
| 22 | 23 | |
| 23 | 24 | attr_accessor :user | ... | ... |
plugins/stoa/test/unit/person_test.rb
| ... | ... | @@ -15,7 +15,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
| 15 | 15 | another_person = Person.new(:usp_id => usp_id) |
| 16 | 16 | another_person.valid? |
| 17 | 17 | |
| 18 | - assert another_person.errors.invalid?(:usp_id) | |
| 18 | + assert another_person.errors.include?(:usp_id) | |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | should 'not allow usp_id as an empty string' do |
| ... | ... | @@ -28,17 +28,17 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
| 28 | 28 | should 'allow nil usp_id only if person has an invitation_code or is a template' do |
| 29 | 29 | person = Person.new(:environment => environment) |
| 30 | 30 | person.valid? |
| 31 | - assert person.errors.invalid?(:usp_id) | |
| 31 | + assert person.errors.include?(:usp_id) | |
| 32 | 32 | |
| 33 | 33 | Task.create!(:code => 12345678) |
| 34 | 34 | person.invitation_code = 12345678 |
| 35 | 35 | person.valid? |
| 36 | - assert !person.errors.invalid?(:usp_id) | |
| 36 | + assert !person.errors.include?(:usp_id) | |
| 37 | 37 | |
| 38 | 38 | person.invitation_code = nil |
| 39 | 39 | person.is_template = true |
| 40 | 40 | person.valid? |
| 41 | - assert !person.errors.invalid?(:usp_id) | |
| 41 | + assert !person.errors.include?(:usp_id) | |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | 44 | should 'allow multiple nil usp_id' do |
| ... | ... | @@ -47,7 +47,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
| 47 | 47 | person = Person.new(:invitation_code => 87654321) |
| 48 | 48 | person.valid? |
| 49 | 49 | |
| 50 | - assert !person.errors.invalid?(:usp_id) | |
| 50 | + assert !person.errors.include?(:usp_id) | |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | 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 | 56 | person = Person.new(:environment => environment, :invitation_code => 87654321) |
| 57 | 57 | person.valid? |
| 58 | 58 | |
| 59 | - assert person.errors.invalid?(:usp_id) | |
| 59 | + assert person.errors.include?(:usp_id) | |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | 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 | 68 | t.finish |
| 69 | 69 | |
| 70 | 70 | person.valid? |
| 71 | - assert !person.errors.invalid?(:usp_id) | |
| 71 | + assert !person.errors.include?(:usp_id) | |
| 72 | 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 | 2 | |
| 3 | 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 | 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 | 20 | end |
| 24 | 21 | |
| 25 | 22 | should 'check existence of usp_id' do |
| ... | ... | @@ -48,4 +45,3 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase |
| 48 | 45 | assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678') |
| 49 | 46 | end |
| 50 | 47 | end |
| 51 | - | ... | ... |
test/unit/application_helper_test.rb
| ... | ... | @@ -606,6 +606,22 @@ class ApplicationHelperTest < ActionView::TestCase |
| 606 | 606 | assert_equal 'Open chat', render_environment_features(:usermenu) |
| 607 | 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 | 625 | should 'not return mime type of profile icon if not requested' do |
| 610 | 626 | stubs(:profile).returns(Person.new) |
| 611 | 627 | stubs(:current_theme).returns('default') | ... | ... |