forked from danatcaret/open-experiments
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on membership... not quite done
- Loading branch information
Showing
7 changed files
with
233 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,159 @@ | |||
#!/usr/bin/env ruby | |||
|
|||
require 'rubygems' | |||
require 'csv' | |||
require 'json' | |||
require 'nakamura' | |||
require 'nakamura/users' | |||
require './import-base' | |||
include SlingInterface | |||
include SlingUsers | |||
include OaeImport | |||
|
|||
|
|||
if ARGV.size < 1 | |||
puts "Usage: import-members.rb PATH_TO_CSV_FILE [PATH_TO_SERVER_CONFIG_FILE.json]" | |||
exit 1 | |||
end | |||
|
|||
|
|||
class SisWorldUploader < OaeImportBase | |||
|
|||
attr_accessor :roleMaps | |||
attr_accessor :groupCache | |||
|
|||
def createManager(server) | |||
@userManager = UserManager.new(server) | |||
@groupCache = {} | |||
end | |||
|
|||
|
|||
def processRow(row) | |||
# 0 user | |||
# 1 world id (groupname) | |||
# 2 role | |||
|
|||
groupId = row[1].to_s | |||
|
|||
groupCacheEntry = @groupCache[groupId]; | |||
|
|||
if (groupCacheEntry.nil?) | |||
group = Group.new(groupId); | |||
|
|||
groupDetails = group.details(@server); | |||
|
|||
groupCacheEntry = { | |||
"group"=> group, | |||
"groupDetails"=> groupDetails, | |||
"roles"=> {} | |||
} | |||
end | |||
|
|||
worldType = groupCacheEntry["groupDetails"]["properties"]["sakai:world-type"] | |||
|
|||
groupRoleMap = @roleMaps[worldType] | |||
|
|||
role = groupRoleMap[row[2].to_s] | |||
|
|||
roleArray = groupCacheEntry["roles"][role] | |||
|
|||
if (roleArray.nil?) | |||
roleArray = [] | |||
end | |||
|
|||
user = row[0]; | |||
|
|||
roleArray << row[0].to_s | |||
|
|||
# cache all the stuff away for now | |||
groupCacheEntry["roles"][role] = roleArray | |||
|
|||
@groupCache[groupId] = groupCacheEntry | |||
end | |||
|
|||
def postProcess() | |||
@groupCache.each_pair do |k,v| | |||
begin | |||
processGroup(k, v) | |||
rescue Exception => e | |||
@exceptional += 1 | |||
@log.warn(e.message) | |||
@log.warn(e.backtrace.join("\n")) | |||
exceptions << "Processing group had error: #{e.message}" | |||
exceptions << "\n" | |||
end | |||
end | |||
end | |||
|
|||
def processGroup(groupId, groupCacheEntry) | |||
group = Group.new(groupId) | |||
rolesJson = groupCacheEntry["groupDetails"]["properties"]["sakai:roles"]; | |||
|
|||
roles = JSON.parse(rolesJson) | |||
|
|||
roles.each do |role| | |||
processRole(role["id"], group, groupCacheEntry) | |||
end | |||
end | |||
|
|||
def processRole(roleId, group, groupCacheEntry) | |||
newRoleUsers = groupCacheEntry["roles"][roleId] | |||
|
|||
roleGroupId = group.name + "-" + roleId | |||
|
|||
roleGroup = Group.new(roleGroupId) | |||
|
|||
currentMembers = roleGroup.members(@server) | |||
|
|||
if (currentMembers.count > 0) | |||
leftOver = currentMembers - newRoleUsers | |||
|
|||
leftOver.each do |removeUser| | |||
roleGroup.remove_member(@server, removeUser) | |||
end | |||
|
|||
@updated += leftOver.count | |||
end | |||
|
|||
if (currentMembers.count > 0) | |||
newRoleUsers = newRoleUsers - currentMembers | |||
end | |||
|
|||
puts newRoleUsers | |||
|
|||
roleGroup.add_members(@server, newRoleUsers) | |||
|
|||
@created += newRoleUsers.count | |||
end | |||
|
|||
def processServerProps(serverInfoFile) | |||
ret = super(serverInfoFile) | |||
|
|||
@roleMaps = @serverProps["members.csv"]["roleMaps"] # maps cle roles to oae roles | |||
|
|||
ret | |||
end | |||
|
|||
def subject | |||
"members.csv file processed: " + currentDate | |||
end | |||
|
|||
def updatedLabel | |||
return "removed" | |||
end | |||
|
|||
def skipFirstRow | |||
skipFirstRowConfig("members.csv") | |||
end | |||
|
|||
def expectedColumns | |||
3 | |||
end | |||
|
|||
end | |||
|
|||
csvFile = ARGV[0] | |||
serverInfo = ARGV[1] || nil | |||
@sisWorld = SisWorldUploader.new(serverInfo) | |||
|
|||
@sisWorld.processFile(csvFile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,6 @@ | |||
W11,10_sis_testing_001b,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,grouped | W11,10-sis-testing-001,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,not-grouped | ||
Sp11,10-sis-testing-002b,,Testing Course 201,SIS Testing,SIS Testing,0,,course,,,grouped | Sp11,10-sis-testing-002,,Testing Course 201,SIS Testing,SIS Testing,0,,course,,,grouped | ||
Sp11,10-sis-testing-022b,,Testing Course 202,SIS Testing,SIS Testing,0,,course,,,grouped | Sp11,10-sis-testing-022,,Testing Course 202,SIS Testing,SIS Testing,0,,course,,,grouped | ||
Sp11,10-sis-testing-220b,,Testing Portfolio 203,SIS Testing,SIS Testing,0,,portfolio,,,grouped | Sp11,10-sis-testing-220,,Testing Portfolio 203,SIS Testing,SIS Testing,0,,portfolio,,,grouped | ||
Sp11,10-sis-testing-222b,,Testing Project 204,SIS Testing,SIS Testing,0,,project,,,grouped | Sp11,10-sis-testing-222,,Testing Project 204,SIS Testing,SIS Testing,0,,project,,,grouped | ||
Su11,10-sis-testing-003b,,Testing Course 301,SIS Testing,SIS Testing,0,,course,,,not-grouped | Su11,10-sis-testing-003,,Testing Course 301,SIS Testing,SIS Testing,0,,course,,,not-grouped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
mbrissette,10-sis-testing-001,Instructor | |||
mpaquette,10-sis-testing-001,Instructor | |||
aphillips,10-sis-testing-002,Instructor | |||
bkoppelman,10-sis-testing-002,Instructor | |||
nwilson,10-sis-testing-002,Instructor | |||
cbuckley,10-sis-testing-022,Instructor | |||
gjohnson,10-sis-testing-022,Instructor | |||
klabelle,10-sis-testing-022,Instructor | |||
coliveira,10-sis-testing-220,Organizer | |||
mbrissette,10-sis-testing-220,Organizer | |||
mpaquette,10-sis-testing-222,Organizer | |||
dlarue,10-sis-testing-222,Organizer | |||
nwilson,10-sis-testing-003,Student | |||
aallen,10-sis-testing-001,Teaching Assistant | |||
aaustin,10-sis-testing-001,Teaching Assistant | |||
abass,10-sis-testing-001,Teaching Assistant | |||
abelanger,10-sis-testing-001,Student | |||
abishop,10-sis-testing-001,Student | |||
aboyer,10-sis-testing-001,Student | |||
abradley,10-sis-testing-001,Student | |||
abrouillette,10-sis-testing-001,Student | |||
aburns,10-sis-testing-001,Student | |||
acaldwell,10-sis-testing-001,Student | |||
aallen,10-sis-testing-002,Teaching Assistant | |||
aaustin,10-sis-testing-002,Teaching Assistant | |||
abass,10-sis-testing-002,Teaching Assistant | |||
abelanger,10-sis-testing-002,Student | |||
abishop,10-sis-testing-002,Student | |||
aboyer,10-sis-testing-002,Student | |||
abradley,10-sis-testing-002,Student | |||
abrouillette,10-sis-testing-002,Student | |||
aburns,10-sis-testing-002,Student | |||
acaldwell,10-sis-testing-002,Student |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters