Commit 3d41877610021fc5894b6e566137ce2bf6a3f2c0

Authored by Weblate
2 parents 27bd922a aca12460

Merge remote-tracking branch 'origin/master'

app/models/user.rb
... ... @@ -114,6 +114,10 @@ class User < ActiveRecord::Base
114 114 u && u.authenticated?(password) ? u : nil
115 115 end
116 116  
  117 + def register_login
  118 + self.update_attribute :last_login_at, Time.now
  119 + end
  120 +
117 121 # Activates the user in the database.
118 122 def activate
119 123 return false unless self.person
... ...
db/migrate/20140519113821_add_last_login_at_to_user.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddLastLoginAtToUser < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :users, :last_login_at, :datetime
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :users, :last_login_at
  8 + end
  9 +end
... ...
lib/authenticated_system.rb
... ... @@ -5,22 +5,23 @@ module AuthenticatedSystem
5 5 def logged_in?
6 6 current_user != nil
7 7 end
8   -
  8 +
9 9 # Accesses the current user from the session.
10 10 def current_user
11 11 @current_user ||= (session[:user] && User.find_by_id(session[:user])) || nil
12 12 end
13   -
  13 +
14 14 # Store the given user in the session.
15 15 def current_user=(new_user)
16 16 if new_user.nil?
17 17 session.delete(:user)
18 18 else
19 19 session[:user] = new_user.id
  20 + new_user.register_login
20 21 end
21 22 @current_user = new_user
22 23 end
23   -
  24 +
24 25 # Check if the user is authorized.
25 26 #
26 27 # Override this method in your controllers if you want to restrict access
... ... @@ -62,7 +63,7 @@ module AuthenticatedSystem
62 63 access_denied
63 64 end
64 65 end
65   -
  66 +
66 67 # Redirect as appropriate when an access request fails.
67 68 #
68 69 # The default action is to redirect to the login screen.
... ... @@ -88,15 +89,15 @@ module AuthenticatedSystem
88 89 end
89 90 end
90 91 false
91   - end
92   -
  92 + end
  93 +
93 94 # Store the URI of the current request in the session.
94 95 #
95 96 # We can return to this location by calling #redirect_back_or_default.
96 97 def store_location(location = request.url)
97 98 session[:return_to] = location
98 99 end
99   -
  100 +
100 101 # Redirect to the URI stored by the most recent store_location call or
101 102 # to the passed default.
102 103 def redirect_back_or_default(default)
... ... @@ -106,7 +107,7 @@ module AuthenticatedSystem
106 107 redirect_to(default)
107 108 end
108 109 end
109   -
  110 +
110 111 # Inclusion hook to make #current_user and #logged_in?
111 112 # available as ActionView helper methods.
112 113 def self.included(base)
... ... @@ -132,6 +133,6 @@ module AuthenticatedSystem
132 133 def get_auth_data
133 134 auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
134 135 auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
135   - return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
  136 + return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
136 137 end
137 138 end
... ...
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
... ... @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock &lt; Block
4 4 end
5 5  
6 6 def default_title
7   - _('Relevant content')
  7 + _('Relevant content')
8 8 end
9 9  
10 10 def help
... ... @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock &lt; Block
53 53 env = owner.environment
54 54 end
55 55  
56   - if env.plugin_enabled?(VotePlugin)
  56 + if env.plugin_enabled?('VotePlugin')
57 57 if self.show_most_liked
58 58 docs = Article.more_positive_votes(owner, self.limit)
59 59 if !docs.blank?
... ...
plugins/relevant_content/test/unit/article.rb
... ... @@ -20,10 +20,10 @@ class RelevantContentBlockTest &lt; ActiveSupport::TestCase
20 20  
21 21 def enable_vote_plugin
22 22 enabled = false
23   - environment=Environment.default
  23 + environment = Environment.default
24 24 if Noosfero::Plugin.all.include?('VotePlugin')
25   - if not environment.enabled_plugins.include?(:vote)
26   - environment.enable_plugin(Vote)
  25 + if not environment.enabled_plugins.include?('VotePlugin')
  26 + environment.enable_plugin(VotePlugin)
27 27 environment.save!
28 28 end
29 29 enabled = true
... ... @@ -145,4 +145,4 @@ class RelevantContentBlockTest &lt; ActiveSupport::TestCase
145 145 assert_equal '23 votes for 29 votes against', articles.first.name
146 146 assert_equal '2 votes against', articles.last.name
147 147 end
148   -end
149 148 \ No newline at end of file
  149 +end
... ...
plugins/relevant_content/test/unit/relevant_content_block_test.rb
... ... @@ -44,4 +44,19 @@ class RelevantContentBlockTest &lt; ActiveSupport::TestCase
44 44 assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]}
45 45 end
46 46  
  47 + should 'not crash if vote plugin is not found' do
  48 + box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile')
  49 + block = RelevantContentPlugin::RelevantContentBlock.new(:box => box)
  50 +
  51 + Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent'])
  52 + # When the plugin is disabled from noosfero instance, its constant name is
  53 + # undefined. To test this case, I have to manually undefine the constant
  54 + # if necessary.
  55 + Object.send(:remove_const, VotePlugin.to_s) if defined? VotePlugin
  56 +
  57 + assert_nothing_raised do
  58 + block.content
  59 + end
  60 + end
  61 +
47 62 end
... ...
plugins/tolerance_time/lib/tolerance_time_plugin.rb
... ... @@ -28,8 +28,7 @@ class ToleranceTimePlugin &lt; Noosfero::Plugin
28 28 end
29 29  
30 30 def cms_controller_filters
31   - p = Proc.new { |context| return if !context.environment.plugin_enabled?(ToleranceTimePlugin) }
32   - block = lambda do
  31 + block = proc do
33 32 content = Article.find(params[:id])
34 33 if ToleranceTimePlugin.expired?(content)
35 34 session[:notice] = _("This content can't be edited anymore because it expired the tolerance time")
... ... @@ -43,8 +42,7 @@ class ToleranceTimePlugin &lt; Noosfero::Plugin
43 42 end
44 43  
45 44 def content_viewer_controller_filters
46   - p = Proc.new { |context| return if !context.environment.plugin_enabled?(ToleranceTimePlugin) }
47   - block = lambda do
  45 + block = proc do
48 46 content = Comment.find(params[:id])
49 47 if ToleranceTimePlugin.expired?(content)
50 48 session[:notice] = _("This content can't be edited anymore because it expired the tolerance time")
... ...