Class: Ideasbugs::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ideasbugs/configuration.rb

Overview

Host-tunable settings. Everything has a safe default, so a fresh install works with zero configuration; the hooks below let an app decide who can send feedback, who can read it, and how submissions are attributed.

Constant Summary collapse

DEFAULT_ADMIN_LAYOUT =

The gem's own dashboard layout. Compared against, so DashboardController can tell "the host left this alone" from "the host chose this".

'ideasbugs/application'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ideasbugs/configuration.rb', line 102

def initialize
  @enabled = ->(_request) { true }
  @authorize_admin = ->(_request) { Rails.env.development? }
  @admin_layout = DEFAULT_ADMIN_LAYOUT
  @base_controller_class = 'ActionController::Base'
  @current_user = ->(_request) {}
  @tenant = ->(_request) {}
  @author_label = ->(user) { user.respond_to?(:email) ? user.email : user&.to_s }
  @kinds = %w[bug feature other]
  @sections = []
  @screenshots = true
  @max_screenshots = 3
  @max_screenshot_size = 5 * 1024 * 1024
  @storage_service = nil
  @rate_limit = { to: 10, within: 60 }
  @show_button = true
  @button_label = nil
  @mount_path = '/feedback'
  @on_submit = ->() {}
end

Instance Attribute Details

#admin_layoutObject

Layout used by the built-in dashboard. Override this to render Ideasbugs inside your app's admin shell, e.g. "admin/application".



25
26
27
# File 'lib/ideasbugs/configuration.rb', line 25

def admin_layout
  @admin_layout
end

#author_labelObject

Turn a resolved user into a short label stored alongside the feedback and shown in the dashboard. Receives whatever #current_user returned.



57
58
59
# File 'lib/ideasbugs/configuration.rb', line 57

def author_label
  @author_label
end

#authorize_adminObject

Per-request gate for the built-in dashboard (browse and triage feedback). Receives the request. Defaults to development only — override it before deploying, e.g. with an admin check.



21
22
23
# File 'lib/ideasbugs/configuration.rb', line 21

def authorize_admin
  @authorize_admin
end

#base_controller_classObject

The controller the DASHBOARD inherits from, as a String so it resolves lazily rather than at config time. Default: a plain 'ActionController::Base', where authorize_admin is the only gate.

Name the controller your own admin already inherits from and the dashboard adopts that whole stack — layout, helpers, authentication, and any request context your before_actions set up. admin_layout covers only the layout, which leaves a host layout calling its own helpers to raise NameError under the engine's isolated namespace.

Only the dashboard uses it. The widget's endpoint stays on the engine's own public controller, so an admin base controller here can never demand a staff session from someone filing a report.



40
41
42
# File 'lib/ideasbugs/configuration.rb', line 40

def base_controller_class
  @base_controller_class
end

#button_labelObject

Text on the floating button. Leave nil to use the localized default (the ideasbugs.button I18n key).



91
92
93
# File 'lib/ideasbugs/configuration.rb', line 91

def button_label
  @button_label
end

#current_userObject

Resolve the current user for attribution (optional). Return an object responding to #id, or nil. Receives the request.



44
45
46
# File 'lib/ideasbugs/configuration.rb', line 44

def current_user
  @current_user
end

#enabledObject

Per-request gate for the widget and the submission endpoint. Return false to hide the widget and reject submissions for this request. Receives the request. Defaults to everyone — feedback collection is meant for real users in production.



16
17
18
# File 'lib/ideasbugs/configuration.rb', line 16

def enabled
  @enabled
end

#kindsObject

The feedback types a user can pick from. Labels resolve through I18n (ideasbugs.kinds.<kind>), so you can rename or add kinds freely.



61
62
63
# File 'lib/ideasbugs/configuration.rb', line 61

def kinds
  @kinds
end

#max_screenshot_sizeObject

Upload limits, enforced server-side and mirrored in the widget.



73
74
75
# File 'lib/ideasbugs/configuration.rb', line 73

def max_screenshot_size
  @max_screenshot_size
end

#max_screenshotsObject

Upload limits, enforced server-side and mirrored in the widget.



73
74
75
# File 'lib/ideasbugs/configuration.rb', line 73

def max_screenshots
  @max_screenshots
end

#mount_pathObject

Where the engine is mounted. The widget posts to "##mount_path/feedbacks", so keep this in sync with the mount line in your routes.



96
97
98
# File 'lib/ideasbugs/configuration.rb', line 96

def mount_path
  @mount_path
end

#on_submitObject

Called with each saved feedback — notify Slack, send an email, open a ticket. Runs inline after save; keep it fast or hand off to a job.



100
101
102
# File 'lib/ideasbugs/configuration.rb', line 100

def on_submit
  @on_submit
end

#rate_limitObject

Per-IP throttle for the public submission endpoint, as keyword arguments for Rails' rate limiter (Rails 7.2+; ignored on 7.1). Read once when the controller loads — set it in an initializer. nil disables throttling.



82
83
84
# File 'lib/ideasbugs/configuration.rb', line 82

def rate_limit
  @rate_limit
end

#screenshotsObject

Allow screenshot uploads. Requires Active Storage in the host app; the widget hides the upload control when this is false or Active Storage is not set up.



70
71
72
# File 'lib/ideasbugs/configuration.rb', line 70

def screenshots
  @screenshots
end

#sectionsObject

Optional list of app areas ("Billing", "Dashboard", …) shown as a select in the widget. Leave empty to hide the select entirely.



65
66
67
# File 'lib/ideasbugs/configuration.rb', line 65

def sections
  @sections
end

#show_buttonObject

Show the floating feedback button. Set false to trigger the widget from your own UI instead: any element with a data-ideasbugs-open attribute opens the form.



87
88
89
# File 'lib/ideasbugs/configuration.rb', line 87

def show_button
  @show_button
end

#storage_serviceObject

The Active Storage service that stores screenshots, as a service name from the host's config/storage.yml. nil uses the environment default.



77
78
79
# File 'lib/ideasbugs/configuration.rb', line 77

def storage_service
  @storage_service
end

#tenantObject

Resolve the current tenant (optional, for multi-tenant apps). Return an opaque key — a GlobalID, an id, a subdomain, a slug — or nil. Receives the request; shaped exactly like current_user/authorize_admin. nil (the default) is a single, global board: today's behavior, unchanged. Each submission is stamped with it and the dashboard scopes to it, so every tenant gets its own board. The recommended key is a GlobalID (record.to_gid.to_s), which also matches the has_feedback concern.



53
54
55
# File 'lib/ideasbugs/configuration.rb', line 53

def tenant
  @tenant
end

Instance Method Details

#feedbacks_endpointObject



123
124
125
# File 'lib/ideasbugs/configuration.rb', line 123

def feedbacks_endpoint
  "#{mount_path.chomp('/')}/feedbacks"
end

#screenshots_enabled?Boolean

Screenshots need Active Storage — both the config switch and the host actually having it loaded.

Returns:

  • (Boolean)


129
130
131
# File 'lib/ideasbugs/configuration.rb', line 129

def screenshots_enabled?
  screenshots && defined?(::ActiveStorage) ? true : false
end