Files
nairobi/app/controllers/verification/sms_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

76 lines
1.8 KiB
Ruby

class Verification::SmsController < ApplicationController
before_action :authenticate_user!
before_action :verify_resident!
before_action :verify_verified!
before_action :verify_lock, only: [:new, :create]
before_action :set_phone, only: :create
skip_authorization_check
def new
@sms = Verification::Sms.new(phone: params[:phone])
end
def create
@sms = Verification::Sms.new(phone: @phone, user: current_user)
if @sms.save
redirect_to edit_sms_path, notice: t("verification.sms.create.flash.success")
else
render :new
end
end
def edit
@sms = Verification::Sms.new
end
def update
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.verified?
current_user.update!(confirmed_phone: current_user.unconfirmed_phone)
if VerifiedUser.phone?(current_user)
current_user.update(verified_at: Time.current)
end
redirect_to_next_path
else
@error = t("verification.sms.update.error")
render :edit
end
end
private
def sms_params
params.require(:sms).permit(allowed_params)
end
def allowed_params
[:phone, :confirmation_code]
end
def set_phone
if verified_user
@phone = @verified_user.phone
else
@phone = sms_params[:phone]
end
end
def verified_user
return false unless params[:verified_user]
@verified_user = VerifiedUser.by_user(current_user).find_by(id: params[:verified_user][:id])
end
def redirect_to_next_path
current_user.reload
if current_user.level_three_verified?
redirect_to account_path, notice: t("verification.sms.update.flash.level_three.success")
else
redirect_to new_letter_path, notice: t("verification.sms.update.flash.level_two.success")
end
end
end