add sis_import_id to groups api
refs CNVS-10408 test plan - import groups through SIS - create groups manually - GET /api/v1/accounts/:account_id/groups should have sis_import_id if you have permissions to see it - check that sis_import_id is in api docs Change-Id: Ibbd63c076835440b760952343d150ce986a386fd Reviewed-on: https://gerrit.instructure.com/29943 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
e16c0a266d
commit
e13d2a42d3
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 2013 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -106,6 +106,16 @@
|
|||
# "example": 4,
|
||||
# "type": "integer"
|
||||
# },
|
||||
# "sis_group_id": {
|
||||
# "description": "The SIS ID of the group. Only included if the user has permission to view SIS information.",
|
||||
# "example": "group4a",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "sis_import_id": {
|
||||
# "description": "The id of the SIS import if created through SIS. Only included if the user has permission to manage SIS information.",
|
||||
# "example": 14,
|
||||
# "type": "integer"
|
||||
# },
|
||||
# "storage_quota_mb": {
|
||||
# "description": "the storage quota for the group, in megabytes",
|
||||
# "example": 50,
|
||||
|
|
|
@ -48,6 +48,7 @@ module Api::V1::Group
|
|||
end
|
||||
hash['html_url'] = group_url(group) if includes.include? 'html_url'
|
||||
hash['sis_group_id'] = group.sis_source_id if group.context_type == 'Account' && group.root_account.grants_rights?(user, session, :read_sis, :manage_sis).values.any?
|
||||
hash['sis_import_id'] = group.sis_batch_id if group.context_type == 'Account' && group.root_account.grants_right?(user, session, :manage_sis)
|
||||
hash
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../file_uploads_spec_helper')
|
||||
|
||||
describe "Groups API", type: :request do
|
||||
def group_json(group, user)
|
||||
{
|
||||
def group_json(group, is_admin = false)
|
||||
json = {
|
||||
'id' => group.id,
|
||||
'name' => group.name,
|
||||
'description' => group.description,
|
||||
|
@ -35,6 +35,11 @@ describe "Groups API", type: :request do
|
|||
'group_category_id' => group.group_category_id,
|
||||
'storage_quota_mb' => group.storage_quota_mb
|
||||
}
|
||||
if group.context_type == 'Account' && is_admin == true
|
||||
json['sis_import_id'] = group.sis_batch_id
|
||||
json['sis_group_id'] = group.sis_source_id
|
||||
end
|
||||
json
|
||||
end
|
||||
|
||||
def membership_json(membership)
|
||||
|
@ -67,7 +72,7 @@ describe "Groups API", type: :request do
|
|||
|
||||
@user = @member
|
||||
json = api_call(:get, "/api/v1/users/self/groups", @category_path_options.merge(:action => "index"))
|
||||
json.should == [group_json(@community, @user), group_json(@group, @user)]
|
||||
json.should == [group_json(@community), group_json(@group)]
|
||||
links = response.headers['Link'].split(",")
|
||||
links.all?{ |l| l =~ /api\/v1\/users\/self\/groups/ }.should be_true
|
||||
end
|
||||
|
@ -80,10 +85,10 @@ describe "Groups API", type: :request do
|
|||
|
||||
@user = @member
|
||||
json = api_call(:get, "/api/v1/users/self/groups?context_type=Course", @category_path_options.merge(:action => "index", :context_type => 'Course'))
|
||||
json.should == [group_json(@group, @user)]
|
||||
json.should == [group_json(@group)]
|
||||
|
||||
json = api_call(:get, "/api/v1/users/self/groups?context_type=Account", @category_path_options.merge(:action => "index", :context_type => 'Account'))
|
||||
json.should == [group_json(@community, @user)]
|
||||
json.should == [group_json(@community)]
|
||||
end
|
||||
|
||||
it "should allow listing all of a course's groups" do
|
||||
|
@ -99,14 +104,22 @@ describe "Groups API", type: :request do
|
|||
|
||||
it "should allow listing all of an account's groups for account admins" do
|
||||
@account = Account.default
|
||||
sis_batch = @account.sis_batches.create
|
||||
SisBatch.where(id: sis_batch).update_all(workflow_state: 'imported')
|
||||
@community.sis_source_id = 'sis'
|
||||
@community.sis_batch_id = sis_batch.id
|
||||
@community.save!
|
||||
account_admin_user(:account => @account)
|
||||
|
||||
json = api_call(:get, "/api/v1/accounts/#{@account.to_param}/groups.json",
|
||||
@category_path_options.merge(:action => 'context_index',
|
||||
:account_id => @account.to_param))
|
||||
json.count.should == 1
|
||||
json.first.should == group_json(@community, true)
|
||||
|
||||
json.first['id'].should == @community.id
|
||||
json.first['sis_source_id'].should == nil
|
||||
json.first['sis_group_id'].should == 'sis'
|
||||
json.first['sis_import_id'].should == sis_batch.id
|
||||
end
|
||||
|
||||
it "should not allow non-admins to view an account's groups" do
|
||||
|
@ -133,7 +146,7 @@ describe "Groups API", type: :request do
|
|||
it "should allow a member to retrieve the group" do
|
||||
@user = @member
|
||||
json = api_call(:get, @community_path, @category_path_options.merge(:group_id => @community.to_param, :action => "show"))
|
||||
json.should == group_json(@community, @user)
|
||||
json.should == group_json(@community)
|
||||
end
|
||||
|
||||
it 'should include permissions' do
|
||||
|
@ -156,7 +169,7 @@ describe "Groups API", type: :request do
|
|||
it "should allow searching by SIS ID" do
|
||||
@community.update_attribute(:sis_source_id, 'abc')
|
||||
json = api_call(:get, "/api/v1/groups/sis_group_id:abc", @category_path_options.merge(:group_id => 'sis_group_id:abc', :action => "show"))
|
||||
json.should == group_json(@community, @user)
|
||||
json.should == group_json(@community)
|
||||
end
|
||||
|
||||
it "should allow anyone to create a new community" do
|
||||
|
@ -169,7 +182,7 @@ describe "Groups API", type: :request do
|
|||
})
|
||||
@community2 = Group.order(:id).last
|
||||
@community2.group_category.should be_communities
|
||||
json.should == group_json(@community2, @user)
|
||||
json.should == group_json(@community2)
|
||||
end
|
||||
|
||||
it "should allow a teacher to create a group in a course" do
|
||||
|
@ -229,7 +242,7 @@ describe "Groups API", type: :request do
|
|||
@community.is_public.should == true
|
||||
@community.join_level.should == "parent_context_auto_join"
|
||||
@community.avatar_attachment.should == avatar
|
||||
json.should == group_json(@community, @user)
|
||||
json.should == group_json(@community)
|
||||
end
|
||||
|
||||
it "should only allow updating a group from private to public" do
|
||||
|
|
Loading…
Reference in New Issue