diff --git a/app/representers/api/v1/user_representer.rb b/app/representers/api/v1/user_representer.rb index 08c591264..097a67db5 100644 --- a/app/representers/api/v1/user_representer.rb +++ b/app/representers/api/v1/user_representer.rb @@ -169,6 +169,14 @@ class UserRepresenter < Roar::Decorator description: 'Whether the user is part of a Key Institutional Partner school' } + property :is_administrator, + type: :boolean, + readable: true, + writeable: false, + schema_info: { + description: 'Whether the user is an Accounts admin' + } + property :grant_tutor_access, type: :boolean, readable: true, diff --git a/spec/representers/api/v1/user_representer_spec.rb b/spec/representers/api/v1/user_representer_spec.rb index 7d0f8cfc2..00e718171 100644 --- a/spec/representers/api/v1/user_representer_spec.rb +++ b/spec/representers/api/v1/user_representer_spec.rb @@ -108,6 +108,19 @@ end end + context 'is_administrator' do + it 'can be read' do + expect(representer.to_hash['is_administrator']).to eq user.is_administrator + end + + it 'cannot be written (attempts are silently ignored)' do + hash = { 'is_administrator' => true } + + expect(user).not_to receive(:is_administrator=) + expect { representer.from_hash(hash) }.not_to change { user.reload.is_administrator } + end + end + context 'grant_tutor_access' do it 'can be read' do expect(representer.to_hash['grant_tutor_access']).to eq user.grant_tutor_access diff --git a/spec/support/user_hash.rb b/spec/support/user_hash.rb index efbb78edd..44adb4a15 100644 --- a/spec/support/user_hash.rb +++ b/spec/support/user_hash.rb @@ -16,6 +16,7 @@ def user_matcher(user, include_private_data: false) uuid: user.uuid, support_identifier: user.support_identifier, is_test: user.is_test?, + is_administrator: user.is_administrator?, salesforce_contact_id: user.salesforce_contact_id, applications: a_collection_containing_exactly( *user.applications.map { |app| { id: app.id, name: app.name } }