tolerance_time_plugin.rb
2 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)
    return false if content.kind_of?(Comment) && !content.article.kind_of?(Article)
    expirable = content.kind_of?(Comment) || (!content.folder? && content.published?)
    publication = ToleranceTimePlugin::Publication.find_by_target(content)
    publication = ToleranceTimePlugin::Publication.create!(:target => content) if expirable && publication.nil?
    person_article = content.kind_of?(Article) && content.profile.kind_of?(Person)
    !person_article && expirable && 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
    block = proc 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_viewer_controller_filters
    block = proc do
      content = Comment.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.article.url
      end
    end
    { :type => 'before_filter',
      :method_name => 'expired_content',
      :options => {:only => 'edit_comment'},
      :block => block }
  end
  def content_expire_edit(content)
    if ToleranceTimePlugin.expired?(content)
      _('The tolerance time for editing this content is over.')
    end
  end
end