Files
nairobi/app/controllers/management/proposals_controller.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

77 lines
2.1 KiB
Ruby

class Management::ProposalsController < Management::BaseController
include HasOrders
include CommentableActions
include Translatable
include MapLocationAttributes
before_action :only_verified_users, except: :print
before_action :set_proposal, only: [:vote, :show]
before_action :parse_search_terms, only: :index
before_action :load_geozones, only: [:edit]
has_orders %w[confidence_score hot_score created_at most_commented random], only: [:index, :print]
has_orders %w[most_voted newest], only: :show
def create
@resource = resource_model.new(strong_params.merge(author: current_user,
published_at: Time.current))
if @resource.save
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
else
load_geozones
set_resource_instance
render :new
end
end
def show
super
@notifications = @proposal.notifications
if request.path != management_proposal_path(@proposal)
redirect_to management_proposal_path(@proposal), status: :moved_permanently
end
end
def vote
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
@proposal.register_vote(managed_user, "yes")
end
def print
@proposals = Proposal.send("sort_by_#{@current_order}").for_render.limit(5)
end
private
def set_proposal
@proposal = Proposal.find(params[:id])
end
def proposal_params
params.require(:proposal).permit(allowed_params)
end
def allowed_params
attributes = [:video_url, :responsible_name, :tag_list,
:terms_of_service, :geozone_id,
map_location_attributes: map_location_attributes]
[*attributes, translation_params(Proposal)]
end
def resource_model
Proposal
end
def only_verified_users
check_verified_user t("management.proposals.alert.unverified_user")
end
def set_comment_flags(comments)
@comment_flags = managed_user ? managed_user.comment_flags(comments) : {}
end
end