Skip to content

Commit 9806a0d

Browse files
authored
Merge pull request #937 from openstax/is-admin-api
is_administrator added to user api
2 parents 0fc60bd + 2aa8722 commit 9806a0d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

app/representers/api/v1/user_representer.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ class UserRepresenter < Roar::Decorator
169169
description: 'Whether the user is part of a Key Institutional Partner school'
170170
}
171171

172+
property :is_administrator,
173+
type: :boolean,
174+
readable: true,
175+
writeable: false,
176+
schema_info: {
177+
description: 'Whether the user is an Accounts admin'
178+
}
179+
172180
property :grant_tutor_access,
173181
type: :boolean,
174182
readable: true,

spec/representers/api/v1/user_representer_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@
108108
end
109109
end
110110

111+
context 'is_administrator' do
112+
it 'can be read' do
113+
expect(representer.to_hash['is_administrator']).to eq user.is_administrator
114+
end
115+
116+
it 'cannot be written (attempts are silently ignored)' do
117+
hash = { 'is_administrator' => true }
118+
119+
expect(user).not_to receive(:is_administrator=)
120+
expect { representer.from_hash(hash) }.not_to change { user.reload.is_administrator }
121+
end
122+
end
123+
111124
context 'grant_tutor_access' do
112125
it 'can be read' do
113126
expect(representer.to_hash['grant_tutor_access']).to eq user.grant_tutor_access

spec/support/user_hash.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def user_matcher(user, include_private_data: false)
1616
uuid: user.uuid,
1717
support_identifier: user.support_identifier,
1818
is_test: user.is_test?,
19+
is_administrator: user.is_administrator?,
1920
salesforce_contact_id: user.salesforce_contact_id,
2021
applications: a_collection_containing_exactly(
2122
*user.applications.map { |app| { id: app.id, name: app.name } }

0 commit comments

Comments
 (0)