Commit 3d41877610021fc5894b6e566137ce2bf6a3f2c0
Exists in
master
and in
27 other branches
Merge remote-tracking branch 'origin/master'
Showing
7 changed files
with
46 additions
and
19 deletions
Show diff stats
app/models/user.rb
@@ -114,6 +114,10 @@ class User < ActiveRecord::Base | @@ -114,6 +114,10 @@ class User < ActiveRecord::Base | ||
114 | u && u.authenticated?(password) ? u : nil | 114 | u && u.authenticated?(password) ? u : nil |
115 | end | 115 | end |
116 | 116 | ||
117 | + def register_login | ||
118 | + self.update_attribute :last_login_at, Time.now | ||
119 | + end | ||
120 | + | ||
117 | # Activates the user in the database. | 121 | # Activates the user in the database. |
118 | def activate | 122 | def activate |
119 | return false unless self.person | 123 | return false unless self.person |
lib/authenticated_system.rb
@@ -5,22 +5,23 @@ module AuthenticatedSystem | @@ -5,22 +5,23 @@ module AuthenticatedSystem | ||
5 | def logged_in? | 5 | def logged_in? |
6 | current_user != nil | 6 | current_user != nil |
7 | end | 7 | end |
8 | - | 8 | + |
9 | # Accesses the current user from the session. | 9 | # Accesses the current user from the session. |
10 | def current_user | 10 | def current_user |
11 | @current_user ||= (session[:user] && User.find_by_id(session[:user])) || nil | 11 | @current_user ||= (session[:user] && User.find_by_id(session[:user])) || nil |
12 | end | 12 | end |
13 | - | 13 | + |
14 | # Store the given user in the session. | 14 | # Store the given user in the session. |
15 | def current_user=(new_user) | 15 | def current_user=(new_user) |
16 | if new_user.nil? | 16 | if new_user.nil? |
17 | session.delete(:user) | 17 | session.delete(:user) |
18 | else | 18 | else |
19 | session[:user] = new_user.id | 19 | session[:user] = new_user.id |
20 | + new_user.register_login | ||
20 | end | 21 | end |
21 | @current_user = new_user | 22 | @current_user = new_user |
22 | end | 23 | end |
23 | - | 24 | + |
24 | # Check if the user is authorized. | 25 | # Check if the user is authorized. |
25 | # | 26 | # |
26 | # Override this method in your controllers if you want to restrict access | 27 | # Override this method in your controllers if you want to restrict access |
@@ -62,7 +63,7 @@ module AuthenticatedSystem | @@ -62,7 +63,7 @@ module AuthenticatedSystem | ||
62 | access_denied | 63 | access_denied |
63 | end | 64 | end |
64 | end | 65 | end |
65 | - | 66 | + |
66 | # Redirect as appropriate when an access request fails. | 67 | # Redirect as appropriate when an access request fails. |
67 | # | 68 | # |
68 | # The default action is to redirect to the login screen. | 69 | # The default action is to redirect to the login screen. |
@@ -88,15 +89,15 @@ module AuthenticatedSystem | @@ -88,15 +89,15 @@ module AuthenticatedSystem | ||
88 | end | 89 | end |
89 | end | 90 | end |
90 | false | 91 | false |
91 | - end | ||
92 | - | 92 | + end |
93 | + | ||
93 | # Store the URI of the current request in the session. | 94 | # Store the URI of the current request in the session. |
94 | # | 95 | # |
95 | # We can return to this location by calling #redirect_back_or_default. | 96 | # We can return to this location by calling #redirect_back_or_default. |
96 | def store_location(location = request.url) | 97 | def store_location(location = request.url) |
97 | session[:return_to] = location | 98 | session[:return_to] = location |
98 | end | 99 | end |
99 | - | 100 | + |
100 | # Redirect to the URI stored by the most recent store_location call or | 101 | # Redirect to the URI stored by the most recent store_location call or |
101 | # to the passed default. | 102 | # to the passed default. |
102 | def redirect_back_or_default(default) | 103 | def redirect_back_or_default(default) |
@@ -106,7 +107,7 @@ module AuthenticatedSystem | @@ -106,7 +107,7 @@ module AuthenticatedSystem | ||
106 | redirect_to(default) | 107 | redirect_to(default) |
107 | end | 108 | end |
108 | end | 109 | end |
109 | - | 110 | + |
110 | # Inclusion hook to make #current_user and #logged_in? | 111 | # Inclusion hook to make #current_user and #logged_in? |
111 | # available as ActionView helper methods. | 112 | # available as ActionView helper methods. |
112 | def self.included(base) | 113 | def self.included(base) |
@@ -132,6 +133,6 @@ module AuthenticatedSystem | @@ -132,6 +133,6 @@ module AuthenticatedSystem | ||
132 | def get_auth_data | 133 | def get_auth_data |
133 | auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) } | 134 | auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) } |
134 | auth_data = request.env[auth_key].to_s.split unless auth_key.blank? | 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 | end | 137 | end |
137 | end | 138 | end |
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
@@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | ||
4 | end | 4 | end |
5 | 5 | ||
6 | def default_title | 6 | def default_title |
7 | - _('Relevant content') | 7 | + _('Relevant content') |
8 | end | 8 | end |
9 | 9 | ||
10 | def help | 10 | def help |
@@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | ||
53 | env = owner.environment | 53 | env = owner.environment |
54 | end | 54 | end |
55 | 55 | ||
56 | - if env.plugin_enabled?(VotePlugin) | 56 | + if env.plugin_enabled?('VotePlugin') |
57 | if self.show_most_liked | 57 | if self.show_most_liked |
58 | docs = Article.more_positive_votes(owner, self.limit) | 58 | docs = Article.more_positive_votes(owner, self.limit) |
59 | if !docs.blank? | 59 | if !docs.blank? |
plugins/relevant_content/test/unit/article.rb
@@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
20 | 20 | ||
21 | def enable_vote_plugin | 21 | def enable_vote_plugin |
22 | enabled = false | 22 | enabled = false |
23 | - environment=Environment.default | 23 | + environment = Environment.default |
24 | if Noosfero::Plugin.all.include?('VotePlugin') | 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 | environment.save! | 27 | environment.save! |
28 | end | 28 | end |
29 | enabled = true | 29 | enabled = true |
@@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
145 | assert_equal '23 votes for 29 votes against', articles.first.name | 145 | assert_equal '23 votes for 29 votes against', articles.first.name |
146 | assert_equal '2 votes against', articles.last.name | 146 | assert_equal '2 votes against', articles.last.name |
147 | end | 147 | end |
148 | -end | ||
149 | \ No newline at end of file | 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 < ActiveSupport::TestCase | @@ -44,4 +44,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
44 | assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} | 44 | assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} |
45 | end | 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 | end | 62 | end |
plugins/tolerance_time/lib/tolerance_time_plugin.rb
@@ -28,8 +28,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | @@ -28,8 +28,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | ||
28 | end | 28 | end |
29 | 29 | ||
30 | def cms_controller_filters | 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 | content = Article.find(params[:id]) | 32 | content = Article.find(params[:id]) |
34 | if ToleranceTimePlugin.expired?(content) | 33 | if ToleranceTimePlugin.expired?(content) |
35 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | 34 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") |
@@ -43,8 +42,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | @@ -43,8 +42,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | ||
43 | end | 42 | end |
44 | 43 | ||
45 | def content_viewer_controller_filters | 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 | content = Comment.find(params[:id]) | 46 | content = Comment.find(params[:id]) |
49 | if ToleranceTimePlugin.expired?(content) | 47 | if ToleranceTimePlugin.expired?(content) |
50 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | 48 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") |