Commit 8a5479a33c669aad92b33ee0ec9d399cafa8e77c
1 parent
3d5ee0f6
Exists in
master
and in
22 other branches
ActionItem153: reworking login block; adding it to environments by default
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1296 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
27 additions
and
23 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -32,14 +32,6 @@ class AccountController < PublicController | @@ -32,14 +32,6 @@ class AccountController < PublicController | ||
32 | render :action => 'login', :layout => false | 32 | render :action => 'login', :layout => false |
33 | end | 33 | end |
34 | 34 | ||
35 | - def login_block | ||
36 | - if logged_in? | ||
37 | - render :action => 'user_info', :layout => 'block' | ||
38 | - else | ||
39 | - render :action => 'login_block', :layout => 'block' | ||
40 | - end | ||
41 | - end | ||
42 | - | ||
43 | # action to register an user to the application | 35 | # action to register an user to the application |
44 | def signup | 36 | def signup |
45 | begin | 37 | begin |
app/helpers/boxes_helper.rb
@@ -51,6 +51,10 @@ module BoxesHelper | @@ -51,6 +51,10 @@ module BoxesHelper | ||
51 | else | 51 | else |
52 | content | 52 | content |
53 | end | 53 | end |
54 | + when Proc | ||
55 | + self.instance_eval(&content) | ||
56 | + else | ||
57 | + raise "Unsupported content for block (#{content.class})" | ||
54 | end | 58 | end |
55 | 59 | ||
56 | classes = ['block', block.css_class_name ].uniq.join(' ') | 60 | classes = ['block', block.css_class_name ].uniq.join(' ') |
app/models/environment.rb
@@ -36,6 +36,8 @@ class Environment < ActiveRecord::Base | @@ -36,6 +36,8 @@ class Environment < ActiveRecord::Base | ||
36 | env.boxes[1].blocks << EnvironmentStatisticsBlock.new | 36 | env.boxes[1].blocks << EnvironmentStatisticsBlock.new |
37 | env.boxes[1].blocks << RecentDocumentsBlock.new | 37 | env.boxes[1].blocks << RecentDocumentsBlock.new |
38 | 38 | ||
39 | + env.boxes[2].blocks << LoginBlock.new | ||
40 | + | ||
39 | end | 41 | end |
40 | 42 | ||
41 | # One Environment can be reached by many domains | 43 | # One Environment can be reached by many domains |
app/models/login_block.rb
@@ -5,7 +5,13 @@ class LoginBlock < Block | @@ -5,7 +5,13 @@ class LoginBlock < Block | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def content | 7 | def content |
8 | - { :controller => 'account', :action => 'login_block' } | 8 | + lambda do |
9 | + if logged_in? | ||
10 | + render :file => 'account/user_info' | ||
11 | + else | ||
12 | + render :file => 'account/login_block' | ||
13 | + end | ||
14 | + end | ||
9 | end | 15 | end |
10 | 16 | ||
11 | end | 17 | end |
app/views/account/login_block.rhtml
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <%= link_to _("New user"), :controller => 'account', :action => 'signup' %> | 15 | <%= link_to _("New user"), :controller => 'account', :action => 'signup' %> |
16 | </div> | 16 | </div> |
17 | <% else %> | 17 | <% else %> |
18 | - <h2><%= @profile.identifier %></h2> | 18 | + <h2><%= user.identifier %></h2> |
19 | <% end %> | 19 | <% end %> |
20 | 20 | ||
21 | </div><!-- end id="login-box" --> | 21 | </div><!-- end id="login-box" --> |
app/views/account/user_info.rhtml
@@ -4,3 +4,7 @@ | @@ -4,3 +4,7 @@ | ||
4 | <li><%= _('User since %d') % user.person_info.created_at.year %></li> | 4 | <li><%= _('User since %d') % user.person_info.created_at.year %></li> |
5 | <li><%= link_to_homepage _('Homepage') %></li> | 5 | <li><%= link_to_homepage _('Homepage') %></li> |
6 | </ul> | 6 | </ul> |
7 | + | ||
8 | +<ul> | ||
9 | + <li><%= lightbox_link_to _('Logout'), :controller => 'account', :action => 'logout_popup' %></li> | ||
10 | +</ul> |
test/functional/account_controller_test.rb
@@ -246,18 +246,6 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -246,18 +246,6 @@ class AccountControllerTest < Test::Unit::TestCase | ||
246 | assert_no_tag :tag => "body" # e.g. no layout | 246 | assert_no_tag :tag => "body" # e.g. no layout |
247 | end | 247 | end |
248 | 248 | ||
249 | - should 'provide login block' do | ||
250 | - get :login_block | ||
251 | - assert_template 'login_block' | ||
252 | - assert_tag :tag => 'body', :attributes => { :class => 'noosfero-block' } | ||
253 | - end | ||
254 | - | ||
255 | - should 'display user info in login block when logged in' do | ||
256 | - login_as('ze') | ||
257 | - get :login_block | ||
258 | - assert_template 'user_info' | ||
259 | - end | ||
260 | - | ||
261 | protected | 249 | protected |
262 | def create_user(options = {}) | 250 | def create_user(options = {}) |
263 | post :signup, :user => { :login => 'quire', :email => 'quire@example.com', | 251 | post :signup, :user => { :login => 'quire', :email => 'quire@example.com', |
test/unit/login_block_test.rb
@@ -12,7 +12,15 @@ class LoginBlockTest < Test::Unit::TestCase | @@ -12,7 +12,15 @@ class LoginBlockTest < Test::Unit::TestCase | ||
12 | end | 12 | end |
13 | 13 | ||
14 | should 'point to account/login_block' do | 14 | should 'point to account/login_block' do |
15 | - assert_equal({ :controller => 'account', :action => 'login_block' }, block.content) | 15 | + self.expects(:logged_in?).returns(false) |
16 | + self.expects(:render).with(:file => 'account/login_block') | ||
17 | + self.instance_eval(& block.content) | ||
18 | + end | ||
19 | + | ||
20 | + should 'display user_info if not logged' do | ||
21 | + self.expects(:logged_in?).returns(true) | ||
22 | + self.expects(:render).with(:file => 'account/user_info') | ||
23 | + self.instance_eval(& block.content) | ||
16 | end | 24 | end |
17 | 25 | ||
18 | end | 26 | end |