Class: LcpRuby::SavedFiltersController

Inherits:
ApplicationController show all
Includes:
DialogRendering
Defined in:
app/controllers/lcp_ruby/saved_filters_controller.rb

Constant Summary

Constants included from DialogRendering

DialogRendering::DIALOG_PASS_THROUGH_KEYS

Constants included from Controller::BearerAuthentication

Controller::BearerAuthentication::BASIC_PREFIX_LENGTH, Controller::BearerAuthentication::BEARER_PREFIX_LENGTH

Instance Method Summary collapse

Methods included from DialogRendering

#composite_dialog?, #defaults_from_params, #dialog_context?, #dialog_form_url, #dialog_locals, #dialog_pass_through_params, #partial_for_dialog_result_style, #render_composite_dialog_form, #render_dialog_form, #render_dialog_form_with_errors, #render_dialog_result, #render_dialog_success, #resolved_dialog_config, #resolved_dialog_page

Methods included from Controller::Authorization

#current_evaluator

Instance Method Details

#createObject

POST /:lcp_slug/saved-filters Creates a new saved filter.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/lcp_ruby/saved_filters_controller.rb', line 23

def create
  return create_from_dialog if dialog_context?

  authorize_create!
  record = build_saved_filter
  limit_error = check_limits(record)
  if limit_error
    render json: { error: limit_error }, status: :unprocessable_content
    return
  end

  if record.save
    render json: serialize_filter(record), status: :created
  else
    render json: { errors: record.errors.full_messages }, status: :unprocessable_content
  end
end

#destroyObject

DELETE /:lcp_slug/saved-filters/:id Deletes a saved filter.



58
59
60
61
62
# File 'app/controllers/lcp_ruby/saved_filters_controller.rb', line 58

def destroy
  authorize_modify!(@saved_filter)
  @saved_filter.destroy!
  render json: { success: true }
end

#indexObject

GET /:lcp_slug/saved-filters Returns visible saved filters for the current user and presenter.



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/lcp_ruby/saved_filters_controller.rb', line 10

def index
  authorize_index!
  filters = SavedFilters::Resolver.visible_filters(
    presenter_name: current_presenter.name,
    user: current_user,
    evaluator: current_evaluator
  )

  render json: filters.map { |f| serialize_filter(f) }
end

#updateObject

PATCH /:lcp_slug/saved-filters/:id Updates an existing saved filter.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/lcp_ruby/saved_filters_controller.rb', line 43

def update
  authorize_modify!(@saved_filter)

  @saved_filter.assign_attributes(saved_filter_params)
  sync_ql_text!(@saved_filter)

  if @saved_filter.save
    render json: serialize_filter(@saved_filter)
  else
    render json: { errors: @saved_filter.errors.full_messages }, status: :unprocessable_content
  end
end