Files
grecia/app/controllers/concerns/commentable_actions.rb
Javi Martín f7e2d724dd Replace ahoy events with real data
We were tracking some events with Ahoy, but in an inconsistent way. For
example, we were tracking when a debate was created, but (probably
accidentally) we were only tracking proposals when they were created
from the management section. For budget investments and their supports,
we weren't using Ahoy events but checking their database tables instead.
And we were only using ahoy events for the charts; for the other stats,
we were using the real data.

While we could actually fix these issues and start tracking events
correctly, existing production data would remain broken because we
didn't track a certain event when it happened. And, besides, why should
we bother, for instance, to track when a debate is created, when we can
instead access that information in the debates table?

There are probably some features related to tracking an event and their
visits, but we weren't using them, and we were storing more user data
than we needed to.

So we're removing the track events, allowing us to simplify the code and
make it more consistent. We aren't removing the `ahoy_events` table in
case existing Consul Democracy installations use it, but we'll remove it
after releasing version 2.2.0 and adding a warning in the release notes.

This change fixes the proposal created chart, since we were only
tracking proposals created in the management section, and opens the
possibility to add more charts in the future using data we didn't track
with Ahoy.

Also note the "Level 2 user Graph" test wasn't testing the graph, so
we're changing it in order to test it. We're also moving it next to the
other graphs test and, since we were tracking the event when we were
confirming the phone, we're renaming to "Level 3 users".

Finally, note that, since we were tracking events when something was
created, we're including the `with_hidden` scope. This is also
consistent with the other stats shown in the admin section as well as
the public stats.
2024-05-09 14:28:32 +02:00

87 lines
2.0 KiB
Ruby

module CommentableActions
extend ActiveSupport::Concern
include Polymorphic
include Search
include RemotelyTranslatable
def index
@resources = resource_model.all
@resources = if @current_order == "recommendations" && current_user.present?
@resources.recommendations(current_user)
else
@resources.for_render
end
@resources = @resources.search(@search_terms) if @search_terms.present?
@resources = @resources.filter_by(@advanced_search_terms)
@resources = @resources.page(params[:page]).send("sort_by_#{@current_order}")
index_customization
@tag_cloud = tag_cloud
set_resources_instance
@remote_translations = detect_remote_translations(@resources, featured_proposals)
end
def show
@commentable = resource
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
set_resource_instance
@remote_translations = detect_remote_translations([@resource], @comment_tree.comments)
end
def new
@resource = resource_model.new
set_geozone
set_resource_instance
end
def suggest
@limit = 5
@resources = @search_terms.present? ? resource_relation.search(@search_terms) : nil
end
def edit
end
def update
if resource.update(strong_params)
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
else
load_geozones
set_resource_instance
render :edit
end
end
private
def tag_cloud
TagCloud.new(resource_model, params[:search])
end
def load_geozones
@geozones = Geozone.order(name: :asc)
end
def set_geozone
geozone_id = params[resource_name.to_sym].try(:[], :geozone_id)
@resource.geozone = Geozone.find(geozone_id) if geozone_id.present?
end
def load_categories
@categories = Tag.category.order(:name)
end
def index_customization
nil
end
def featured_proposals
@featured_proposals ||= []
end
end