From 1d8a912ca3195f3d7e02ef74f7f73605406a024d Mon Sep 17 00:00:00 2001 From: Mark Dewey Date: Wed, 8 May 2024 19:07:26 +0000 Subject: [PATCH] (mvp) --- .../analytics/v0/analytics_controller.rb | 15 +++++++++---- .../spec/request/v0/analytics_request_spec.rb | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 modules/analytics/spec/request/v0/analytics_request_spec.rb diff --git a/modules/analytics/app/controllers/analytics/v0/analytics_controller.rb b/modules/analytics/app/controllers/analytics/v0/analytics_controller.rb index 46e7cc70cdc..108a9c6a2c9 100644 --- a/modules/analytics/app/controllers/analytics/v0/analytics_controller.rb +++ b/modules/analytics/app/controllers/analytics/v0/analytics_controller.rb @@ -1,11 +1,18 @@ module Analytics module V0 class AnalyticsController < ApplicationController - skip_before_action :authenticate - + before_action :authenticate def index - data = { hello: 'world', salt: Settings.analytics.unique_user.salt } - render json: data + return unless current_user + render json: { + user_fingerprint: get_user_fingerprint(current_user.uuid) + } + end + + private + + def get_user_fingerprint(user_property) + Digest::SHA256.hexdigest("#{Settings.analytics.unique_user.salt}#{user_property}") end end end diff --git a/modules/analytics/spec/request/v0/analytics_request_spec.rb b/modules/analytics/spec/request/v0/analytics_request_spec.rb new file mode 100644 index 00000000000..3c094750f33 --- /dev/null +++ b/modules/analytics/spec/request/v0/analytics_request_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'V0::Analytics', type: :request do + before do + sign_in_as(current_user) + end + + describe 'GET `index`' do + let(:current_user) { build(:user, :loa3, icn: '123498767V234859', uuid:'test-guid') } + + it 'returns things' do + get '/analytics/v0/user/hashes' + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)).to eq({ 'user_fingerprint' => 'e867710d806a3533f0843405c3ba9bdd0769b2ff84fcce8f75e6b64a406e70c3' }) + end + + + end +end