tolerance_time_plugin.rb
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require_dependency 'ext/article'
require_dependency 'ext/comment'
class ToleranceTimePlugin < Noosfero::Plugin
def self.plugin_name
"Tolerance Time"
end
def self.plugin_description
_("Adds a tolerance time for editing content after its publication")
end
def self.expired?(content)
publication = ToleranceTimePlugin::Publication.find_by_target(content)
(content.kind_of?(Comment) || (!content.folder? && content.published?)) &&
((!publication.present? && !content.profile.kind_of?(Person)) || (publication.present? && publication.expired?))
end
def control_panel_buttons
{:title => _('Tolerance Adjustements'), :url => {:controller => 'tolerance_time_plugin_myprofile', :profile => context.profile.identifier}, :icon => 'tolerance-time' }
end
def stylesheet?
true
end
def cms_controller_filters
return if !context.environment.plugin_enabled?(ToleranceTimePlugin)
block = lambda do
content = Article.find(params[:id])
if ToleranceTimePlugin.expired?(content)
session[:notice] = _('This content can\'t be edited anymore because it expired the tolerance time')
redirect_to content.url
end
end
{ :type => 'before_filter',
:method_name => 'expired_content',
:options => {:only => 'edit'},
:block => block }
end
def content_expire_edit(content)
if ToleranceTimePlugin.expired?(content)
_('The tolerance time for editing this content is over.')
end
end
end