allow canvas api to take uuid as a user request param
closes CNVS-36510 test plan: - <your canvas url>/api/v1/users/uuid:<a user uuid>/profile will return a user profile Change-Id: I771636daddab8d0a79e4b199da1e48032ca9a8b6 Reviewed-on: https://gerrit.instructure.com/111195 Tested-by: Jenkins Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Chris Wang <cwang@instructure.com>
This commit is contained in:
parent
db41925a7e
commit
90fcc0999e
10
lib/api.rb
10
lib/api.rb
|
@ -112,8 +112,9 @@ module Api
|
|||
'id' => 'users.id',
|
||||
'sis_integration_id' => 'pseudonyms.integration_id',
|
||||
'lti_context_id' => 'users.lti_context_id',
|
||||
'lti_user_id' => 'users.lti_context_id' }.freeze,
|
||||
:is_not_scoped_to_account => ['users.id', 'users.lti_context_id'].freeze,
|
||||
'lti_user_id' => 'users.lti_context_id',
|
||||
'uuid' => 'users.uuid' }.freeze,
|
||||
:is_not_scoped_to_account => ['users.id', 'users.lti_context_id', 'users.uuid'].freeze,
|
||||
:scope => 'pseudonyms.account_id',
|
||||
:joins => :pseudonym }.freeze,
|
||||
'accounts' =>
|
||||
|
@ -138,6 +139,7 @@ module Api
|
|||
|
||||
MAX_ID_LENGTH = (2**63 - 1).to_s.length
|
||||
ID_REGEX = %r{\A\d{1,#{MAX_ID_LENGTH}}\z}
|
||||
USER_UUID_REGEX = %r{\Auuid:(\w{40,})\z}
|
||||
|
||||
def self.sis_parse_id(id, lookups, _current_user = nil,
|
||||
root_account: nil)
|
||||
|
@ -152,6 +154,8 @@ module Api
|
|||
sis_id = $2
|
||||
elsif id =~ ID_REGEX
|
||||
return lookups['id'], (id =~ /\A\d+\z/ ? id.to_i : id)
|
||||
elsif id =~ USER_UUID_REGEX
|
||||
return lookups['uuid'], $1
|
||||
else
|
||||
return nil, nil
|
||||
end
|
||||
|
@ -214,12 +218,10 @@ module Api
|
|||
|
||||
def self.relation_for_sis_mapping_and_columns(relation, columns, sis_mapping, sis_root_account)
|
||||
raise ArgumentError, "sis_root_account required for lookups" unless sis_root_account.is_a?(Account)
|
||||
|
||||
return relation.none if columns.empty?
|
||||
relation = relation.all unless relation.is_a?(ActiveRecord::Relation)
|
||||
|
||||
not_scoped_to_account = sis_mapping[:is_not_scoped_to_account] || []
|
||||
|
||||
if columns.length == 1 && not_scoped_to_account.include?(columns.keys.first)
|
||||
relation = relation.where(columns)
|
||||
else
|
||||
|
|
|
@ -183,6 +183,10 @@ describe Api do
|
|||
account.save!
|
||||
expect(@api.api_find(Account, "lti_context_id:#{account.lti_context_id}")).to eq account
|
||||
end
|
||||
|
||||
it "should find user by uuid" do
|
||||
expect(@api.api_find(User, "uuid:#{@user.uuid}")).to eq @user
|
||||
end
|
||||
end
|
||||
|
||||
context 'api_find_all' do
|
||||
|
@ -199,6 +203,10 @@ describe Api do
|
|||
expect(@api.api_find_all(User, [@user.id])).to eq [@user]
|
||||
end
|
||||
|
||||
it 'should find a simple record with uuid' do
|
||||
expect(@api.api_find_all(User, ["uuid:#{@user.uuid}"])).to eq [@user]
|
||||
end
|
||||
|
||||
it 'should not find a missing record' do
|
||||
expect(@api.api_find_all(User, [(User.all.map(&:id).max + 1)])).to eq []
|
||||
end
|
||||
|
@ -442,6 +450,11 @@ describe Api do
|
|||
expect(Api.sis_parse_id(" hex:sis_login_id:7369737573657233406578616d706c652e636f6d ", @lookups)).to eq ["LOWER(pseudonyms.unique_id)", "LOWER('sisuser3@example.com')"]
|
||||
expect(Api.sis_parse_id(" sis_login_id:sisuser3@example.com\t", @lookups)).to eq ["LOWER(pseudonyms.unique_id)", "LOWER('sisuser3@example.com')"]
|
||||
end
|
||||
|
||||
it 'should handle user uuid' do
|
||||
expect(Api.sis_parse_id("uuid:tExtjERcuxGKFLO6XxwIBCeXZvZXLdXzs8LV0gK0", @lookups)).to \
|
||||
eq ["users.uuid", "tExtjERcuxGKFLO6XxwIBCeXZvZXLdXzs8LV0gK0"]
|
||||
end
|
||||
end
|
||||
|
||||
context 'sis_parse_ids' do
|
||||
|
@ -570,6 +583,8 @@ describe Api do
|
|||
expect(Api.sis_parse_id("sis_account_id:1", lookups)).to eq [nil, nil]
|
||||
expect(Api.sis_parse_id("sis_section_id:1", lookups)).to eq [nil, nil]
|
||||
expect(Api.sis_parse_id("1", lookups)).to eq ["users.id", 1]
|
||||
expect(Api.sis_parse_id("uuid:tExtjERcuxGKFLO6XxwIBCeXZvZXLdXzs8LV0gK0", lookups)).to \
|
||||
eq ["users.uuid", "tExtjERcuxGKFLO6XxwIBCeXZvZXLdXzs8LV0gK0"]
|
||||
end
|
||||
|
||||
it 'should correctly capture account lookups' do
|
||||
|
|
Loading…
Reference in New Issue