Class: Redmine::Activity::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/activity/fetcher.rb

Overview

Class used to retrieve activity events

Constant Summary collapse

@@constantized_providers =

Needs to be unloaded in development mode

Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, options = {}) ⇒ Fetcher


24
25
26
27
28
29
30
31
# File 'lib/redmine/activity/fetcher.rb', line 24

def initialize(user, options={})
  options.assert_valid_keys(:project, :with_subprojects, :author)
  @user = user
  @project = options[:project]
  @options = options

  @scope = event_types
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


19
20
21
# File 'lib/redmine/activity/fetcher.rb', line 19

def project
  @project
end

#scopeObject

Returns the value of attribute scope


19
20
21
# File 'lib/redmine/activity/fetcher.rb', line 19

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user


19
20
21
# File 'lib/redmine/activity/fetcher.rb', line 19

def user
  @user
end

Instance Method Details

#default_scope!Object

Resets the scope to the default scope


71
72
73
# File 'lib/redmine/activity/fetcher.rb', line 71

def default_scope!
  @scope = Redmine::Activity.default_event_types
end

#event_typesObject

Returns an array of available event types


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/redmine/activity/fetcher.rb', line 34

def event_types
  return @event_types unless @event_types.nil?

  @event_types = Redmine::Activity.available_event_types
  if @project
    @event_types = @event_types.select do |o|
      @project.self_and_descendants.detect do |p|
        permissions = constantized_providers(o).collect do |p|
          p.activity_provider_options[o].try(:[], :permission)
        end.compact
        return @user.allowed_to?("view_#{o}".to_sym, @project) if permissions.blank?
        permissions.all? {|p| @user.allowed_to?(p, @project) } if @project
      end
    end
  end
  @event_types
end

#events(from = nil, to = nil, options = {}) ⇒ Object

Returns an array of events for the given date range sorted in reverse chronological order


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/redmine/activity/fetcher.rb', line 77

def events(from = nil, to = nil, options={})
  e = []
  @options[:limit] = options[:limit]

  @scope.each do |event_type|
    constantized_providers(event_type).each do |provider|
      e += provider.find_events(event_type, @user, from, to, @options)
    end
  end

  e.sort! {|a,b| b.event_datetime <=> a.event_datetime}

  if options[:limit]
    e = e.slice(0, options[:limit])
  end
  e
end

#scope_select(&block) ⇒ Object

Yields to filter the activity scope


53
54
55
# File 'lib/redmine/activity/fetcher.rb', line 53

def scope_select(&block)
  @scope = @scope.select {|t| yield t }
end