Class: EventsFinder

Inherits:
Object
  • Object
show all
Includes:
FinderMethods, FinderWithCrossProjectAccess
Defined in:
app/finders/events_finder.rb

Constant Summary collapse

MAX_PER_PAGE =
100

Instance Attribute Summary collapse

Attributes included from FinderWithCrossProjectAccess

#should_skip_cross_project_check

Instance Method Summary collapse

Methods included from FinderMethods

#find, #find_by, #find_by!

Methods included from FinderWithCrossProjectAccess

#can_read_cross_project?, #can_read_project?, #find, #find_by, #find_by!, #skip_cross_project_check

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Constructor Details

#initialize(params = {}) ⇒ EventsFinder

Used to filter Events

Arguments:

source - which user or project to looks for events on
current_user - only return events for projects visible to this user
scope - return all events across a user's projects
params:
  action: string
  target_type: string
  before: datetime
  after: datetime
  per_page: integer (max. 100)
  page: integer
  with_associations: boolean
  sort: 'asc' or 'desc'


28
29
30
31
32
33
# File 'app/finders/events_finder.rb', line 28

def initialize(params = {})
  @source = params.delete(:source)
  @current_user = params.delete(:current_user)
  @scope = params.delete(:scope)
  @params = params
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



9
10
11
# File 'app/finders/events_finder.rb', line 9

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'app/finders/events_finder.rb', line 9

def params
  @params
end

#scopeObject (readonly)

Returns the value of attribute scope.



9
10
11
# File 'app/finders/events_finder.rb', line 9

def scope
  @scope
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'app/finders/events_finder.rb', line 9

def source
  @source
end

Instance Method Details

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/finders/events_finder.rb', line 35

def execute
  return Event.none if cannot_access_private_profile?

  events = get_events

  events = by_current_user_access(events)
  events = by_action(events)
  events = by_target_type(events)
  events = by_created_at_before(events)
  events = by_created_at_after(events)
  events = sort(events)

  paginated_filtered_by_user_visibility(events)
end