Skip to content

Commit

Permalink
Merge pull request #937 from openstax/is-admin-api
Browse files Browse the repository at this point in the history
is_administrator added to user api
  • Loading branch information
edwoodward authored Jan 26, 2021
2 parents 0fc60bd + 2aa8722 commit 9806a0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/representers/api/v1/user_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions spec/representers/api/v1/user_representer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/support/user_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down

0 comments on commit 9806a0d

Please sign in to comment.