Skip to content

Commit

Permalink
Consent preferences (#1252)
Browse files Browse the repository at this point in the history
* add json field for storing user consent preferences

* update specs
  • Loading branch information
mwvolo authored Aug 13, 2024
1 parent d7a500a commit a3649f4
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def find
def find_or_create
OSU::AccessPolicy.require_action_allowed!(:create, current_api_user, User)
# OpenStax::Api#standard_(update|create) require an ActiveRecord model, which we don't have
# Substitue a Hashie::Mash to read the JSON encoded body
# Substitute a Hashie::Mash to read the JSON encoded body
payload = consume!(Hashie::Mash.new, represent_with: Api::V1::FindOrCreateUserRepresenter)
payload.application = current_api_user.application

Expand Down
31 changes: 3 additions & 28 deletions app/representers/api/v1/user_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class UserRepresenter < Roar::Decorator
readable: true,
writeable: false

property :support_identifier,
type: String,
property :consent_preferences,
type: JSON,
readable: true,
writeable: false
writeable: true

property :is_not_gdpr_location,
if: ->(user_options:, **) { user_options.try(:fetch, :include_private_data, false) },
Expand Down Expand Up @@ -102,15 +102,6 @@ class UserRepresenter < Roar::Decorator
description: "One of #{User.faculty_statuses.keys.map(&:to_s).inspect}"
}

property :needs_to_complete_educator_profile?,
as: :needs_complete_edu_profile,
type: String,
readable: true,
writeable: false,
schema_info: {
description: "New flow faculty user needs to finish signing up?"
}

property :role,
as: :self_reported_role,
if: ->(user_options:, **) { user_options.try(:fetch, :include_private_data, false) },
Expand Down Expand Up @@ -161,14 +152,6 @@ class UserRepresenter < Roar::Decorator
description: "One of #{User.school_locations.keys.map(&:to_s).inspect}"
}

property :is_kip,
type: :boolean,
readable: true,
writeable: false,
schema_info: {
description: 'Whether the user is part of a Key Institutional Partner school'
}

property :is_administrator,
type: :boolean,
readable: true,
Expand All @@ -177,14 +160,6 @@ class UserRepresenter < Roar::Decorator
description: 'Whether the user is an Accounts admin'
}

property :grant_tutor_access,
type: :boolean,
readable: true,
writeable: false,
schema_info: {
description: 'Whether the user should be granted Tutor access'
}

collection :contact_infos,
if: ->(user_options:, **) { user_options.try(:fetch, :include_private_data, false) },
decorator: ContactInfoRepresenter
Expand Down
9 changes: 9 additions & 0 deletions app/views/admin/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
</div>
<% end %>

<div class="form-group">
<%= f.label :consent_preferences, 'Consent Preferences', class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="form-control-static">
<%= @user.consent_preferences %>
</div>
</div>
</div>

<% if @user.school %>
<div class="form-group">
<%= f.label :school, class: "col-sm-2 control-label" %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240808171751_add_consent_preferences_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddConsentPreferencesToUser < ActiveRecord::Migration[5.2]
def change
add_column :users, :consent_preferences, :jsonb
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_01_23_173834) do
ActiveRecord::Schema.define(version: 2024_08_08_171751) do

# These are extensions that must be enabled in order to support this database
enable_extension "citext"
Expand Down Expand Up @@ -471,6 +471,7 @@
t.boolean "sheer_id_webhook_received"
t.jsonb "books_used_details"
t.string "adopter_status"
t.jsonb "consent_preferences"
t.index "lower((first_name)::text)", name: "index_users_on_first_name"
t.index "lower((last_name)::text)", name: "index_users_on_last_name"
t.index "lower((username)::text)", name: "index_users_on_username_case_insensitive"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
uuid {Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3)}
role { User::STUDENT_ROLE }
school { FactoryBot.build(:school) }
consent_preferences { JSON.generate({'accepted': ['functional', 'analytical'], 'rejected': ['essential', 'personalization']}) }

is_profile_complete { true }

Expand Down
4 changes: 2 additions & 2 deletions spec/representers/api/v1/user_representer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
end
end

context 'support_identifier' do
context 'consent_preferences' do
it 'can be read' do
expect(representer.to_hash['support_identifier']).to eq user.support_identifier
expect(representer.to_hash['consent_preferences']).to eq user.consent_preferences
end

it 'cannot be written (attempts are silently ignored)' do
Expand Down
3 changes: 1 addition & 2 deletions spec/support/user_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ def user_matcher(user, include_private_data: false)
first_name: user.first_name,
last_name: user.last_name,
full_name: user.full_name,
needs_complete_edu_profile: false,
title: user.title,
suffix: user.suffix,
uuid: user.uuid,
support_identifier: user.support_identifier,
consent_preferences: user.consent_preferences,
is_test: user.is_test?,
is_administrator: user.is_administrator?,
salesforce_contact_id: user.salesforce_contact_id,
Expand Down

0 comments on commit a3649f4

Please sign in to comment.